From 83bee2a59e6df750b6f072779f6abd6165768ad3 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Thu, 18 Mar 2021 12:44:41 -0500 Subject: [PATCH] Replace hasTasksSubscription with hasTasksAccount --- app/src/main/java/org/tasks/Tasks.kt | 2 +- app/src/main/java/org/tasks/billing/Inventory.kt | 13 ++++++------- .../main/java/org/tasks/billing/PurchaseDialog.kt | 7 +++++-- .../main/java/org/tasks/filters/FilterProvider.kt | 2 +- .../java/org/tasks/injection/ViewModelModule.kt | 2 +- app/src/main/java/org/tasks/jobs/SyncCaldavWork.kt | 2 +- .../org/tasks/preferences/fragments/TasksAccount.kt | 2 +- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/tasks/Tasks.kt b/app/src/main/java/org/tasks/Tasks.kt index 2b5bf8dbe..d9fd7ea5b 100644 --- a/app/src/main/java/org/tasks/Tasks.kt +++ b/app/src/main/java/org/tasks/Tasks.kt @@ -76,7 +76,7 @@ class Tasks : Application(), Configuration.Provider { } private fun backgroundWork() = CoroutineScope(Dispatchers.Default).launch { - inventory.updateTasksSubscription() + inventory.updateTasksAccount() NotificationSchedulerIntentService.enqueueWork(context, false) CalendarNotificationIntentService.enqueueWork(context) refreshScheduler.get().scheduleAll() diff --git a/app/src/main/java/org/tasks/billing/Inventory.kt b/app/src/main/java/org/tasks/billing/Inventory.kt index cae8539c3..8b4c391f2 100644 --- a/app/src/main/java/org/tasks/billing/Inventory.kt +++ b/app/src/main/java/org/tasks/billing/Inventory.kt @@ -28,7 +28,7 @@ class Inventory @Inject constructor( private val purchases: MutableMap = HashMap() val subscription = MutableLiveData() - var hasTasksSubscription = false + var hasTasksAccount = false private set fun clear() { @@ -62,16 +62,15 @@ class Inventory @Inject constructor( get() { return BuildConfig.FLAVOR == "generic" || (BuildConfig.DEBUG && preferences.getBoolean(R.string.p_debug_pro, false)) - || hasTasksSubscription + || hasTasksAccount || field } private set - suspend fun updateTasksSubscription() { - hasTasksSubscription = - subscription.value?.isTasksSubscription == true || caldavDao.getAccounts(TYPE_TASKS).any { - it.isTasksSubscription(context) - } + suspend fun updateTasksAccount() { + hasTasksAccount = caldavDao.getAccounts(TYPE_TASKS).any { + it.isTasksSubscription(context) + } } fun purchased(sku: String) = purchases.containsKey(sku) diff --git a/app/src/main/java/org/tasks/billing/PurchaseDialog.kt b/app/src/main/java/org/tasks/billing/PurchaseDialog.kt index 59e4d9dc4..d72eaf6da 100644 --- a/app/src/main/java/org/tasks/billing/PurchaseDialog.kt +++ b/app/src/main/java/org/tasks/billing/PurchaseDialog.kt @@ -63,12 +63,15 @@ class PurchaseDialog : DialogFragment(), OnPurchasesUpdated { private var priceChanged = false private var nameYourPrice = false + private val hasTasksSubscription + get() = inventory.subscription.value?.isTasksSubscription == true + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { binding = ActivityPurchaseBinding.inflate(layoutInflater) ButterKnife.bind(this, binding.root) if (savedInstanceState == null) { - nameYourPrice = !isTasksPayment && !inventory.hasTasksSubscription + nameYourPrice = !isTasksPayment && !hasTasksSubscription } else { binding.slider.value = savedInstanceState.getFloat(EXTRA_PRICE) priceChanged = savedInstanceState.getBoolean(EXTRA_PRICE_CHANGED) @@ -124,7 +127,7 @@ class PurchaseDialog : DialogFragment(), OnPurchasesUpdated { var benefits = "### ${getString(when { nameYourPrice -> R.string.name_your_price !inventory.hasPro -> R.string.upgrade_to_pro - !inventory.hasTasksSubscription -> R.string.button_upgrade + !hasTasksSubscription -> R.string.button_upgrade else -> R.string.manage_subscription })}" benefits += if (nameYourPrice) { diff --git a/app/src/main/java/org/tasks/filters/FilterProvider.kt b/app/src/main/java/org/tasks/filters/FilterProvider.kt index 1dc074c09..2e6c8c21c 100644 --- a/app/src/main/java/org/tasks/filters/FilterProvider.kt +++ b/app/src/main/java/org/tasks/filters/FilterProvider.kt @@ -178,7 +178,7 @@ class FilterProvider @Inject constructor( private val navDrawerFooter: List get() = listOf(NavigationDrawerSeparator()) - .plusIf(BuildConfig.FLAVOR == "generic" && !inventory.hasTasksSubscription) { + .plusIf(BuildConfig.FLAVOR == "generic" && !inventory.hasTasksAccount) { NavigationDrawerAction( context.getString(R.string.TLA_menu_donate), R.drawable.ic_outline_attach_money_24px, diff --git a/app/src/main/java/org/tasks/injection/ViewModelModule.kt b/app/src/main/java/org/tasks/injection/ViewModelModule.kt index 3b4bfa68f..d5b0ef06e 100644 --- a/app/src/main/java/org/tasks/injection/ViewModelModule.kt +++ b/app/src/main/java/org/tasks/injection/ViewModelModule.kt @@ -20,5 +20,5 @@ class ViewModelModule { inventory: Inventory, google: Lazy, mapbox: Lazy - ): PlaceSearch = if (inventory.hasTasksSubscription) google.get() else mapbox.get() + ): PlaceSearch = if (inventory.hasTasksAccount) google.get() else mapbox.get() } \ No newline at end of file diff --git a/app/src/main/java/org/tasks/jobs/SyncCaldavWork.kt b/app/src/main/java/org/tasks/jobs/SyncCaldavWork.kt index 3311f852f..6d21cdd67 100644 --- a/app/src/main/java/org/tasks/jobs/SyncCaldavWork.kt +++ b/app/src/main/java/org/tasks/jobs/SyncCaldavWork.kt @@ -34,7 +34,7 @@ class SyncCaldavWork @AssistedInject constructor( override suspend fun doSync() { caldavJobs().awaitAll() - inventory.updateTasksSubscription() + inventory.updateTasksAccount() } private suspend fun caldavJobs(): List> = coroutineScope { diff --git a/app/src/main/java/org/tasks/preferences/fragments/TasksAccount.kt b/app/src/main/java/org/tasks/preferences/fragments/TasksAccount.kt index 3a6ed3a77..cfa262714 100644 --- a/app/src/main/java/org/tasks/preferences/fragments/TasksAccount.kt +++ b/app/src/main/java/org/tasks/preferences/fragments/TasksAccount.kt @@ -96,7 +96,7 @@ class TasksAccount : BaseAccountPreference() { override suspend fun removeAccount() { // try to delete session from caldav.tasks.org taskDeleter.delete(caldavAccount) - inventory.updateTasksSubscription() + inventory.updateTasksAccount() } override fun onResume() {