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
3 changes: 2 additions & 1 deletion app/src/main/java/com/leanbitlab/lwidget/AwidgetProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,14 @@ class AwidgetProvider : AppWidgetProvider() {
}

internal fun formatEventTimeText(
context: Context,
event: EventInfo,
today: LocalDate = LocalDate.now(),
showDayAbbr: Boolean = true,
is24Hour: Boolean = false
): String {
val mapped = CalendarFetcher.EventInfo(event.id, event.title, event.begin, event.end, event.isLocal, event.isAllDay)
return CalendarFetcher.formatEventTimeText(mapped, today, showDayAbbr, is24Hour)
return CalendarFetcher.formatEventTimeText(context, mapped, today, showDayAbbr, is24Hour)
}

internal fun calculateDailySteps(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ internal fun MainActivity.setupThemeSection(colorOptions: List<String>) {
}

internal fun MainActivity.setupLanguageSection() {
// Language names stay in their own script so users can always find theirs.
// i18n-ignore-start
val languages = listOf(
LanguageOption("", getString(R.string.lang_system_default)),
LanguageOption("en", "English"),
Expand All @@ -152,6 +154,7 @@ internal fun MainActivity.setupLanguageSection() {
LanguageOption("ja", "日本語 (Japanese)"),
LanguageOption("tr", "Türkçe (Turkish)")
)
// i18n-ignore-end
val languageLabels = languages.map { it.displayName }
val currentLocales = androidx.appcompat.app.AppCompatDelegate.getApplicationLocales()
val currentTag = if (currentLocales.isEmpty) "" else currentLocales.get(0)?.language ?: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ internal fun MainActivity.setupBatterySection() {

internal fun MainActivity.setupTempSection() {
// Temp
val tempUnitOptions = listOf("Celsius (°C)", "Fahrenheit (°F)")
val tempUnitOptions = listOf(getString(R.string.temp_unit_celsius), getString(R.string.temp_unit_fahrenheit))
bindFoldedSection(
R.id.header_temp, R.drawable.ic_temp, getString(R.string.section_temp),
R.id.content_temp, R.id.row_temp_toggle,
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/leanbitlab/lwidget/SettingsSearch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ internal fun MainActivity.setupGlobalSettingsSearch() {
}
}

// English search keywords (not shown in UI).
// i18n-ignore-start
val cardMap = mapOf(
// Style Tab
R.id.card_appearance_presets to listOf("presets", "themes", "minimal", "neon", "cockpit", "sunset", "monochrome", "snowfall"),
Expand Down Expand Up @@ -115,6 +117,7 @@ internal fun MainActivity.setupGlobalSettingsSearch() {
R.id.card_about to listOf("about", "version", "github", "source code", "developer", "license", "privacy", "author"),
R.id.card_changelog to listOf("changelog", "whats new", "updates", "history")
)
// i18n-ignore-end

val headerLabels: List<View> = listOfNotNull(
findViewById(R.id.label_category_content),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ object CalendarFetcher {
}

internal fun formatEventTimeText(
context: Context,
event: EventInfo,
today: LocalDate = LocalDate.now(),
showDayAbbr: Boolean = true,
Expand All @@ -78,9 +79,9 @@ object CalendarFetcher {
val isOngoingToday = eventDate.isEqual(today) || (eventDate.isBefore(today) && eventEndDate.isAfter(today))

if (isOngoingToday) {
"Today"
context.getString(R.string.label_today)
} else if (eventDate.isEqual(tomorrow)) {
"Tomorrow"
context.getString(R.string.label_tomorrow)
} else if (eventDate.isAfter(today) && eventDate.isBefore(oneWeekLater)) {
if (showDayAbbr) eventTime.format(allDayNearFormatter)
else eventTime.format(getFormatter("d"))
Expand All @@ -91,9 +92,9 @@ object CalendarFetcher {
val eventTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(event.begin), ZoneId.systemDefault())
val eventDate = eventTime.toLocalDate()
if (eventDate.isEqual(today)) {
"Today ${eventTime.format(timeFormatter)}"
context.getString(R.string.label_today_time, eventTime.format(timeFormatter))
} else if (eventDate.isEqual(tomorrow)) {
"Tomorrow ${eventTime.format(timeFormatter)}"
context.getString(R.string.label_tomorrow_time, eventTime.format(timeFormatter))
} else if (eventDate.isBefore(oneWeekLater)) {
if (showDayAbbr) "${eventTime.format(dayTimeFormatter)}"
else eventTime.format(timeFormatter)
Expand Down Expand Up @@ -207,7 +208,7 @@ object CalendarFetcher {
val is24Hour = timeFormatIdx == 1 || (timeFormatIdx == 0 && android.text.format.DateFormat.is24HourFormat(context))

if (events.isEmpty()) {
views.setTextViewText(eventViews[0], "No events today")
views.setTextViewText(eventViews[0], context.getString(R.string.widget_no_events_today))
secondaryColor.applyTextColor(views, eventViews[0])
views.setTextViewTextSize(eventViews[0], android.util.TypedValue.COMPLEX_UNIT_SP, textSizeSp)
views.setViewVisibility(eventViews[0], android.view.View.VISIBLE)
Expand All @@ -232,7 +233,7 @@ object CalendarFetcher {
for (i in eventViews.indices) {
if (i < events.size) {
val event = events[i]
val timeText = formatEventTimeText(event, today, showDayAbbr, is24Hour)
val timeText = formatEventTimeText(context, event, today, showDayAbbr, is24Hour)

val fullText = "• $timeText ${event.title}"
val spannable = SpannableString(fullText)
Expand Down Expand Up @@ -275,7 +276,7 @@ object CalendarFetcher {
context, android.Manifest.permission.READ_CALENDAR
) != android.content.pm.PackageManager.PERMISSION_GRANTED) {
// Interactive permission prompt in widget
views.setTextViewText(eventViews[0], "• Tap to grant calendar permission")
views.setTextViewText(eventViews[0], "• " + context.getString(R.string.widget_tap_grant_calendar))
secondaryColor.applyTextColor(views, eventViews[0])
views.setTextViewTextSize(eventViews[0], android.util.TypedValue.COMPLEX_UNIT_SP, textSizeSp)
views.setViewVisibility(eventViews[0], android.view.View.VISIBLE)
Expand Down
35 changes: 18 additions & 17 deletions app/src/main/java/com/leanbitlab/lwidget/render/WidgetRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ object WidgetRenderer {
// Branching for partial TICK/event updates
if (mode == UpdateMode.STEPS_ONLY) {
val stepViews = RemoteViews(context.packageName, layoutId)
if (showSteps) SystemStatsFetcher.loadStepCount(stepViews, prefs)
if (showSteps) SystemStatsFetcher.loadStepCount(context, stepViews, prefs)
return stepViews
} else if (mode == UpdateMode.TICK) {
val tickViews = RemoteViews(context.packageName, layoutId)
SystemStatsFetcher.updateBatteryAndTemp(context, tickViews, prefs, showBattery, showTemp)
if (showSteps) SystemStatsFetcher.loadStepCount(tickViews, prefs)
if (showSteps) SystemStatsFetcher.loadStepCount(context, tickViews, prefs)
if (showScreenTime) SystemStatsFetcher.updateScreenTime(context, tickViews, prefs)
if (showData) SystemStatsFetcher.updateDataUsage(context, tickViews, prefs)
if (showStorage) SystemStatsFetcher.updateStorageStats(tickViews, prefs)
if (showStorage) SystemStatsFetcher.updateStorageStats(context, tickViews, prefs)
if (showRam) SystemStatsFetcher.updateRamStats(context, tickViews, prefs)
return tickViews
} else if (mode == UpdateMode.CALENDAR_ONLY) {
Expand Down Expand Up @@ -356,20 +356,21 @@ object WidgetRenderer {
)) {
hasWarning = true
weatherCode = fCode
val dayText = when (index) {
0 -> "today"
1 -> "tomorrow"
else -> {
val localDate = java.time.LocalDate.now().plusDays(index.toLong())
localDate.dayOfWeek.getDisplayName(java.time.format.TextStyle.SHORT, java.util.Locale.getDefault())
}
val dayName = if (index > 1) {
java.time.LocalDate.now().plusDays(index.toLong())
.dayOfWeek.getDisplayName(java.time.format.TextStyle.SHORT, java.util.Locale.getDefault())
} else ""
fun dayRes(todayRes: Int, tomorrowRes: Int, onRes: Int) = when (index) {
0 -> context.getString(todayRes)
1 -> context.getString(tomorrowRes)
else -> context.getString(onRes, dayName)
}
val precipString = if (forecast.precipProbability != null && forecast.precipProbability > 0) "${forecast.precipProbability}% " else ""
val conditionWarning = when (fCode) {
in listOf(500, 501, 502, 503, 504, 511, 520, 521, 522, 531) -> if (index <= 1) "Rain $dayText" else "Rain on $dayText"
in listOf(600, 601, 602, 611, 612, 615, 616, 620, 621, 622) -> if (index <= 1) "Snow $dayText" else "Snow on $dayText"
in listOf(210, 211, 212, 221, 230, 231, 232) -> if (index <= 1) "Storm $dayText" else "Storm on $dayText"
else -> "Warning"
in listOf(500, 501, 502, 503, 504, 511, 520, 521, 522, 531) -> dayRes(R.string.weather_rain_today, R.string.weather_rain_tomorrow, R.string.weather_rain_on)
in listOf(600, 601, 602, 611, 612, 615, 616, 620, 621, 622) -> dayRes(R.string.weather_snow_today, R.string.weather_snow_tomorrow, R.string.weather_snow_on)
in listOf(210, 211, 212, 221, 230, 231, 232) -> dayRes(R.string.weather_storm_today, R.string.weather_storm_tomorrow, R.string.weather_storm_on)
else -> context.getString(R.string.weather_warning)
}
weatherText = "$precipString$conditionWarning"
break
Expand All @@ -379,7 +380,7 @@ object WidgetRenderer {

var conditionText = weatherText
if (conditionText.isNullOrEmpty()) {
conditionText = "Unknown"
conditionText = context.getString(R.string.weather_unknown)
}

val weatherDrawableRes = when (weatherCode) {
Expand Down Expand Up @@ -439,7 +440,7 @@ object WidgetRenderer {
if (showStorage) {
views.setTextViewTextSize(R.id.text_storage, android.util.TypedValue.COMPLEX_UNIT_SP, sizeStorage)
secondaryColor.applyTextColor(views, R.id.text_storage)
SystemStatsFetcher.updateStorageStats(views, prefs)
SystemStatsFetcher.updateStorageStats(context, views, prefs)
}

// RAM
Expand All @@ -456,7 +457,7 @@ object WidgetRenderer {
views.setTextViewTextSize(R.id.text_steps, android.util.TypedValue.COMPLEX_UNIT_SP, sizeSteps)
secondaryColor.applyTextColor(views, R.id.text_steps)
secondaryColor.applyColorFilter(views, R.id.icon_steps)
SystemStatsFetcher.loadStepCount(views, prefs)
SystemStatsFetcher.loadStepCount(context, views, prefs)
}

// Screen Time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ object SystemStatsFetcher {
val totalMinutes = totalForegroundTime / (1000 * 60)
val hours = totalMinutes / 60
val mins = totalMinutes % 60
val timeString = if (hours > 0) "${hours}h ${mins}m" else "${mins}m"
val timeString = if (hours > 0) context.getString(R.string.duration_hours_minutes, hours, mins) else context.getString(R.string.duration_minutes, mins)
val span = SpannableString(timeString)
if (isBold) span.setSpan(StyleSpan(Typeface.BOLD), 0, span.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
views.setTextViewText(R.id.text_screen_time, span)
Expand Down Expand Up @@ -221,7 +221,7 @@ object SystemStatsFetcher {
}
}

fun updateStorageStats(views: RemoteViews, prefs: SharedPreferences) {
fun updateStorageStats(context: Context, views: RemoteViews, prefs: SharedPreferences) {
try {
val path = Environment.getDataDirectory()
val stat = StatFs(path.path)
Expand All @@ -239,7 +239,7 @@ object SystemStatsFetcher {

views.setTextViewText(R.id.text_storage, span)
} catch (e: Exception) {
views.setTextViewText(R.id.text_storage, "Err")
views.setTextViewText(R.id.text_storage, context.getString(R.string.widget_error))
}
}

Expand All @@ -263,7 +263,7 @@ object SystemStatsFetcher {

views.setTextViewText(R.id.text_ram, span)
} catch (e: Exception) {
views.setTextViewText(R.id.text_ram, "Err")
views.setTextViewText(R.id.text_ram, context.getString(R.string.widget_error))
}
}

Expand All @@ -279,7 +279,7 @@ object SystemStatsFetcher {
return (totalSteps - baselineSteps).toInt().coerceAtLeast(0)
}

fun loadStepCount(views: RemoteViews, prefs: SharedPreferences) {
fun loadStepCount(context: Context, views: RemoteViews, prefs: SharedPreferences) {
try {
val totalSteps = prefs.getFloat("last_total_steps", 0f)
val baselineSteps = prefs.getFloat("step_baseline", 0f)
Expand All @@ -294,7 +294,7 @@ object SystemStatsFetcher {

views.setTextViewText(R.id.text_steps, span)
} catch (e: Exception) {
views.setTextViewText(R.id.text_steps, "Err")
views.setTextViewText(R.id.text_steps, context.getString(R.string.widget_error))
}
}

Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/leanbitlab/lwidget/tasks/TasksFetcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ object TasksFetcher {
return tasks
}

fun formatDueSuffix(dueMillis: Long): String {
fun formatDueSuffix(context: Context, dueMillis: Long): String {
if (dueMillis <= 0) return ""
val dueDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(dueMillis), ZoneId.systemDefault()).toLocalDate()
val today = LocalDate.now()
val tomorrow = today.plusDays(1)

return if (dueDate.isBefore(today)) {
" (Overdue)"
" (${context.getString(R.string.label_overdue)})"
} else if (dueDate.isEqual(today)) {
" (Today)"
" (${context.getString(R.string.label_today)})"
} else if (dueDate.isEqual(tomorrow)) {
" (Tomorrow)"
" (${context.getString(R.string.label_tomorrow)})"
} else {
val df = CalendarFetcher.getFormatter("MMM d")
" (${dueDate.format(df)})"
Expand All @@ -90,7 +90,7 @@ object TasksFetcher {
context.checkSelfPermission(PERMISSION_READ_TASKS_ASTRID) == android.content.pm.PackageManager.PERMISSION_GRANTED

if (!hasPerm) {
views.setTextViewText(eventViews[0], "• Tap to grant Tasks.org permission")
views.setTextViewText(eventViews[0], "• " + context.getString(R.string.widget_tap_grant_tasks))
views.setViewVisibility(eventViews[0], android.view.View.VISIBLE)
views.setTextViewTextSize(eventViews[0], android.util.TypedValue.COMPLEX_UNIT_SP, textSizeSp)

Expand Down Expand Up @@ -119,7 +119,7 @@ object TasksFetcher {
val taskIntent = com.leanbitlab.lwidget.render.WidgetRenderer.getLaunchIntent(context, "org.tasks")
for (i in tasks.indices) {
val task = tasks[i]
val dueSuffix = formatDueSuffix(task.dueMillis)
val dueSuffix = formatDueSuffix(context, task.dueMillis)
val fullText = "• ${task.title}$dueSuffix"
val spannable = SpannableString(fullText)
spannable.setSpan(ForegroundColorSpan(accentColor), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
Expand Down
Loading
Loading