Skip to content

Commit 9421ee4

Browse files
author
LeanBitLab
committed
Fix widget outline and implement dynamic settings visibility
1 parent be7c4d2 commit 9421ee4

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

app/src/main/java/com/leanbitlab/lwidget/AwidgetProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ class AwidgetProvider : AppWidgetProvider() {
217217
}
218218
}
219219

220+
val showOutline = prefs.getBoolean("show_outline", false)
220221
val outlineColor = resolveOutlineColor(outlineColorIdx)
221222
views.setImageViewResource(R.id.widget_outline, R.drawable.widget_bg_outline)
222-
views.setViewVisibility(R.id.widget_outline, android.view.View.VISIBLE)
223+
views.setViewVisibility(R.id.widget_outline, if (showOutline) android.view.View.VISIBLE else android.view.View.GONE)
223224
views.setInt(R.id.widget_outline, "setColorFilter", outlineColor)
224225
// Use same alpha as background? Or opaque? Usually outline is opaque or matches?
225226
// "Background Transparency" usually refers to the panel fill. Let's keep outline opaque for now or maybe full opacity.

app/src/main/java/com/leanbitlab/lwidget/MainActivity.kt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,15 @@ class MainActivity : AppCompatActivity() {
114114
contentSwitches.clear()
115115

116116
// Time: Def True, 48sp
117-
bindSection(R.id.section_time, getString(R.string.section_time), "show_time", true, "size_time", 48f, 12f, 120f, isContent = true, iconResId = R.drawable.ic_time)
117+
bindSection(R.id.section_time, getString(R.string.section_time), "show_time", true, "size_time", 48f, 12f, 120f, isContent = true, iconResId = R.drawable.ic_time) { isChecked ->
118+
findViewById<View>(R.id.section_time_format).visibility = if (isChecked) View.VISIBLE else View.GONE
119+
}
118120
bindSelector(R.id.section_time_format, getString(R.string.section_time_format), "time_format_idx", listOf(getString(R.string.format_12h), getString(R.string.format_24h)), 0, iconResId = R.drawable.ic_time)
119121

120122
// World Clock: Def False, 18sp (New)
121-
bindSection(R.id.section_world_clock, getString(R.string.section_world_clock), "show_world_clock", false, "size_world_clock", 18f, 10f, 64f, isContent = true, iconResId = R.drawable.ic_world)
123+
bindSection(R.id.section_world_clock, getString(R.string.section_world_clock), "show_world_clock", false, "size_world_clock", 18f, 10f, 64f, isContent = true, iconResId = R.drawable.ic_world) { isChecked ->
124+
findViewById<View>(R.id.section_world_clock_zone).visibility = if (isChecked) View.VISIBLE else View.GONE
125+
}
122126

123127

124128
val zoneIds = java.time.ZoneId.getAvailableZoneIds().sorted()
@@ -128,7 +132,9 @@ class MainActivity : AppCompatActivity() {
128132
bindSection(R.id.section_next_alarm, getString(R.string.section_next_alarm), "show_next_alarm", true, "size_next_alarm", 14f, 10f, 48f, isContent = true, iconResId = R.drawable.ic_alarm)
129133

130134
// Date: Def True, 14sp
131-
bindSection(R.id.section_date, getString(R.string.section_date), "show_date", true, "size_date", 14f, 10f, 64f, isContent = true, iconResId = R.drawable.ic_date)
135+
bindSection(R.id.section_date, getString(R.string.section_date), "show_date", true, "size_date", 14f, 10f, 64f, isContent = true, iconResId = R.drawable.ic_date) { isChecked ->
136+
findViewById<View>(R.id.section_date_format).visibility = if (isChecked) View.VISIBLE else View.GONE
137+
}
132138
bindSelector(R.id.section_date_format, getString(R.string.section_date_format), "date_format_idx", listOf(getString(R.string.date_format_full), getString(R.string.date_format_short), getString(R.string.date_format_numeric)), 0, iconResId = R.drawable.ic_date)
133139

134140
// Battery: Def True, 48sp
@@ -254,7 +260,19 @@ class MainActivity : AppCompatActivity() {
254260

255261

256262
// Outline: Def False (Renamed from Glow)
257-
bindToggle(R.id.section_outline, getString(R.string.section_outline), "show_outline", false, iconResId = R.drawable.ic_outline)
263+
bindToggle(R.id.section_outline, getString(R.string.section_outline), "show_outline", false, iconResId = R.drawable.ic_outline) { isChecked ->
264+
val outlineColorSection = findViewById<View>(R.id.section_outline_color)
265+
val sliders = findViewById<View>(R.id.sliders_outline)
266+
val idx = prefs.getInt("outline_color_idx", 0)
267+
268+
if (isChecked) {
269+
outlineColorSection.visibility = View.VISIBLE
270+
sliders.visibility = if (idx == 2) View.VISIBLE else View.GONE
271+
} else {
272+
outlineColorSection.visibility = View.GONE
273+
sliders.visibility = View.GONE
274+
}
275+
}
258276

259277
// Light Theme: Def False
260278
bindToggle(R.id.section_theme, getString(R.string.section_theme), "use_light_theme", false, iconResId = R.drawable.ic_sun)
@@ -314,7 +332,8 @@ class MainActivity : AppCompatActivity() {
314332
minSize: Float,
315333
maxSize: Float,
316334
isContent: Boolean = false,
317-
iconResId: Int? = null
335+
iconResId: Int? = null,
336+
onChanged: ((Boolean) -> Unit)? = null
318337
): SwitchMaterial {
319338
val section = findViewById<View>(sectionId)
320339
val tvTitle = section.findViewById<TextView>(R.id.item_title)
@@ -341,6 +360,7 @@ class MainActivity : AppCompatActivity() {
341360
val isShown = prefs.getBoolean(prefShowKey, defShow)
342361
switch.isChecked = isShown
343362
sizeContainer.visibility = if (isShown) View.VISIBLE else View.GONE
363+
onChanged?.invoke(isShown)
344364

345365
// Common Listener (can be overridden returned switch)
346366
switch.setOnCheckedChangeListener { _, isChecked ->
@@ -350,6 +370,7 @@ class MainActivity : AppCompatActivity() {
350370
}
351371
prefs.edit().putBoolean(prefShowKey, isChecked).apply()
352372
sizeContainer.visibility = if (isChecked) View.VISIBLE else View.GONE
373+
onChanged?.invoke(isChecked)
353374
updateWidget()
354375
if (isContent) updateToggleAvailability()
355376
}
@@ -379,7 +400,8 @@ class MainActivity : AppCompatActivity() {
379400
prefShowKey: String,
380401
defShow: Boolean,
381402
isContent: Boolean = false,
382-
iconResId: Int? = null
403+
iconResId: Int? = null,
404+
onChanged: ((Boolean) -> Unit)? = null
383405
) {
384406
val section = findViewById<View>(sectionId)
385407
val tvTitle = section.findViewById<TextView>(R.id.item_title)
@@ -404,13 +426,15 @@ class MainActivity : AppCompatActivity() {
404426
// Load Toggle
405427
val isShown = prefs.getBoolean(prefShowKey, defShow)
406428
switch.isChecked = isShown
429+
onChanged?.invoke(isShown)
407430

408431
switch.setOnCheckedChangeListener { _, isChecked ->
409432
if (isChecked && !checkLimit()) {
410433
switch.isChecked = false
411434
return@setOnCheckedChangeListener
412435
}
413436
prefs.edit().putBoolean(prefShowKey, isChecked).apply()
437+
onChanged?.invoke(isChecked)
414438
updateWidget()
415439
if (isContent) updateToggleAvailability()
416440
}

0 commit comments

Comments
 (0)