diff --git a/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt b/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt index b84a6c3e..514aafd9 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt @@ -58,6 +58,7 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe internal var listTaskDAV: ListView? = null internal val openTasksPackage = "org.dmfs.tasks" + internal val tasksOrgPackage = "org.tasks" private val onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, _ -> val list = parent as ListView @@ -110,6 +111,10 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe tbTaskDAV.inflateMenu(R.menu.taskdav_actions) tbTaskDAV.setOnMenuItemClickListener(this) tbTaskDAV.setTitle(R.string.settings_taskdav) + if (!packageInstalled(this, tasksOrgPackage)) { + val tasksInstallMenuItem = tbTaskDAV.menu.findItem(R.id.install_tasksorg) + tasksInstallMenuItem.setVisible(true) + } if (!packageInstalled(this, openTasksPackage)) { val tasksInstallMenuItem = tbTaskDAV.menu.findItem(R.id.install_opentasks) tasksInstallMenuItem.setVisible(true) @@ -166,6 +171,25 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe return true } + fun installPackage(packagename: String) { + val fdroidPackageName = "org.fdroid.fdroid" + val gplayPackageName = "com.android.vending" + val intent = Intent(Intent.ACTION_VIEW).apply { + data = Uri.parse( + "https://f-droid.org/en/packages/$packagename/") + } + if (packageInstalled(this, fdroidPackageName)) { + intent.setPackage(fdroidPackageName) + } else if (packageInstalled(this, gplayPackageName)) { + intent.apply { + data = Uri.parse( + "https://play.google.com/store/apps/details?id=$packagename") + setPackage(gplayPackageName) + } + } + startActivity(intent) + } + override fun onMenuItemClick(item: MenuItem): Boolean { val info: CollectionInfo when (item.itemId) { @@ -184,23 +208,11 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe info.enumType = CollectionInfo.Type.ADDRESS_BOOK startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info)) } + R.id.install_tasksorg -> { + installPackage(tasksOrgPackage) + } R.id.install_opentasks -> { - val fdroidPackageName = "org.fdroid.fdroid" - val gplayPackageName = "com.android.vending" - val intent = Intent(Intent.ACTION_VIEW).apply { - data = Uri.parse( - "https://f-droid.org/en/packages/$openTasksPackage/") - } - if (packageInstalled(this, fdroidPackageName)) { - intent.setPackage(fdroidPackageName) - } else if (packageInstalled(this, gplayPackageName)) { - intent.apply { - data = Uri.parse( - "https://play.google.com/store/apps/details?id=$openTasksPackage") - setPackage(gplayPackageName) - } - } - startActivity(intent) + installPackage(openTasksPackage) } } return false diff --git a/app/src/main/res/menu/taskdav_actions.xml b/app/src/main/res/menu/taskdav_actions.xml index fa3e80f6..0c3bc11c 100644 --- a/app/src/main/res/menu/taskdav_actions.xml +++ b/app/src/main/res/menu/taskdav_actions.xml @@ -8,6 +8,9 @@ -->