Skip to content

Commit 53182f0

Browse files
committed
adding some protection related fields to the Note model
1 parent 4724eeb commit 53182f0

File tree

7 files changed

+38
-21
lines changed

7 files changed

+38
-21
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ class MainActivity : SimpleActivity() {
538538
val checklistItems = fileText.parseChecklistItems()
539539
if (checklistItems != null) {
540540
val title = it.absolutePath.getFilenameFromPath().substringBeforeLast('.')
541-
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST.value)
541+
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
542542
displayNewNoteDialog(note.value, title = title, setChecklistAsDefault = true)
543543
} else {
544544
runOnUiThread {
@@ -637,10 +637,10 @@ class MainActivity : SimpleActivity() {
637637
}
638638

639639
if (checklistItems != null) {
640-
val note = Note(null, noteTitle, content, NoteType.TYPE_CHECKLIST.value)
640+
val note = Note(null, noteTitle, content, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
641641
displayNewNoteDialog(note.value, title = noteTitle, setChecklistAsDefault = true)
642642
} else if (!canSyncNoteWithFile) {
643-
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value)
643+
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
644644
displayNewNoteDialog(note.value, title = noteTitle, "")
645645
} else {
646646
val items = arrayListOf(
@@ -650,7 +650,7 @@ class MainActivity : SimpleActivity() {
650650
RadioGroupDialog(this, items) {
651651
val syncFile = it as Int == EXPORT_FILE_SYNC
652652
val path = if (syncFile) uri.toString() else ""
653-
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value)
653+
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
654654
displayNewNoteDialog(note.value, title = noteTitle, path)
655655
}
656656
}
@@ -663,9 +663,9 @@ class MainActivity : SimpleActivity() {
663663
val fileText = it.readText().trim()
664664
val checklistItems = fileText.parseChecklistItems()
665665
val note = if (checklistItems != null) {
666-
Note(null, title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value)
666+
Note(null, title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
667667
} else {
668-
Note(null, title, "", NoteType.TYPE_TEXT.value, path)
668+
Note(null, title, "", NoteType.TYPE_TEXT.value, path, PROTECTION_NONE, "")
669669
}
670670

671671
if (mNotes.any { it.title.equals(note.title, true) }) {

app/src/main/kotlin/com/simplemobiletools/notes/pro/databases/NotesDatabase.kt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.room.RoomDatabase
77
import androidx.room.migration.Migration
88
import androidx.sqlite.db.SupportSQLiteDatabase
99
import com.simplemobiletools.commons.helpers.DEFAULT_WIDGET_BG_COLOR
10+
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
1011
import com.simplemobiletools.notes.pro.R
1112
import com.simplemobiletools.notes.pro.helpers.DEFAULT_WIDGET_TEXT_COLOR
1213
import com.simplemobiletools.notes.pro.helpers.NoteType
@@ -16,7 +17,7 @@ import com.simplemobiletools.notes.pro.models.Note
1617
import com.simplemobiletools.notes.pro.models.Widget
1718
import java.util.concurrent.Executors
1819

19-
@Database(entities = [Note::class, Widget::class], version = 2)
20+
@Database(entities = [Note::class, Widget::class], version = 3)
2021
abstract class NotesDatabase : RoomDatabase() {
2122

2223
abstract fun NotesDao(): NotesDao
@@ -31,14 +32,15 @@ abstract class NotesDatabase : RoomDatabase() {
3132
synchronized(NotesDatabase::class) {
3233
if (db == null) {
3334
db = Room.databaseBuilder(context.applicationContext, NotesDatabase::class.java, "notes.db")
34-
.addCallback(object : Callback() {
35-
override fun onCreate(db: SupportSQLiteDatabase) {
36-
super.onCreate(db)
37-
insertFirstNote(context)
38-
}
39-
})
40-
.addMigrations(MIGRATION_1_2)
41-
.build()
35+
.addCallback(object : Callback() {
36+
override fun onCreate(db: SupportSQLiteDatabase) {
37+
super.onCreate(db)
38+
insertFirstNote(context)
39+
}
40+
})
41+
.addMigrations(MIGRATION_1_2)
42+
.addMigrations(MIGRATION_2_3)
43+
.build()
4244
db!!.openHelper.setWriteAheadLoggingEnabled(true)
4345
}
4446
}
@@ -53,7 +55,7 @@ abstract class NotesDatabase : RoomDatabase() {
5355
private fun insertFirstNote(context: Context) {
5456
Executors.newSingleThreadScheduledExecutor().execute {
5557
val generalNote = context.resources.getString(R.string.general_note)
56-
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value)
58+
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
5759
db!!.NotesDao().insertOrUpdate(note)
5860
}
5961
}
@@ -66,5 +68,14 @@ abstract class NotesDatabase : RoomDatabase() {
6668
}
6769
}
6870
}
71+
72+
private val MIGRATION_2_3 = object : Migration(2, 3) {
73+
override fun migrate(database: SupportSQLiteDatabase) {
74+
database.apply {
75+
execSQL("ALTER TABLE notes ADD COLUMN protection_type INTEGER DEFAULT $PROTECTION_NONE NOT NULL")
76+
execSQL("ALTER TABLE notes ADD COLUMN protection_hash TEXT DEFAULT '' NOT NULL")
77+
}
78+
}
79+
}
6980
}
7081
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ImportFolderDialog.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.simplemobiletools.commons.extensions.getFilenameFromPath
66
import com.simplemobiletools.commons.extensions.humanizePath
77
import com.simplemobiletools.commons.extensions.isMediaFile
88
import com.simplemobiletools.commons.extensions.setupDialogStuff
9+
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
910
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
1011
import com.simplemobiletools.notes.pro.R
1112
import com.simplemobiletools.notes.pro.activities.SimpleActivity
@@ -77,7 +78,7 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
7778
}
7879

7980
private fun saveNote(title: String, value: String, type: Int, path: String) {
80-
val note = Note(null, title, value, type, path)
81+
val note = Note(null, title, value, type, path, PROTECTION_NONE, "")
8182
NotesHelper(activity).insertOrUpdateNote(note)
8283
}
8384
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewNoteDialog.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
77
import com.simplemobiletools.commons.extensions.showKeyboard
88
import com.simplemobiletools.commons.extensions.toast
99
import com.simplemobiletools.commons.extensions.value
10+
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
1011
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
1112
import com.simplemobiletools.notes.pro.R
1213
import com.simplemobiletools.notes.pro.extensions.config
@@ -44,7 +45,7 @@ class NewNoteDialog(val activity: Activity, title: String? = null, val setCheckl
4445
else -> {
4546
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) NoteType.TYPE_CHECKLIST.value else NoteType.TYPE_TEXT.value
4647
activity.config.lastCreatedNoteType = type
47-
val newNote = Note(null, title, "", type)
48+
val newNote = Note(null, title, "", type, "", PROTECTION_NONE, "")
4849
callback(newNote)
4950
dismiss()
5051
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenFileDialog.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.appcompat.app.AlertDialog
55
import com.simplemobiletools.commons.extensions.getFilenameFromPath
66
import com.simplemobiletools.commons.extensions.humanizePath
77
import com.simplemobiletools.commons.extensions.setupDialogStuff
8+
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
89
import com.simplemobiletools.notes.pro.R
910
import com.simplemobiletools.notes.pro.activities.SimpleActivity
1011
import com.simplemobiletools.notes.pro.helpers.NoteType
@@ -45,7 +46,7 @@ class OpenFileDialog(val activity: SimpleActivity, val path: String, val callbac
4546

4647
private fun saveNote(storeContent: String, storePath: String) {
4748
val filename = path.getFilenameFromPath()
48-
val note = Note(null, filename, storeContent, NoteType.TYPE_TEXT.value, storePath)
49+
val note = Note(null, filename, storeContent, NoteType.TYPE_TEXT.value, storePath, PROTECTION_NONE, "")
4950
callback(note)
5051
dialog.dismiss()
5152
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/NotesHelper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.net.Uri
55
import android.os.Handler
66
import android.os.Looper
7+
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
78
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
89
import com.simplemobiletools.notes.pro.R
910
import com.simplemobiletools.notes.pro.extensions.config
@@ -35,7 +36,7 @@ class NotesHelper(val context: Context) {
3536

3637
if (notes.isEmpty()) {
3738
val generalNote = context.resources.getString(R.string.general_note)
38-
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value)
39+
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
3940
context.notesDB.insertOrUpdate(note)
4041
notes.add(note)
4142
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/models/Note.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ data class Note(
1414
@ColumnInfo(name = "title") var title: String,
1515
@ColumnInfo(name = "value") var value: String,
1616
@ColumnInfo(name = "type") var type: Int,
17-
@ColumnInfo(name = "path") var path: String = "") {
17+
@ColumnInfo(name = "path") var path: String,
18+
@ColumnInfo(name = "protection_type") var protectionType: Int,
19+
@ColumnInfo(name = "protection_hash") var protectionHash: String) {
1820

1921
fun getNoteStoredValue(context: Context): String? {
2022
return if (path.isNotEmpty()) {

0 commit comments

Comments
 (0)