mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-16 19:51:07 -04:00
Force restart when proxy URL is changed
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package com.aurora.store.view.ui.commons
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.aurora.store.R
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
@AndroidEntryPoint
|
||||
class ForceRestartDialog: DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.force_restart_title)
|
||||
.setMessage(R.string.force_restart_summary)
|
||||
.setPositiveButton(getString(R.string.action_restart)) { _, _ -> restartApp() }
|
||||
.create()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,7 @@ class NetworkPreference : BasePreferenceFragment(),
|
||||
} else {
|
||||
remove(PREFERENCE_PROXY_URL)
|
||||
remove(PREFERENCE_PROXY_INFO)
|
||||
findNavController().navigate(R.id.forceRestartDialog)
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.aurora.store.view.ui.preferences
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AlertDialog
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.WindowManager
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.aurora.extensions.showKeyboard
|
||||
import com.aurora.extensions.toast
|
||||
import com.aurora.store.R
|
||||
@@ -30,13 +32,18 @@ class ProxyURLDialog: DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val view = layoutInflater.inflate(R.layout.dialog_text_input_edit_text, null)
|
||||
return MaterialAlertDialogBuilder(requireContext())
|
||||
val alertDialog = MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.pref_network_proxy_url)
|
||||
.setMessage(R.string.pref_network_proxy_url_message)
|
||||
.setView(view)
|
||||
.setPositiveButton(getString(R.string.add)) { _, _ -> saveProxyUrl() }
|
||||
.setPositiveButton(getString(R.string.add), null)
|
||||
.setNegativeButton(getString(android.R.string.cancel)) { _, _ -> dialog?.dismiss()}
|
||||
.create()
|
||||
|
||||
alertDialog.setOnShowListener {
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { saveProxyUrl() }
|
||||
}
|
||||
return alertDialog
|
||||
}
|
||||
|
||||
@SuppressLint("AuthLeak") // False-positive
|
||||
@@ -62,6 +69,7 @@ class ProxyURLDialog: DialogFragment() {
|
||||
save(PREFERENCE_PROXY_URL, url)
|
||||
save(PREFERENCE_PROXY_INFO, gson.toJson(proxyInfo))
|
||||
toast(R.string.toast_proxy_success)
|
||||
findNavController().navigate(R.id.forceRestartDialog)
|
||||
return
|
||||
} else {
|
||||
toast(R.string.toast_proxy_failed)
|
||||
|
||||
@@ -491,4 +491,8 @@
|
||||
android:id="@+id/proxyURLDialog"
|
||||
android:name="com.aurora.store.view.ui.preferences.ProxyURLDialog"
|
||||
android:label="@string/pref_network_proxy_url" />
|
||||
<dialog
|
||||
android:id="@+id/forceRestartDialog"
|
||||
android:name="com.aurora.store.view.ui.commons.ForceRestartDialog"
|
||||
android:label="@string/force_restart_title" />
|
||||
</navigation>
|
||||
|
||||
@@ -479,4 +479,8 @@
|
||||
|
||||
<!-- UpdatesFragment -->
|
||||
<string name="check_updates">Check for updates</string>
|
||||
|
||||
<!-- ForceRestartDialog -->
|
||||
<string name="force_restart_title">Restart Aurora Store</string>
|
||||
<string name="force_restart_summary">Aurora Store needs to be restarted to apply the newly changed settings</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user