Show 'Launch' button for force stopped apps

in backup status screen.
This commit is contained in:
Torsten Grote 2024-10-30 12:15:15 -03:00
parent 0fa14025b3
commit 13e3dadeb4
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
4 changed files with 34 additions and 1 deletions

View file

@ -18,6 +18,8 @@ import android.view.View.VISIBLE
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView.ScaleType import android.widget.ImageView.ScaleType
import android.widget.TextView import android.widget.TextView
import android.widget.Toast
import android.widget.Toast.LENGTH_SHORT
import androidx.core.content.ContextCompat.startActivity import androidx.core.content.ContextCompat.startActivity
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.DiffUtil.DiffResult import androidx.recyclerview.widget.DiffUtil.DiffResult
@ -106,6 +108,7 @@ internal class AppStatusAdapter(private val toggleListener: AppStatusToggleListe
progressBar.visibility = INVISIBLE progressBar.visibility = INVISIBLE
checkBox.visibility = VISIBLE checkBox.visibility = VISIBLE
checkBox.isChecked = item.enabled checkBox.isChecked = item.enabled
button.visibility = GONE
} else { } else {
v.setOnClickListener(null) v.setOnClickListener(null)
v.setOnLongClickListener { v.setOnLongClickListener {
@ -116,6 +119,7 @@ internal class AppStatusAdapter(private val toggleListener: AppStatusToggleListe
true true
} }
setState(item.status, false) setState(item.status, false)
button.visibility = GONE
if (item.status == SUCCEEDED) { if (item.status == SUCCEEDED) {
appInfo.text = if (item.size == null) { appInfo.text = if (item.size == null) {
item.time.toRelativeTime(context) item.time.toRelativeTime(context)
@ -135,6 +139,18 @@ internal class AppStatusAdapter(private val toggleListener: AppStatusToggleListe
appInfo.visibility = VISIBLE appInfo.visibility = VISIBLE
} }
// setState() above sets appInfo state for other cases already // setState() above sets appInfo state for other cases already
if (item.status == FAILED_WAS_STOPPED) {
button.setOnClickListener {
val packageManager = context.packageManager
packageManager.getLaunchIntentForPackage(item.packageName)?.let { i ->
context.startActivity(i)
} ?: run {
val s = R.string.backup_app_stopped_no_intent
Toast.makeText(context, s, LENGTH_SHORT).show()
}
}
button.visibility = VISIBLE
}
checkBox.visibility = INVISIBLE checkBox.visibility = INVISIBLE
} }
// show disabled items differently // show disabled items differently

View file

@ -11,6 +11,7 @@ import android.view.View
import android.view.View.GONE import android.view.View.GONE
import android.view.View.INVISIBLE import android.view.View.INVISIBLE
import android.view.View.VISIBLE import android.view.View.VISIBLE
import android.widget.Button
import android.widget.ImageView import android.widget.ImageView
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
@ -33,6 +34,7 @@ internal abstract class AppViewHolder(protected val v: View) : RecyclerView.View
protected val appStatus: ImageView = v.requireViewById(R.id.appStatus) protected val appStatus: ImageView = v.requireViewById(R.id.appStatus)
protected val progressBar: ProgressBar = v.requireViewById(R.id.progressBar) protected val progressBar: ProgressBar = v.requireViewById(R.id.progressBar)
protected val checkBox: MaterialCheckBox = v.requireViewById(R.id.checkboxView) protected val checkBox: MaterialCheckBox = v.requireViewById(R.id.checkboxView)
protected val button: Button = v.requireViewById(R.id.button)
init { init {
// don't use clickable background by default // don't use clickable background by default

View file

@ -46,7 +46,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:visibility="gone" android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/appName" app:layout_constraintEnd_toEndOf="@+id/appName"
app:layout_constraintStart_toStartOf="@+id/appName" app:layout_constraintStart_toStartOf="@+id/appName"
app:layout_constraintTop_toBottomOf="@+id/appName" app:layout_constraintTop_toBottomOf="@+id/appName"
@ -84,4 +83,18 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" /> tools:visibility="visible" />
<Button
android:id="@+id/button"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/backup_app_stopped_button"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/appName"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/appName"
app:layout_constraintTop_toBottomOf="@+id/appInfo"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -188,6 +188,8 @@
<string name="backup_contacts">Local contacts</string> <string name="backup_contacts">Local contacts</string>
<string name="backup_system_apps">System apps</string> <string name="backup_system_apps">System apps</string>
<string name="backup_section_user">Apps</string> <string name="backup_section_user">Apps</string>
<string name="backup_app_stopped_button">Launch</string>
<string name="backup_app_stopped_no_intent">Cannot launch app</string>
<!-- This text gets shown for apps that the OS did not try to backup for whatever reason e.g. no backup was run yet --> <!-- This text gets shown for apps that the OS did not try to backup for whatever reason e.g. no backup was run yet -->
<string name="backup_app_not_yet_backed_up">Waiting to back up…</string> <string name="backup_app_not_yet_backed_up">Waiting to back up…</string>
<string name="restore_app_not_yet_backed_up">Was not yet backed up</string> <string name="restore_app_not_yet_backed_up">Was not yet backed up</string>