Skip to content

Commit d321868

Browse files
committed
handle password protection at widget creation
1 parent 0f54560 commit d321868

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import com.google.gson.Gson
1313
import com.google.gson.reflect.TypeToken
1414
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
1515
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
16+
import com.simplemobiletools.commons.dialogs.SecurityDialog
1617
import com.simplemobiletools.commons.extensions.*
1718
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
19+
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
1820
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
1921
import com.simplemobiletools.commons.models.RadioItem
2022
import com.simplemobiletools.notes.pro.R
@@ -99,7 +101,8 @@ class WidgetConfigureActivity : SimpleActivity() {
99101
NotesHelper(this).getNotes {
100102
mNotes = it
101103
notes_picker_holder.beVisibleIf(mNotes.size > 1 && !mIsCustomizingColors)
102-
updateCurrentNote(mNotes.first())
104+
val note = mNotes.firstOrNull { !it.isLocked() } ?: return@getNotes
105+
updateCurrentNote(note)
103106
}
104107
}
105108

@@ -111,7 +114,16 @@ class WidgetConfigureActivity : SimpleActivity() {
111114

112115
RadioGroupDialog(this, items, mCurrentNoteId.toInt()) {
113116
val selectedId = it as Int
114-
updateCurrentNote(mNotes.first { it.id!!.toInt() == selectedId })
117+
val note = mNotes.firstOrNull { it.id!!.toInt() == selectedId } ?: return@RadioGroupDialog
118+
if (note.protectionType == PROTECTION_NONE) {
119+
updateCurrentNote(note)
120+
} else {
121+
SecurityDialog(this, note.protectionHash, note.protectionType) { hash, type, success ->
122+
if (success) {
123+
updateCurrentNote(note)
124+
}
125+
}
126+
}
115127
}
116128
}
117129

@@ -146,6 +158,11 @@ class WidgetConfigureActivity : SimpleActivity() {
146158
}
147159

148160
private fun saveConfig() {
161+
if (mCurrentNoteId == 0L) {
162+
finish()
163+
return
164+
}
165+
149166
val views = RemoteViews(packageName, R.layout.activity_main)
150167
views.setBackgroundColor(R.id.text_note_view, mBgColor)
151168
views.setBackgroundColor(R.id.checklist_note_view, mBgColor)

0 commit comments

Comments
 (0)