Skip to content

Commit 0f54560

Browse files
committed
properly handle password protection of menu items
1 parent 81c6da2 commit 0f54560

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,27 @@ class MainActivity : SimpleActivity() {
169169
saveCurrentNote(false)
170170
}
171171

172+
val fragment = getCurrentFragment()
172173
when (item.itemId) {
173-
R.id.open_search -> openSearch()
174+
R.id.open_search -> fragment?.handleUnlocking { openSearch() }
174175
R.id.open_note -> displayOpenNoteDialog()
175-
R.id.save_note -> saveNote()
176+
R.id.save_note -> fragment?.handleUnlocking { saveNote() }
176177
R.id.undo -> undo()
177178
R.id.redo -> redo()
178179
R.id.new_note -> displayNewNoteDialog()
179-
R.id.rename_note -> displayRenameDialog()
180-
R.id.share -> shareText()
180+
R.id.rename_note -> fragment?.handleUnlocking { displayRenameDialog() }
181+
R.id.share -> fragment?.handleUnlocking { shareText() }
181182
R.id.lock_note -> lockNote()
182183
R.id.unlock_note -> unlockNote()
183184
R.id.open_file -> tryOpenFile()
184185
R.id.import_folder -> openFolder()
185-
R.id.export_as_file -> tryExportAsFile()
186+
R.id.export_as_file -> fragment?.handleUnlocking { tryExportAsFile() }
186187
R.id.export_all_notes -> tryExportAllNotes()
187-
R.id.print -> printText()
188-
R.id.delete_note -> displayDeleteNotePrompt()
188+
R.id.print -> fragment?.handleUnlocking { printText() }
189+
R.id.delete_note -> fragment?.handleUnlocking { displayDeleteNotePrompt() }
189190
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
190191
R.id.about -> launchAbout()
191-
R.id.remove_done_items -> removeDoneItems()
192+
R.id.remove_done_items -> fragment?.handleUnlocking { removeDoneItems() }
192193
else -> return super.onOptionsItemSelected(item)
193194
}
194195
return true
@@ -421,6 +422,8 @@ class MainActivity : SimpleActivity() {
421422
}
422423
}
423424

425+
private fun getCurrentFragment() = mAdapter?.getFragment(view_pager.currentItem)
426+
424427
private val currentTextFragment: TextFragment? get() = mAdapter?.textFragment(view_pager.currentItem)
425428

426429
private fun selectSearchMatch(editText: MyEditText) {
@@ -775,7 +778,7 @@ class MainActivity : SimpleActivity() {
775778
var failCount = 0
776779
NotesHelper(this).getNotes {
777780
mNotes = it
778-
mNotes.forEachIndexed { index, note ->
781+
mNotes.filter { !it.isLocked() }.forEachIndexed { index, note ->
779782
val filename = if (extension.isEmpty()) note.title else "${note.title}.$extension"
780783
val file = File(parent, filename)
781784
if (!filename.isAValidFilename()) {

app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
4545
}
4646
}
4747

48+
fun getFragment(position: Int) = fragments[position]
49+
4850
fun isChecklistFragment(position: Int): Boolean = (fragments[position] is ChecklistFragment)
4951

5052
fun textFragment(position: Int): TextFragment? = (fragments[position] as? TextFragment)

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import kotlinx.android.synthetic.main.fragment_checklist.view.*
2525
class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
2626

2727
private var noteId = 0L
28-
private var note: Note? = null
2928

3029
lateinit var view: ViewGroup
3130

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/NoteFragment.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import com.simplemobiletools.commons.dialogs.SecurityDialog
77
import com.simplemobiletools.commons.extensions.applyColorFilter
88
import com.simplemobiletools.commons.extensions.beVisibleIf
99
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
10+
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
1011
import com.simplemobiletools.notes.pro.extensions.config
1112
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
1213
import com.simplemobiletools.notes.pro.models.Note
1314
import kotlinx.android.synthetic.main.fragment_checklist.view.*
1415

1516
abstract class NoteFragment : Fragment() {
1617
protected var shouldShowLockedContent = false
18+
protected var note: Note? = null
1719

1820
protected fun setupLockedViews(view: ViewGroup, note: Note) {
1921
view.apply {
@@ -26,12 +28,22 @@ abstract class NoteFragment : Fragment() {
2628
note_locked_show.setTextColor(context!!.getAdjustedPrimaryColor())
2729
note_locked_show.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize())
2830
note_locked_show.setOnClickListener {
29-
SecurityDialog(activity!!, note.protectionHash, note.protectionType) { hash, type, success ->
30-
if (success) {
31-
shouldShowLockedContent = true
32-
checkLockState()
33-
}
34-
}
31+
handleUnlocking()
32+
}
33+
}
34+
}
35+
36+
fun handleUnlocking(callback: (() -> Unit)? = null) {
37+
if (callback != null && (note!!.protectionType == PROTECTION_NONE || shouldShowLockedContent)) {
38+
callback()
39+
return
40+
}
41+
42+
SecurityDialog(activity!!, note!!.protectionHash, note!!.protectionType) { hash, type, success ->
43+
if (success) {
44+
shouldShowLockedContent = true
45+
checkLockState()
46+
callback?.invoke()
3547
}
3648
}
3749
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class TextFragment : NoteFragment() {
3838
private var isUndoOrRedo = false
3939
private var skipTextUpdating = false
4040
private var noteId = 0L
41-
private var note: Note? = null
4241

4342
lateinit var view: ViewGroup
4443

0 commit comments

Comments
 (0)