From 13e3dadeb454972b2d8cedac3379751b4dd3e720 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 30 Oct 2024 12:15:15 -0300 Subject: [PATCH] Show 'Launch' button for force stopped apps in backup status screen. --- .../seedvault/settings/AppStatusAdapter.kt | 16 ++++++++++++++++ .../stevesoltys/seedvault/ui/AppViewHolder.kt | 2 ++ app/src/main/res/layout/list_item_app_status.xml | 15 ++++++++++++++- app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusAdapter.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusAdapter.kt index 3f8cfba2..fcd2381c 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusAdapter.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusAdapter.kt @@ -18,6 +18,8 @@ import android.view.View.VISIBLE import android.view.ViewGroup import android.widget.ImageView.ScaleType import android.widget.TextView +import android.widget.Toast +import android.widget.Toast.LENGTH_SHORT import androidx.core.content.ContextCompat.startActivity import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil.DiffResult @@ -106,6 +108,7 @@ internal class AppStatusAdapter(private val toggleListener: AppStatusToggleListe progressBar.visibility = INVISIBLE checkBox.visibility = VISIBLE checkBox.isChecked = item.enabled + button.visibility = GONE } else { v.setOnClickListener(null) v.setOnLongClickListener { @@ -116,6 +119,7 @@ internal class AppStatusAdapter(private val toggleListener: AppStatusToggleListe true } setState(item.status, false) + button.visibility = GONE if (item.status == SUCCEEDED) { appInfo.text = if (item.size == null) { item.time.toRelativeTime(context) @@ -135,6 +139,18 @@ internal class AppStatusAdapter(private val toggleListener: AppStatusToggleListe appInfo.visibility = VISIBLE } // 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 } // show disabled items differently diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/AppViewHolder.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/AppViewHolder.kt index e5448d0f..c5a99367 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/AppViewHolder.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/AppViewHolder.kt @@ -11,6 +11,7 @@ import android.view.View import android.view.View.GONE import android.view.View.INVISIBLE import android.view.View.VISIBLE +import android.widget.Button import android.widget.ImageView import android.widget.ProgressBar 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 progressBar: ProgressBar = v.requireViewById(R.id.progressBar) protected val checkBox: MaterialCheckBox = v.requireViewById(R.id.checkboxView) + protected val button: Button = v.requireViewById(R.id.button) init { // don't use clickable background by default diff --git a/app/src/main/res/layout/list_item_app_status.xml b/app/src/main/res/layout/list_item_app_status.xml index 29d288b6..26979941 100644 --- a/app/src/main/res/layout/list_item_app_status.xml +++ b/app/src/main/res/layout/list_item_app_status.xml @@ -46,7 +46,6 @@ android:layout_height="wrap_content" android:layout_marginTop="4dp" android:visibility="gone" - app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="@+id/appName" app:layout_constraintStart_toStartOf="@+id/appName" app:layout_constraintTop_toBottomOf="@+id/appName" @@ -84,4 +83,18 @@ app:layout_constraintTop_toTopOf="parent" tools:visibility="visible" /> +