mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-22 19:40:07 +01:00
adding some protection related fields to the Note model
This commit is contained in:
parent
4724eebedc
commit
53182f0507
@ -538,7 +538,7 @@ class MainActivity : SimpleActivity() {
|
||||
val checklistItems = fileText.parseChecklistItems()
|
||||
if (checklistItems != null) {
|
||||
val title = it.absolutePath.getFilenameFromPath().substringBeforeLast('.')
|
||||
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST.value)
|
||||
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
|
||||
displayNewNoteDialog(note.value, title = title, setChecklistAsDefault = true)
|
||||
} else {
|
||||
runOnUiThread {
|
||||
@ -637,10 +637,10 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
if (checklistItems != null) {
|
||||
val note = Note(null, noteTitle, content, NoteType.TYPE_CHECKLIST.value)
|
||||
val note = Note(null, noteTitle, content, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
|
||||
displayNewNoteDialog(note.value, title = noteTitle, setChecklistAsDefault = true)
|
||||
} else if (!canSyncNoteWithFile) {
|
||||
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value)
|
||||
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
|
||||
displayNewNoteDialog(note.value, title = noteTitle, "")
|
||||
} else {
|
||||
val items = arrayListOf(
|
||||
@ -650,7 +650,7 @@ class MainActivity : SimpleActivity() {
|
||||
RadioGroupDialog(this, items) {
|
||||
val syncFile = it as Int == EXPORT_FILE_SYNC
|
||||
val path = if (syncFile) uri.toString() else ""
|
||||
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value)
|
||||
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
|
||||
displayNewNoteDialog(note.value, title = noteTitle, path)
|
||||
}
|
||||
}
|
||||
@ -663,9 +663,9 @@ class MainActivity : SimpleActivity() {
|
||||
val fileText = it.readText().trim()
|
||||
val checklistItems = fileText.parseChecklistItems()
|
||||
val note = if (checklistItems != null) {
|
||||
Note(null, title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value)
|
||||
Note(null, title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
|
||||
} else {
|
||||
Note(null, title, "", NoteType.TYPE_TEXT.value, path)
|
||||
Note(null, title, "", NoteType.TYPE_TEXT.value, path, PROTECTION_NONE, "")
|
||||
}
|
||||
|
||||
if (mNotes.any { it.title.equals(note.title, true) }) {
|
||||
|
@ -7,6 +7,7 @@ import androidx.room.RoomDatabase
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.simplemobiletools.commons.helpers.DEFAULT_WIDGET_BG_COLOR
|
||||
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.helpers.DEFAULT_WIDGET_TEXT_COLOR
|
||||
import com.simplemobiletools.notes.pro.helpers.NoteType
|
||||
@ -16,7 +17,7 @@ import com.simplemobiletools.notes.pro.models.Note
|
||||
import com.simplemobiletools.notes.pro.models.Widget
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
@Database(entities = [Note::class, Widget::class], version = 2)
|
||||
@Database(entities = [Note::class, Widget::class], version = 3)
|
||||
abstract class NotesDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun NotesDao(): NotesDao
|
||||
@ -31,14 +32,15 @@ abstract class NotesDatabase : RoomDatabase() {
|
||||
synchronized(NotesDatabase::class) {
|
||||
if (db == null) {
|
||||
db = Room.databaseBuilder(context.applicationContext, NotesDatabase::class.java, "notes.db")
|
||||
.addCallback(object : Callback() {
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
super.onCreate(db)
|
||||
insertFirstNote(context)
|
||||
}
|
||||
})
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.build()
|
||||
.addCallback(object : Callback() {
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
super.onCreate(db)
|
||||
insertFirstNote(context)
|
||||
}
|
||||
})
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.addMigrations(MIGRATION_2_3)
|
||||
.build()
|
||||
db!!.openHelper.setWriteAheadLoggingEnabled(true)
|
||||
}
|
||||
}
|
||||
@ -53,7 +55,7 @@ abstract class NotesDatabase : RoomDatabase() {
|
||||
private fun insertFirstNote(context: Context) {
|
||||
Executors.newSingleThreadScheduledExecutor().execute {
|
||||
val generalNote = context.resources.getString(R.string.general_note)
|
||||
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value)
|
||||
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
|
||||
db!!.NotesDao().insertOrUpdate(note)
|
||||
}
|
||||
}
|
||||
@ -66,5 +68,14 @@ abstract class NotesDatabase : RoomDatabase() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val MIGRATION_2_3 = object : Migration(2, 3) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.apply {
|
||||
execSQL("ALTER TABLE notes ADD COLUMN protection_type INTEGER DEFAULT $PROTECTION_NONE NOT NULL")
|
||||
execSQL("ALTER TABLE notes ADD COLUMN protection_hash TEXT DEFAULT '' NOT NULL")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.simplemobiletools.commons.extensions.getFilenameFromPath
|
||||
import com.simplemobiletools.commons.extensions.humanizePath
|
||||
import com.simplemobiletools.commons.extensions.isMediaFile
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||
@ -77,7 +78,7 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
|
||||
}
|
||||
|
||||
private fun saveNote(title: String, value: String, type: Int, path: String) {
|
||||
val note = Note(null, title, value, type, path)
|
||||
val note = Note(null, title, value, type, path, PROTECTION_NONE, "")
|
||||
NotesHelper(activity).insertOrUpdateNote(note)
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.showKeyboard
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.value
|
||||
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.extensions.config
|
||||
@ -44,7 +45,7 @@ class NewNoteDialog(val activity: Activity, title: String? = null, val setCheckl
|
||||
else -> {
|
||||
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) NoteType.TYPE_CHECKLIST.value else NoteType.TYPE_TEXT.value
|
||||
activity.config.lastCreatedNoteType = type
|
||||
val newNote = Note(null, title, "", type)
|
||||
val newNote = Note(null, title, "", type, "", PROTECTION_NONE, "")
|
||||
callback(newNote)
|
||||
dismiss()
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.extensions.getFilenameFromPath
|
||||
import com.simplemobiletools.commons.extensions.humanizePath
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.notes.pro.helpers.NoteType
|
||||
@ -45,7 +46,7 @@ class OpenFileDialog(val activity: SimpleActivity, val path: String, val callbac
|
||||
|
||||
private fun saveNote(storeContent: String, storePath: String) {
|
||||
val filename = path.getFilenameFromPath()
|
||||
val note = Note(null, filename, storeContent, NoteType.TYPE_TEXT.value, storePath)
|
||||
val note = Note(null, filename, storeContent, NoteType.TYPE_TEXT.value, storePath, PROTECTION_NONE, "")
|
||||
callback(note)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.extensions.config
|
||||
@ -35,7 +36,7 @@ class NotesHelper(val context: Context) {
|
||||
|
||||
if (notes.isEmpty()) {
|
||||
val generalNote = context.resources.getString(R.string.general_note)
|
||||
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value)
|
||||
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
|
||||
context.notesDB.insertOrUpdate(note)
|
||||
notes.add(note)
|
||||
}
|
||||
|
@ -14,7 +14,9 @@ data class Note(
|
||||
@ColumnInfo(name = "title") var title: String,
|
||||
@ColumnInfo(name = "value") var value: String,
|
||||
@ColumnInfo(name = "type") var type: Int,
|
||||
@ColumnInfo(name = "path") var path: String = "") {
|
||||
@ColumnInfo(name = "path") var path: String,
|
||||
@ColumnInfo(name = "protection_type") var protectionType: Int,
|
||||
@ColumnInfo(name = "protection_hash") var protectionHash: String) {
|
||||
|
||||
fun getNoteStoredValue(context: Context): String? {
|
||||
return if (path.isNotEmpty()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user