ForceRestartDialog: Use ProcessPhoenix as well
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
package com.aurora.store.view.ui.commons
|
package com.aurora.store.view.ui.commons
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import com.aurora.store.R
|
import com.aurora.store.R
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import com.jakewharton.processphoenix.ProcessPhoenix
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlin.system.exitProcess
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ForceRestartDialog: DialogFragment() {
|
class ForceRestartDialog: DialogFragment() {
|
||||||
@@ -16,7 +15,9 @@ class ForceRestartDialog: DialogFragment() {
|
|||||||
return MaterialAlertDialogBuilder(requireContext())
|
return MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(R.string.force_restart_title)
|
.setTitle(R.string.force_restart_title)
|
||||||
.setMessage(R.string.force_restart_summary)
|
.setMessage(R.string.force_restart_summary)
|
||||||
.setPositiveButton(getString(R.string.action_restart)) { _, _ -> restartApp() }
|
.setPositiveButton(getString(R.string.action_restart)) { _, _ ->
|
||||||
|
ProcessPhoenix.triggerRebirth(requireContext())
|
||||||
|
}
|
||||||
.create()
|
.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,17 +25,4 @@ class ForceRestartDialog: DialogFragment() {
|
|||||||
super.onResume()
|
super.onResume()
|
||||||
dialog?.setCancelable(false)
|
dialog?.setCancelable(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun restartApp() {
|
|
||||||
val context = requireContext()
|
|
||||||
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
|
||||||
val componentName = intent?.component
|
|
||||||
|
|
||||||
val newIntent = Intent.makeRestartActivityTask(componentName).apply {
|
|
||||||
setPackage(context.packageName)
|
|
||||||
}
|
|
||||||
|
|
||||||
startActivity(newIntent)
|
|
||||||
exitProcess(0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user