From 26516d72a27668f53c2a0237d2446156dab1f7a6 Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Tue, 24 Aug 2021 16:23:41 +0300 Subject: [PATCH] Disable Nextcloud restore when not installed and no store available Attempting to install Nextcloud in SetupWizard on a device that has no app store installed results in a crash. Disable the option and use an appropriate summary. Change-Id: Ie3dff8d85ed68b27858fa37b3efb97eb345fa372 --- .../ui/storage/StorageRootFetcher.kt | 19 +++++++++++-------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootFetcher.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootFetcher.kt index 643435e8..50027a6b 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootFetcher.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootFetcher.kt @@ -156,11 +156,19 @@ internal class StorageRootFetcher(private val context: Context, private val isRe data = Uri.parse("nc://login/server:") putExtra("onlyAdd", true) } + val marketIntent = + Intent(ACTION_VIEW, Uri.parse("market://details?id=$NEXTCLOUD_PACKAGE")).apply { + addFlags(FLAG_ACTIVITY_NEW_TASK) + } val isInstalled = packageManager.resolveActivity(intent, 0) != null + val canInstall = packageManager.resolveActivity(marketIntent, 0) != null val summaryRes = if (isInstalled) { if (isRestore) R.string.storage_fake_nextcloud_summary_installed else R.string.storage_fake_nextcloud_summary_unavailable - } else R.string.storage_fake_nextcloud_summary + } else { + if (canInstall) R.string.storage_fake_nextcloud_summary + else R.string.storage_fake_nextcloud_summary_unavailable_market + } val root = StorageRoot( authority = AUTHORITY_NEXTCLOUD, rootId = "fake", @@ -171,15 +179,10 @@ internal class StorageRootFetcher(private val context: Context, private val isRe availableBytes = null, isUsb = false, requiresNetwork = true, - enabled = !isInstalled || isRestore, + enabled = isInstalled || canInstall, overrideClickListener = { if (isInstalled) context.startActivity(intent) - else { - val uri = Uri.parse("market://details?id=$NEXTCLOUD_PACKAGE") - val i = Intent(ACTION_VIEW, uri) - i.addFlags(FLAG_ACTIVITY_NEW_TASK) - context.startActivity(i) - } + else if (canInstall) context.startActivity(marketIntent) } ) roots.add(root) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e502e9c7..7682402e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -54,6 +54,7 @@ Tap to install Tap to set up account Account not available. Set one up (or disable passcode). + Not installed Initializing backup location… This may take some time… Looking for backups…