mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-22 03:20:16 +01:00
lets store the widget text and background colors separately per widget
This commit is contained in:
parent
b71768a0dc
commit
93c6079fa9
@ -150,7 +150,7 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
views.setBackgroundColor(R.id.text_note_view, mBgColor)
|
||||
views.setBackgroundColor(R.id.checklist_note_view, mBgColor)
|
||||
AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views)
|
||||
val widget = Widget(null, mWidgetId, mCurrentNoteId)
|
||||
val widget = Widget(null, mWidgetId, mCurrentNoteId, mBgColor, mTextColor)
|
||||
ensureBackgroundThread {
|
||||
widgetsDB.insertOrUpdate(widget)
|
||||
}
|
||||
|
@ -4,8 +4,11 @@ import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
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.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.helpers.DEFAULT_WIDGET_TEXT_COLOR
|
||||
import com.simplemobiletools.notes.pro.helpers.TYPE_TEXT
|
||||
import com.simplemobiletools.notes.pro.interfaces.NotesDao
|
||||
import com.simplemobiletools.notes.pro.interfaces.WidgetsDao
|
||||
@ -13,7 +16,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 = 1)
|
||||
@Database(entities = [Note::class, Widget::class], version = 2)
|
||||
abstract class NotesDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun NotesDao(): NotesDao
|
||||
@ -34,6 +37,7 @@ abstract class NotesDatabase : RoomDatabase() {
|
||||
insertFirstNote(context)
|
||||
}
|
||||
})
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.build()
|
||||
db!!.openHelper.setWriteAheadLoggingEnabled(true)
|
||||
}
|
||||
@ -53,5 +57,14 @@ abstract class NotesDatabase : RoomDatabase() {
|
||||
db!!.NotesDao().insertOrUpdate(note)
|
||||
}
|
||||
}
|
||||
|
||||
private val MIGRATION_1_2 = object : Migration(1, 2) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.apply {
|
||||
execSQL("ALTER TABLE widgets ADD COLUMN widget_bg_color INTEGER NOT NULL DEFAULT $DEFAULT_WIDGET_BG_COLOR")
|
||||
execSQL("ALTER TABLE widgets ADD COLUMN widget_text_color INTEGER NOT NULL DEFAULT $DEFAULT_WIDGET_TEXT_COLOR")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.simplemobiletools.notes.pro.helpers
|
||||
|
||||
import android.graphics.Color
|
||||
|
||||
const val NOTE_ID = "note_id"
|
||||
const val OPEN_NOTE_ID = "open_note_id"
|
||||
const val DONE_CHECKLIST_ITEM_ALPHA = 0.4f
|
||||
val DEFAULT_WIDGET_TEXT_COLOR = Color.parseColor("#FFF57C00")
|
||||
|
||||
// shared preferences
|
||||
const val CURRENT_NOTE_ID = "current_note_id"
|
||||
|
@ -9,4 +9,6 @@ import androidx.room.PrimaryKey
|
||||
data class Widget(
|
||||
@PrimaryKey(autoGenerate = true) var id: Long?,
|
||||
@ColumnInfo(name = "widget_id") var widgetId: Int,
|
||||
@ColumnInfo(name = "note_id") var noteId: Long)
|
||||
@ColumnInfo(name = "note_id") var noteId: Long,
|
||||
@ColumnInfo(name = "widget_bg_color") var widgetBgColor: Int,
|
||||
@ColumnInfo(name = "widget_text_color") var widgetTextColor: Int)
|
||||
|
Loading…
x
Reference in New Issue
Block a user