Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions app/src/main/java/com/leanbitlab/lwidget/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class MainActivity : AppCompatActivity() {
StepCounterService.startServiceIfEnabled(this)
// Only the visible tab is inflated and bound before the first frame; the rest follow when idle.
bindTab(savedTabIndex())
findViewById<View>(R.id.preview_backdrop_tap)?.setOnClickListener {
previewBackdropDark = !(previewBackdropDark ?: autoBackdropDark)
setupPreviewWallpaper()
}
setupPreviewWallpaper()
setupTabLayout()
setupGlobalSettingsSearch()
Expand Down Expand Up @@ -186,18 +190,12 @@ class MainActivity : AppCompatActivity() {
}

@android.annotation.SuppressLint("MissingPermission")
/** Backdrop picked with the preview's corner button; null = automatic (contrasts with the widget). */
private var previewBackdropDark: Boolean? = null
private var autoBackdropDark = true

private fun setupPreviewWallpaper() {
val wallpaperView = findViewById<ImageView>(R.id.preview_wallpaper) ?: return
try {
val wallpaperManager = android.app.WallpaperManager.getInstance(this)
val wallpaperDrawable = wallpaperManager.drawable
if (wallpaperDrawable != null) {
wallpaperView.setImageDrawable(wallpaperDrawable)
return
}
} catch (e: Exception) {
// Fallback to themed gradient
}

val isSystemInNightMode = (resources.configuration.uiMode and android.content.res.Configuration.UI_MODE_NIGHT_MASK) == android.content.res.Configuration.UI_MODE_NIGHT_YES
val themeMode = prefs.getInt("theme_mode", if (prefs.getBoolean("use_system_theme", true)) 0 else 2)
Expand Down Expand Up @@ -238,7 +236,9 @@ class MainActivity : AppCompatActivity() {
}
}

wallpaperView.setImageResource(if (isWidgetDark) R.drawable.bg_preview_wallpaper_dark else R.drawable.bg_preview_wallpaper_light)
autoBackdropDark = isWidgetDark
val dark = previewBackdropDark ?: isWidgetDark
wallpaperView.setImageResource(if (dark) R.drawable.bg_preview_wallpaper_dark else R.drawable.bg_preview_wallpaper_light)
}

