Add showing manipulation warnings in the child overview screen

This commit is contained in:
Jonas L 2019-01-22 14:23:09 +01:00
parent 9163fd4353
commit 62a7dcde34
6 changed files with 86 additions and 1 deletions

View file

@ -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 {

View file

@ -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,

View file

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

View file

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Open TimeLimit Copyright <C> 2019 Jonas Lochmann
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<androidx.cardview.widget.CardView
android:theme="@style/AppThemeDarkOverlay"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:background="@color/orange"
android:orientation="vertical"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:drawablePadding="8dp"
android:drawableStart="@drawable/ic_warning_white_24dp"
android:text="@string/manage_child_manipulation_title"
android:textAppearance="?android:textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:textAppearance="?android:textAppearanceMedium"
android:text="@string/manage_child_manipulation_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.cardview.widget.CardView>

View file

@ -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.
</string>
<string name="manage_child_manipulation_text">
Es gab eine Manipulation.
Gehen Sie zurück zur Übersicht und öffnen Sie den Geräte-Eintrag für Details.
</string>
</resources>

View file

@ -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>
<string name="manage_child_manipulation_title" translatable="false">@string/manage_device_manipulation_title</string>
<string name="manage_child_manipulation_text">
There was a manipulation.
Go back to the overview and open the device entry for details.
</string>
</resources>