Compare commits
14
Commits
8458f0fce5
...
v0.2.11
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27d1a4b6ea | ||
|
|
5ae35c4cac | ||
|
|
75c4a43d57 | ||
|
|
0c75afab4e | ||
|
|
0c2ec3f20c | ||
|
|
daf16f0e67 | ||
|
|
8ccd4430da | ||
|
|
98ffa47fa4 | ||
|
|
dfd0b75521 | ||
|
|
d9c1942f2a | ||
|
|
bc6edc4a04 | ||
|
|
d03f9eee67 | ||
|
|
7eff7300d0 | ||
|
|
7cc3245b97 |
No files matched your search
@@ -64,7 +64,7 @@ jobs:
|
|||||||
echo "$KEYSTORE_BASE64" | base64 -d > "$RUNNER_TEMP/release.keystore"
|
echo "$KEYSTORE_BASE64" | base64 -d > "$RUNNER_TEMP/release.keystore"
|
||||||
echo "KEYSTORE_PATH=$RUNNER_TEMP/release.keystore" >> $GITHUB_ENV
|
echo "KEYSTORE_PATH=$RUNNER_TEMP/release.keystore" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Android Release APKs bauen
|
- name: Android Release APK bauen
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
@@ -79,33 +79,23 @@ jobs:
|
|||||||
|
|
||||||
APK_DIR="app/build/outputs/apk/release"
|
APK_DIR="app/build/outputs/apk/release"
|
||||||
|
|
||||||
echo "Gefundene Original-APKs in $APK_DIR:"
|
echo "Gefundene APKs in $APK_DIR:"
|
||||||
ls -lh "$APK_DIR"
|
ls -lh "$APK_DIR"
|
||||||
|
|
||||||
for APK in "$APK_DIR"/*.apk; do
|
SRC="$APK_DIR/app-release.apk"
|
||||||
[ -e "$APK" ] || continue
|
if [ ! -f "$SRC" ]; then
|
||||||
|
echo "app-release.apk nicht gefunden (evtl. unsigniert oder anderer Name)"
|
||||||
if [[ "$APK" == *"unsigned"* || "$APK" == *"WeekFocus-"* ]]; then
|
exit 1
|
||||||
continue
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FILENAME=$(basename "$APK")
|
TARGET_PATH="$APK_DIR/WeekFocus-${VERSION}.apk"
|
||||||
VARIANT=$(echo "$FILENAME" | sed -E 's/^app-(.*)-release\.apk$/\1/')
|
mv "$SRC" "$TARGET_PATH"
|
||||||
if [ "$VARIANT" = "$FILENAME" ]; then
|
|
||||||
VARIANT="release"
|
|
||||||
fi
|
|
||||||
|
|
||||||
TARGET_NAME="WeekFocus-${VERSION}-${VARIANT}.apk"
|
echo "Signatur prüfen für $(basename "$TARGET_PATH")..."
|
||||||
TARGET_PATH="$APK_DIR/$TARGET_NAME"
|
|
||||||
|
|
||||||
mv "$APK" "$TARGET_PATH"
|
|
||||||
|
|
||||||
echo "Signatur prüfen für $TARGET_NAME..."
|
|
||||||
"$ANDROID_HOME/build-tools/35.0.0/apksigner" verify --verbose "$TARGET_PATH"
|
"$ANDROID_HOME/build-tools/35.0.0/apksigner" verify --verbose "$TARGET_PATH"
|
||||||
done
|
|
||||||
|
|
||||||
echo "Finale Release-APKs:"
|
echo "Finale Release-APK:"
|
||||||
ls -lh "$APK_DIR"/WeekFocus-*.apk
|
ls -lh "$TARGET_PATH"
|
||||||
env:
|
env:
|
||||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
||||||
@@ -142,7 +132,7 @@ jobs:
|
|||||||
echo "Release-Notes:"
|
echo "Release-Notes:"
|
||||||
cat "$NOTES_FILE"
|
cat "$NOTES_FILE"
|
||||||
|
|
||||||
- name: Release in Gitea erstellen und APKs hochladen
|
- name: Release in Gitea erstellen und APK hochladen
|
||||||
env:
|
env:
|
||||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|||||||
+13
-1
@@ -1,5 +1,17 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.2.11] - 2026-10-29
|
||||||
|
### New
|
||||||
|
* ability to edit words (with swiping to the left)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
* delete words with swiping to the right (instead of pressing the button)
|
||||||
|
|
||||||
|
## [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
|
||||||
@@ -8,7 +20,7 @@
|
|||||||
|
|
||||||
## [1.1.3] - 2026-10-03
|
## [1.1.3] - 2026-10-03
|
||||||
### Changed
|
### Changed
|
||||||
- chore: refactor: switch from release github action to bash
|
- chore: refactor: switch from release GitHub Action to bash
|
||||||
|
|
||||||
## [1.1.1] - 2026-10-03
|
## [1.1.1] - 2026-10-03
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
+10
-3
@@ -27,14 +27,15 @@ android {
|
|||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|
||||||
splits {
|
// not necessary
|
||||||
|
/*splits {
|
||||||
abi {
|
abi {
|
||||||
isEnable = true
|
isEnable = true
|
||||||
reset()
|
reset()
|
||||||
include("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
|
include("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
|
||||||
isUniversalApk = true
|
isUniversalApk = true
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
create("release") {
|
create("release") {
|
||||||
@@ -56,8 +57,13 @@ android {
|
|||||||
release {
|
release {
|
||||||
signingConfig = signingConfigs.getByName("release")
|
signingConfig = signingConfigs.getByName("release")
|
||||||
optimization {
|
optimization {
|
||||||
enable = false
|
enable = true
|
||||||
}
|
}
|
||||||
|
isShrinkResources = true
|
||||||
|
proguardFiles(
|
||||||
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
|
"proguard-rules.pro"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
@@ -72,6 +78,7 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(platform(libs.androidx.compose.bom))
|
implementation(platform(libs.androidx.compose.bom))
|
||||||
implementation(libs.androidx.activity.compose)
|
implementation(libs.androidx.activity.compose)
|
||||||
|
implementation(libs.androidx.compose.animation)
|
||||||
implementation(libs.androidx.compose.material3)
|
implementation(libs.androidx.compose.material3)
|
||||||
implementation(libs.androidx.compose.ui)
|
implementation(libs.androidx.compose.ui)
|
||||||
implementation(libs.androidx.compose.ui.graphics)
|
implementation(libs.androidx.compose.ui.graphics)
|
||||||
|
|||||||
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
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,29 +2,177 @@ package de.schanbro.weekfocus.screens
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.animateColorAsState
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material.icons.filled.Delete
|
import androidx.compose.material.icons.filled.Delete
|
||||||
|
import androidx.compose.material.icons.filled.Edit
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalFocusManager
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import de.schanbro.weekfocus.R
|
import de.schanbro.weekfocus.R
|
||||||
import de.schanbro.weekfocus.updateWidget
|
import de.schanbro.weekfocus.updateWidget
|
||||||
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun SwipeableWordItem(
|
||||||
|
word: String,
|
||||||
|
onDeleteRequest: () -> Unit,
|
||||||
|
onEditRequest: () -> Unit,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
val haptic = LocalHapticFeedback.current
|
||||||
|
|
||||||
|
val dismissState = rememberSwipeToDismissBoxState(
|
||||||
|
confirmValueChange = { value ->
|
||||||
|
when (value) {
|
||||||
|
SwipeToDismissBoxValue.StartToEnd -> onDeleteRequest() // nach rechts
|
||||||
|
SwipeToDismissBoxValue.EndToStart -> onEditRequest() // nach links
|
||||||
|
SwipeToDismissBoxValue.Settled -> Unit
|
||||||
|
}
|
||||||
|
false // Karte springt immer zurück, Dialog übernimmt
|
||||||
|
},
|
||||||
|
positionalThreshold = { totalDistance -> totalDistance * 0.4f }
|
||||||
|
)
|
||||||
|
|
||||||
|
// Haptisches Feedback, sobald die Schwelle überschritten wird
|
||||||
|
LaunchedEffect(dismissState.targetValue) {
|
||||||
|
if (dismissState.targetValue != SwipeToDismissBoxValue.Settled) {
|
||||||
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SwipeToDismissBox(
|
||||||
|
state = dismissState,
|
||||||
|
modifier = modifier,
|
||||||
|
backgroundContent = {
|
||||||
|
val direction = dismissState.dismissDirection
|
||||||
|
val isDelete = direction == SwipeToDismissBoxValue.StartToEnd
|
||||||
|
val isEdit = direction == SwipeToDismissBoxValue.EndToStart
|
||||||
|
|
||||||
|
val color by animateColorAsState(
|
||||||
|
targetValue = when {
|
||||||
|
isDelete -> MaterialTheme.colorScheme.errorContainer
|
||||||
|
isEdit -> MaterialTheme.colorScheme.secondaryContainer
|
||||||
|
else -> Color.Transparent
|
||||||
|
},
|
||||||
|
label = "swipeBackground"
|
||||||
|
)
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.clip(MaterialTheme.shapes.medium)
|
||||||
|
.background(color)
|
||||||
|
.padding(horizontal = 20.dp),
|
||||||
|
contentAlignment = if (isDelete) Alignment.CenterStart else Alignment.CenterEnd
|
||||||
|
) {
|
||||||
|
when {
|
||||||
|
isDelete -> Icon(
|
||||||
|
Icons.Default.Delete,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.onErrorContainer
|
||||||
|
)
|
||||||
|
isEdit -> Icon(
|
||||||
|
Icons.Default.Edit,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.onSecondaryContainer
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
ElevatedCard(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
shape = MaterialTheme.shapes.medium,
|
||||||
|
colors = CardDefaults.elevatedCardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainerLow
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = word,
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp, vertical = 16.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun DeleteWordDialog(
|
||||||
|
word: String,
|
||||||
|
onConfirm: () -> Unit,
|
||||||
|
onDismiss: () -> Unit
|
||||||
|
) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
icon = { Icon(Icons.Default.Delete, contentDescription = null) },
|
||||||
|
title = { Text("Wort löschen?") },
|
||||||
|
text = { Text("„$word“ wird dauerhaft entfernt.") },
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onConfirm) { Text("Löschen") }
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismiss) { Text("Abbrechen") }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun EditWordDialog(
|
||||||
|
word: String,
|
||||||
|
onSave: (String) -> Unit,
|
||||||
|
onDismiss: () -> Unit
|
||||||
|
) {
|
||||||
|
var text by remember(word) { mutableStateOf(word) }
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
icon = { Icon(Icons.Default.Edit, contentDescription = null) },
|
||||||
|
title = { Text("Wort bearbeiten") },
|
||||||
|
text = {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = text,
|
||||||
|
onValueChange = { text = it },
|
||||||
|
singleLine = true,
|
||||||
|
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||||
|
keyboardActions = KeyboardActions(onDone = { onSave(text) })
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = { onSave(text) },
|
||||||
|
enabled = text.isNotBlank()
|
||||||
|
) { Text("Speichern") }
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismiss) { Text("Abbrechen") }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun WordListScreen(modifier: Modifier = Modifier) {
|
fun WordListScreen(modifier: Modifier = Modifier) {
|
||||||
@@ -43,25 +191,40 @@ fun WordListScreen(modifier: Modifier = Modifier) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val haptic = LocalHapticFeedback.current
|
||||||
|
var wordToDelete by remember { mutableStateOf<String?>(null) }
|
||||||
|
var wordToEdit by remember { mutableStateOf<String?>(null) }
|
||||||
|
|
||||||
fun saveWords() {
|
fun saveWords() {
|
||||||
sharedPrefs.edit().putStringSet("words_key", wordList.toSet()).apply()
|
sharedPrefs.edit().putStringSet("words_key", wordList.toSet()).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addCurrentWord() {
|
fun addCurrentWord() {
|
||||||
val trimmed = textInput.trim()
|
val trimmed = textInput.trim()
|
||||||
if (trimmed.isNotEmpty()) {
|
if (trimmed.isNotEmpty() && trimmed !in wordList) {
|
||||||
wordList.add(0, trimmed)
|
wordList.add(0, trimmed)
|
||||||
saveWords()
|
saveWords()
|
||||||
updateWidget(context)
|
updateWidget(context)
|
||||||
textInput = ""
|
textInput = ""
|
||||||
focusManager.clearFocus() // Fokus aufheben & Tastatur schließen
|
focusManager.clearFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateWord(old: String, new: String) {
|
||||||
|
val trimmed = new.trim()
|
||||||
|
val index = wordList.indexOf(old)
|
||||||
|
// Duplikate vermeiden, da das Set ohnehin keine doppelten Einträge speichert
|
||||||
|
if (index >= 0 && trimmed.isNotEmpty() && (trimmed == old || trimmed !in wordList)) {
|
||||||
|
wordList[index] = trimmed
|
||||||
|
saveWords()
|
||||||
|
updateWidget(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
// Auf Klicks im leeren Bereich reagieren -> Fokus aufheben
|
// Auf Klicks im leeren Bereich reagieren → Fokus aufheben
|
||||||
.pointerInput(Unit) {
|
.pointerInput(Unit) {
|
||||||
detectTapGestures(onTap = {
|
detectTapGestures(onTap = {
|
||||||
focusManager.clearFocus()
|
focusManager.clearFocus()
|
||||||
@@ -127,43 +290,39 @@ fun WordListScreen(modifier: Modifier = Modifier) {
|
|||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
contentPadding = PaddingValues(bottom = 16.dp)
|
contentPadding = PaddingValues(bottom = 16.dp)
|
||||||
) {
|
) {
|
||||||
itemsIndexed(wordList) { index, word ->
|
items(items = wordList, key = { it }) { word ->
|
||||||
ElevatedCard(
|
SwipeableWordItem(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
word = word,
|
||||||
shape = MaterialTheme.shapes.medium,
|
onDeleteRequest = { wordToDelete = word },
|
||||||
colors = CardDefaults.elevatedCardColors(
|
onEditRequest = { wordToEdit = word },
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceContainerLow
|
modifier = Modifier.animateItem() // ältere Compose-Versionen: animateItemPlacement()
|
||||||
)
|
)
|
||||||
) {
|
}
|
||||||
Row(
|
}
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
wordToDelete?.let { word ->
|
||||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
DeleteWordDialog(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
word = word,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
onConfirm = {
|
||||||
) {
|
wordList.remove(word)
|
||||||
Text(
|
|
||||||
text = word,
|
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
|
||||||
color = MaterialTheme.colorScheme.onSurface,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
)
|
|
||||||
IconButton(
|
|
||||||
onClick = {
|
|
||||||
wordList.removeAt(index)
|
|
||||||
saveWords()
|
saveWords()
|
||||||
updateWidget(context)
|
updateWidget(context)
|
||||||
}
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
) {
|
wordToDelete = null
|
||||||
Icon(
|
},
|
||||||
imageVector = Icons.Default.Delete,
|
onDismiss = { wordToDelete = null }
|
||||||
contentDescription = "Entfernen",
|
|
||||||
tint = MaterialTheme.colorScheme.error
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
wordToEdit?.let { word ->
|
||||||
}
|
EditWordDialog(
|
||||||
|
word = word,
|
||||||
|
onSave = { new ->
|
||||||
|
updateWord(word, new)
|
||||||
|
wordToEdit = null
|
||||||
|
},
|
||||||
|
onDismiss = { wordToEdit = null }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ lifecycleRuntimeKtx = "2.11.0"
|
|||||||
activityCompose = "1.13.0"
|
activityCompose = "1.13.0"
|
||||||
kotlin = "2.4.20"
|
kotlin = "2.4.20"
|
||||||
composeBom = "2026.09.00"
|
composeBom = "2026.09.00"
|
||||||
|
animation = "1.12.1"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
@@ -25,6 +26,7 @@ androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-
|
|||||||
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
||||||
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
|
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||||
androidx-material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended" }
|
androidx-material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended" }
|
||||||
|
androidx-compose-animation = { group = "androidx.compose.animation", name = "animation", version.ref = "animation" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
|
|||||||
Reference in new issue
Block a user