Use updated security API

This commit is contained in:
Andrii Chubko 2021-08-24 19:24:55 +03:00
parent bd28e3e4a1
commit fadf9bed7e
4 changed files with 37 additions and 32 deletions

View File

@ -57,7 +57,7 @@ android {
dependencies { dependencies {
// implementation 'com.github.SimpleMobileTools:Simple-Commons:c45f0d662a' // implementation 'com.github.SimpleMobileTools:Simple-Commons:c45f0d662a'
implementation 'com.github.qwertyfinger:Simple-Commons:d61a1c0910' implementation 'com.github.qwertyfinger:Simple-Commons:615349768d'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.documentfile:documentfile:1.0.1' implementation 'androidx.documentfile:documentfile:1.0.1'

View File

@ -83,7 +83,8 @@ class MainActivity : SimpleActivity() {
initViewPager(intent.getLongExtra(OPEN_NOTE_ID, -1L)) initViewPager(intent.getLongExtra(OPEN_NOTE_ID, -1L))
pager_title_strip.setTextSize(TypedValue.COMPLEX_UNIT_PX, getPercentageFontSize()) pager_title_strip.setTextSize(TypedValue.COMPLEX_UNIT_PX, getPercentageFontSize())
pager_title_strip.layoutParams.height = (pager_title_strip.height + resources.getDimension(R.dimen.activity_margin) * 2 * (config.fontSizePercentage / 100f)).toInt() pager_title_strip.layoutParams.height =
(pager_title_strip.height + resources.getDimension(R.dimen.activity_margin) * 2 * (config.fontSizePercentage / 100f)).toInt()
checkWhatsNewDialog() checkWhatsNewDialog()
checkIntents(intent) checkIntents(intent)
@ -1080,18 +1081,22 @@ class MainActivity : SimpleActivity() {
} }
private fun unlockNote() { private fun unlockNote() {
SecurityDialog(this, mCurrentNote.protectionHash, mCurrentNote.protectionType) { hash, type, success -> performSecurityCheck(
if (success) { protectionType = mCurrentNote.protectionType,
mCurrentNote.protectionHash = "" requiredHash = mCurrentNote.protectionHash,
mCurrentNote.protectionType = PROTECTION_NONE successCallback = { _, _ -> removeProtection() }
NotesHelper(this).insertOrUpdateNote(mCurrentNote) { )
getCurrentFragment()?.apply { }
shouldShowLockedContent = true
checkLockState() private fun removeProtection() {
} mCurrentNote.protectionHash = ""
invalidateOptionsMenu() mCurrentNote.protectionType = PROTECTION_NONE
} NotesHelper(this).insertOrUpdateNote(mCurrentNote) {
getCurrentFragment()?.apply {
shouldShowLockedContent = true
checkLockState()
} }
invalidateOptionsMenu()
} }
} }

View File

@ -13,7 +13,6 @@ import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.dialogs.ColorPickerDialog import com.simplemobiletools.commons.dialogs.ColorPickerDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.dialogs.SecurityDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
import com.simplemobiletools.commons.helpers.PROTECTION_NONE import com.simplemobiletools.commons.helpers.PROTECTION_NONE
@ -105,13 +104,12 @@ class WidgetConfigureActivity : SimpleActivity() {
if (mNotes.size == 1 && note == null) { if (mNotes.size == 1 && note == null) {
note = mNotes.first() note = mNotes.first()
SecurityDialog(this, note.protectionHash, note.protectionType) { hash, type, success -> performSecurityCheck(
if (success) { protectionType = note.protectionType,
updateCurrentNote(note) requiredHash = note.protectionHash,
} else { successCallback = { _, _ -> updateCurrentNote(note) },
finish() failureCallback = { finish() }
} )
}
} else { } else {
if (note != null) { if (note != null) {
updateCurrentNote(note) updateCurrentNote(note)
@ -132,11 +130,11 @@ class WidgetConfigureActivity : SimpleActivity() {
if (note.protectionType == PROTECTION_NONE) { if (note.protectionType == PROTECTION_NONE) {
updateCurrentNote(note) updateCurrentNote(note)
} else { } else {
SecurityDialog(this, note.protectionHash, note.protectionType) { hash, type, success -> performSecurityCheck(
if (success) { protectionType = note.protectionType,
updateCurrentNote(note) requiredHash = note.protectionHash,
} successCallback = { _, _ -> updateCurrentNote(note) }
} )
} }
} }
} }

View File

@ -3,10 +3,10 @@ package com.simplemobiletools.notes.pro.fragments
import android.util.TypedValue import android.util.TypedValue
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.simplemobiletools.commons.dialogs.SecurityDialog
import com.simplemobiletools.commons.extensions.applyColorFilter import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.performSecurityCheck
import com.simplemobiletools.commons.helpers.PROTECTION_NONE import com.simplemobiletools.commons.helpers.PROTECTION_NONE
import com.simplemobiletools.notes.pro.extensions.config import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
@ -22,10 +22,10 @@ abstract class NoteFragment : Fragment() {
note_locked_layout.beVisibleIf(note.isLocked() && !shouldShowLockedContent) note_locked_layout.beVisibleIf(note.isLocked() && !shouldShowLockedContent)
note_locked_image.applyColorFilter(config!!.textColor) note_locked_image.applyColorFilter(config!!.textColor)
note_locked_label.setTextColor(context!!.config.textColor) note_locked_label.setTextColor(requireContext().config.textColor)
note_locked_label.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize()) note_locked_label.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize())
note_locked_show.setTextColor(context!!.getAdjustedPrimaryColor()) note_locked_show.setTextColor(requireContext().getAdjustedPrimaryColor())
note_locked_show.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize()) note_locked_show.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize())
note_locked_show.setOnClickListener { note_locked_show.setOnClickListener {
handleUnlocking() handleUnlocking()
@ -39,13 +39,15 @@ abstract class NoteFragment : Fragment() {
return return
} }
SecurityDialog(activity!!, note!!.protectionHash, note!!.protectionType) { hash, type, success -> activity?.performSecurityCheck(
if (success) { protectionType = note!!.protectionType,
requiredHash = note!!.protectionHash,
successCallback = { _, _ ->
shouldShowLockedContent = true shouldShowLockedContent = true
checkLockState() checkLockState()
callback?.invoke() callback?.invoke()
} }
} )
} }
abstract fun checkLockState() abstract fun checkLockState()