properly handle password protection of menu items

This commit is contained in:
tibbi
2021-05-20 23:12:19 +02:00
parent 81c6da22d4
commit 0f5456086e
5 changed files with 32 additions and 17 deletions

View File

@ -25,7 +25,6 @@ import kotlinx.android.synthetic.main.fragment_checklist.view.*
class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
private var noteId = 0L
private var note: Note? = null
lateinit var view: ViewGroup

View File

@ -7,6 +7,7 @@ import com.simplemobiletools.commons.dialogs.SecurityDialog
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
import com.simplemobiletools.notes.pro.models.Note
@ -14,6 +15,7 @@ import kotlinx.android.synthetic.main.fragment_checklist.view.*
abstract class NoteFragment : Fragment() {
protected var shouldShowLockedContent = false
protected var note: Note? = null
protected fun setupLockedViews(view: ViewGroup, note: Note) {
view.apply {
@ -26,12 +28,22 @@ abstract class NoteFragment : Fragment() {
note_locked_show.setTextColor(context!!.getAdjustedPrimaryColor())
note_locked_show.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize())
note_locked_show.setOnClickListener {
SecurityDialog(activity!!, note.protectionHash, note.protectionType) { hash, type, success ->
if (success) {
shouldShowLockedContent = true
checkLockState()
}
}
handleUnlocking()
}
}
}
fun handleUnlocking(callback: (() -> Unit)? = null) {
if (callback != null && (note!!.protectionType == PROTECTION_NONE || shouldShowLockedContent)) {
callback()
return
}
SecurityDialog(activity!!, note!!.protectionHash, note!!.protectionType) { hash, type, success ->
if (success) {
shouldShowLockedContent = true
checkLockState()
callback?.invoke()
}
}
}

View File

@ -38,7 +38,6 @@ class TextFragment : NoteFragment() {
private var isUndoOrRedo = false
private var skipTextUpdating = false
private var noteId = 0L
private var note: Note? = null
lateinit var view: ViewGroup