From b921356feb11d32387a1a9243e25a682b1a7f015 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 9 Dec 2018 21:15:51 +0100 Subject: [PATCH] remember last created note type --- .../simplemobiletools/notes/pro/dialogs/NewNoteDialog.kt | 6 +++++- .../com/simplemobiletools/notes/pro/helpers/Config.kt | 4 ++++ .../com/simplemobiletools/notes/pro/helpers/Constants.kt | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewNoteDialog.kt index 115d3fbc..d2dd901b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewNoteDialog.kt @@ -8,6 +8,7 @@ import com.simplemobiletools.commons.extensions.showKeyboard import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.value import com.simplemobiletools.notes.pro.R +import com.simplemobiletools.notes.pro.extensions.config import com.simplemobiletools.notes.pro.extensions.notesDB import com.simplemobiletools.notes.pro.helpers.TYPE_CHECKLIST import com.simplemobiletools.notes.pro.helpers.TYPE_TEXT @@ -16,7 +17,9 @@ import kotlinx.android.synthetic.main.dialog_new_note.view.* class NewNoteDialog(val activity: Activity, callback: (note: Note) -> Unit) { init { - val view = activity.layoutInflater.inflate(R.layout.dialog_new_note, null) + val view = activity.layoutInflater.inflate(R.layout.dialog_new_note, null).apply { + new_note_type.check(if (activity.config.lastCreatedNoteType == TYPE_TEXT) type_text_note.id else type_checklist.id) + } AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, null) @@ -32,6 +35,7 @@ class NewNoteDialog(val activity: Activity, callback: (note: Note) -> Unit) { activity.notesDB.getNoteIdWithTitle(title) != null -> activity.toast(R.string.title_taken) else -> { val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) TYPE_CHECKLIST else TYPE_TEXT + activity.config.lastCreatedNoteType = type val newNote = Note(null, title, "", type) callback(newNote) dismiss() diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Config.kt index 760a36f3..300b2e09 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Config.kt @@ -72,4 +72,8 @@ class Config(context: Context) : BaseConfig(context) { var useIncognitoMode: Boolean get() = prefs.getBoolean(USE_INCOGNITO_MODE, false) set(useIncognitoMode) = prefs.edit().putBoolean(USE_INCOGNITO_MODE, useIncognitoMode).apply() + + var lastCreatedNoteType: Int + get() = prefs.getInt(LAST_CREATED_NOTE_TYPE, TYPE_TEXT) + set(lastCreatedNoteType) = prefs.edit().putInt(LAST_CREATED_NOTE_TYPE, lastCreatedNoteType).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Constants.kt index bf91fe8a..04335887 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Constants.kt @@ -21,6 +21,7 @@ const val LAST_USED_EXTENSION = "last_used_extension" const val LAST_USED_SAVE_PATH = "last_used_save_path" const val ENABLE_LINE_WRAP = "enable_line_wrap" const val USE_INCOGNITO_MODE = "use_incognito_mode" +const val LAST_CREATED_NOTE_TYPE = "last_created_note_type" // gravity const val GRAVITY_LEFT = 0