Compare commits
6
Commits
dfd0b75521
...
v1.2.10
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c75afab4e | ||
|
|
0c2ec3f20c | ||
|
|
daf16f0e67 | ||
|
|
8ccd4430da | ||
|
|
98ffa47fa4 | ||
|
|
7cc3245b97 |
No files matched your search
@@ -50,7 +50,7 @@ jobs:
|
|||||||
|
|
||||||
"$SDKMANAGER" --sdk_root="$SDK_PATH" \
|
"$SDKMANAGER" --sdk_root="$SDK_PATH" \
|
||||||
"platform-tools" \
|
"platform-tools" \
|
||||||
"platforms;android-37" \
|
"platforms;android-35" \
|
||||||
"build-tools;35.0.0"
|
"build-tools;35.0.0"
|
||||||
|
|
||||||
echo "ANDROID_HOME=$SDK_PATH" >> $GITHUB_ENV
|
echo "ANDROID_HOME=$SDK_PATH" >> $GITHUB_ENV
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.2.10] - 2026-10-08
|
||||||
|
### Changed
|
||||||
|
* implemented a better choosing of the focus word.
|
||||||
|
* reduced apk file size from 44MB to 2.2MB
|
||||||
|
|
||||||
## [1.2.0] - 2026-10-04
|
## [1.2.0] - 2026-10-04
|
||||||
### New
|
### New
|
||||||
* navigation
|
* navigation
|
||||||
|
|||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
# Project-specific R8/ProGuard rules for WeekFocus.
|
||||||
|
# Default Android and Compose rules are applied automatically via consumer rules.
|
||||||
|
|
||||||
|
# Keep line numbers for readable stack traces
|
||||||
|
-keepattributes SourceFile,LineNumberTable
|
||||||
|
-renamesourcefileattribute SourceFile
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
|
||||||
|
<!-- Nötig, damit der Wochenwechsel-Alarm nach einem Neustart neu geplant wird -->
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@@ -28,6 +30,10 @@
|
|||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
<action android:name="android.intent.action.DATE_CHANGED" />
|
||||||
|
<action android:name="android.intent.action.TIME_SET" />
|
||||||
|
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.appwidget.provider"
|
android:name="android.appwidget.provider"
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package de.schanbro.weekfocus
|
package de.schanbro.weekfocus
|
||||||
|
|
||||||
import android.appwidget.AppWidgetManager
|
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
@@ -35,6 +33,13 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
// Falls das Widget (z.B. durch Energiesparmodus) nicht rechtzeitig aktualisiert
|
||||||
|
// wurde, wird es beim Öffnen der App nachgezogen.
|
||||||
|
updateWidget(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@@ -133,12 +138,9 @@ fun PlaceholderScreen(title: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bleibt als Top-Level-Funktion erhalten, damit WordListScreen unverändert weiter funktioniert.
|
||||||
|
*/
|
||||||
fun updateWidget(context: Context) {
|
fun updateWidget(context: Context) {
|
||||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
SimpleWidget.updateAllWidgets(context)
|
||||||
val componentName = ComponentName(context, SimpleWidget::class.java)
|
|
||||||
val appWidgetIds = appWidgetManager.getAppWidgetIds(componentName)
|
|
||||||
|
|
||||||
for (appWidgetId in appWidgetIds) {
|
|
||||||
SimpleWidget.updateAppWidget(context, appWidgetManager, appWidgetId)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,35 @@
|
|||||||
package de.schanbro.weekfocus
|
package de.schanbro.weekfocus
|
||||||
|
|
||||||
|
import android.app.AlarmManager
|
||||||
|
import android.app.PendingIntent
|
||||||
import android.appwidget.AppWidgetManager
|
import android.appwidget.AppWidgetManager
|
||||||
import android.appwidget.AppWidgetProvider
|
import android.appwidget.AppWidgetProvider
|
||||||
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import androidx.compose.ui.res.stringResource
|
import java.time.DayOfWeek
|
||||||
import java.util.Calendar
|
import java.time.LocalDate
|
||||||
import java.util.Random
|
import java.time.ZoneId
|
||||||
|
import java.time.temporal.ChronoUnit
|
||||||
|
import java.time.temporal.IsoFields
|
||||||
|
import java.time.temporal.TemporalAdjusters
|
||||||
|
|
||||||
class SimpleWidget : AppWidgetProvider() {
|
class SimpleWidget : AppWidgetProvider() {
|
||||||
|
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
// Verarbeitet u.a. APPWIDGET_UPDATE / ENABLED / DISABLED und ruft die Callbacks unten auf
|
||||||
|
super.onReceive(context, intent)
|
||||||
|
|
||||||
|
when (intent.action) {
|
||||||
|
ACTION_WEEK_CHANGED,
|
||||||
|
Intent.ACTION_BOOT_COMPLETED, // Alarme überleben keinen Neustart
|
||||||
|
Intent.ACTION_DATE_CHANGED,
|
||||||
|
Intent.ACTION_TIME_CHANGED, // "android.intent.action.TIME_SET"
|
||||||
|
Intent.ACTION_TIMEZONE_CHANGED -> updateAllWidgets(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onUpdate(
|
override fun onUpdate(
|
||||||
context: Context,
|
context: Context,
|
||||||
appWidgetManager: AppWidgetManager,
|
appWidgetManager: AppWidgetManager,
|
||||||
@@ -18,40 +38,141 @@ class SimpleWidget : AppWidgetProvider() {
|
|||||||
for (appWidgetId in appWidgetIds) {
|
for (appWidgetId in appWidgetIds) {
|
||||||
updateAppWidget(context, appWidgetManager, appWidgetId)
|
updateAppWidget(context, appWidgetManager, appWidgetId)
|
||||||
}
|
}
|
||||||
|
// Selbstheilung: stellt sicher, dass immer ein Wochenwechsel-Alarm existiert
|
||||||
|
scheduleNextWeekChange(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onEnabled(context: Context) {
|
||||||
|
// Erstes Widget wurde platziert
|
||||||
|
scheduleNextWeekChange(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDisabled(context: Context) {
|
||||||
|
// Letztes Widget wurde entfernt
|
||||||
|
cancelWeekChange(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val ACTION_WEEK_CHANGED = "de.schanbro.weekfocus.ACTION_WEEK_CHANGED"
|
||||||
|
|
||||||
|
private const val PREFS_NAME = "WeekFocusPrefs"
|
||||||
|
private const val KEY_WORDS = "words_key"
|
||||||
|
private const val KEY_WEEK = "current_week_key"
|
||||||
|
private const val KEY_WORD = "current_word"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktualisiert alle Widget-Instanzen und plant den nächsten Wochenwechsel.
|
||||||
|
*/
|
||||||
|
fun updateAllWidgets(context: Context) {
|
||||||
|
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||||
|
val componentName = ComponentName(context, SimpleWidget::class.java)
|
||||||
|
val appWidgetIds = appWidgetManager.getAppWidgetIds(componentName)
|
||||||
|
if (appWidgetIds.isEmpty()) return
|
||||||
|
|
||||||
|
for (appWidgetId in appWidgetIds) {
|
||||||
|
updateAppWidget(context, appWidgetManager, appWidgetId)
|
||||||
|
}
|
||||||
|
scheduleNextWeekChange(context)
|
||||||
|
}
|
||||||
|
|
||||||
fun updateAppWidget(
|
fun updateAppWidget(
|
||||||
context: Context,
|
context: Context,
|
||||||
appWidgetManager: AppWidgetManager,
|
appWidgetManager: AppWidgetManager,
|
||||||
appWidgetId: Int
|
appWidgetId: Int
|
||||||
) {
|
) {
|
||||||
// 1. SharedPreferences auslesen
|
val displayText = resolveWordOfWeek(context)
|
||||||
val sharedPrefs = context.getSharedPreferences("WeekFocusPrefs", Context.MODE_PRIVATE)
|
?: context.getString(R.string.msg_no_words)
|
||||||
val savedSet = sharedPrefs.getStringSet("words_key", emptySet()) ?: emptySet()
|
|
||||||
val wordList = savedSet.toList()
|
|
||||||
|
|
||||||
// 2. Aktuelle Kalenderwoche & Jahr bestimmen
|
|
||||||
val calendar = Calendar.getInstance()
|
|
||||||
val weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR)
|
|
||||||
val year = calendar.get(Calendar.YEAR)
|
|
||||||
|
|
||||||
// 3. Wort für die aktuelle Kalenderwoche auswählen
|
|
||||||
val displayText = if (wordList.isNotEmpty()) {
|
|
||||||
// Kombinierter Seed aus Jahr und Kalenderwoche
|
|
||||||
val seed = (year * 100 + weekOfYear).toLong()
|
|
||||||
val random = Random(seed)
|
|
||||||
val randomIndex = random.nextInt(wordList.size)
|
|
||||||
wordList[randomIndex]
|
|
||||||
} else {
|
|
||||||
context.getString(R.string.msg_no_words)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. RemoteViews aktualisieren
|
|
||||||
val views = RemoteViews(context.packageName, R.layout.widget_main)
|
val views = RemoteViews(context.packageName, R.layout.widget_main)
|
||||||
views.setTextViewText(R.id.appwidget_text, displayText)
|
views.setTextViewText(R.id.appwidget_text, displayText)
|
||||||
|
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ISO-Kalenderwoche (Montag = Wochenbeginn, unabhängig von der Geräte-Locale)
|
||||||
|
* kombiniert mit dem zugehörigen Wochenjahr, z.B. 202641.
|
||||||
|
*
|
||||||
|
* Das Wochenjahr (nicht das Kalenderjahr!) verhindert, dass sich der Wert
|
||||||
|
* um Neujahr mitten in der Woche ändert.
|
||||||
|
*/
|
||||||
|
internal fun weekKeyFor(date: LocalDate): Int {
|
||||||
|
val weekBasedYear = date.get(IsoFields.WEEK_BASED_YEAR)
|
||||||
|
val week = date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR)
|
||||||
|
return weekBasedYear * 100 + week
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liefert das Wort der aktuellen Woche.
|
||||||
|
*
|
||||||
|
* - Die Liste wird sortiert, damit die Reihenfolge deterministisch ist
|
||||||
|
* (ein Set hat keine garantierte Reihenfolge).
|
||||||
|
* - Das gewählte Wort wird pro Woche gespeichert. Dadurch ändert sich das Wort
|
||||||
|
* nicht, wenn Wörter hinzugefügt oder gelöscht werden. Nur wenn das aktuelle
|
||||||
|
* Wort selbst gelöscht wird, wird neu gewählt.
|
||||||
|
*/
|
||||||
|
private fun resolveWordOfWeek(context: Context): String? {
|
||||||
|
val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||||
|
val words = (prefs.getStringSet(KEY_WORDS, emptySet()) ?: emptySet()).sorted()
|
||||||
|
|
||||||
|
if (words.isEmpty()) {
|
||||||
|
prefs.edit().remove(KEY_WEEK).remove(KEY_WORD).apply()
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val weekKey = weekKeyFor(LocalDate.now())
|
||||||
|
val storedWord = prefs.getString(KEY_WORD, null)
|
||||||
|
if (prefs.getInt(KEY_WEEK, -1) == weekKey && storedWord != null && storedWord in words) {
|
||||||
|
return storedWord
|
||||||
|
}
|
||||||
|
|
||||||
|
val currentMonday = LocalDate.now().with(DayOfWeek.MONDAY)
|
||||||
|
val weeksSinceEpoch = ChronoUnit.WEEKS.between(LocalDate.ofEpochDay(4), currentMonday) // 5.1.1970 war ein Montag
|
||||||
|
val word = words[(weeksSinceEpoch % words.size).toInt()]
|
||||||
|
|
||||||
|
prefs.edit()
|
||||||
|
.putInt(KEY_WEEK, weekKey)
|
||||||
|
.putString(KEY_WORD, word)
|
||||||
|
.apply()
|
||||||
|
return word
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plant einen Alarm für den nächsten Montag, 00:00 Uhr (lokale Zeit).
|
||||||
|
* Bewusst ohne Exact-Alarm-Berechtigung: Eine Verzögerung von wenigen Minuten
|
||||||
|
* ist für ein Wochenwort unkritisch.
|
||||||
|
*/
|
||||||
|
private fun scheduleNextWeekChange(context: Context) {
|
||||||
|
val alarmManager = context.getSystemService(AlarmManager::class.java) ?: return
|
||||||
|
|
||||||
|
val triggerAtMillis = LocalDate.now()
|
||||||
|
.with(TemporalAdjusters.next(DayOfWeek.MONDAY)) // "next" schließt heute aus
|
||||||
|
.atStartOfDay(ZoneId.systemDefault())
|
||||||
|
.toInstant()
|
||||||
|
.toEpochMilli()
|
||||||
|
|
||||||
|
alarmManager.setAndAllowWhileIdle(
|
||||||
|
AlarmManager.RTC_WAKEUP,
|
||||||
|
triggerAtMillis,
|
||||||
|
weekChangePendingIntent(context)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun cancelWeekChange(context: Context) {
|
||||||
|
val alarmManager = context.getSystemService(AlarmManager::class.java) ?: return
|
||||||
|
alarmManager.cancel(weekChangePendingIntent(context))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun weekChangePendingIntent(context: Context): PendingIntent {
|
||||||
|
val intent = Intent(context, SimpleWidget::class.java).apply {
|
||||||
|
action = ACTION_WEEK_CHANGED
|
||||||
|
}
|
||||||
|
return PendingIntent.getBroadcast(
|
||||||
|
context,
|
||||||
|
0,
|
||||||
|
intent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user