fix: apply colors to all widgets (#211)

Refs: https://github.com/FossifyOrg/Notes/issues/201
This commit is contained in:
Agnieszka C
2025-08-30 19:20:38 +02:00
committed by GitHub
parent 3707294108
commit 479eb22e48
5 changed files with 33 additions and 35 deletions

View File

@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Fixed
- Fixed widgets customization ([#201])
## [1.4.0] - 2025-07-15
### Added
@@ -73,6 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#157]: https://github.com/FossifyOrg/Notes/issues/157
[#164]: https://github.com/FossifyOrg/Notes/issues/164
[#178]: https://github.com/FossifyOrg/Notes/issues/178
[#201]: https://github.com/FossifyOrg/Notes/issues/201
[Unreleased]: https://github.com/FossifyOrg/Notes/compare/1.4.0...HEAD
[1.4.0]: https://github.com/FossifyOrg/Notes/compare/1.3.1...1.4.0

View File

@@ -9,7 +9,6 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.text.TextUtilsCompat
import androidx.core.view.ViewCompat
import kotlinx.serialization.SerializationException
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.fossify.commons.dialogs.ConfirmationDialog
import org.fossify.commons.dialogs.PermissionRequiredDialog
@@ -45,12 +44,7 @@ import org.fossify.notes.extensions.requestUnlockNotes
import org.fossify.notes.extensions.scheduleNextAutomaticBackup
import org.fossify.notes.extensions.updateWidgets
import org.fossify.notes.extensions.widgetsDB
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_BG_COLOR
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_ID
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_KEY_ID
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_NOTE_ID
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_SHOW_TITLE
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_TEXT_COLOR
import org.fossify.notes.helpers.ALL_WIDGET_IDS
import org.fossify.notes.helpers.FONT_SIZE_100_PERCENT
import org.fossify.notes.helpers.FONT_SIZE_125_PERCENT
import org.fossify.notes.helpers.FONT_SIZE_150_PERCENT
@@ -67,7 +61,6 @@ import org.fossify.notes.helpers.GRAVITY_END
import org.fossify.notes.helpers.GRAVITY_START
import org.fossify.notes.helpers.NotesHelper
import org.fossify.notes.models.Note
import org.fossify.notes.models.Widget
import java.util.Locale
import kotlin.system.exitProcess
@@ -343,30 +336,19 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupCustomizeWidgetColors() {
var widgetToCustomize: Widget? = null
var allWidgetIds = intArrayOf()
binding.settingsWidgetColorCustomizationHolder.setOnClickListener {
Intent(this, WidgetConfigureActivity::class.java).apply {
putExtra(IS_CUSTOMIZING_COLORS, true)
widgetToCustomize?.apply {
putExtra(CUSTOMIZED_WIDGET_ID, widgetId)
putExtra(CUSTOMIZED_WIDGET_KEY_ID, id)
putExtra(CUSTOMIZED_WIDGET_NOTE_ID, noteId)
putExtra(CUSTOMIZED_WIDGET_BG_COLOR, widgetBgColor)
putExtra(CUSTOMIZED_WIDGET_TEXT_COLOR, widgetTextColor)
putExtra(CUSTOMIZED_WIDGET_SHOW_TITLE, widgetShowTitle)
}
putExtra(ALL_WIDGET_IDS, allWidgetIds)
startActivity(this)
}
}
ensureBackgroundThread {
val widgets = widgetsDB.getWidgets().filter { it.widgetId != 0 }
if (widgets.size == 1) {
widgetToCustomize = widgets.first()
}
allWidgetIds = widgets.map { it.widgetId }.toIntArray()
}
}

View File

@@ -41,6 +41,7 @@ class WidgetConfigureActivity : SimpleActivity() {
private var mIsCustomizingColors = false
private var mShowTitle = false
private var mNotes = listOf<Note>()
private var mAllWidgetIds = intArrayOf()
private val binding by viewBinding(WidgetConfigBinding::inflate)
public override fun onCreate(savedInstanceState: Bundle?) {
@@ -107,6 +108,7 @@ class WidgetConfigureActivity : SimpleActivity() {
updateTextColor()
mIsCustomizingColors = extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false
mAllWidgetIds = extras?.getIntArray(ALL_WIDGET_IDS) ?: intArrayOf()
binding.notesPickerHolder.beVisibleIf(!mIsCustomizingColors)
binding.textNoteViewTitle.beGoneIf(!mShowTitle)
@@ -189,23 +191,29 @@ class WidgetConfigureActivity : SimpleActivity() {
}
private fun saveConfig() {
if (mCurrentNoteId == 0L) {
if (!mIsCustomizingColors && mCurrentNoteId == 0L) {
finish()
return
}
val views = RemoteViews(packageName, R.layout.activity_main)
views.setBackgroundColor(R.id.text_note_view, mBgColor)
views.setBackgroundColor(R.id.checklist_note_view, mBgColor)
AppWidgetManager.getInstance(this)?.updateAppWidget(mWidgetId, views) ?: return
if (!mIsCustomizingColors) {
val views = RemoteViews(packageName, R.layout.activity_main)
views.setBackgroundColor(R.id.text_note_view, mBgColor)
views.setBackgroundColor(R.id.checklist_note_view, mBgColor)
AppWidgetManager.getInstance(this)?.updateAppWidget(mWidgetId, views) ?: return
val extras = intent.extras
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, mShowTitle)
ensureBackgroundThread {
widgetsDB.insertOrUpdate(widget)
val extras = intent.extras
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, mShowTitle)
ensureBackgroundThread {
widgetsDB.insertOrUpdate(widget)
}
} else {
ensureBackgroundThread {
widgetsDB.updateWidgetColors(mBgColor, mTextColor)
}
}
storeWidgetBackground()
@@ -226,8 +234,9 @@ class WidgetConfigureActivity : SimpleActivity() {
}
private fun requestWidgetUpdate() {
val widgetIds = if (mAllWidgetIds.isNotEmpty()) mAllWidgetIds else intArrayOf(mWidgetId)
Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetProvider::class.java).apply {
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(mWidgetId))
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds)
sendBroadcast(this)
}
}

View File

@@ -12,6 +12,7 @@ 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"
const val ALL_WIDGET_IDS = "all_widget_ids"
const val SHORTCUT_NEW_TEXT_NOTE = "shortcut_new_text_note"
const val SHORTCUT_NEW_CHECKLIST = "shortcut_new_checklist"
const val NEW_TEXT_NOTE = "new_text_note"

View File

@@ -22,4 +22,7 @@ interface WidgetsDao {
@Query("DELETE FROM widgets WHERE widget_id = :widgetId")
fun deleteWidgetId(widgetId: Int)
@Query("UPDATE widgets SET widget_bg_color = :bgColor, widget_text_color = :textColor")
fun updateWidgetColors(bgColor: Int, textColor: Int)
}