private fun setupTabLayout() {
Expand Down Expand Up @@ -285,6 +285,11 @@ class MainActivity : AppCompatActivity() {
try {
val remoteViews = AwidgetProvider.Companion.buildAppWidgetRemoteViews(this, currentWidgetId, UpdateMode.FULL)
val view = remoteViews.apply(applicationContext, previewContainer)
// With events and tasks both on, the preview shows the events page only
if (prefs.getBoolean("show_events", false) && prefs.getBoolean("show_tasks", false)) {
view.findViewById<View>(R.id.events_page)?.visibility = View.VISIBLE
view.findViewById<View>(R.id.tasks_page)?.visibility = View.GONE
}
previewContainer.removeAllViews()
previewContainer.addView(view)
} catch (e: Exception) {
Expand Down Expand Up @@ -389,7 +394,8 @@ class MainActivity : AppCompatActivity() {
android.os.Looper.myQueue().addIdleHandler {
if (!isFinishing && !isDestroyed) {
bindTab(next)
bindRemainingTabsWhenIdle()
// Idle handlers run once per idle period: post, so the queue goes idle again for the next tab
updateHandler.post { bindRemainingTabsWhenIdle() }
}
false
}
Expand Down
22 changes: 14 additions & 8 deletions app/src/main/java/com/leanbitlab/lwidget/SettingsAccordion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import android.widget.ImageView
import android.widget.ListView
import android.widget.TextView
import android.view.ViewGroup
import com.google.android.material.card.MaterialCardView
import com.google.android.material.slider.Slider
import com.google.android.material.switchmaterial.SwitchMaterial
import androidx.core.widget.NestedScrollView
Expand Down Expand Up @@ -127,12 +126,21 @@ internal fun MainActivity.bindFoldedSection(
toggleSectionExpansion(header, content, chevron, expandedPrefKey, sectionKey)
}

// Toggle row
// The Enable switch sits in the section header. The whole row is moved there at bind time,
// so its ids, lookups (row_*_toggle -> row_switch) and listeners stay exactly as they were.
val toggleRow = findViewById<View>(toggleRowId)
val toggleSwitch = toggleRow.findViewById<SwitchMaterial>(R.id.row_switch)
val toggleLabel = toggleRow.findViewById<TextView>(R.id.row_label)
val toggleCard = toggleRow.findViewById<MaterialCardView>(R.id.toggle_row_card)
toggleLabel.setText(R.string.label_enable)
toggleRow.findViewById<TextView>(R.id.row_label).visibility = View.GONE
if (toggleRow.parent !== header) {
(toggleRow.parent as ViewGroup).removeView(toggleRow)
toggleRow.setPaddingRelative(0, 0, (8 * resources.displayMetrics.density).toInt(), 0)
val headerRow = header as ViewGroup
headerRow.addView(
toggleRow, headerRow.indexOfChild(chevron),
android.widget.LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
)
}
toggleSwitch.contentDescription = title

toggleSwitch.tag = prefShowKey
if (isContent) contentSwitches.add(toggleSwitch)
Expand All @@ -143,7 +151,6 @@ internal fun MainActivity.bindFoldedSection(
// Sub-settings alpha
val subSettings = subSettingsContainerId?.let { findViewById<View>(it) }
subSettings?.alpha = if (isShown) 1.0f else 0.4f
updateToggleCardStyle(toggleCard, isShown)

// Child rows visibility
val sizeRow = sizeRowId?.let { findViewById<View>(it) }
Expand All @@ -161,9 +168,8 @@ internal fun MainActivity.bindFoldedSection(
toggleSwitch.setOnCheckedChangeListener { _, isChecked ->
prefs.edit().putBoolean(prefShowKey, isChecked).apply()
subSettings?.alpha = if (isChecked) 1.0f else 0.4f
updateToggleCardStyle(toggleCard, isChecked)

val parentViewGroup = (toggleRow.parent as? ViewGroup)
val parentViewGroup = content as? ViewGroup
if (parentViewGroup != null) {
TransitionManager.beginDelayedTransition(
parentViewGroup,
Expand Down
26 changes: 2 additions & 24 deletions app/src/main/java/com/leanbitlab/lwidget/SettingsBinders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import android.view.View
import android.widget.AutoCompleteTextView
import android.widget.TextView
import android.view.ViewGroup
import com.google.android.material.card.MaterialCardView
import com.google.android.material.slider.Slider
import com.google.android.material.switchmaterial.SwitchMaterial
import androidx.transition.AutoTransition
Expand Down Expand Up @@ -182,31 +181,10 @@ internal fun MainActivity.updateColorVisibility(useDynamicColors: Boolean) {
}
}

internal fun MainActivity.updateToggleCardStyle(card: MaterialCardView?, enabled: Boolean) {
if (card == null) return
if (enabled) {
card.setCardBackgroundColor(android.graphics.Color.TRANSPARENT)
card.strokeWidth = (1f * resources.displayMetrics.density).toInt()
card.setStrokeColor(android.content.res.ColorStateList.valueOf(
com.google.android.material.color.MaterialColors.getColor(card, com.google.android.material.R.attr.colorPrimary)
))
} else {
card.setCardBackgroundColor(
com.google.android.material.color.MaterialColors.getColor(card, com.google.android.material.R.attr.colorSurfaceContainerLow)
)
card.setStrokeColor(android.content.res.ColorStateList.valueOf(
com.google.android.material.color.MaterialColors.getColor(card, com.google.android.material.R.attr.colorOutlineVariant)
))
}
}

// Helper for callers who override the toggle listener to update row visibility
internal fun MainActivity.updateFeatureRowVisibility(switch: SwitchMaterial, isChecked: Boolean, vararg rowIds: Int) {
val toggleRow = switch.parent as? View
val toggleCard = toggleRow?.findViewById<MaterialCardView>(R.id.toggle_row_card)
updateToggleCardStyle(toggleCard, isChecked)

val parentViewGroup = (toggleRow?.parent as? ViewGroup)
// Animate the rows' own container (the switch itself may sit in the section header)
val parentViewGroup = rowIds.firstOrNull()?.let { findViewById<View>(it)?.parent as? ViewGroup }
if (parentViewGroup != null) {
TransitionManager.beginDelayedTransition(
parentViewGroup,
Expand Down
49 changes: 23 additions & 26 deletions app/src/main/java/com/leanbitlab/lwidget/render/WidgetRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object WidgetRenderer {
PendingIntent.getBroadcast(context, 12, switchIntent, PendingIntent.FLAG_IMMUTABLE)
)
}
applyEventsTap(context, views, appWidgetId, showEventsNow.not() && showTasks)
applyEventsTap(context, views, prefs, showEventsNow.not() && showTasks)
}

/**
Expand All @@ -124,23 +124,34 @@ object WidgetRenderer {
}

/** Tapping the block opens Tasks.org while the tasks page is showing, otherwise it fully redraws this widget. */
private fun applyEventsTap(context: Context, views: RemoteViews, appWidgetId: Int, tasksPageShowing: Boolean) {
/** A tap anywhere on the block opens the Tasks app on the tasks page, else the calendar app (as the date does). */
private fun applyEventsTap(context: Context, views: RemoteViews, prefs: SharedPreferences, tasksPageShowing: Boolean) {
val tasksIntent = if (tasksPageShowing) getLaunchIntent(context, "org.tasks") else null
val tapIntent = if (tasksIntent != null) {
PendingIntent.getActivity(context, 11, tasksIntent, PendingIntent.FLAG_IMMUTABLE)
} else {
// A full update reloads events and tasks; the battery tick would skip them.
// The per-widget data keeps each widget's PendingIntent (and its id extra) distinct.
val refreshIntent = Intent(context, AwidgetProvider::class.java).apply {
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
data = android.net.Uri.parse("lwidget://widget/$appWidgetId/refresh")
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(appWidgetId))
}
PendingIntent.getBroadcast(context, 10, refreshIntent, PendingIntent.FLAG_IMMUTABLE)
calendarPendingIntent(context, prefs)
}
views.setOnClickPendingIntent(R.id.events_container, tapIntent)
}

// Calendar Click Action (Issue #55)
private fun calendarPendingIntent(context: Context, prefs: SharedPreferences): PendingIntent {
val selectedCalPkg = prefs.getString("calendar_app_package", "default") ?: "default"
val calendarPackages = listOf("org.fossify.calendar", "com.simplemobiletools.calendar", "com.google.android.calendar", "com.android.calendar")
val baseCalIntent = Intent(Intent.ACTION_VIEW).apply {
data = android.net.Uri.parse("content://com.android.calendar/time")
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
val calendarIntent = if (selectedCalPkg != "default") {
getLaunchIntent(context, selectedCalPkg)
?: getBestIntent(context, calendarPackages, baseCalIntent)
} else {
getBestIntent(context, calendarPackages, baseCalIntent)
}
return PendingIntent.getActivity(context, 1, calendarIntent, PendingIntent.FLAG_IMMUTABLE)
}

private fun getLayout(fontIdx: Int): Int {
return when (fontIdx) {
1 -> R.layout.widget_layout_serif
Expand Down Expand Up @@ -322,7 +333,7 @@ object WidgetRenderer {
val pageViews = RemoteViews(context.packageName, layoutId)
pageViews.setDisplayedChild(R.id.events_flipper, if (showEventsNow) 0 else 1)
applyEventsSwitchArrow(pageViews, showEventsNow)
applyEventsTap(context, pageViews, appWidgetId, showTasksNow)
applyEventsTap(context, pageViews, prefs, showTasksNow)
return pageViews
} else if (mode == UpdateMode.ALARM_ONLY) {
val alarmViews = RemoteViews(context.packageName, layoutId)
Expand Down Expand Up @@ -639,21 +650,7 @@ object WidgetRenderer {
val alarmPendingIntent = PendingIntent.getActivity(context, 0, alarmIntent, PendingIntent.FLAG_IMMUTABLE)
views.setOnClickPendingIntent(R.id.clock_time, alarmPendingIntent)

// Calendar Click Action (Issue #55)
val selectedCalPkg = prefs.getString("calendar_app_package", "default") ?: "default"
val calendarPackages = listOf("org.fossify.calendar", "com.simplemobiletools.calendar", "com.google.android.calendar", "com.android.calendar")
val baseCalIntent = Intent(Intent.ACTION_VIEW).apply {
data = android.net.Uri.parse("content://com.android.calendar/time")
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
val calendarIntent = if (selectedCalPkg != "default") {
getLaunchIntent(context, selectedCalPkg)
?: getBestIntent(context, calendarPackages, baseCalIntent)
} else {
getBestIntent(context, calendarPackages, baseCalIntent)
}
val calendarPendingIntent = PendingIntent.getActivity(context, 1, calendarIntent, PendingIntent.FLAG_IMMUTABLE)
views.setOnClickPendingIntent(R.id.clock_date, calendarPendingIntent)
views.setOnClickPendingIntent(R.id.clock_date, calendarPendingIntent(context, prefs))

val batteryIntent = Intent(Intent.ACTION_POWER_USAGE_SUMMARY)
val batteryPendingIntent = PendingIntent.getActivity(context, 2, batteryIntent, PendingIntent.FLAG_IMMUTABLE)
Expand Down
9 changes: 2 additions & 7 deletions app/src/main/res/drawable/bg_preview_wallpaper.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Flat preview backdrop (no gradient), so the widget is judged on a plain light or dark surface -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:startColor="#1E293B"
android:centerColor="#0F172A"
android:endColor="#334155"
android:type="linear" />
<corners android:radius="20dp" />
<solid android:color="@color/preview_backdrop_dark" />
</shape>
9 changes: 2 additions & 7 deletions app/src/main/res/drawable/bg_preview_wallpaper_dark.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Flat preview backdrop (no gradient), so the widget is judged on a plain light or dark surface -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:startColor="#1E293B"
android:centerColor="#0F172A"
android:endColor="#334155"
android:type="linear" />
<corners android:radius="20dp" />
<solid android:color="@color/preview_backdrop_dark" />
</shape>
9 changes: 2 additions & 7 deletions app/src/main/res/drawable/bg_preview_wallpaper_light.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Flat preview backdrop (no gradient), so the widget is judged on a plain light or dark surface -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:startColor="#E2E8F0"
android:centerColor="#F1F5F9"
android:endColor="#E2E8F0"
android:type="linear" />
<corners android:radius="20dp" />
<solid android:color="@color/preview_backdrop_light" />
</shape>
1 change: 0 additions & 1 deletion app/src/main/res/drawable/bg_tab_container.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
android:shape="rectangle">
<corners android:radius="18dp"/>
<solid android:color="?attr/colorSurfaceContainerHigh"/>
<stroke android:width="1dp" android:color="?attr/colorOutlineVariant"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_drag_indicator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M11,18c0,1.1 -0.9,2 -2,2s-2,-0.9 -2,-2 0.9,-2 2,-2 2,0.9 2,2zM9,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM9,4c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM15,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM15,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM15,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</vector>
12 changes: 9 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="18dp"
app:cardCornerRadius="16dp"
app:cardElevation="0dp"
app:strokeWidth="1dp"
app:strokeColor="?attr/colorOutlineVariant"
android:clipChildren="true"
android:clipToPadding="true">

Expand All @@ -167,6 +165,14 @@
android:padding="8dp"
android:clipChildren="false"
android:clipToPadding="false" />

<!-- A tap anywhere on the preview flips its backdrop between light and dark -->
<View
android:id="@+id/preview_backdrop_tap"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/preview_backdrop_toggle" />
</FrameLayout>
</com.google.android.material.card.MaterialCardView>
</FrameLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/settings_color_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
android:layout_height="32dp"
android:layout_marginEnd="12dp"
app:cardCornerRadius="8dp"
app:cardElevation="1dp"
app:cardElevation="0dp"
app:strokeWidth="1dp"
app:strokeColor="?attr/colorOutlineVariant">

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/settings_color_sliders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:layout_marginEnd="16dp"
android:layout_gravity="center_vertical"
app:cardCornerRadius="12dp"
app:cardElevation="2dp"
app:cardElevation="0dp"
app:strokeWidth="1dp"
app:strokeColor="?attr/colorOutlineVariant">

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/settings_folded_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
android:gravity="center_vertical"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="14dp"
android:paddingBottom="14dp"
android:minHeight="56dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true">
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/settings_reorder_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:layout_height="36dp"
android:padding="6dp"
android:layout_marginEnd="10dp"
android:src="@drawable/ic_reorder"
android:src="@drawable/ic_drag_indicator"
android:contentDescription="@string/a11y_drag_to_reorder"
app:tint="?attr/colorPrimary"/>

Expand Down
Loading
Loading