Skip to content

Commit

Permalink
Show 'Launch' button for force stopped apps
Browse files Browse the repository at this point in the history
in backup status screen.
  • Loading branch information
grote committed Oct 30, 2024
1 parent 0fa1402 commit 13e3dad
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/res/layout/list_item_app_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -84,4 +83,18 @@
app:layout_constraintTop_toTopOf="parent"
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>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@
<string name="backup_contacts">Local contacts</string>
<string name="backup_system_apps">System 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 -->
<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>
Expand Down

0 comments on commit 13e3dad

Please sign in to comment.