Bring the user to app system settings when long tapping apps

This commit is contained in:
Torsten Grote 2020-09-18 16:45:25 -03:00 committed by Chirayu Desai
parent 9f85a66235
commit db0721cd8d
2 changed files with 13 additions and 5 deletions

View file

@ -1,12 +1,16 @@
package com.stevesoltys.seedvault.settings package com.stevesoltys.seedvault.settings
import android.content.Intent
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.net.Uri
import android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View 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.view.ViewGroup import android.view.ViewGroup
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
import androidx.recyclerview.widget.RecyclerView.Adapter import androidx.recyclerview.widget.RecyclerView.Adapter
@ -54,8 +58,8 @@ internal class AppStatusAdapter(private val toggleListener: AppStatusToggleListe
fun bind(item: AppStatus) { fun bind(item: AppStatus) {
appName.text = item.name appName.text = item.name
appIcon.setImageDrawable(item.icon) appIcon.setImageDrawable(item.icon)
if (editMode) {
v.background = clickableBackground v.background = clickableBackground
if (editMode) {
v.setOnClickListener { v.setOnClickListener {
switchView.toggle() switchView.toggle()
item.enabled = switchView.isChecked item.enabled = switchView.isChecked
@ -67,8 +71,14 @@ internal class AppStatusAdapter(private val toggleListener: AppStatusToggleListe
switchView.visibility = VISIBLE switchView.visibility = VISIBLE
switchView.isChecked = item.enabled switchView.isChecked = item.enabled
} else { } else {
v.background = null
v.setOnClickListener(null) v.setOnClickListener(null)
v.setOnLongClickListener {
val intent = Intent(ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.fromParts("package", item.packageName, null)
}
startActivity(context, intent, null)
true
}
setStatus(item.status) setStatus(item.status)
if (item.status == SUCCEEDED) { if (item.status == SUCCEEDED) {
appInfo.text = item.time.toRelativeTime(context) appInfo.text = item.time.toRelativeTime(context)

View file

@ -23,8 +23,7 @@ import com.stevesoltys.seedvault.restore.AppRestoreStatus.IN_PROGRESS
import com.stevesoltys.seedvault.restore.AppRestoreStatus.NOT_YET_BACKED_UP import com.stevesoltys.seedvault.restore.AppRestoreStatus.NOT_YET_BACKED_UP
import com.stevesoltys.seedvault.restore.AppRestoreStatus.SUCCEEDED import com.stevesoltys.seedvault.restore.AppRestoreStatus.SUCCEEDED
internal abstract class AppViewHolder(protected val v: View) : RecyclerView.ViewHolder(v) {
internal open class AppViewHolder(protected val v: View) : RecyclerView.ViewHolder(v) {
protected val context: Context = v.context protected val context: Context = v.context
protected val pm: PackageManager = context.packageManager protected val pm: PackageManager = context.packageManager
@ -43,7 +42,6 @@ internal open class AppViewHolder(protected val v: View) : RecyclerView.ViewHold
} }
protected fun setStatus(status: AppRestoreStatus) { protected fun setStatus(status: AppRestoreStatus) {
v.background = null
if (status == IN_PROGRESS) { if (status == IN_PROGRESS) {
appInfo.visibility = GONE appInfo.visibility = GONE
appStatus.visibility = INVISIBLE appStatus.visibility = INVISIBLE