From 17a83eaab303c3dc98360cc5589fe2399f5e9f4d Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Mon, 10 Jan 2022 12:09:19 -0300 Subject: [PATCH] Always add a storage option placeholder for DavX5 --- .idea/dictionaries/user.xml | 1 + .../seedvault/ui/storage/SafStorageOptions.kt | 50 +++++++++++++++++++ .../ui/storage/StorageRootFetcher.kt | 1 + .../ui/storage/StorageRootResolver.kt | 3 ++ app/src/main/res/drawable/davx5.xml | 5 ++ .../main/res/drawable/davx5_foreground.xml | 36 +++++++++++++ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 5 ++ 8 files changed, 102 insertions(+) create mode 100644 app/src/main/res/drawable/davx5.xml create mode 100644 app/src/main/res/drawable/davx5_foreground.xml diff --git a/.idea/dictionaries/user.xml b/.idea/dictionaries/user.xml index 131779fd..2317866a 100644 --- a/.idea/dictionaries/user.xml +++ b/.idea/dictionaries/user.xml @@ -3,6 +3,7 @@ apk chunker + davx ejectable hasher hkdf diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/SafStorageOptions.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/SafStorageOptions.kt index 3ad63d8d..c0140b2a 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/SafStorageOptions.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/SafStorageOptions.kt @@ -9,6 +9,8 @@ import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.ui.storage.StorageOption.SafOption import com.stevesoltys.seedvault.ui.storage.StorageRootResolver.getIcon +private const val DAVX5_PACKAGE = "at.bitfire.davdroid" +private const val DAVX5_ACTIVITY = "at.bitfire.davdroid.ui.webdav.WebdavMountsActivity" private const val NEXTCLOUD_PACKAGE = "com.nextcloud.client" private const val NEXTCLOUD_ACTIVITY = "com.owncloud.android.authentication.AuthenticatorActivity" @@ -26,6 +28,7 @@ internal class SafStorageOptions( internal fun checkOrAddExtraRoots(roots: ArrayList) { checkOrAddUsbRoot(roots) + checkOrAddDavX5Root(roots) checkOrAddNextCloudRoot(roots) } @@ -47,6 +50,53 @@ internal class SafStorageOptions( roots.add(root) } + /** + * This adds a fake Dav X5 entry if no real one was found. + * + * If Dav X5 is *not* installed, + * the user will always have the option to install it by clicking the entry. + * + * If it *is* installed and this is restore, the user can set up a new account by clicking. + */ + private fun checkOrAddDavX5Root(roots: ArrayList) { + if (doNotInclude(AUTHORITY_DAVX5, roots)) return + + val intent = Intent().apply { + addFlags(FLAG_ACTIVITY_NEW_TASK) + setClassName(DAVX5_PACKAGE, DAVX5_ACTIVITY) + } + val marketIntent = + Intent(ACTION_VIEW, Uri.parse("market://details?id=$DAVX5_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_davx5_summary_installed + else R.string.storage_fake_davx5_summary_unavailable + } else { + if (canInstall) R.string.storage_fake_davx5_summary + else R.string.storage_fake_davx5_summary_unavailable_market + } + val root = SafOption( + authority = AUTHORITY_DAVX5, + rootId = "fake", + documentId = "fake", + icon = getIcon(context, AUTHORITY_DAVX5, "fake", 0), + title = context.getString(R.string.storage_fake_davx5_title), + summary = context.getString(summaryRes), + availableBytes = null, + isUsb = false, + requiresNetwork = true, + enabled = isInstalled || canInstall, + nonDefaultAction = { + if (isInstalled) context.startActivity(intent) + else if (canInstall) context.startActivity(marketIntent) + } + ) + roots.add(root) + } + /** * This adds a fake Nextcloud entry if no real one was found. * 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 3f586f17..96c27d0e 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 @@ -23,6 +23,7 @@ const val ROOT_ID_HOME = "home" const val AUTHORITY_DOWNLOADS = "com.android.providers.downloads.documents" const val AUTHORITY_NEXTCLOUD = "org.nextcloud.documents" +const val AUTHORITY_DAVX5 = "at.bitfire.davdroid.webdav" internal interface RemovableStorageListener { fun onStorageChanged() diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootResolver.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootResolver.kt index 37e60969..ead92a8f 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootResolver.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootResolver.kt @@ -96,6 +96,9 @@ internal object StorageRootResolver { authority == AUTHORITY_NEXTCLOUD -> { context.getDrawable(R.drawable.nextcloud) } + authority == AUTHORITY_DAVX5 -> { + context.getDrawable(R.drawable.davx5) + } else -> null } } diff --git a/app/src/main/res/drawable/davx5.xml b/app/src/main/res/drawable/davx5.xml new file mode 100644 index 00000000..4edc85fa --- /dev/null +++ b/app/src/main/res/drawable/davx5.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/davx5_foreground.xml b/app/src/main/res/drawable/davx5_foreground.xml new file mode 100644 index 00000000..b7e50784 --- /dev/null +++ b/app/src/main/res/drawable/davx5_foreground.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index c5b22ded..9525e4ee 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -11,4 +11,5 @@ #20ffffff #558B2F #F9A825 + #7cb342 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3b122295..3fdac732 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -60,6 +60,11 @@ Tap to set up account Account not available. Set one up (or disable passcode). Not installed + DAVx⁵ + @string/storage_fake_nextcloud_summary + Tap to set up a WebDAV mount + WebDAV mount not available. Set one up. + @string/storage_fake_nextcloud_summary_unavailable_market Initializing backup location… This may take some time… Looking for backups…