diff options
Diffstat (limited to 'ui/src/main')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt | 33 | ||||
-rw-r--r-- | ui/src/main/res/values/strings.xml | 3 |
2 files changed, 23 insertions, 13 deletions
diff --git a/ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt b/ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt index 8c1a8124..30da3b07 100644 --- a/ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt +++ b/ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt @@ -12,6 +12,7 @@ import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope +import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar import com.wireguard.android.R @@ -34,7 +35,6 @@ class SnackbarUpdateShower(private val fragment: Fragment) { private val statusSnackbar = makeSnackbar(fragment, view, anchor) private var showingAction: Boolean = false private var showingStatus: Boolean = false - private var permanentAction: Boolean = false private fun makeSnackbar(fragment: Fragment, view: View, anchor: View?): Snackbar { val snackbar = Snackbar.make(fragment.requireContext(), view, "", Snackbar.LENGTH_INDEFINITE) @@ -49,7 +49,7 @@ class SnackbarUpdateShower(private val fragment: Fragment) { snackbar.addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() { override fun onDismissed(snackbar: Snackbar?, @DismissEvent event: Int) { super.onDismissed(snackbar, event) - if (event == DISMISS_EVENT_MANUAL || (event == DISMISS_EVENT_ACTION && !permanentAction) || + if (event == DISMISS_EVENT_MANUAL || event == DISMISS_EVENT_ACTION || (snackbar == actionSnackbar && !showingAction) || (snackbar == statusSnackbar && !showingStatus) ) return @@ -62,12 +62,11 @@ class SnackbarUpdateShower(private val fragment: Fragment) { return snackbar } - fun showAction(text: String, action: String, permanent: Boolean = false, listener: View.OnClickListener) { + fun showAction(text: String, action: String, listener: View.OnClickListener) { if (showingStatus) { showingStatus = false statusSnackbar.dismiss() } - permanentAction = permanent actionSnackbar.setText(text) actionSnackbar.setAction(action, listener) if (!showingAction) { @@ -148,15 +147,25 @@ class SnackbarUpdateShower(private val fragment: Fragment) { } is Updater.Progress.Corrupt -> { - snackbar.showAction(context.getString(R.string.updater_corrupt), context.getString(R.string.updater_corrupt_navigate), true) { - val intent = Intent(Intent.ACTION_VIEW) - intent.data = Uri.parse(progress.downloadUrl) - try { + MaterialAlertDialogBuilder(context) + .setTitle(R.string.updater_corrupt_title) + .setMessage(R.string.updater_corrupt_message) + .setPositiveButton(R.string.updater_corrupt_navigate) { _, _ -> + val intent = Intent(Intent.ACTION_VIEW) + intent.data = Uri.parse(progress.downloadUrl) + try { + context.startActivity(intent) + } catch (e: Throwable) { + Toast.makeText(context, ErrorMessages[e], Toast.LENGTH_SHORT).show() + } + }.setCancelable(false).setOnDismissListener { + val intent = Intent(Intent.ACTION_MAIN) + intent.addCategory(Intent.CATEGORY_HOME) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) context.startActivity(intent) - } catch (e: Throwable) { - Toast.makeText(context, ErrorMessages[e], Toast.LENGTH_SHORT).show() - } - } + System.exit(0) + }.show() } } }.launchIn(fragment.lifecycleScope) diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml index acaa9dcc..4c9ab2d4 100644 --- a/ui/src/main/res/values/strings.xml +++ b/ui/src/main/res/values/strings.xml @@ -240,7 +240,8 @@ <string name="updater_download_progress_nototal">Downloading update: %s</string> <string name="updater_installing">Installing update…</string> <string name="updater_failure">Update failure: %s. Will retry momentarily…</string> - <string name="updater_corrupt">This application is corrupt. Please re-download it.</string> + <string name="updater_corrupt_title">Application Corrupt</string> + <string name="updater_corrupt_message">This application is corrupt. Please re-download the APK from the website linked below. After, uninstall this application, and reinstall it from downloaded APK.</string> <string name="updater_corrupt_navigate">Open Website</string> <string name="version_summary">%1$s backend %2$s</string> <string name="version_summary_checking">Checking %s backend version</string> |