diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt index e8e32378..951f3ad5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt @@ -169,26 +169,27 @@ class MainActivity : SimpleActivity() { saveCurrentNote(false) } + val fragment = getCurrentFragment() when (item.itemId) { - R.id.open_search -> openSearch() + R.id.open_search -> fragment?.handleUnlocking { openSearch() } R.id.open_note -> displayOpenNoteDialog() - R.id.save_note -> saveNote() + R.id.save_note -> fragment?.handleUnlocking { saveNote() } R.id.undo -> undo() R.id.redo -> redo() R.id.new_note -> displayNewNoteDialog() - R.id.rename_note -> displayRenameDialog() - R.id.share -> shareText() + R.id.rename_note -> fragment?.handleUnlocking { displayRenameDialog() } + R.id.share -> fragment?.handleUnlocking { shareText() } R.id.lock_note -> lockNote() R.id.unlock_note -> unlockNote() R.id.open_file -> tryOpenFile() R.id.import_folder -> openFolder() - R.id.export_as_file -> tryExportAsFile() + R.id.export_as_file -> fragment?.handleUnlocking { tryExportAsFile() } R.id.export_all_notes -> tryExportAllNotes() - R.id.print -> printText() - R.id.delete_note -> displayDeleteNotePrompt() + R.id.print -> fragment?.handleUnlocking { printText() } + R.id.delete_note -> fragment?.handleUnlocking { displayDeleteNotePrompt() } R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java)) R.id.about -> launchAbout() - R.id.remove_done_items -> removeDoneItems() + R.id.remove_done_items -> fragment?.handleUnlocking { removeDoneItems() } else -> return super.onOptionsItemSelected(item) } return true @@ -421,6 +422,8 @@ class MainActivity : SimpleActivity() { } } + private fun getCurrentFragment() = mAdapter?.getFragment(view_pager.currentItem) + private val currentTextFragment: TextFragment? get() = mAdapter?.textFragment(view_pager.currentItem) private fun selectSearchMatch(editText: MyEditText) { @@ -775,7 +778,7 @@ class MainActivity : SimpleActivity() { var failCount = 0 NotesHelper(this).getNotes { mNotes = it - mNotes.forEachIndexed { index, note -> + mNotes.filter { !it.isLocked() }.forEachIndexed { index, note -> val filename = if (extension.isEmpty()) note.title else "${note.title}.$extension" val file = File(parent, filename) if (!filename.isAValidFilename()) { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt index f2fdcbc4..3e4ca20a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt @@ -45,6 +45,8 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List, val activity } } + fun getFragment(position: Int) = fragments[position] + fun isChecklistFragment(position: Int): Boolean = (fragments[position] is ChecklistFragment) fun textFragment(position: Int): TextFragment? = (fragments[position] as? TextFragment) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt index 496e6cf3..86b7aed5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/NoteFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/NoteFragment.kt index 2878e8fa..46663a03 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/NoteFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/NoteFragment.kt @@ -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() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt index afdb962d..3cf5991f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt @@ -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