Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions app/schemas/com.philkes.notallyx.data.NotallyDatabase/10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"formatVersion": 1,
"database": {
"version": 10,
"identityHash": "8cb21a4c0f6224c35dc6038a4feb74d0",
"entities": [
{
"tableName": "BaseNote",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` TEXT NOT NULL, `folder` TEXT NOT NULL, `color` TEXT NOT NULL, `title` TEXT NOT NULL, `pinned` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `modifiedTimestamp` INTEGER NOT NULL, `labels` TEXT NOT NULL, `body` TEXT NOT NULL, `spans` TEXT NOT NULL, `items` TEXT NOT NULL, `images` TEXT NOT NULL, `files` TEXT NOT NULL, `audios` TEXT NOT NULL, `reminders` TEXT NOT NULL, `viewMode` TEXT NOT NULL, `isPinnedToStatus` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "type",
"columnName": "type",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "folder",
"columnName": "folder",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "color",
"columnName": "color",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "pinned",
"columnName": "pinned",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "timestamp",
"columnName": "timestamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "modifiedTimestamp",
"columnName": "modifiedTimestamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "labels",
"columnName": "labels",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "body",
"columnName": "body",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "spans",
"columnName": "spans",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "items",
"columnName": "items",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "images",
"columnName": "images",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "files",
"columnName": "files",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "audios",
"columnName": "audios",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "reminders",
"columnName": "reminders",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "viewMode",
"columnName": "viewMode",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isPinnedToStatus",
"columnName": "isPinnedToStatus",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [
{
"name": "index_BaseNote_id_folder_pinned_timestamp_labels",
"unique": false,
"columnNames": [
"id",
"folder",
"pinned",
"timestamp",
"labels"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_BaseNote_id_folder_pinned_timestamp_labels` ON `${TABLE_NAME}` (`id`, `folder`, `pinned`, `timestamp`, `labels`)"
}
],
"foreignKeys": []
},
{
"tableName": "Label",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`value` TEXT NOT NULL, PRIMARY KEY(`value`))",
"fields": [
{
"fieldPath": "value",
"columnName": "value",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"value"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '8cb21a4c0f6224c35dc6038a4feb74d0')"
]
}
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@

</receiver>

