mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
adding widget support too
This commit is contained in:
@ -27,10 +27,7 @@ import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.adapters.NotesPagerAdapter
|
||||
import com.simplemobiletools.notes.pro.databases.NotesDatabase
|
||||
import com.simplemobiletools.notes.pro.dialogs.*
|
||||
import com.simplemobiletools.notes.pro.extensions.config
|
||||
import com.simplemobiletools.notes.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.notes.pro.extensions.getTextSize
|
||||
import com.simplemobiletools.notes.pro.extensions.updateWidgets
|
||||
import com.simplemobiletools.notes.pro.extensions.*
|
||||
import com.simplemobiletools.notes.pro.helpers.MIME_TEXT_PLAIN
|
||||
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
||||
import com.simplemobiletools.notes.pro.helpers.OPEN_NOTE_ID
|
||||
@ -576,7 +573,14 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun doDeleteNote(note: Note, deleteFile: Boolean) {
|
||||
dbHelper.deleteNote(mCurrentNote.id!!)
|
||||
Thread {
|
||||
notesDB.deleteNote(note)
|
||||
widgetsDB.deleteNoteWidgets(note.id!!)
|
||||
refreshNotes(note, deleteFile)
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun refreshNotes(note: Note, deleteFile: Boolean) {
|
||||
NotesHelper(this).getNotes {
|
||||
mNotes = it
|
||||
val firstNoteId = mNotes[0].id
|
||||
|
@ -15,8 +15,8 @@ import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.extensions.config
|
||||
import com.simplemobiletools.notes.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.notes.pro.extensions.getTextSize
|
||||
import com.simplemobiletools.notes.pro.extensions.widgetsDB
|
||||
import com.simplemobiletools.notes.pro.helpers.MyWidgetProvider
|
||||
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
@ -29,7 +29,7 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
private var mBgColor = 0
|
||||
private var mBgColorWithoutTransparency = 0
|
||||
private var mTextColor = 0
|
||||
private var mCurrentNoteId = 0
|
||||
private var mCurrentNoteId = 0L
|
||||
private var mIsCustomizingColors = false
|
||||
private var mNotes = ArrayList<Note>()
|
||||
|
||||
@ -95,14 +95,14 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
items.add(RadioItem(it.id!!.toInt(), it.title))
|
||||
}
|
||||
|
||||
RadioGroupDialog(this, items, mCurrentNoteId) {
|
||||
RadioGroupDialog(this, items, mCurrentNoteId.toInt()) {
|
||||
val selectedId = it as Int
|
||||
updateCurrentNote(mNotes.first { it.id!!.toInt() == selectedId })
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateCurrentNote(note: Note) {
|
||||
mCurrentNoteId = note.id!!.toInt()
|
||||
mCurrentNoteId = note.id!!
|
||||
notes_picker_value.text = note.title
|
||||
val sampleValue = if (note.value.isEmpty() || mIsCustomizingColors) getString(R.string.widget_config) else note.value
|
||||
notes_view.text = sampleValue
|
||||
@ -113,7 +113,9 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
views.setBackgroundColor(R.id.notes_view, mBgColor)
|
||||
AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views)
|
||||
val widget = Widget(null, mWidgetId, mCurrentNoteId)
|
||||
dbHelper.insertWidget(widget)
|
||||
Thread {
|
||||
widgetsDB.insertOrUpdate(widget)
|
||||
}.start()
|
||||
|
||||
storeWidgetBackground()
|
||||
requestWidgetUpdate()
|
||||
|
Reference in New Issue
Block a user