Add UI to manage notification filter

This commit is contained in:
Jonas L 2019-03-04 00:00:00 +00:00
parent 7ae4c30e3e
commit d7fd43685b
6 changed files with 166 additions and 0 deletions

View file

@ -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
}
}
}
}
})
}
}

View file

@ -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() }