<receiver android:name=".presentation.activity.note.reminders.ReminderReceiver" android:enabled="true" android:exported="true" >
<receiver android:name=".presentation.activity.note.reminders.ReminderReceiver" android:enabled="true" android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED" />
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/philkes/notallyx/NotallyXApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.work.WorkManager
import com.google.android.material.color.DynamicColors
import com.philkes.notallyx.NotallyXApplication.Companion.AUTO_REMOVE_DELETED_NOTES
import com.philkes.notallyx.NotallyXApplication.Companion.TAG
import com.philkes.notallyx.data.NotallyDatabase
import com.philkes.notallyx.presentation.setEnabledSecureFlag
import com.philkes.notallyx.presentation.view.misc.NotNullLiveData
import com.philkes.notallyx.presentation.viewmodel.preference.BiometricLock
Expand All @@ -26,6 +27,7 @@ import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreference
import com.philkes.notallyx.presentation.viewmodel.preference.Theme
import com.philkes.notallyx.presentation.widget.WidgetProvider
import com.philkes.notallyx.utils.AutoRemoveDeletedNotesWorker
import com.philkes.notallyx.utils.PinnedNotificationManager
import com.philkes.notallyx.utils.backup.AUTO_BACKUP_WORK_NAME
import com.philkes.notallyx.utils.backup.autoBackupOnSave
import com.philkes.notallyx.utils.backup.autoBackupOnSaveFileExists
Expand Down Expand Up @@ -67,6 +69,7 @@ class NotallyXApplication : Application(), Application.ActivityLifecycleCallback
} else {
setTheme(R.style.AppTheme)
}
restorePinnedNotifications()
preferences.theme.observeForeverWithPrevious { (oldTheme, theme) ->
when (theme) {
Theme.DARK,
Expand Down Expand Up @@ -159,6 +162,20 @@ class NotallyXApplication : Application(), Application.ActivityLifecycleCallback
return folderBefore != folderAfter
}

private fun restorePinnedNotifications() {
runOnIODispatcher {
NotallyDatabase.getDatabase(this@NotallyXApplication, false)
.value
.getBaseNoteDao()
.getAllPinnedToStatusNotes()
.forEach { note ->
if (note.isPinnedToStatus) {
PinnedNotificationManager.notify(this@NotallyXApplication, note)
}
}
}
}

private fun checkUpdatePeriodicBackup(
backupFolderBefore: String?,
backupFolder: String,
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/philkes/notallyx/data/NotallyDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import java.io.File
import net.zetetic.database.sqlcipher.SupportOpenHelperFactory

@TypeConverters(Converters::class)
@Database(entities = [BaseNote::class, Label::class], version = 9)
@Database(entities = [BaseNote::class, Label::class], version = 10)
abstract class NotallyDatabase : RoomDatabase() {

abstract fun getLabelDao(): LabelDao
Expand Down Expand Up @@ -161,6 +161,7 @@ abstract class NotallyDatabase : RoomDatabase() {
Migration7,
Migration8,
Migration9,
Migration10,
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
System.loadLibrary("sqlcipher")
Expand Down Expand Up @@ -300,5 +301,14 @@ abstract class NotallyDatabase : RoomDatabase() {
)
}
}

object Migration10 : Migration(9, 10) {

override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"ALTER TABLE `BaseNote` ADD COLUMN `isPinnedToStatus` INTEGER NOT NULL DEFAULT 0"
)
}
}
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/philkes/notallyx/data/dao/BaseNoteDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ interface BaseNoteDao {
@Query("SELECT * FROM BaseNote WHERE folder = 'NOTES' ORDER BY pinned DESC, timestamp DESC")
suspend fun getAllNotes(): List<BaseNote>

@Query(
"SELECT * FROM BaseNote WHERE folder = 'NOTES' AND isPinnedToStatus = 1 ORDER BY timestamp DESC"
)
suspend fun getAllPinnedToStatusNotes(): List<BaseNote>

@Query("SELECT * FROM BaseNote") fun getAllAsync(): LiveData<List<BaseNote>>

@Query("SELECT * FROM BaseNote") fun getAll(): List<BaseNote>
Expand Down Expand Up @@ -155,6 +160,11 @@ interface BaseNoteDao {
@Query("SELECT id, reminders FROM BaseNote WHERE reminders IS NOT NULL AND reminders != '[]'")
suspend fun getAllReminders(): List<NoteIdReminder>

@Query(
"SELECT * FROM BaseNote WHERE folder = 'NOTES' AND ((reminders IS NOT NULL AND reminders != '[]') OR isPinnedToStatus == 1)"
)
suspend fun getAllWithRemindersOrPinned(): List<BaseNote>

@Query("SELECT color FROM BaseNote WHERE id = :id ") fun getColorOfNote(id: Long): String?

@Query(
Expand Down Expand Up @@ -201,6 +211,12 @@ interface BaseNoteDao {
@Query("UPDATE BaseNote SET pinned = :pinned WHERE id IN (:ids)")
suspend fun updatePinned(ids: LongArray, pinned: Boolean)

@Query("UPDATE BaseNote SET isPinnedToStatus = :isPinnedToStatus WHERE id = :id")
fun updatePinnedToStatus(id: Long, isPinnedToStatus: Boolean)

@Query("UPDATE BaseNote SET isPinnedToStatus = :isPinnedToStatus WHERE id IN (:ids)")
fun updatePinnedToStatus(ids: LongArray, isPinnedToStatus: Boolean)

@Query("UPDATE BaseNote SET labels = :labels WHERE id = :id")
suspend fun updateLabels(id: Long, labels: List<String>)

Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/philkes/notallyx/data/dao/DaoExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.philkes.notallyx.data.dao

import android.content.Context
import com.philkes.notallyx.data.model.Folder
import com.philkes.notallyx.utils.cancelPinAndReminders
import com.philkes.notallyx.utils.pinAndScheduleReminders

suspend fun Context.moveBaseNotes(baseNoteDao: BaseNoteDao, ids: LongArray, folder: Folder) {
// Only reminders of notes in NOTES folder are active
if (folder == Folder.DELETED) {
baseNoteDao.move(ids, folder, System.currentTimeMillis())
} else {
baseNoteDao.move(ids, folder)
}
val notes = baseNoteDao.getByIds(ids)
// Only reminders of notes in NOTES folder are active
when (folder) {
Folder.NOTES -> pinAndScheduleReminders(notes)
else -> cancelPinAndReminders(notes)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ fun EvernoteNote.mapToBaseNote(): BaseNote {
audios = audios,
reminders = mutableListOf(),
NoteViewMode.EDIT,
false,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class GoogleKeepImporter : ExternalImporter {
audios = audios,
reminders = mutableListOf(),
NoteViewMode.EDIT,
false,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class PlainTextImporter : ExternalImporter {
audios = listOf(),
reminders = listOf(),
NoteViewMode.EDIT,
false,
)
)
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/philkes/notallyx/data/model/BaseNote.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ data class BaseNote(
val audios: List<Audio>,
val reminders: List<Reminder>,
val viewMode: NoteViewMode,
val isPinnedToStatus: Boolean,
) : Item {

companion object {
Expand Down Expand Up @@ -55,10 +56,20 @@ data class BaseNote(
if (audios != other.audios) return false
if (reminders != other.reminders) return false
if (viewMode != other.viewMode) return false
if (isPinnedToStatus != other.isPinnedToStatus) return false

return true
}

fun equalContents(other: BaseNote?): Boolean {
if (other == null) return false
return type == other.type &&
title == other.title &&
body == other.body &&
spans == other.spans &&
items == other.items
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + type.hashCode()
Expand All @@ -76,6 +87,7 @@ data class BaseNote(
result = 31 * result + audios.hashCode()
result = 31 * result + reminders.hashCode()
result = 31 * result + viewMode.hashCode()
result = 31 * result + isPinnedToStatus.hashCode()
return result
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ fun String.toBaseNote(): BaseNote {
?: COLOR_DEFAULT
val title = jsonObject.getStringOrDefault("title", "")
val pinned = jsonObject.getBooleanOrDefault("pinned", false)
val pinnedToStatusBar = jsonObject.getBooleanOrDefault("isPinnedToStatus", false)
val timestamp = jsonObject.getLongOrDefault("timestamp", System.currentTimeMillis())
val modifiedTimestamp = jsonObject.getLongOrDefault("modifiedTimestamp", timestamp)
val labels = Converters.jsonToLabels(jsonObject.getArrayOrEmpty("labels"))
Expand Down Expand Up @@ -152,6 +153,7 @@ fun String.toBaseNote(): BaseNote {
audios,
reminders,
viewMode,
pinnedToStatusBar,
)
}

Expand Down
Loading