Added confirmation during self limitation before enabling limits for a category again

This commit is contained in:
Jonas Lochmann 2022-09-19 02:00:00 +02:00
parent 12b83a66f5
commit 989e328bc7
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
4 changed files with 87 additions and 7 deletions

View file

@ -0,0 +1,77 @@
/*
* TimeLimit Copyright <C> 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 <https://www.gnu.org/licenses/>.
*/
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)
}

View file

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

View file

@ -808,6 +808,9 @@
<string name="manage_child_special_mode_wizard_disable_limits_title">Begrenzungen von %s deaktivieren</string>
<string name="manage_child_special_mode_wizard_disable_limits_option">Begrenzungen vorübergehend deaktivieren</string>
<string name="manage_child_confirm_enable_limits_again_title">Begrenzungen aktivieren</string>
<string name="manage_child_confirm_enable_limits_again_text">Sollen die Begrenzungen für die Kategorie %s wirklich wieder aktiviert werden?</string>
<string name="manage_device_activity_level_blocking_title">Sperren auf Activity-Ebene</string>
<string name="manage_device_activity_level_blocking_text">
Das ermöglicht es (abhänging von den Apps), einige Funktionen in Apps zu sperren.

View file

@ -861,6 +861,9 @@
<string name="manage_child_special_mode_wizard_disable_limits_title">Disable limits for %s</string>
<string name="manage_child_special_mode_wizard_disable_limits_option">disable limits temporarily</string>
<string name="manage_child_confirm_enable_limits_again_title">Enable limitations</string>
<string name="manage_child_confirm_enable_limits_again_text">Would you like to enable the limitations for the category %s?</string>
<string name="manage_device_activity_level_blocking_title">Activity level blocking</string>
<string name="manage_device_activity_level_blocking_text">
This allows (depending on the App) blocking some features within an App.