mirror of
https://codeberg.org/timelimit/opentimelimit-android.git
synced 2025-10-05 02:39:34 +02:00
Add showing manipulation warnings in the child overview screen
This commit is contained in:
parent
9163fd4353
commit
62a7dcde34
6 changed files with 86 additions and 1 deletions
|
@ -31,6 +31,7 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
private const val TYPE_ITEM = 0
|
||||
private const val TYPE_ADD = 1
|
||||
private const val TYPE_INTRO = 2
|
||||
private const val TYPE_MANIPULATION_WARNING = 3
|
||||
}
|
||||
|
||||
var categories: List<ManageChildCategoriesListItem>? by Delegates.observable(null as List<ManageChildCategoriesListItem>?) { _, _, _ -> notifyDataSetChanged() }
|
||||
|
@ -48,6 +49,7 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
is CategoryItem -> item.category.id.hashCode()
|
||||
CreateCategoryItem -> item.hashCode()
|
||||
CategoriesIntroductionHeader -> item.hashCode()
|
||||
ManipulationWarningCategoryItem -> item.hashCode()
|
||||
}.toLong()
|
||||
}
|
||||
|
||||
|
@ -55,6 +57,7 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
is CategoryItem -> TYPE_ITEM
|
||||
CreateCategoryItem -> TYPE_ADD
|
||||
CategoriesIntroductionHeader -> TYPE_INTRO
|
||||
ManipulationWarningCategoryItem -> TYPE_MANIPULATION_WARNING
|
||||
}
|
||||
|
||||
override fun getItemCount() = categories?.size ?: 0
|
||||
|
@ -90,6 +93,12 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
.inflate(R.layout.category_list_intro, parent, false)
|
||||
)
|
||||
|
||||
TYPE_MANIPULATION_WARNING ->
|
||||
ManipulationWarningViewHolder(
|
||||
LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.manage_child_manipulation_warning, parent, false)
|
||||
)
|
||||
|
||||
else -> throw IllegalStateException()
|
||||
}
|
||||
|
||||
|
@ -126,6 +135,9 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
CategoriesIntroductionHeader -> {
|
||||
// nothing to do
|
||||
}
|
||||
ManipulationWarningCategoryItem -> {
|
||||
// nothing to do
|
||||
}
|
||||
}.let { }
|
||||
}
|
||||
}
|
||||
|
@ -133,6 +145,7 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
sealed class ViewHolder(view: View): RecyclerView.ViewHolder(view)
|
||||
class AddViewHolder(view: View): ViewHolder(view)
|
||||
class IntroViewHolder(view: View): ViewHolder(view)
|
||||
class ManipulationWarningViewHolder(view: View): ViewHolder(view)
|
||||
class ItemViewHolder(val binding: CategoryRichCardBinding): ViewHolder(binding.root)
|
||||
|
||||
interface Handlers {
|
||||
|
|
|
@ -20,6 +20,7 @@ import io.timelimit.android.data.model.Category
|
|||
sealed class ManageChildCategoriesListItem
|
||||
object CategoriesIntroductionHeader: ManageChildCategoriesListItem()
|
||||
object CreateCategoryItem: ManageChildCategoriesListItem()
|
||||
object ManipulationWarningCategoryItem: ManageChildCategoriesListItem()
|
||||
data class CategoryItem(
|
||||
val category: Category,
|
||||
val isBlockedTimeNow: Boolean,
|
||||
|
|
|
@ -40,6 +40,10 @@ class ManageChildCategoriesModel(application: Application): AndroidViewModel(app
|
|||
}
|
||||
}
|
||||
|
||||
private val childDevices = childId.switchMap { logic.database.device().getDevicesByUserId(it) }
|
||||
|
||||
private val hasChildDevicesWithManipulation = childDevices.map { devices -> devices.find { device -> device.hasAnyManipulation } != null }.ignoreUnchanged()
|
||||
|
||||
private val childEntry = childId.switchMap { logic.database.user().getChildUserByIdLive(it) }
|
||||
|
||||
private val childTimezone = childEntry.mapToTimezone()
|
||||
|
@ -113,7 +117,7 @@ class ManageChildCategoriesModel(application: Application): AndroidViewModel(app
|
|||
|
||||
private val hasShownHint = logic.database.config().wereHintsShown(HintsToShow.CATEGORIES_INTRODUCTION)
|
||||
|
||||
val listContent = hasShownHint.switchMap { hasShownHint ->
|
||||
private val listContentStep1 = hasShownHint.switchMap { hasShownHint ->
|
||||
categoryItems.map { categoryItems ->
|
||||
if (hasShownHint) {
|
||||
categoryItems + listOf(CreateCategoryItem)
|
||||
|
@ -122,4 +126,14 @@ class ManageChildCategoriesModel(application: Application): AndroidViewModel(app
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
val listContent = hasChildDevicesWithManipulation.switchMap { hasChildDevicesWithManipulation ->
|
||||
listContentStep1.map { listContent ->
|
||||
if (hasChildDevicesWithManipulation) {
|
||||
listOf(ManipulationWarningCategoryItem) + listContent
|
||||
} else {
|
||||
listContent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue