Changed NoteType to the enum class in Note.kt

This commit is contained in:
merkost 2023-07-10 11:19:55 +10:00
parent 932699a0ba
commit e8b8d2be1d
11 changed files with 54 additions and 45 deletions

View File

@ -44,6 +44,7 @@ import com.simplemobiletools.notes.pro.extensions.*
import com.simplemobiletools.notes.pro.fragments.TextFragment import com.simplemobiletools.notes.pro.fragments.TextFragment
import com.simplemobiletools.notes.pro.helpers.* import com.simplemobiletools.notes.pro.helpers.*
import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.item_checklist.* import kotlinx.android.synthetic.main.item_checklist.*
import java.io.File import java.io.File
@ -165,12 +166,12 @@ class MainActivity : SimpleActivity() {
main_toolbar.menu.apply { main_toolbar.menu.apply {
findItem(R.id.undo).apply { findItem(R.id.undo).apply {
isVisible = showUndoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value isVisible = showUndoButton && mCurrentNote.type == NoteType.TYPE_TEXT
icon?.alpha = if (isEnabled) 255 else 127 icon?.alpha = if (isEnabled) 255 else 127
} }
findItem(R.id.redo).apply { findItem(R.id.redo).apply {
isVisible = showRedoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value isVisible = showRedoButton && mCurrentNote.type == NoteType.TYPE_TEXT
icon?.alpha = if (isEnabled) 255 else 127 icon?.alpha = if (isEnabled) 255 else 127
} }
@ -187,7 +188,7 @@ class MainActivity : SimpleActivity() {
saveNoteButton = findItem(R.id.save_note) saveNoteButton = findItem(R.id.save_note)
saveNoteButton!!.isVisible = saveNoteButton!!.isVisible =
!config.autosaveNotes && showSaveButton && (::mCurrentNote.isInitialized && mCurrentNote.type == NoteType.TYPE_TEXT.value) !config.autosaveNotes && showSaveButton && (::mCurrentNote.isInitialized && mCurrentNote.type == NoteType.TYPE_TEXT)
} }
pager_tab_strip.beVisibleIf(multipleNotesExist) pager_tab_strip.beVisibleIf(multipleNotesExist)
@ -281,7 +282,7 @@ class MainActivity : SimpleActivity() {
} }
} }
private fun isCurrentItemChecklist() = if (::mCurrentNote.isInitialized) mCurrentNote.type == NoteType.TYPE_CHECKLIST.value else false private fun isCurrentItemChecklist() = if (::mCurrentNote.isInitialized) mCurrentNote.type == NoteType.TYPE_CHECKLIST else false
@SuppressLint("NewApi") @SuppressLint("NewApi")
private fun checkShortcuts() { private fun checkShortcuts() {
@ -353,10 +354,10 @@ class MainActivity : SimpleActivity() {
val file = File(realPath) val file = File(realPath)
handleUri(Uri.fromFile(file)) handleUri(Uri.fromFile(file))
} else if (intent.getBooleanExtra(NEW_TEXT_NOTE, false)) { } else if (intent.getBooleanExtra(NEW_TEXT_NOTE, false)) {
val newTextNote = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "") val newTextNote = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_TEXT, "", PROTECTION_NONE, "")
addNewNote(newTextNote) addNewNote(newTextNote)
} else if (intent.getBooleanExtra(NEW_CHECKLIST, false)) { } else if (intent.getBooleanExtra(NEW_CHECKLIST, false)) {
val newChecklist = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "") val newChecklist = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_CHECKLIST, "", PROTECTION_NONE, "")
addNewNote(newChecklist) addNewNote(newChecklist)
} else { } else {
handleUri(data!!) handleUri(data!!)
@ -431,7 +432,7 @@ class MainActivity : SimpleActivity() {
} }
} }
if (!config.showKeyboard || mCurrentNote.type == NoteType.TYPE_CHECKLIST.value) { if (!config.showKeyboard || mCurrentNote.type == NoteType.TYPE_CHECKLIST) {
hideKeyboard() hideKeyboard()
} }
refreshMenuItems() refreshMenuItems()
@ -663,7 +664,7 @@ class MainActivity : SimpleActivity() {
val checklistItems = fileText.parseChecklistItems() val checklistItems = fileText.parseChecklistItems()
if (checklistItems != null) { if (checklistItems != null) {
val title = it.absolutePath.getFilenameFromPath().substringBeforeLast('.') val title = it.absolutePath.getFilenameFromPath().substringBeforeLast('.')
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "") val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST, "", PROTECTION_NONE, "")
runOnUiThread { runOnUiThread {
OpenFileDialog(this, it.path) { OpenFileDialog(this, it.path) {
displayNewNoteDialog(note.value, title = it.title, it.path, setChecklistAsDefault = true) displayNewNoteDialog(note.value, title = it.title, it.path, setChecklistAsDefault = true)
@ -765,7 +766,7 @@ class MainActivity : SimpleActivity() {
} }
} }
val noteType = if (checklistItems != null) NoteType.TYPE_CHECKLIST.value else NoteType.TYPE_TEXT.value val noteType = if (checklistItems != null) NoteType.TYPE_CHECKLIST else NoteType.TYPE_TEXT
if (!canSyncNoteWithFile) { if (!canSyncNoteWithFile) {
val note = Note(null, noteTitle, content, noteType, "", PROTECTION_NONE, "") val note = Note(null, noteTitle, content, noteType, "", PROTECTION_NONE, "")
displayNewNoteDialog(note.value, title = noteTitle, "") displayNewNoteDialog(note.value, title = noteTitle, "")
@ -791,9 +792,9 @@ class MainActivity : SimpleActivity() {
val fileText = it.readText().trim() val fileText = it.readText().trim()
val checklistItems = fileText.parseChecklistItems() val checklistItems = fileText.parseChecklistItems()
val note = if (checklistItems != null) { val note = if (checklistItems != null) {
Note(null, title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "") Note(null, title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST, "", PROTECTION_NONE, "")
} else { } else {
Note(null, title, "", NoteType.TYPE_TEXT.value, path, PROTECTION_NONE, "") Note(null, title, "", NoteType.TYPE_TEXT, path, PROTECTION_NONE, "")
} }
if (mNotes.any { it.title.equals(note.title, true) }) { if (mNotes.any { it.title.equals(note.title, true) }) {
@ -864,10 +865,10 @@ class MainActivity : SimpleActivity() {
private fun exportAsFile() { private fun exportAsFile() {
ExportFileDialog(this, mCurrentNote) { ExportFileDialog(this, mCurrentNote) {
val textToExport = if (mCurrentNote.type == NoteType.TYPE_TEXT.value) getCurrentNoteText() else mCurrentNote.value val textToExport = if (mCurrentNote.type == NoteType.TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value
if (textToExport == null || textToExport.isEmpty()) { if (textToExport == null || textToExport.isEmpty()) {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
} else if (mCurrentNote.type == NoteType.TYPE_TEXT.value) { } else if (mCurrentNote.type == NoteType.TYPE_TEXT) {
showExportFilePickUpdateDialog(it, textToExport) showExportFilePickUpdateDialog(it, textToExport)
} else { } else {
tryExportNoteValueToFile(it, mCurrentNote.title, textToExport, true) tryExportNoteValueToFile(it, mCurrentNote.title, textToExport, true)
@ -1018,7 +1019,7 @@ class MainActivity : SimpleActivity() {
private fun getCurrentNoteText() = getPagerAdapter().getCurrentNoteViewText(view_pager.currentItem) private fun getCurrentNoteText() = getPagerAdapter().getCurrentNoteViewText(view_pager.currentItem)
private fun getCurrentNoteValue(): String { private fun getCurrentNoteValue(): String {
return if (mCurrentNote.type == NoteType.TYPE_TEXT.value) { return if (mCurrentNote.type == NoteType.TYPE_TEXT) {
getCurrentNoteText() ?: "" getCurrentNoteText() ?: ""
} else { } else {
getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: "" getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: ""
@ -1026,7 +1027,7 @@ class MainActivity : SimpleActivity() {
} }
private fun getPrintableText(): String { private fun getPrintableText(): String {
return if (mCurrentNote.type == NoteType.TYPE_TEXT.value) { return if (mCurrentNote.type == NoteType.TYPE_TEXT) {
getCurrentNoteText() ?: "" getCurrentNoteText() ?: ""
} else { } else {
var printableText = "" var printableText = ""
@ -1041,7 +1042,7 @@ class MainActivity : SimpleActivity() {
private fun saveCurrentNote(force: Boolean) { private fun saveCurrentNote(force: Boolean) {
getPagerAdapter().saveCurrentNote(view_pager.currentItem, force) getPagerAdapter().saveCurrentNote(view_pager.currentItem, force)
if (mCurrentNote.type == NoteType.TYPE_CHECKLIST.value) { if (mCurrentNote.type == NoteType.TYPE_CHECKLIST) {
mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: "" mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: ""
} }
} }
@ -1139,8 +1140,8 @@ class MainActivity : SimpleActivity() {
} }
private fun shareText() { private fun shareText() {
val text = if (mCurrentNote.type == NoteType.TYPE_TEXT.value) getCurrentNoteText() else mCurrentNote.value val text = if (mCurrentNote.type == NoteType.TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value
if (text == null || text.isEmpty()) { if (text.isNullOrEmpty()) {
toast(R.string.cannot_share_empty_text) toast(R.string.cannot_share_empty_text)
return return
} }

View File

@ -27,6 +27,7 @@ import com.simplemobiletools.notes.pro.extensions.widgetsDB
import com.simplemobiletools.notes.pro.helpers.* import com.simplemobiletools.notes.pro.helpers.*
import com.simplemobiletools.notes.pro.models.ChecklistItem import com.simplemobiletools.notes.pro.models.ChecklistItem
import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import com.simplemobiletools.notes.pro.models.Widget import com.simplemobiletools.notes.pro.models.Widget
import kotlinx.android.synthetic.main.widget_config.* import kotlinx.android.synthetic.main.widget_config.*
@ -156,7 +157,7 @@ class WidgetConfigureActivity : SimpleActivity() {
mCurrentNoteId = note.id!! mCurrentNoteId = note.id!!
notes_picker_value.text = note.title notes_picker_value.text = note.title
text_note_view_title.text = note.title text_note_view_title.text = note.title
if (note.type == NoteType.TYPE_CHECKLIST.value) { if (note.type == NoteType.TYPE_CHECKLIST) {
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
val items = Gson().fromJson<ArrayList<ChecklistItem>>(note.value, checklistItemType) ?: ArrayList(1) val items = Gson().fromJson<ArrayList<ChecklistItem>>(note.value, checklistItemType) ?: ArrayList(1)
items.apply { items.apply {

View File

@ -10,8 +10,8 @@ import com.simplemobiletools.notes.pro.fragments.ChecklistFragment
import com.simplemobiletools.notes.pro.fragments.NoteFragment import com.simplemobiletools.notes.pro.fragments.NoteFragment
import com.simplemobiletools.notes.pro.fragments.TextFragment import com.simplemobiletools.notes.pro.fragments.TextFragment
import com.simplemobiletools.notes.pro.helpers.NOTE_ID import com.simplemobiletools.notes.pro.helpers.NOTE_ID
import com.simplemobiletools.notes.pro.helpers.NoteType
import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity: Activity) : FragmentStatePagerAdapter(fm) { class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity: Activity) : FragmentStatePagerAdapter(fm) {
private var fragments: HashMap<Int, NoteFragment> = LinkedHashMap() private var fragments: HashMap<Int, NoteFragment> = LinkedHashMap()
@ -30,7 +30,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
return fragments[position]!! return fragments[position]!!
} }
val fragment = if (note.type == NoteType.TYPE_TEXT.value) TextFragment() else ChecklistFragment() val fragment = if (note.type == NoteType.TYPE_TEXT) TextFragment() else ChecklistFragment()
fragment.arguments = bundle fragment.arguments = bundle
fragments[position] = fragment fragments[position] = fragment
return fragment return fragment

View File

@ -20,6 +20,7 @@ import com.simplemobiletools.notes.pro.extensions.notesDB
import com.simplemobiletools.notes.pro.helpers.* import com.simplemobiletools.notes.pro.helpers.*
import com.simplemobiletools.notes.pro.models.ChecklistItem import com.simplemobiletools.notes.pro.models.ChecklistItem
import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory { class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
private val textIds = arrayOf( private val textIds = arrayOf(
@ -43,7 +44,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
} }
val textSize = context.getPercentageFontSize() / context.resources.displayMetrics.density val textSize = context.getPercentageFontSize() / context.resources.displayMetrics.density
if (note!!.type == NoteType.TYPE_CHECKLIST.value) { if (note!!.type == NoteType.TYPE_CHECKLIST) {
remoteView = RemoteViews(context.packageName, R.layout.item_checklist_widget).apply { remoteView = RemoteViews(context.packageName, R.layout.item_checklist_widget).apply {
val checklistItem = checklistItems.getOrNull(position) ?: return@apply val checklistItem = checklistItems.getOrNull(position) ?: return@apply
val widgetNewTextColor = if (checklistItem.isDone) widgetTextColor.adjustAlpha(DONE_CHECKLIST_ITEM_ALPHA) else widgetTextColor val widgetNewTextColor = if (checklistItem.isDone) widgetTextColor.adjustAlpha(DONE_CHECKLIST_ITEM_ALPHA) else widgetTextColor
@ -123,7 +124,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
widgetTextColor = intent.getIntExtra(WIDGET_TEXT_COLOR, DEFAULT_WIDGET_TEXT_COLOR) widgetTextColor = intent.getIntExtra(WIDGET_TEXT_COLOR, DEFAULT_WIDGET_TEXT_COLOR)
val noteId = intent.getLongExtra(NOTE_ID, 0L) val noteId = intent.getLongExtra(NOTE_ID, 0L)
note = context.notesDB.getNoteWithId(noteId) note = context.notesDB.getNoteWithId(noteId)
if (note?.type == NoteType.TYPE_CHECKLIST.value) { if (note?.type == NoteType.TYPE_CHECKLIST) {
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
checklistItems = Gson().fromJson<ArrayList<ChecklistItem>>(note!!.getNoteStoredValue(context), checklistItemType) ?: ArrayList(1) checklistItems = Gson().fromJson<ArrayList<ChecklistItem>>(note!!.getNoteStoredValue(context), checklistItemType) ?: ArrayList(1)
@ -135,7 +136,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
override fun hasStableIds() = true override fun hasStableIds() = true
override fun getCount(): Int { override fun getCount(): Int {
return if (note?.type == NoteType.TYPE_CHECKLIST.value) { return if (note?.type == NoteType.TYPE_CHECKLIST) {
checklistItems.size checklistItems.size
} else { } else {
1 1

View File

@ -9,10 +9,10 @@ import androidx.sqlite.db.SupportSQLiteDatabase
import com.simplemobiletools.commons.helpers.PROTECTION_NONE import com.simplemobiletools.commons.helpers.PROTECTION_NONE
import com.simplemobiletools.notes.pro.R import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.helpers.DEFAULT_WIDGET_TEXT_COLOR import com.simplemobiletools.notes.pro.helpers.DEFAULT_WIDGET_TEXT_COLOR
import com.simplemobiletools.notes.pro.helpers.NoteType
import com.simplemobiletools.notes.pro.interfaces.NotesDao import com.simplemobiletools.notes.pro.interfaces.NotesDao
import com.simplemobiletools.notes.pro.interfaces.WidgetsDao import com.simplemobiletools.notes.pro.interfaces.WidgetsDao
import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import com.simplemobiletools.notes.pro.models.Widget import com.simplemobiletools.notes.pro.models.Widget
import java.util.concurrent.Executors import java.util.concurrent.Executors
@ -57,7 +57,7 @@ abstract class NotesDatabase : RoomDatabase() {
private fun insertFirstNote(context: Context) { private fun insertFirstNote(context: Context) {
Executors.newSingleThreadScheduledExecutor().execute { Executors.newSingleThreadScheduledExecutor().execute {
val generalNote = context.resources.getString(R.string.general_note) val generalNote = context.resources.getString(R.string.general_note)
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "") val note = Note(null, generalNote, "", NoteType.TYPE_TEXT, "", PROTECTION_NONE, "")
db!!.NotesDao().insertOrUpdate(note) db!!.NotesDao().insertOrUpdate(note)
} }
} }

View File

@ -9,10 +9,11 @@ import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.extensions.notesDB import com.simplemobiletools.notes.pro.extensions.notesDB
import com.simplemobiletools.notes.pro.extensions.parseChecklistItems import com.simplemobiletools.notes.pro.extensions.parseChecklistItems
import com.simplemobiletools.notes.pro.helpers.NoteType
import com.simplemobiletools.notes.pro.helpers.NotesHelper import com.simplemobiletools.notes.pro.helpers.NotesHelper
import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.dialog_import_folder.view.* import com.simplemobiletools.notes.pro.models.NoteType
import kotlinx.android.synthetic.main.dialog_import_folder.view.open_file_filename
import kotlinx.android.synthetic.main.dialog_import_folder.view.open_file_type
import java.io.File import java.io.File
class ImportFolderDialog(val activity: SimpleActivity, val path: String, val callback: () -> Unit) : AlertDialog.Builder(activity) { class ImportFolderDialog(val activity: SimpleActivity, val path: String, val callback: () -> Unit) : AlertDialog.Builder(activity) {
@ -50,21 +51,21 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
activity.notesDB.getNoteIdWithTitle(filename) != null -> false activity.notesDB.getNoteIdWithTitle(filename) != null -> false
else -> true else -> true
} }
}.forEach { }?.forEach {
val storePath = if (updateFilesOnEdit) it.absolutePath else "" val storePath = if (updateFilesOnEdit) it.absolutePath else ""
val title = it.absolutePath.getFilenameFromPath() val title = it.absolutePath.getFilenameFromPath()
val value = if (updateFilesOnEdit) "" else it.readText() val value = if (updateFilesOnEdit) "" else it.readText()
val fileText = it.readText().trim() val fileText = it.readText().trim()
val checklistItems = fileText.parseChecklistItems() val checklistItems = fileText.parseChecklistItems()
if (checklistItems != null) { if (checklistItems != null) {
saveNote(title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value, "") saveNote(title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST, "")
} else { } else {
if (updateFilesOnEdit) { if (updateFilesOnEdit) {
activity.handleSAFDialog(path) { activity.handleSAFDialog(path) {
saveNote(title, value, NoteType.TYPE_TEXT.value, storePath) saveNote(title, value, NoteType.TYPE_TEXT, storePath)
} }
} else { } else {
saveNote(title, value, NoteType.TYPE_TEXT.value, storePath) saveNote(title, value, NoteType.TYPE_TEXT, storePath)
} }
} }
} }
@ -75,7 +76,7 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
} }
} }
private fun saveNote(title: String, value: String, type: Int, path: String) { private fun saveNote(title: String, value: String, type: NoteType, path: String) {
val note = Note(null, title, value, type, path, PROTECTION_NONE, "") val note = Note(null, title, value, type, path, PROTECTION_NONE, "")
NotesHelper(activity).insertOrUpdateNote(note) NotesHelper(activity).insertOrUpdateNote(note)
} }

View File

@ -8,8 +8,8 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.notes.pro.R import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.extensions.config import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.notesDB import com.simplemobiletools.notes.pro.extensions.notesDB
import com.simplemobiletools.notes.pro.helpers.NoteType
import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import kotlinx.android.synthetic.main.dialog_new_note.view.* import kotlinx.android.synthetic.main.dialog_new_note.view.*
class NewNoteDialog(val activity: Activity, title: String? = null, val setChecklistAsDefault: Boolean, callback: (note: Note) -> Unit) { class NewNoteDialog(val activity: Activity, title: String? = null, val setChecklistAsDefault: Boolean, callback: (note: Note) -> Unit) {
@ -40,12 +40,12 @@ class NewNoteDialog(val activity: Activity, title: String? = null, val setCheckl
activity.notesDB.getNoteIdWithTitle(newTitle) != null -> activity.toast(R.string.title_taken) activity.notesDB.getNoteIdWithTitle(newTitle) != null -> activity.toast(R.string.title_taken)
else -> { else -> {
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) { val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) {
NoteType.TYPE_CHECKLIST.value NoteType.TYPE_CHECKLIST
} else { } else {
NoteType.TYPE_TEXT.value NoteType.TYPE_TEXT
} }
activity.config.lastCreatedNoteType = type activity.config.lastCreatedNoteType = type.value
val newNote = Note(null, newTitle, "", type, "", PROTECTION_NONE, "") val newNote = Note(null, newTitle, "", type, "", PROTECTION_NONE, "")
callback(newNote) callback(newNote)
alertDialog.dismiss() alertDialog.dismiss()

View File

@ -9,8 +9,8 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.PROTECTION_NONE import com.simplemobiletools.commons.helpers.PROTECTION_NONE
import com.simplemobiletools.notes.pro.R import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.helpers.NoteType
import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import kotlinx.android.synthetic.main.dialog_open_file.view.* import kotlinx.android.synthetic.main.dialog_open_file.view.*
import java.io.File import java.io.File
@ -47,7 +47,7 @@ class OpenFileDialog(val activity: SimpleActivity, val path: String, val callbac
private fun saveNote(storeContent: String, storePath: String) { private fun saveNote(storeContent: String, storePath: String) {
val filename = path.getFilenameFromPath() val filename = path.getFilenameFromPath()
val note = Note(null, filename, storeContent, NoteType.TYPE_TEXT.value, storePath, PROTECTION_NONE, "") val note = Note(null, filename, storeContent, NoteType.TYPE_TEXT, storePath, PROTECTION_NONE, "")
callback(note) callback(note)
dialog?.dismiss() dialog?.dismiss()
} }

View File

@ -5,6 +5,7 @@ import android.content.Context
import android.os.Environment import android.os.Environment
import android.view.Gravity import android.view.Gravity
import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.commons.helpers.BaseConfig
import com.simplemobiletools.notes.pro.models.NoteType
class Config(context: Context) : BaseConfig(context) { class Config(context: Context) : BaseConfig(context) {
companion object { companion object {

View File

@ -10,6 +10,7 @@ import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.extensions.config import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.notesDB import com.simplemobiletools.notes.pro.extensions.notesDB
import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import java.io.File import java.io.File
class NotesHelper(val context: Context) { class NotesHelper(val context: Context) {
@ -36,7 +37,7 @@ class NotesHelper(val context: Context) {
if (notes.isEmpty()) { if (notes.isEmpty()) {
val generalNote = context.resources.getString(R.string.general_note) val generalNote = context.resources.getString(R.string.general_note)
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "") val note = Note(null, generalNote, "", NoteType.TYPE_TEXT, "", PROTECTION_NONE, "")
context.notesDB.insertOrUpdate(note) context.notesDB.insertOrUpdate(note)
notes.add(note) notes.add(note)
} }

View File

@ -2,23 +2,26 @@ package com.simplemobiletools.notes.pro.models
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import androidx.room.ColumnInfo import androidx.room.*
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
import com.simplemobiletools.commons.extensions.isBiometricIdAvailable import com.simplemobiletools.commons.extensions.isBiometricIdAvailable
import com.simplemobiletools.commons.helpers.PROTECTION_FINGERPRINT import com.simplemobiletools.commons.helpers.PROTECTION_FINGERPRINT
import com.simplemobiletools.commons.helpers.PROTECTION_NONE import com.simplemobiletools.commons.helpers.PROTECTION_NONE
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import java.io.File import java.io.File
/**
* Represents a note.
*
* @property value The content of the note. Could be plain text or [ChecklistItem]
* @property type The type of the note. Should be one of the [NoteType] enum entries.
*/
@Serializable @Serializable
@Entity(tableName = "notes", indices = [(Index(value = ["id"], unique = true))]) @Entity(tableName = "notes", indices = [(Index(value = ["id"], unique = true))])
data class Note( data class Note(
@PrimaryKey(autoGenerate = true) var id: Long?, @PrimaryKey(autoGenerate = true) var id: Long?,
@ColumnInfo(name = "title") var title: String, @ColumnInfo(name = "title") var title: String,
@ColumnInfo(name = "value") var value: String, @ColumnInfo(name = "value") var value: String,
@ColumnInfo(name = "type") var type: Int, @ColumnInfo(name = "type") var type: NoteType,
@ColumnInfo(name = "path") var path: String, @ColumnInfo(name = "path") var path: String,
@ColumnInfo(name = "protection_type") var protectionType: Int, @ColumnInfo(name = "protection_type") var protectionType: Int,
@ColumnInfo(name = "protection_hash") var protectionHash: String @ColumnInfo(name = "protection_hash") var protectionHash: String