diff --git a/app/src/main/java/io/timelimit/android/ui/manage/child/category/Adapter.kt b/app/src/main/java/io/timelimit/android/ui/manage/child/category/Adapter.kt index 3b52b5d..40d4313 100644 --- a/app/src/main/java/io/timelimit/android/ui/manage/child/category/Adapter.kt +++ b/app/src/main/java/io/timelimit/android/ui/manage/child/category/Adapter.kt @@ -31,6 +31,7 @@ class Adapter: RecyclerView.Adapter() { 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? by Delegates.observable(null as List?) { _, _, _ -> notifyDataSetChanged() } @@ -48,6 +49,7 @@ class Adapter: RecyclerView.Adapter() { is CategoryItem -> item.category.id.hashCode() CreateCategoryItem -> item.hashCode() CategoriesIntroductionHeader -> item.hashCode() + ManipulationWarningCategoryItem -> item.hashCode() }.toLong() } @@ -55,6 +57,7 @@ class Adapter: RecyclerView.Adapter() { 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() { .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() { CategoriesIntroductionHeader -> { // nothing to do } + ManipulationWarningCategoryItem -> { + // nothing to do + } }.let { } } } @@ -133,6 +145,7 @@ class Adapter: RecyclerView.Adapter() { 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 { diff --git a/app/src/main/java/io/timelimit/android/ui/manage/child/category/Items.kt b/app/src/main/java/io/timelimit/android/ui/manage/child/category/Items.kt index 6213caa..3167e56 100644 --- a/app/src/main/java/io/timelimit/android/ui/manage/child/category/Items.kt +++ b/app/src/main/java/io/timelimit/android/ui/manage/child/category/Items.kt @@ -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, diff --git a/app/src/main/java/io/timelimit/android/ui/manage/child/category/ManageChildCategoriesModel.kt b/app/src/main/java/io/timelimit/android/ui/manage/child/category/ManageChildCategoriesModel.kt index c452de2..fc36f0c 100644 --- a/app/src/main/java/io/timelimit/android/ui/manage/child/category/ManageChildCategoriesModel.kt +++ b/app/src/main/java/io/timelimit/android/ui/manage/child/category/ManageChildCategoriesModel.kt @@ -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 + } + } + } } diff --git a/app/src/main/res/layout/manage_child_manipulation_warning.xml b/app/src/main/res/layout/manage_child_manipulation_warning.xml new file mode 100644 index 0000000..a676f2b --- /dev/null +++ b/app/src/main/res/layout/manage_child_manipulation_warning.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + diff --git a/app/src/main/res/values-de/strings-manage-child.xml b/app/src/main/res/values-de/strings-manage-child.xml index da8eeb3..208686d 100644 --- a/app/src/main/res/values-de/strings-manage-child.xml +++ b/app/src/main/res/values-de/strings-manage-child.xml @@ -32,4 +32,9 @@ Sie können mehrere Apps und Einschränkungen je Kategorie wählen. Das ermöglicht es z.B., eine Zeitbegrenzung für alle Spiele festzulegen. + + + Es gab eine Manipulation. + Gehen Sie zurück zur Übersicht und öffnen Sie den Geräte-Eintrag für Details. + diff --git a/app/src/main/res/values/strings-manage-child.xml b/app/src/main/res/values/strings-manage-child.xml index 12cdec8..14b890b 100644 --- a/app/src/main/res/values/strings-manage-child.xml +++ b/app/src/main/res/values/strings-manage-child.xml @@ -32,4 +32,10 @@ You can select multiple Apps and limits per category. This allows for example to set one limit for all games. + + @string/manage_device_manipulation_title + + There was a manipulation. + Go back to the overview and open the device entry for details. +