Skip to content

Commit 479eb22

Browse files
authored
fix: apply colors to all widgets (#211)
Refs: #201
1 parent 3707294 commit 479eb22

File tree

5 files changed

+34
-36
lines changed

5 files changed

+34
-36
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Fixed widgets customization ([#201])
810

911
## [1.4.0] - 2025-07-15
1012
### Added
@@ -73,6 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7375
[#157]: https://github.com/FossifyOrg/Notes/issues/157
7476
[#164]: https://github.com/FossifyOrg/Notes/issues/164
7577
[#178]: https://github.com/FossifyOrg/Notes/issues/178
78+
[#201]: https://github.com/FossifyOrg/Notes/issues/201
7679

7780
[Unreleased]: https://github.com/FossifyOrg/Notes/compare/1.4.0...HEAD
7881
[1.4.0]: https://github.com/FossifyOrg/Notes/compare/1.3.1...1.4.0

app/src/main/kotlin/org/fossify/notes/activities/SettingsActivity.kt

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.activity.result.contract.ActivityResultContracts
99
import androidx.core.text.TextUtilsCompat
1010
import androidx.core.view.ViewCompat
1111
import kotlinx.serialization.SerializationException
12-
import kotlinx.serialization.encodeToString
1312
import kotlinx.serialization.json.Json
1413
import org.fossify.commons.dialogs.ConfirmationDialog
1514
import org.fossify.commons.dialogs.PermissionRequiredDialog
@@ -45,12 +44,7 @@ import org.fossify.notes.extensions.requestUnlockNotes
4544
import org.fossify.notes.extensions.scheduleNextAutomaticBackup
4645
import org.fossify.notes.extensions.updateWidgets
4746
import org.fossify.notes.extensions.widgetsDB
48-
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_BG_COLOR
49-
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_ID
50-
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_KEY_ID
51-
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_NOTE_ID
52-
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_SHOW_TITLE
53-
import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_TEXT_COLOR
47+
import org.fossify.notes.helpers.ALL_WIDGET_IDS
5448
import org.fossify.notes.helpers.FONT_SIZE_100_PERCENT
5549
import org.fossify.notes.helpers.FONT_SIZE_125_PERCENT
5650
import org.fossify.notes.helpers.FONT_SIZE_150_PERCENT
@@ -67,7 +61,6 @@ import org.fossify.notes.helpers.GRAVITY_END
6761
import org.fossify.notes.helpers.GRAVITY_START
6862
import org.fossify.notes.helpers.NotesHelper
6963
import org.fossify.notes.models.Note
70-
import org.fossify.notes.models.Widget
7164
import java.util.Locale
7265
import kotlin.system.exitProcess
7366

@@ -343,30 +336,19 @@ class SettingsActivity : SimpleActivity() {
343336
}
344337

345338
private fun setupCustomizeWidgetColors() {
346-
var widgetToCustomize: Widget? = null
339+
var allWidgetIds = intArrayOf()
347340

348341
binding.settingsWidgetColorCustomizationHolder.setOnClickListener {
349342
Intent(this, WidgetConfigureActivity::class.java).apply {
350343
putExtra(IS_CUSTOMIZING_COLORS, true)
351-
352-
widgetToCustomize?.apply {
353-
putExtra(CUSTOMIZED_WIDGET_ID, widgetId)
354-
putExtra(CUSTOMIZED_WIDGET_KEY_ID, id)
355-
putExtra(CUSTOMIZED_WIDGET_NOTE_ID, noteId)
356-
putExtra(CUSTOMIZED_WIDGET_BG_COLOR, widgetBgColor)
357-
putExtra(CUSTOMIZED_WIDGET_TEXT_COLOR, widgetTextColor)
358-
putExtra(CUSTOMIZED_WIDGET_SHOW_TITLE, widgetShowTitle)
359-
}
360-
344+
putExtra(ALL_WIDGET_IDS, allWidgetIds)
361345
startActivity(this)
362346
}
363347
}
364348

365349
ensureBackgroundThread {
366350
val widgets = widgetsDB.getWidgets().filter { it.widgetId != 0 }
367-
if (widgets.size == 1) {
368-
widgetToCustomize = widgets.first()
369-
}
351+
allWidgetIds = widgets.map { it.widgetId }.toIntArray()
370352
}
371353
}
372354

app/src/main/kotlin/org/fossify/notes/activities/WidgetConfigureActivity.kt

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class WidgetConfigureActivity : SimpleActivity() {
4141
private var mIsCustomizingColors = false
4242
private var mShowTitle = false
4343
private var mNotes = listOf<Note>()
44+
private var mAllWidgetIds = intArrayOf()
4445
private val binding by viewBinding(WidgetConfigBinding::inflate)
4546

4647
public override fun onCreate(savedInstanceState: Bundle?) {
@@ -107,6 +108,7 @@ class WidgetConfigureActivity : SimpleActivity() {
107108

108109
updateTextColor()
109110
mIsCustomizingColors = extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false
111+
mAllWidgetIds = extras?.getIntArray(ALL_WIDGET_IDS) ?: intArrayOf()
110112
binding.notesPickerHolder.beVisibleIf(!mIsCustomizingColors)
111113
binding.textNoteViewTitle.beGoneIf(!mShowTitle)
112114

@@ -189,23 +191,29 @@ class WidgetConfigureActivity : SimpleActivity() {
189191
}
190192

191193
private fun saveConfig() {
192-
if (mCurrentNoteId == 0L) {
194+
if (!mIsCustomizingColors && mCurrentNoteId == 0L) {
193195
finish()
194196
return
195197
}
196198

197-
val views = RemoteViews(packageName, R.layout.activity_main)
198-
views.setBackgroundColor(R.id.text_note_view, mBgColor)
199-
views.setBackgroundColor(R.id.checklist_note_view, mBgColor)
200-
AppWidgetManager.getInstance(this)?.updateAppWidget(mWidgetId, views) ?: return
201-
202-
val extras = intent.extras
203-
val id = if (extras?.containsKey(CUSTOMIZED_WIDGET_KEY_ID) == true) extras.getLong(CUSTOMIZED_WIDGET_KEY_ID) else null
204-
mWidgetId = extras?.getInt(CUSTOMIZED_WIDGET_ID, mWidgetId) ?: mWidgetId
205-
mCurrentNoteId = extras?.getLong(CUSTOMIZED_WIDGET_NOTE_ID, mCurrentNoteId) ?: mCurrentNoteId
206-
val widget = Widget(id, mWidgetId, mCurrentNoteId, mBgColor, mTextColor, mShowTitle)
207-
ensureBackgroundThread {
208-
widgetsDB.insertOrUpdate(widget)
199+
if (!mIsCustomizingColors) {
200+
val views = RemoteViews(packageName, R.layout.activity_main)
201+
views.setBackgroundColor(R.id.text_note_view, mBgColor)
202+
views.setBackgroundColor(R.id.checklist_note_view, mBgColor)
203+
AppWidgetManager.getInstance(this)?.updateAppWidget(mWidgetId, views) ?: return
204+
205+
val extras = intent.extras
206+
val id = if (extras?.containsKey(CUSTOMIZED_WIDGET_KEY_ID) == true) extras.getLong(CUSTOMIZED_WIDGET_KEY_ID) else null
207+
mWidgetId = extras?.getInt(CUSTOMIZED_WIDGET_ID, mWidgetId) ?: mWidgetId
208+
mCurrentNoteId = extras?.getLong(CUSTOMIZED_WIDGET_NOTE_ID, mCurrentNoteId) ?: mCurrentNoteId
209+
val widget = Widget(id, mWidgetId, mCurrentNoteId, mBgColor, mTextColor, mShowTitle)
210+
ensureBackgroundThread {
211+
widgetsDB.insertOrUpdate(widget)
212+
}
213+
} else {
214+
ensureBackgroundThread {
215+
widgetsDB.updateWidgetColors(mBgColor, mTextColor)
216+
}
209217
}
210218

211219
storeWidgetBackground()
@@ -226,8 +234,9 @@ class WidgetConfigureActivity : SimpleActivity() {
226234
}
227235

228236
private fun requestWidgetUpdate() {
237+
val widgetIds = if (mAllWidgetIds.isNotEmpty()) mAllWidgetIds else intArrayOf(mWidgetId)
229238
Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetProvider::class.java).apply {
230-
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(mWidgetId))
239+
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds)
231240
sendBroadcast(this)
232241
}
233242
}

app/src/main/kotlin/org/fossify/notes/helpers/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const val CUSTOMIZED_WIDGET_NOTE_ID = "customized_widget_note_id"
1212
const val CUSTOMIZED_WIDGET_BG_COLOR = "customized_widget_bg_color"
1313
const val CUSTOMIZED_WIDGET_TEXT_COLOR = "customized_widget_text_color"
1414
const val CUSTOMIZED_WIDGET_SHOW_TITLE = "customized_widget_show_title"
15+
const val ALL_WIDGET_IDS = "all_widget_ids"
1516
const val SHORTCUT_NEW_TEXT_NOTE = "shortcut_new_text_note"
1617
const val SHORTCUT_NEW_CHECKLIST = "shortcut_new_checklist"
1718
const val NEW_TEXT_NOTE = "new_text_note"

app/src/main/kotlin/org/fossify/notes/interfaces/WidgetsDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ interface WidgetsDao {
2222

2323
@Query("DELETE FROM widgets WHERE widget_id = :widgetId")
2424
fun deleteWidgetId(widgetId: Int)
25+
26+
@Query("UPDATE widgets SET widget_bg_color = :bgColor, widget_text_color = :textColor")
27+
fun updateWidgetColors(bgColor: Int, textColor: Int)
2528
}

0 commit comments

Comments
 (0)