From 989e328bc73df458f4df64cdacb4dcac452a6740 Mon Sep 17 00:00:00 2001 From: Jonas Lochmann Date: Mon, 19 Sep 2022 02:00:00 +0200 Subject: [PATCH] Added confirmation during self limitation before enabling limits for a category again --- .../ConfirmEnableLimitsAgainDialogFragment.kt | 77 +++++++++++++++++++ .../category/ManageChildCategoriesFragment.kt | 11 +-- app/src/main/res/values-de/strings.xml | 3 + app/src/main/res/values/strings.xml | 3 + 4 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/io/timelimit/android/ui/manage/child/category/ConfirmEnableLimitsAgainDialogFragment.kt diff --git a/app/src/main/java/io/timelimit/android/ui/manage/child/category/ConfirmEnableLimitsAgainDialogFragment.kt b/app/src/main/java/io/timelimit/android/ui/manage/child/category/ConfirmEnableLimitsAgainDialogFragment.kt new file mode 100644 index 0000000..747dc5d --- /dev/null +++ b/app/src/main/java/io/timelimit/android/ui/manage/child/category/ConfirmEnableLimitsAgainDialogFragment.kt @@ -0,0 +1,77 @@ +/* + * TimeLimit Copyright 2019 - 2022 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 . + */ +package io.timelimit.android.ui.manage.child.category + +import android.app.Dialog +import android.os.Bundle +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager +import io.timelimit.android.R +import io.timelimit.android.extensions.showSafe +import io.timelimit.android.sync.actions.UpdateCategoryDisableLimitsAction +import io.timelimit.android.ui.main.getActivityViewModel + +class ConfirmEnableLimitsAgainDialogFragment: DialogFragment() { + companion object { + private const val DIALOG_TAG = "ConfirmEnableLimitsAgainDialogFragment" + private const val CHILD_ID = "childId" + private const val CATEGORY_ID = "categoryId" + + fun newInstance(childId: String, categoryId: String) = ConfirmEnableLimitsAgainDialogFragment().apply { + arguments = Bundle().apply { + putString(CHILD_ID, childId) + putString(CATEGORY_ID, categoryId) + } + } + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val auth = getActivityViewModel(requireActivity()) + val childId = requireArguments().getString(CHILD_ID)!! + val categoryId = requireArguments().getString(CATEGORY_ID)!! + + auth.authenticatedUserOrChild.observe(this) + { if (it?.second?.id != childId) dismissAllowingStateLoss() } + + return AlertDialog.Builder(requireContext(), theme) + .setTitle(R.string.manage_child_confirm_enable_limits_again_title) + .setMessage(getString(R.string.manage_child_confirm_enable_limits_again_text, "")) + .setNegativeButton(R.string.generic_cancel, null) + .setPositiveButton(R.string.generic_enable) { _, _ -> + auth.tryDispatchParentAction( + action = UpdateCategoryDisableLimitsAction( + categoryId = categoryId, + endTime = 0 + ), + allowAsChild = true + ) + } + .create() + .also { alert -> + auth.logic.database.category().getCategoryByChildIdAndId(childId, categoryId).observe(this) + { category -> + if (category == null) dismissAllowingStateLoss() + else alert.setMessage(getString( + R.string.manage_child_confirm_enable_limits_again_text, + category.title + )) + } + } + } + + fun show(fragmentManager: FragmentManager) = showSafe(fragmentManager, DIALOG_TAG) +} \ No newline at end of file diff --git a/app/src/main/java/io/timelimit/android/ui/manage/child/category/ManageChildCategoriesFragment.kt b/app/src/main/java/io/timelimit/android/ui/manage/child/category/ManageChildCategoriesFragment.kt index 879a51c..a218f6f 100644 --- a/app/src/main/java/io/timelimit/android/ui/manage/child/category/ManageChildCategoriesFragment.kt +++ b/app/src/main/java/io/timelimit/android/ui/manage/child/category/ManageChildCategoriesFragment.kt @@ -106,13 +106,10 @@ class ManageChildCategoriesFragment : Fragment() { ) ) } else if (auth.isParentOrChildAuthenticated(params.childId) && category.mode is CategorySpecialMode.TemporarilyAllowed) { - auth.tryDispatchParentAction( - action = UpdateCategoryDisableLimitsAction( - categoryId = category.category.id, - endTime = 0 - ), - allowAsChild = true - ) + ConfirmEnableLimitsAgainDialogFragment.newInstance( + childId = params.childId, + categoryId = category.category.id + ).show(parentFragmentManager); false } else if ( auth.isParentOrChildAuthenticated(params.childId) && (!(category.mode is CategorySpecialMode.TemporarilyBlocked && category.mode.endTime == null)) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 8e41403..1c9a6d0 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -808,6 +808,9 @@ Begrenzungen von %s deaktivieren Begrenzungen vorübergehend deaktivieren + Begrenzungen aktivieren + Sollen die Begrenzungen für die Kategorie %s wirklich wieder aktiviert werden? + Sperren auf Activity-Ebene Das ermöglicht es (abhänging von den Apps), einige Funktionen in Apps zu sperren. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 21084fa..6ff51a1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -861,6 +861,9 @@ Disable limits for %s disable limits temporarily + Enable limitations + Would you like to enable the limitations for the category %s? + Activity level blocking This allows (depending on the App) blocking some features within an App.