diff --git a/app/src/main/java/io/timelimit/android/ui/manage/parent/key/ManageUserKeyView.kt b/app/src/main/java/io/timelimit/android/ui/manage/parent/key/ManageUserKeyView.kt index d5c7ddd..6d7c8a5 100644 --- a/app/src/main/java/io/timelimit/android/ui/manage/parent/key/ManageUserKeyView.kt +++ b/app/src/main/java/io/timelimit/android/ui/manage/parent/key/ManageUserKeyView.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2020 Jonas Lochmann + * 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 @@ -46,16 +46,24 @@ object ManageUserKeyView { view.addKeyButton.setOnClickListener { if (auth.requestAuthenticationOrReturnTrue()) { - AddUserKeyDialogFragment.newInstance(userId).show(fragmentManager) + if (auth.authenticatedUser.value?.second?.id == userId) { + AddUserKeyDialogFragment.newInstance(userId).show(fragmentManager) + } else { + ParentKeyWrongUserDialogFragment.newInstance().show(fragmentManager) + } } } view.removeKeyButton.setOnClickListener { if (auth.requestAuthenticationOrReturnTrue()) { - val database = auth.database + if (auth.authenticatedUser.value?.second?.id == userId) { + val database = auth.database - Threads.database.execute { - database.userKey().deleteUserKeySync(userId) + Threads.database.execute { + database.userKey().deleteUserKeySync(userId) + } + } else { + ParentKeyWrongUserDialogFragment.newInstance().show(fragmentManager) } } } diff --git a/app/src/main/java/io/timelimit/android/ui/manage/parent/key/ParentKeyWrongUserDialogFragment.kt b/app/src/main/java/io/timelimit/android/ui/manage/parent/key/ParentKeyWrongUserDialogFragment.kt new file mode 100644 index 0000000..3831234 --- /dev/null +++ b/app/src/main/java/io/timelimit/android/ui/manage/parent/key/ParentKeyWrongUserDialogFragment.kt @@ -0,0 +1,39 @@ +/* + * 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.parent.key + +import android.app.AlertDialog +import android.app.Dialog +import android.os.Bundle +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager +import io.timelimit.android.R +import io.timelimit.android.extensions.showSafe + +class ParentKeyWrongUserDialogFragment: DialogFragment() { + companion object { + private const val DIALOG_TAG = "ParentKeyWrongUserDialogFragment" + + fun newInstance() = ParentKeyWrongUserDialogFragment() + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = AlertDialog.Builder(requireContext(), theme) + .setMessage(R.string.manage_user_key_wrong_user) + .setPositiveButton(R.string.generic_ok, null) + .create() + + fun show(fragmentManager: FragmentManager) = showSafe(fragmentManager, DIALOG_TAG) +} \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index b8e74e4..4731917 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -1086,6 +1086,7 @@ Der Schlüssel wurde hinzugefügt Dies ist kein gültiger TimeLimit-Schlüssel Dieser Schlüssel ist schon bei einem anderen Benutzer hinterlegt + Nur der Benutzer selbst kann seine Schlüssel verwalten E-Mail-Adresse verknüpfen Es wurde keine E-Mail-Adresse verknüpft diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 87739e0..2f50582 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1134,6 +1134,7 @@ The key was added This was no valid TimeLimit key This key is already linked to an other user + Only the user itself can manage his keys Link mail address No mail address was linked