mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
Added note title to widget (#268)
This commit is contained in:
@ -227,6 +227,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
putExtra(CUSTOMIZED_WIDGET_NOTE_ID, noteId)
|
||||
putExtra(CUSTOMIZED_WIDGET_BG_COLOR, widgetBgColor)
|
||||
putExtra(CUSTOMIZED_WIDGET_TEXT_COLOR, widgetTextColor)
|
||||
putExtra(CUSTOMIZED_WIDGET_SHOW_TITLE, widgetShowTitle)
|
||||
}
|
||||
|
||||
startActivity(this)
|
||||
|
@ -38,6 +38,7 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
private var mTextColor = 0
|
||||
private var mCurrentNoteId = 0L
|
||||
private var mIsCustomizingColors = false
|
||||
private var mShowTitle = false
|
||||
private var mNotes = ArrayList<Note>()
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -59,6 +60,10 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
config_text_color.setOnClickListener { pickTextColor() }
|
||||
notes_picker_value.setOnClickListener { showNoteSelector() }
|
||||
notes_picker_holder.background = ColorDrawable(config.backgroundColor)
|
||||
show_note_title_holder.setOnClickListener {
|
||||
show_note_title.toggle()
|
||||
handleNoteTitleDisplay()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@ -73,12 +78,13 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
|
||||
private fun initVariables() {
|
||||
val extras = intent.extras
|
||||
if (extras?.getLong(CUSTOMIZED_WIDGET_ID, 0L) == 0L) {
|
||||
if (extras?.getInt(CUSTOMIZED_WIDGET_ID, 0) == 0) {
|
||||
mBgColor = config.widgetBgColor
|
||||
mTextColor = config.widgetTextColor
|
||||
} else {
|
||||
mBgColor = extras?.getInt(CUSTOMIZED_WIDGET_BG_COLOR) ?: config.widgetBgColor
|
||||
mTextColor = extras?.getInt(CUSTOMIZED_WIDGET_TEXT_COLOR) ?: config.widgetTextColor
|
||||
mShowTitle = extras?.getBoolean(CUSTOMIZED_WIDGET_SHOW_TITLE) ?: false
|
||||
}
|
||||
|
||||
mBgAlpha = Color.alpha(mBgColor) / 255.toFloat()
|
||||
@ -97,6 +103,7 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
updateTextColor()
|
||||
mIsCustomizingColors = extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false
|
||||
notes_picker_holder.beVisibleIf(!mIsCustomizingColors)
|
||||
text_note_view_title.beGoneIf(!mShowTitle)
|
||||
|
||||
NotesHelper(this).getNotes {
|
||||
mNotes = it
|
||||
@ -145,6 +152,7 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
private fun updateCurrentNote(note: Note) {
|
||||
mCurrentNoteId = note.id!!
|
||||
notes_picker_value.text = note.title
|
||||
text_note_view_title.text = note.title
|
||||
if (note.type == NoteType.TYPE_CHECKLIST.value) {
|
||||
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
||||
val items = Gson().fromJson<ArrayList<ChecklistItem>>(note.value, checklistItemType) ?: ArrayList(1)
|
||||
@ -188,7 +196,7 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
val id = if (extras?.containsKey(CUSTOMIZED_WIDGET_KEY_ID) == true) extras.getLong(CUSTOMIZED_WIDGET_KEY_ID) else null
|
||||
mWidgetId = extras?.getInt(CUSTOMIZED_WIDGET_ID, mWidgetId) ?: mWidgetId
|
||||
mCurrentNoteId = extras?.getLong(CUSTOMIZED_WIDGET_NOTE_ID, mCurrentNoteId) ?: mCurrentNoteId
|
||||
val widget = Widget(id, mWidgetId, mCurrentNoteId, mBgColor, mTextColor)
|
||||
val widget = Widget(id, mWidgetId, mCurrentNoteId, mBgColor, mTextColor, mShowTitle)
|
||||
ensureBackgroundThread {
|
||||
widgetsDB.insertOrUpdate(widget)
|
||||
}
|
||||
@ -222,12 +230,14 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
text_note_view.setBackgroundColor(mBgColor)
|
||||
checklist_note_view.setBackgroundColor(mBgColor)
|
||||
config_save.setBackgroundColor(mBgColor)
|
||||
text_note_view_title.setBackgroundColor(mBgColor)
|
||||
config_bg_color.setFillWithStroke(mBgColor, Color.BLACK)
|
||||
}
|
||||
|
||||
private fun updateTextColor() {
|
||||
config_save.setTextColor(mTextColor)
|
||||
text_note_view.setTextColor(mTextColor)
|
||||
text_note_view_title.setTextColor(mTextColor)
|
||||
(checklist_note_view.adapter as? ChecklistAdapter)?.updateTextColor(mTextColor)
|
||||
config_text_color.setFillWithStroke(mTextColor, Color.BLACK)
|
||||
}
|
||||
@ -249,4 +259,10 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleNoteTitleDisplay() {
|
||||
val showTitle = show_note_title.isChecked
|
||||
text_note_view_title.beGoneIf(!showTitle)
|
||||
mShowTitle = showTitle
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,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 = 3)
|
||||
@Database(entities = [Note::class, Widget::class], version = 4)
|
||||
abstract class NotesDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun NotesDao(): NotesDao
|
||||
@ -40,6 +40,7 @@ abstract class NotesDatabase : RoomDatabase() {
|
||||
})
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.addMigrations(MIGRATION_2_3)
|
||||
.addMigrations(MIGRATION_3_4)
|
||||
.build()
|
||||
db!!.openHelper.setWriteAheadLoggingEnabled(true)
|
||||
}
|
||||
@ -77,5 +78,13 @@ abstract class NotesDatabase : RoomDatabase() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val MIGRATION_3_4 = object : Migration(3, 4) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.apply {
|
||||
execSQL("ALTER TABLE widgets ADD COLUMN widget_show_title INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.notes.pro.extensions.config
|
||||
import com.simplemobiletools.notes.pro.extensions.notesDB
|
||||
import com.simplemobiletools.notes.pro.extensions.updateWidgets
|
||||
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
import kotlinx.android.synthetic.main.dialog_new_note.view.*
|
||||
@ -78,6 +79,8 @@ class RenameNoteDialog(val activity: SimpleActivity, val note: Note, val current
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
activity.baseContext.updateWidgets()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ const val CUSTOMIZED_WIDGET_KEY_ID = "customized_widget_key_id"
|
||||
const val CUSTOMIZED_WIDGET_NOTE_ID = "customized_widget_note_id"
|
||||
const val CUSTOMIZED_WIDGET_BG_COLOR = "customized_widget_bg_color"
|
||||
const val CUSTOMIZED_WIDGET_TEXT_COLOR = "customized_widget_text_color"
|
||||
const val CUSTOMIZED_WIDGET_SHOW_TITLE = "customized_widget_show_title"
|
||||
val DEFAULT_WIDGET_TEXT_COLOR = Color.parseColor("#FFF57C00")
|
||||
|
||||
// shared preferences
|
||||
|
@ -9,10 +9,13 @@ import android.net.Uri
|
||||
import android.widget.RemoteViews
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.getLaunchIntent
|
||||
import com.simplemobiletools.commons.extensions.setText
|
||||
import com.simplemobiletools.commons.extensions.setVisibleIf
|
||||
import com.simplemobiletools.commons.helpers.WIDGET_TEXT_COLOR
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SplashActivity
|
||||
import com.simplemobiletools.notes.pro.extensions.notesDB
|
||||
import com.simplemobiletools.notes.pro.extensions.widgetsDB
|
||||
import com.simplemobiletools.notes.pro.models.Widget
|
||||
import com.simplemobiletools.notes.pro.services.WidgetService
|
||||
@ -31,7 +34,11 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
for (widgetId in appWidgetIds) {
|
||||
val widget = context.widgetsDB.getWidgetWithWidgetId(widgetId) ?: continue
|
||||
val views = RemoteViews(context.packageName, R.layout.widget)
|
||||
val note = context.notesDB.getNoteWithId(widget.noteId)
|
||||
views.applyColorFilter(R.id.notes_widget_background, widget.widgetBgColor)
|
||||
views.setTextColor(R.id.widget_note_title, widget.widgetTextColor)
|
||||
views.setText(R.id.widget_note_title, note?.title ?: "")
|
||||
views.setVisibleIf(R.id.widget_note_title, widget.widgetShowTitle)
|
||||
setupAppOpenIntent(context, views, R.id.notes_widget_holder, widget)
|
||||
|
||||
Intent(context, WidgetService::class.java).apply {
|
||||
|
@ -11,4 +11,5 @@ data class Widget(
|
||||
@ColumnInfo(name = "widget_id") var widgetId: Int,
|
||||
@ColumnInfo(name = "note_id") var noteId: Long,
|
||||
@ColumnInfo(name = "widget_bg_color") var widgetBgColor: Int,
|
||||
@ColumnInfo(name = "widget_text_color") var widgetTextColor: Int)
|
||||
@ColumnInfo(name = "widget_text_color") var widgetTextColor: Int,
|
||||
@ColumnInfo(name = "widget_show_title") var widgetShowTitle: Boolean)
|
||||
|
Reference in New Issue
Block a user