mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-03 17:59:51 +02:00
Add UI to manage notification filter
This commit is contained in:
parent
7ae4c30e3e
commit
d7fd43685b
6 changed files with 166 additions and 0 deletions
|
@ -0,0 +1,53 @@
|
|||
package io.timelimit.android.ui.manage.category.settings
|
||||
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import io.timelimit.android.data.model.Category
|
||||
import io.timelimit.android.databinding.CategoryNotificationFilterBinding
|
||||
import io.timelimit.android.livedata.mergeLiveData
|
||||
import io.timelimit.android.sync.actions.UpdateCategoryBlockAllNotificationsAction
|
||||
import io.timelimit.android.ui.main.ActivityViewModel
|
||||
import io.timelimit.android.ui.payment.RequiresPurchaseDialogFragment
|
||||
|
||||
object CategoryNotificationFilter {
|
||||
fun bind(
|
||||
view: CategoryNotificationFilterBinding,
|
||||
auth: ActivityViewModel,
|
||||
categoryLive: LiveData<Category?>,
|
||||
lifecycleOwner: LifecycleOwner,
|
||||
fragmentManager: FragmentManager
|
||||
) {
|
||||
val premium = auth.logic.fullVersion.shouldProvideFullVersionFunctions
|
||||
|
||||
mergeLiveData(categoryLive, premium).observe(lifecycleOwner, Observer { (category, hasPremium) ->
|
||||
val shouldBeChecked = category?.blockAllNotifications ?: false
|
||||
|
||||
view.checkbox.setOnCheckedChangeListener { _, _ -> }
|
||||
view.checkbox.isChecked = shouldBeChecked
|
||||
view.checkbox.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked != shouldBeChecked) {
|
||||
if (isChecked && (hasPremium != true)) {
|
||||
RequiresPurchaseDialogFragment().show(fragmentManager)
|
||||
view.checkbox.isChecked = shouldBeChecked
|
||||
} else {
|
||||
if (
|
||||
category != null &&
|
||||
auth.tryDispatchParentAction(
|
||||
UpdateCategoryBlockAllNotificationsAction(
|
||||
categoryId = category.id,
|
||||
blocked = isChecked
|
||||
)
|
||||
)
|
||||
) {
|
||||
// ok
|
||||
} else {
|
||||
view.checkbox.isChecked = shouldBeChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -69,6 +69,14 @@ class CategorySettingsFragment : Fragment() {
|
|||
auth = auth
|
||||
)
|
||||
|
||||
CategoryNotificationFilter.bind(
|
||||
view = binding.notificationFilter,
|
||||
lifecycleOwner = this,
|
||||
fragmentManager = fragmentManager!!,
|
||||
auth = auth,
|
||||
categoryLive = categoryEntry
|
||||
)
|
||||
|
||||
binding.btnDeleteCategory.setOnClickListener { deleteCategory() }
|
||||
binding.editCategoryTitleGo.setOnClickListener { renameCategory() }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue