mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-02-02 23:27:33 +01:00
removing some redundant old DB related things
This commit is contained in:
parent
0635dac078
commit
db6642ca9e
@ -1,7 +1,5 @@
|
|||||||
package com.simplemobiletools.notes.pro.helpers
|
package com.simplemobiletools.notes.pro.helpers
|
||||||
|
|
||||||
import android.appwidget.AppWidgetManager
|
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
@ -11,7 +9,6 @@ import android.database.sqlite.SQLiteOpenHelper
|
|||||||
import com.simplemobiletools.commons.extensions.getIntValue
|
import com.simplemobiletools.commons.extensions.getIntValue
|
||||||
import com.simplemobiletools.commons.extensions.getStringValue
|
import com.simplemobiletools.commons.extensions.getStringValue
|
||||||
import com.simplemobiletools.notes.pro.R
|
import com.simplemobiletools.notes.pro.R
|
||||||
import com.simplemobiletools.notes.pro.extensions.config
|
|
||||||
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.models.Widget
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -44,20 +41,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
|
|||||||
insertFirstNote(db)
|
insertFirstNote(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {}
|
||||||
if (oldVersion < 2) {
|
|
||||||
db.execSQL("ALTER TABLE $NOTES_TABLE_NAME ADD COLUMN $COL_TYPE INTEGER DEFAULT 0")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldVersion < 3) {
|
|
||||||
db.execSQL("ALTER TABLE $NOTES_TABLE_NAME ADD COLUMN $COL_PATH TEXT DEFAULT ''")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldVersion < 4) {
|
|
||||||
db.execSQL("CREATE TABLE $WIDGETS_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_WIDGET_ID INTEGER DEFAULT 0, $COL_NOTE_ID INTEGER DEFAULT 0)")
|
|
||||||
insertFirstWidget(db)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun insertFirstNote(db: SQLiteDatabase) {
|
private fun insertFirstNote(db: SQLiteDatabase) {
|
||||||
val generalNote = mContext.resources.getString(R.string.general_note)
|
val generalNote = mContext.resources.getString(R.string.general_note)
|
||||||
@ -65,25 +49,11 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
|
|||||||
insertNote(note, db)
|
insertNote(note, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if a user has exactly 1 widget active, prefill it. Can happen only at upgrading from older app versions
|
|
||||||
private fun insertFirstWidget(db: SQLiteDatabase) {
|
|
||||||
val widgetIDs = AppWidgetManager.getInstance(mContext).getAppWidgetIds(ComponentName(mContext, MyWidgetProvider::class.java))
|
|
||||||
if (widgetIDs.size == 1) {
|
|
||||||
val widget = Widget(widgetIDs.first(), mContext.config.widgetNoteId)
|
|
||||||
insertWidget(widget, db)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun insertNote(note: Note, db: SQLiteDatabase) {
|
private fun insertNote(note: Note, db: SQLiteDatabase) {
|
||||||
val values = fillNoteContentValues(note)
|
val values = fillNoteContentValues(note)
|
||||||
db.insert(NOTES_TABLE_NAME, null, values)
|
db.insert(NOTES_TABLE_NAME, null, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun insertWidget(widget: Widget, db: SQLiteDatabase) {
|
|
||||||
val values = fillWidgetContentValues(widget)
|
|
||||||
db.insert(WIDGETS_TABLE_NAME, null, values)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun insertNote(note: Note): Int {
|
fun insertNote(note: Note): Int {
|
||||||
val values = fillNoteContentValues(note)
|
val values = fillNoteContentValues(note)
|
||||||
return mDb.insertWithOnConflict(NOTES_TABLE_NAME, null, values, CONFLICT_IGNORE).toInt()
|
return mDb.insertWithOnConflict(NOTES_TABLE_NAME, null, values, CONFLICT_IGNORE).toInt()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user