Skip to content

Commit 93c6079

Browse files
committed
lets store the widget text and background colors separately per widget
1 parent b71768a commit 93c6079

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class WidgetConfigureActivity : SimpleActivity() {
150150
views.setBackgroundColor(R.id.text_note_view, mBgColor)
151151
views.setBackgroundColor(R.id.checklist_note_view, mBgColor)
152152
AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views)
153-
val widget = Widget(null, mWidgetId, mCurrentNoteId)
153+
val widget = Widget(null, mWidgetId, mCurrentNoteId, mBgColor, mTextColor)
154154
ensureBackgroundThread {
155155
widgetsDB.insertOrUpdate(widget)
156156
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ import android.content.Context
44
import androidx.room.Database
55
import androidx.room.Room
66
import androidx.room.RoomDatabase
7+
import androidx.room.migration.Migration
78
import androidx.sqlite.db.SupportSQLiteDatabase
9+
import com.simplemobiletools.commons.helpers.DEFAULT_WIDGET_BG_COLOR
810
import com.simplemobiletools.notes.pro.R
11+
import com.simplemobiletools.notes.pro.helpers.DEFAULT_WIDGET_TEXT_COLOR
912
import com.simplemobiletools.notes.pro.helpers.TYPE_TEXT
1013
import com.simplemobiletools.notes.pro.interfaces.NotesDao
1114
import com.simplemobiletools.notes.pro.interfaces.WidgetsDao
1215
import com.simplemobiletools.notes.pro.models.Note
1316
import com.simplemobiletools.notes.pro.models.Widget
1417
import java.util.concurrent.Executors
1518

16-
@Database(entities = [Note::class, Widget::class], version = 1)
19+
@Database(entities = [Note::class, Widget::class], version = 2)
1720
abstract class NotesDatabase : RoomDatabase() {
1821

1922
abstract fun NotesDao(): NotesDao
@@ -34,6 +37,7 @@ abstract class NotesDatabase : RoomDatabase() {
3437
insertFirstNote(context)
3538
}
3639
})
40+
.addMigrations(MIGRATION_1_2)
3741
.build()
3842
db!!.openHelper.setWriteAheadLoggingEnabled(true)
3943
}
@@ -53,5 +57,14 @@ abstract class NotesDatabase : RoomDatabase() {
5357
db!!.NotesDao().insertOrUpdate(note)
5458
}
5559
}
60+
61+
private val MIGRATION_1_2 = object : Migration(1, 2) {
62+
override fun migrate(database: SupportSQLiteDatabase) {
63+
database.apply {
64+
execSQL("ALTER TABLE widgets ADD COLUMN widget_bg_color INTEGER NOT NULL DEFAULT $DEFAULT_WIDGET_BG_COLOR")
65+
execSQL("ALTER TABLE widgets ADD COLUMN widget_text_color INTEGER NOT NULL DEFAULT $DEFAULT_WIDGET_TEXT_COLOR")
66+
}
67+
}
68+
}
5669
}
5770
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.simplemobiletools.notes.pro.helpers
22

3+
import android.graphics.Color
4+
35
const val NOTE_ID = "note_id"
46
const val OPEN_NOTE_ID = "open_note_id"
57
const val DONE_CHECKLIST_ITEM_ALPHA = 0.4f
8+
val DEFAULT_WIDGET_TEXT_COLOR = Color.parseColor("#FFF57C00")
69

710
// shared preferences
811
const val CURRENT_NOTE_ID = "current_note_id"

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ import androidx.room.PrimaryKey
99
data class Widget(
1010
@PrimaryKey(autoGenerate = true) var id: Long?,
1111
@ColumnInfo(name = "widget_id") var widgetId: Int,
12-
@ColumnInfo(name = "note_id") var noteId: Long)
12+
@ColumnInfo(name = "note_id") var noteId: Long,
13+
@ColumnInfo(name = "widget_bg_color") var widgetBgColor: Int,
14+
@ColumnInfo(name = "widget_text_color") var widgetTextColor: Int)

0 commit comments

Comments
 (0)