Replace hasTasksSubscription with hasTasksAccount

pull/1419/head
Alex Baker 4 years ago
parent 7f3c1f1756
commit 83bee2a59e

@ -76,7 +76,7 @@ class Tasks : Application(), Configuration.Provider {
} }
private fun backgroundWork() = CoroutineScope(Dispatchers.Default).launch { private fun backgroundWork() = CoroutineScope(Dispatchers.Default).launch {
inventory.updateTasksSubscription() inventory.updateTasksAccount()
NotificationSchedulerIntentService.enqueueWork(context, false) NotificationSchedulerIntentService.enqueueWork(context, false)
CalendarNotificationIntentService.enqueueWork(context) CalendarNotificationIntentService.enqueueWork(context)
refreshScheduler.get().scheduleAll() refreshScheduler.get().scheduleAll()

@ -28,7 +28,7 @@ class Inventory @Inject constructor(
private val purchases: MutableMap<String, Purchase> = HashMap() private val purchases: MutableMap<String, Purchase> = HashMap()
val subscription = MutableLiveData<Purchase?>() val subscription = MutableLiveData<Purchase?>()
var hasTasksSubscription = false var hasTasksAccount = false
private set private set
fun clear() { fun clear() {
@ -62,14 +62,13 @@ class Inventory @Inject constructor(
get() { get() {
return BuildConfig.FLAVOR == "generic" return BuildConfig.FLAVOR == "generic"
|| (BuildConfig.DEBUG && preferences.getBoolean(R.string.p_debug_pro, false)) || (BuildConfig.DEBUG && preferences.getBoolean(R.string.p_debug_pro, false))
|| hasTasksSubscription || hasTasksAccount
|| field || field
} }
private set private set
suspend fun updateTasksSubscription() { suspend fun updateTasksAccount() {
hasTasksSubscription = hasTasksAccount = caldavDao.getAccounts(TYPE_TASKS).any {
subscription.value?.isTasksSubscription == true || caldavDao.getAccounts(TYPE_TASKS).any {
it.isTasksSubscription(context) it.isTasksSubscription(context)
} }
} }

@ -63,12 +63,15 @@ class PurchaseDialog : DialogFragment(), OnPurchasesUpdated {
private var priceChanged = false private var priceChanged = false
private var nameYourPrice = false private var nameYourPrice = false
private val hasTasksSubscription
get() = inventory.subscription.value?.isTasksSubscription == true
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
binding = ActivityPurchaseBinding.inflate(layoutInflater) binding = ActivityPurchaseBinding.inflate(layoutInflater)
ButterKnife.bind(this, binding.root) ButterKnife.bind(this, binding.root)
if (savedInstanceState == null) { if (savedInstanceState == null) {
nameYourPrice = !isTasksPayment && !inventory.hasTasksSubscription nameYourPrice = !isTasksPayment && !hasTasksSubscription
} else { } else {
binding.slider.value = savedInstanceState.getFloat(EXTRA_PRICE) binding.slider.value = savedInstanceState.getFloat(EXTRA_PRICE)
priceChanged = savedInstanceState.getBoolean(EXTRA_PRICE_CHANGED) priceChanged = savedInstanceState.getBoolean(EXTRA_PRICE_CHANGED)
@ -124,7 +127,7 @@ class PurchaseDialog : DialogFragment(), OnPurchasesUpdated {
var benefits = "### ${getString(when { var benefits = "### ${getString(when {
nameYourPrice -> R.string.name_your_price nameYourPrice -> R.string.name_your_price
!inventory.hasPro -> R.string.upgrade_to_pro !inventory.hasPro -> R.string.upgrade_to_pro
!inventory.hasTasksSubscription -> R.string.button_upgrade !hasTasksSubscription -> R.string.button_upgrade
else -> R.string.manage_subscription else -> R.string.manage_subscription
})}" })}"
benefits += if (nameYourPrice) { benefits += if (nameYourPrice) {

@ -178,7 +178,7 @@ class FilterProvider @Inject constructor(
private val navDrawerFooter: List<FilterListItem> private val navDrawerFooter: List<FilterListItem>
get() = listOf(NavigationDrawerSeparator()) get() = listOf(NavigationDrawerSeparator())
.plusIf(BuildConfig.FLAVOR == "generic" && !inventory.hasTasksSubscription) { .plusIf(BuildConfig.FLAVOR == "generic" && !inventory.hasTasksAccount) {
NavigationDrawerAction( NavigationDrawerAction(
context.getString(R.string.TLA_menu_donate), context.getString(R.string.TLA_menu_donate),
R.drawable.ic_outline_attach_money_24px, R.drawable.ic_outline_attach_money_24px,

@ -20,5 +20,5 @@ class ViewModelModule {
inventory: Inventory, inventory: Inventory,
google: Lazy<PlaceSearchGoogle>, google: Lazy<PlaceSearchGoogle>,
mapbox: Lazy<PlaceSearchMapbox> mapbox: Lazy<PlaceSearchMapbox>
): PlaceSearch = if (inventory.hasTasksSubscription) google.get() else mapbox.get() ): PlaceSearch = if (inventory.hasTasksAccount) google.get() else mapbox.get()
} }

@ -34,7 +34,7 @@ class SyncCaldavWork @AssistedInject constructor(
override suspend fun doSync() { override suspend fun doSync() {
caldavJobs().awaitAll() caldavJobs().awaitAll()
inventory.updateTasksSubscription() inventory.updateTasksAccount()
} }
private suspend fun caldavJobs(): List<Deferred<Unit>> = coroutineScope { private suspend fun caldavJobs(): List<Deferred<Unit>> = coroutineScope {

@ -96,7 +96,7 @@ class TasksAccount : BaseAccountPreference() {
override suspend fun removeAccount() { override suspend fun removeAccount() {
// try to delete session from caldav.tasks.org // try to delete session from caldav.tasks.org
taskDeleter.delete(caldavAccount) taskDeleter.delete(caldavAccount)
inventory.updateTasksSubscription() inventory.updateTasksAccount()
} }
override fun onResume() { override fun onResume() {

Loading…
Cancel
Save