mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-05-06 09:58:45 +02:00
create a table for widgets
This commit is contained in:
parent
e7ff0c6e15
commit
d0e731fcb7
@ -109,7 +109,7 @@ class WidgetConfigureActivity : SimpleActivity() {
|
|||||||
val views = RemoteViews(packageName, R.layout.activity_main)
|
val views = RemoteViews(packageName, R.layout.activity_main)
|
||||||
views.setBackgroundColor(R.id.notes_view, mBgColor)
|
views.setBackgroundColor(R.id.notes_view, mBgColor)
|
||||||
AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views)
|
AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views)
|
||||||
val widget = Widget(mWidgetId, mCurrentNoteId)
|
val widget = Widget(null, mWidgetId, mCurrentNoteId)
|
||||||
dbHelper.insertWidget(widget)
|
dbHelper.insertWidget(widget)
|
||||||
|
|
||||||
storeWidgetBackground()
|
storeWidgetBackground()
|
||||||
|
@ -6,15 +6,19 @@ import androidx.room.Room
|
|||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
import com.simplemobiletools.notes.pro.interfaces.NotesDao
|
import com.simplemobiletools.notes.pro.interfaces.NotesDao
|
||||||
|
import com.simplemobiletools.notes.pro.interfaces.WidgetsDao
|
||||||
import com.simplemobiletools.notes.pro.models.Note
|
import com.simplemobiletools.notes.pro.models.Note
|
||||||
|
import com.simplemobiletools.notes.pro.models.Widget
|
||||||
import com.simplemobiletools.notes.pro.objects.MyExecutor
|
import com.simplemobiletools.notes.pro.objects.MyExecutor
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
@Database(entities = [Note::class], version = 1)
|
@Database(entities = [Note::class, Widget::class], version = 1)
|
||||||
abstract class NotesDatabase : RoomDatabase() {
|
abstract class NotesDatabase : RoomDatabase() {
|
||||||
|
|
||||||
abstract fun NotesDao(): NotesDao
|
abstract fun NotesDao(): NotesDao
|
||||||
|
|
||||||
|
abstract fun WidgetsDao(): WidgetsDao
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private var db: NotesDatabase? = null
|
private var db: NotesDatabase? = null
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.simplemobiletools.notes.pro.R
|
|||||||
import com.simplemobiletools.notes.pro.databases.NotesDatabase
|
import com.simplemobiletools.notes.pro.databases.NotesDatabase
|
||||||
import com.simplemobiletools.notes.pro.helpers.*
|
import com.simplemobiletools.notes.pro.helpers.*
|
||||||
import com.simplemobiletools.notes.pro.interfaces.NotesDao
|
import com.simplemobiletools.notes.pro.interfaces.NotesDao
|
||||||
|
import com.simplemobiletools.notes.pro.interfaces.WidgetsDao
|
||||||
|
|
||||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||||
|
|
||||||
@ -15,6 +16,8 @@ val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext)
|
|||||||
|
|
||||||
val Context.notesDB: NotesDao get() = NotesDatabase.getInstance(applicationContext).NotesDao()
|
val Context.notesDB: NotesDao get() = NotesDatabase.getInstance(applicationContext).NotesDao()
|
||||||
|
|
||||||
|
val Context.widgetsDB: WidgetsDao get() = NotesDatabase.getInstance(applicationContext).WidgetsDao()
|
||||||
|
|
||||||
fun Context.getTextSize() = when (config.fontSize) {
|
fun Context.getTextSize() = when (config.fontSize) {
|
||||||
FONT_SIZE_SMALL -> resources.getDimension(R.dimen.smaller_text_size)
|
FONT_SIZE_SMALL -> resources.getDimension(R.dimen.smaller_text_size)
|
||||||
FONT_SIZE_LARGE -> resources.getDimension(R.dimen.big_text_size)
|
FONT_SIZE_LARGE -> resources.getDimension(R.dimen.big_text_size)
|
||||||
|
@ -201,7 +201,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
|
|||||||
do {
|
do {
|
||||||
val widgetId = cursor.getIntValue(COL_WIDGET_ID)
|
val widgetId = cursor.getIntValue(COL_WIDGET_ID)
|
||||||
val noteId = cursor.getIntValue(COL_NOTE_ID)
|
val noteId = cursor.getIntValue(COL_NOTE_ID)
|
||||||
val widget = Widget(widgetId, noteId)
|
val widget = Widget(0, widgetId, noteId)
|
||||||
widgets.add(widget)
|
widgets.add(widget)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.simplemobiletools.notes.pro.interfaces
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.simplemobiletools.notes.pro.models.Widget
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface WidgetsDao {
|
||||||
|
@Query("SELECT * FROM widgets")
|
||||||
|
fun getWidgets(): List<Widget>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun insertOrUpdate(widget: Widget): Long
|
||||||
|
}
|
@ -1,3 +1,12 @@
|
|||||||
package com.simplemobiletools.notes.pro.models
|
package com.simplemobiletools.notes.pro.models
|
||||||
|
|
||||||
data class Widget(var widgetId: Int, var noteId: Int)
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Index
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = "widgets", indices = [(Index(value = ["widget_id"], unique = true))])
|
||||||
|
data class Widget(
|
||||||
|
@PrimaryKey(autoGenerate = true) var id: Int?,
|
||||||
|
@ColumnInfo(name = "widget_id") var widgetId: Int,
|
||||||
|
@ColumnInfo(name = "note_id") var noteId: Int)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user