Compare commits

...
52 Commits
Author SHA1 Message Date
robin 200b834d1c Merge branch 'main' into feat/auto-update 2026-10-30 11:56:09 +00:00
robin 0fcc9ba514 refactor: move update code to folder update 2026-10-30 12:55:37 +01:00
robin 8d38c319a2 feat: ask for network permission before checking for updates 2026-10-30 12:50:15 +01:00
robin 90ce637846 feat: auto update 2026-10-30 12:42:29 +01:00
robin f77080f6f2 CHANGELOG update 2026-10-30 12:33:22 +01:00
robin f161db3345 Merge pull request 'fix: show app icon' (#35) from fix/splashscreen-light into main
Reviewed-on: robin/WeekFocus#35
2026-10-30 11:26:47 +00:00
robin 32ae274da3 fix: show app icon 2026-10-30 12:26:14 +01:00
robin 431f61e683 CHANGELOG update
Build & Release Android App / build (push) Successful in 14m33s
2026-10-29 18:11:33 +01:00
robin 2cadfa8972 Merge pull request 'style: dark mode support on splash screen' (#33) from style/splash-screen into main
Reviewed-on: robin/WeekFocus#33
2026-10-29 17:10:17 +00:00
robin 77bcaddc55 style: dark mode support on splash screen 2026-10-29 18:09:55 +01:00
robin a2d049e280 Merge pull request 'chore(l10n): add translations' (#31) from chore(l10n)/translation into main
Build & Release Android App / build (push) Successful in 8m24s
Reviewed-on: robin/WeekFocus#31
2026-10-29 16:41:08 +00:00
robin a393624d03 chore(l10n): add translations 2026-10-29 17:40:35 +01:00
robin 27d1a4b6ea Merge pull request 'Feat/edit words' (#30) from feat/edit-words into main
Build & Release Android App / build (push) Successful in 20m22s
Reviewed-on: robin/WeekFocus#30
2026-10-29 16:23:20 +00:00
robin 5ae35c4cac CHANGELOG update 2026-10-29 17:22:42 +01:00
robin 75c4a43d57 feat: ability to edit words 2026-10-29 17:19:15 +01:00
robin 0c75afab4e CHANGELOG update
Build & Release Android App / build (push) Successful in 16m15s
2026-10-08 15:20:25 +02:00
robin 0c2ec3f20c chore: add proguard-rules.pro
Build & Release Android App / build (push) Successful in 18m51s
2026-10-08 14:55:36 +02:00
robin daf16f0e67 chore: adjust workflow
Build & Release Android App / build (push) Failing after 18m42s
2026-10-08 14:35:15 +02:00
robin 8ccd4430da Merge pull request 'refactor: implement better choosing of the word' (#23) from test/widget-automation into main
Build & Release Android App / build (push) Failing after 54s
Reviewed-on: #23
2026-10-08 11:45:25 +00:00
robin 98ffa47fa4 Merge branch 'main' into test/widget-automation 2026-10-08 11:45:17 +00:00
robin dfd0b75521 Merge pull request 'Chore/reduce apk size' (#29) from chore/reduce-apk-size into main
Reviewed-on: #29
2026-10-07 14:50:17 +00:00
robin d9c1942f2a Merge branch 'main' into chore/reduce-apk-size 2026-10-07 14:50:08 +00:00
robin bc6edc4a04 chore: adjust workflow 2026-10-07 16:49:40 +02:00
robin d03f9eee67 chore: enable R8 (Code-Shrinking) 2026-10-07 16:48:13 +02:00
robin 7eff7300d0 chore: disable abi (apk-split) 2026-10-07 16:45:22 +02:00
robin 8458f0fce5 Merge pull request 'Chore/smaller apk' (#28) from chore/smaller-apk into main
Build & Release Android App / build (push) Successful in 19m5s
Reviewed-on: #28
2026-10-07 14:08:54 +00:00
robin e444abecae Merge branch 'main' into chore/smaller-apk 2026-10-07 14:08:43 +00:00
robin 3bac488893 chore: force to use JDK 17 2026-10-07 16:08:14 +02:00
robin b8195b74f1 chore: force to use JDK 17 2026-10-07 16:06:27 +02:00
robin f431fb272d chore: force to use JDK 17 2026-10-07 16:03:39 +02:00
robin 107f1c3955 Merge pull request 'chore: fix workflow 2' (#26) from chore/smaller-apk into main
Build & Release Android App / build (push) Failing after 1m16s
Reviewed-on: #26
2026-10-07 13:57:30 +00:00
robin ce1eba6b83 Merge branch 'main' into chore/smaller-apk 2026-10-07 13:57:20 +00:00
robin 4b8e2bc88d chore: fix workflow 2026-10-07 15:56:01 +02:00
robin c71851702f Merge pull request 'chore: fix workflow' (#25) from chore/smaller-apk into main
Reviewed-on: #25
2026-10-07 13:44:27 +00:00
robin 4c04a5260c Merge branch 'main' into chore/smaller-apk 2026-10-07 13:44:17 +00:00
robin 90e477cb04 chore: fix workflow
Build & Release Android App / build (push) Failing after 47s
2026-10-07 15:43:51 +02:00
robin 82d4fa331b Merge pull request 'chore: apk-splits' (#24) from chore/smaller-apk into main
Reviewed-on: #24
2026-10-07 13:27:42 +00:00
robin 6206a47fc7 chore: apk-splits
Build & Release Android App / build (push) Failing after 3m51s
chore: adjust workflow in Gitea
chore(deps): update versions
2026-10-07 15:19:22 +02:00
robin ff78c71ab5 Merge pull request 'chore: automaticly mark as prerelease if necessary' (#19) from chore into main
Reviewed-on: #19
2026-10-06 15:19:59 +00:00
robin c6d6ac359b chore: automaticly mark as prerelease if necessary 2026-10-06 15:19:44 +00:00
robin 7cc3245b97 refactor: implement better choosing of the word 2026-10-06 17:06:13 +02:00
robin 8cacb6f582 Merge pull request 'chore(l10n): update translations' (#17) from weblate-translations into main
Reviewed-on: #17
2026-10-04 15:32:04 +00:00
robin 86882fafcb chore(l10n): update German (formal) translation
chore(l10n): update English translation

Co-authored-by: Weblate Admin <robin@schanbros.de>
Language: English
Language: German (formal)
Progress: 100.0% (7 of 7 strings)
Translate-URL: https://weblate.schamagusa.de/projects/weekfocus/weekfocus/de@formal/
Translate-URL: https://weblate.schamagusa.de/projects/weekfocus/weekfocus/en/
Translation: WeekFocus/WeekFocus
2026-10-04 15:31:23 +00:00
robin edb11b360b CHANGELOG update
Build & Release Android App / build (push) Successful in 19m15s
2026-10-04 17:22:47 +02:00
robin 18c375979c Merge pull request 'feat: better layout' (#16) from feat/better-layout into main
Reviewed-on: #16
2026-10-04 15:18:58 +00:00
robin 2545498dc2 feat: navigation
feat: remove word
2026-10-04 17:17:23 +02:00
robin fd20b5d91e chore: debug/dev builds besides normal builds 2026-10-04 15:53:24 +02:00
robin 76cf592cd1 Merge pull request 'chore(l10n): update translations' (#14) from weblate-translations into main
Reviewed-on: #14
2026-10-04 12:58:52 +00:00
robin d134b0cd0a chore(l10n): update English translation
chore(l10n): update German (formal) translation

Co-authored-by: Weblate Admin <robin@schanbros.de>
Language: English
Language: German (formal)
Progress: 100.0% (7 of 7 strings)
Translate-URL: https://weblate.schamagusa.de/projects/weekfocus/weekfocus/de@formal/
Translate-URL: https://weblate.schamagusa.de/projects/weekfocus/weekfocus/en/
Translation: WeekFocus/WeekFocus
2026-10-04 12:54:11 +00:00
robin 4a62373992 refactor: move hardcoded texts to strings.xml 2026-10-04 14:19:38 +02:00
robin e589693c67 README.md aktualisiert 2026-10-04 10:19:26 +00:00
robin f5568cf211 README.md aktualisiert 2026-10-03 17:45:08 +00:00
25 changed files with 1183 additions and 203 deletions

No files matched your search

+32 -22
View File
@@ -1,4 +1,3 @@
# .gitea/workflows/build-release.yml
name: Build & Release Android App
on:
@@ -19,6 +18,7 @@ jobs:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
- name: Code auschecken
uses: actions/checkout@v4
@@ -46,14 +46,12 @@ jobs:
rm /tmp/tools.zip
fi
# Lizenzen korrekt akzeptieren (kein "yes |", wegen pipefail/SIGPIPE)
"$SDKMANAGER" --sdk_root="$SDK_PATH" --licenses < <(yes) > /dev/null
# Benötigte Pakete direkt installieren
"$SDKMANAGER" --sdk_root="$SDK_PATH" \
"platform-tools" \
"platforms;android-37.0" \
"build-tools;36.0.0"
"platforms;android-35" \
"build-tools;35.0.0"
echo "ANDROID_HOME=$SDK_PATH" >> $GITHUB_ENV
echo "ANDROID_SDK_ROOT=$SDK_PATH" >> $GITHUB_ENV
@@ -71,33 +69,33 @@ jobs:
set -euo pipefail
VERSION="${GITHUB_REF_NAME#v}"
echo "Baue Version: $VERSION"
./gradlew assembleRelease \
--no-daemon \
-Dorg.gradle.java.home="$JAVA_HOME" \
-Porg.gradle.java.installations.auto-download=false \
-PversionNameOverride="$VERSION"
echo "Erzeugte APK-Dateien:"
find app/build/outputs -type f -name "*.apk" -print
APK_DIR="app/build/outputs/apk/release"
APK_SOURCE="$(find app/build/outputs/apk/release -maxdepth 1 -type f -name "*.apk" ! -name "*unsigned*" | head -n 1)"
echo "Gefundene APKs in $APK_DIR:"
ls -lh "$APK_DIR"
if [ -z "$APK_SOURCE" ]; then
echo "Keine Release-APK gefunden."
SRC="$APK_DIR/app-release.apk"
if [ ! -f "$SRC" ]; then
echo "app-release.apk nicht gefunden (evtl. unsigniert oder anderer Name)"
exit 1
fi
APK_DIR="app/build/outputs/apk/release"
APK_NAME="WeekFocus-${VERSION}.apk"
APK_TARGET="$APK_DIR/$APK_NAME"
TARGET_PATH="$APK_DIR/WeekFocus-${VERSION}.apk"
mv "$SRC" "$TARGET_PATH"
mv "$APK_SOURCE" "$APK_TARGET"
echo "Signatur prüfen für $(basename "$TARGET_PATH")..."
"$ANDROID_HOME/build-tools/35.0.0/apksigner" verify --verbose "$TARGET_PATH"
"$ANDROID_HOME/build-tools/36.0.0/apksigner" verify --verbose "$APK_TARGET"
echo "APK erstellt: $APK_TARGET"
ls -lh "$APK_DIR"
echo "Finale Release-APK:"
ls -lh "$TARGET_PATH"
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
@@ -141,14 +139,22 @@ jobs:
run: |
set -euo pipefail
TAG="$GITHUB_REF_NAME"
VERSION="${TAG#v}"
NOTES_FILE="$RUNNER_TEMP/release_notes.md"
AUTH="Authorization: token $TOKEN"
# Release holen oder neu anlegen
CODE=$(curl -sS -o release.json -w '%{http_code}' -H "$AUTH" "$API/releases/tags/$TAG")
if [ "$CODE" = "404" ]; then
if [[ "$VERSION" =~ (alpha|beta|rc|dev) ]]; then
IS_PRERELEASE="true"
else
IS_PRERELEASE="false"
fi
jq -n --arg tag "$TAG" --arg name "$TAG" --rawfile body "$NOTES_FILE" \
'{tag_name:$tag, name:$name, body:$body}' > payload.json
--argjson prerelease "$IS_PRERELEASE" \
'{tag_name:$tag, name:$name, body:$body, prerelease:$prerelease}' > payload.json
curl -fsS -X POST -H "$AUTH" -H "Content-Type: application/json" \
-d @payload.json "$API/releases" -o release.json
elif [ "$CODE" != "200" ]; then
@@ -156,14 +162,18 @@ jobs:
cat release.json
exit 1
fi
RELEASE_ID=$(jq -r .id release.json)
# APK hochladen, gleichnamige alte Assets vorher löschen
for APK in app/build/outputs/apk/release/WeekFocus-*.apk; do
[ -e "$APK" ] || continue
NAME=$(basename "$APK")
echo "Lade Hoch: $NAME"
for ID in $(jq -r --arg n "$NAME" '.assets[]? | select(.name==$n) | .id' release.json); do
curl -fsS -X DELETE -H "$AUTH" "$API/releases/$RELEASE_ID/assets/$ID"
done
curl -fsS -X POST -H "$AUTH" -F "attachment=@$APK" \
"$API/releases/$RELEASE_ID/assets?name=$NAME"
done
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="jbr-25" 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" />
</component>
<component name="ProjectType">
+26 -1
View File
@@ -1,8 +1,33 @@
# Changelog
## [1.3.0]
### Fixed
* show app icon on splash screen
## [1.2.12] - 2026-10-29
### New
* dark mode support on the splash screen
## [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
### New
* navigation
* ability to delete words
* better layout
## [1.1.3] - 2026-10-03
### 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
### Changed
+42 -25
View File
@@ -11,20 +11,19 @@
<img src="https://raw.githubusercontent.com/ImranR98/Obtainium/main/assets/graphics/badge_obtainium.png" alt="Get it on Obtainium" height="64">
</a>
[![Release](https://img.shields.io/gitea/v/release/Schanbro/WeekFocus?gitea_url=https://git.schamagusa.de&label=Release)](https://git.schamagusa.de/Schanbro/WeekFocus/releases)
[![License: GPL-3.0](https://img.shields.io/badge/License-GPL--3.0-blue)](LICENSE)
[![Translation status](https://weblate.schamagusa.de/widgets/weekfocus/-/svg-badge.svg)](https://weblate.schamagusa.de/engage/weekfocus/)
![Android 8.0+](https://img.shields.io/badge/Android-8.0%2B-3DDC84?logo=android&logoColor=white)
![Kotlin](https://img.shields.io/badge/Kotlin-7F52FF?logo=kotlin&logoColor=white)
![Jetpack Compose](https://img.shields.io/badge/Jetpack%20Compose-4285F4?logo=jetpackcompose&logoColor=white)
![Stars](https://img.shields.io/gitea/stars/Schanbro/WeekFocus?gitea_url=https://git.schamagusa.de)
![Forks](https://img.shields.io/gitea/forks/Schanbro/WeekFocus?gitea_url=https://git.schamagusa.de)
![Open issues](https://img.shields.io/gitea/issues/open/Schanbro/WeekFocus?gitea_url=https://git.schamagusa.de)
![Last commit](https://img.shields.io/gitea/last-commit/Schanbro/WeekFocus?gitea_url=https://git.schamagusa.de)
[![Release](https://img.shields.io/gitea/v/release/Schanbro/WeekFocus?gitea_url=https://git.schamagusa.de&style=for-the-badge&label=Release)](https://git.schamagusa.de/Schanbro/WeekFocus/releases)
[![License: GPL-3.0](https://img.shields.io/badge/License-GPL--3.0-blue?style=for-the-badge)](LICENSE)
<!--[![Translation status](https://weblate.schamagusa.de/widgets/weekfocus/-/svg-badge.svg)](https://weblate.schamagusa.de/engage/weekfocus/)-->
![Android](https://img.shields.io/badge/Android-10%2B-3DDC84?style=for-the-badge&logo=android&logoColor=white)
![Language: Kotlin](https://img.shields.io/badge/Language-Kotlin-7F52FF?style=for-the-badge&logo=kotlin&logoColor=white)
![UI: Jetpack Compose](https://img.shields.io/badge/UI-Jetpack%20Compose-4285F4?style=for-the-badge&logo=jetpackcompose&logoColor=white)
![Design: Material 3](https://img.shields.io/badge/Design-Material%203-3DDC84?style=for-the-badge)
<!--[![Stars](https://img.shields.io/gitea/stars/Schanbro/WeekFocus?gitea_url=https://git.schamagusa.de&style=for-the-badge)](https://git.schamagusa.de/Schanbro/WeekFocus)
[![Forks](https://img.shields.io/gitea/forks/Schanbro/WeekFocus?gitea_url=https://git.schamagusa.de&style=for-the-badge)](https://git.schamagusa.de/Schanbro/WeekFocus)-->
[![Open Issues](https://img.shields.io/gitea/issues/open/Schanbro/WeekFocus?gitea_url=https://git.schamagusa.de&style=for-the-badge)](https://git.schamagusa.de/Schanbro/WeekFocus/issues)
[![Last Commit](https://img.shields.io/gitea/last-commit/Schanbro/WeekFocus?gitea_url=https://git.schamagusa.de&style=for-the-badge)](https://git.schamagusa.de/Schanbro/WeekFocus)
</div>
@@ -35,9 +34,9 @@
- [About](#about)
- [How It Works](#how-it-works)
- [Features](#features)
- [Screenshots](#screenshots)
- [Installation](#installation)
- [Building from Source](#building-from-source)
- [Releases](#releases)
- [Contributing](#contributing)
- [License](#license)
- [Translations](#translations)
@@ -65,16 +64,6 @@ No streaks, no pressure, no clutter. Just a gentle daily reminder of what you wa
- 🔒 No ads, no tracking, no unnecessary permissions
- ⚡ Lightweight and battery-friendly
## Screenshots
<!-- Add screenshots here, for example:
<p align="center">
<img src="docs/screenshots/1.png" width="24%" />
<img src="docs/screenshots/2.png" width="24%" />
<img src="docs/screenshots/3.png" width="24%" />
</p>
-->
## Installation
### Recommended: Obtainium
@@ -82,8 +71,7 @@ No streaks, no pressure, no clutter. Just a gentle daily reminder of what you wa
With [Obtainium](https://github.com/ImranR98/Obtainium) you get updates directly from this repository, no app store required.
1. Install Obtainium on your Android device.
2. Tap the badge above or open this link:
[Add WeekFocus to Obtainium](https://apps.obtainium.imranr.dev/redirect?r=obtainium://add/https://git.schamagusa.de/Schanbro/WeekFocus)
2. Tap the badge above.
3. Confirm and install the app.
Alternatively, tap **Add App** in Obtainium and paste this URL:
@@ -104,6 +92,7 @@ https://git.schamagusa.de/Schanbro/WeekFocus
- [Android Studio](https://developer.android.com/studio) (latest stable)
- JDK 17 or newer
- Android SDK platform 37 (`minSdk` 29, `targetSdk` 37)
**Steps**
@@ -115,6 +104,34 @@ cd WeekFocus
The resulting APK is located in `app/build/outputs/apk/debug/`.
## Releases
Releases are built automatically with Gitea Actions. Pushing a tag that starts with `v` triggers the workflow, which builds and signs the APK and publishes it as a release together with the notes from `CHANGELOG.md`.
### Starting a release build
Create a tag and push it. The tag name determines the app version (`v1.1.3` builds version `1.1.3`):
```bash
git tag v1.1.3
git push origin v1.1.3
```
You can follow the build under **Actions** in the repository. When it finishes, the signed `WeekFocus-1.1.3.apk` appears on the [Releases](https://git.schamagusa.de/Schanbro/WeekFocus/releases) page.
### Release notes
The workflow takes the notes from the section of `CHANGELOG.md` whose heading starts with the version number:
```markdown
## 1.1.3
- Added Weblate translations
- Fixed widget update at the start of a new week
```
If no matching section exists, the release gets a short placeholder text instead.
## Contributing
Contributions are welcome!
+26 -6
View File
@@ -5,7 +5,6 @@ plugins {
val tagVersion = (project.findProperty("versionNameOverride") as String?) ?: "0.0.0-dev"
// "1.2.3" oder "1.2.3-alpha9" -> Kern "1.2.3" für den versionCode
val core = tagVersion
.removePrefix("v")
.substringBefore("-")
@@ -16,20 +15,28 @@ val patch = parts.getOrElse(2) { 0 }
android {
namespace = "de.schanbro.weekfocus"
compileSdk {
version = release(37)
}
compileSdk = 37
defaultConfig {
applicationId = "de.schanbro.weekfocus"
minSdk = 29
targetSdk = 37
versionCode = major * 10000 + minor * 100 + patch
versionCode = (major * 10000 + minor * 100 + patch).coerceAtLeast(1)
versionName = tagVersion
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
// not necessary
/*splits {
abi {
isEnable = true
reset()
include("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
isUniversalApk = true
}
}*/
signingConfigs {
create("release") {
val ksPath = System.getenv("KEYSTORE_PATH")
@@ -43,11 +50,20 @@ android {
}
buildTypes {
debug {
applicationIdSuffix = ".debug"
versionNameSuffix = "-dev"
}
release {
signingConfig = signingConfigs.getByName("release")
optimization {
enable = false
enable = true
}
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
@@ -62,6 +78,7 @@ android {
dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.animation)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.graphics)
@@ -75,4 +92,7 @@ dependencies {
androidTestImplementation(libs.androidx.junit)
debugImplementation(libs.androidx.compose.ui.test.manifest)
debugImplementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.material.icons.extended)
implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.7")
}
+6
View File
@@ -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
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">WeekFocus-dev</string>
</resources>
+22 -3
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 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" />
<!-- used for auto-update -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<application
android:allowBackup="true"
@@ -15,7 +21,7 @@
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.WeekFocus"
android:theme="@style/Theme.WeekFocus.Splash"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -28,11 +34,24 @@
android:exported="true">
<intent-filter>
<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>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_info" />
</receiver>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>
@@ -6,123 +6,147 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.List
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.List
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import android.appwidget.AppWidgetManager
import android.content.ComponentName
import de.schanbro.weekfocus.ui.theme.WeekFocusTheme
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.stringResource
import de.schanbro.weekfocus.ui.theme.WeekFocusTheme
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import de.schanbro.weekfocus.screens.WordListScreen
import de.schanbro.weekfocus.update.NetworkPermissionGate
import de.schanbro.weekfocus.update.UpdateHandler
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
WeekFocusTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
WordListScreen(
modifier = Modifier.padding(innerPadding)
MainScreen()
NetworkPermissionGate {
UpdateHandler()
}
}
}
}
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)
@Composable
fun MainScreen() {
var selectedTab by remember { mutableIntStateOf(0) }
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
Scaffold(
modifier = Modifier
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
LargeTopAppBar(
title = {
Text(
when (selectedTab) {
0 -> stringResource(R.string.title_home)
1 -> stringResource(R.string.title_words)
2 -> stringResource(R.string.title_settings)
else -> stringResource(R.string.app_name)
}
)
},
scrollBehavior = scrollBehavior,
colors = TopAppBarDefaults.largeTopAppBarColors(
containerColor = MaterialTheme.colorScheme.surface,
scrolledContainerColor = MaterialTheme.colorScheme.surfaceContainer
)
)
},
bottomBar = {
NavigationBar {
NavigationBarItem(
selected = selectedTab == 0,
onClick = { selectedTab = 0 },
icon = {
Icon(
imageVector = if (selectedTab == 0) Icons.Filled.Home else Icons.Outlined.Home,
contentDescription = stringResource(R.string.title_home)
)
},
label = { Text(stringResource(R.string.title_home)) }
)
NavigationBarItem(
selected = selectedTab == 1,
onClick = { selectedTab = 1 },
icon = {
Icon(
imageVector = if (selectedTab == 1) Icons.Filled.List else Icons.Outlined.List,
contentDescription = stringResource(R.string.title_words)
)
},
label = { Text(stringResource(R.string.title_words)) }
)
NavigationBarItem(
selected = selectedTab == 2,
onClick = { selectedTab = 2 },
icon = {
Icon(
imageVector = if (selectedTab == 2) Icons.Filled.Settings else Icons.Outlined.Settings,
contentDescription = stringResource(R.string.title_settings)
)
},
label = { Text(stringResource(R.string.title_settings)) }
)
}
}
) { innerPadding ->
Surface(
modifier = Modifier
.fillMaxSize()
.padding(innerPadding),
color = MaterialTheme.colorScheme.background
) {
when (selectedTab) {
0 -> PlaceholderScreen(title = stringResource(R.string.title_weekly_focus))
1 -> WordListScreen()
2 -> PlaceholderScreen(title = stringResource(R.string.title_settings))
}
}
}
}
@Composable
fun WordListScreen(modifier: Modifier = Modifier) {
val context = LocalContext.current
val sharedPrefs = remember {
context.getSharedPreferences("WeekFocusPrefs", Context.MODE_PRIVATE)
}
// Wörter aus SharedPreferences laden und Zustand verwalten
var textInput by remember { mutableStateOf("") }
val wordList = remember {
mutableStateListOf<String>().apply {
val savedSet = sharedPrefs.getStringSet("words_key", emptySet()) ?: emptySet()
addAll(savedSet)
}
}
// Funktion zum Speichern in SharedPreferences
fun saveWords() {
sharedPrefs.edit().putStringSet("words_key", wordList.toSet()).apply()
}
Column(
modifier = modifier
.fillMaxSize()
.padding(16.dp)
fun PlaceholderScreen(title: String) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
// Eingabefeld für ein neues Wort
OutlinedTextField(
value = textInput,
onValueChange = { textInput = it },
label = { Text(stringResource(R.string.hint_new_word)) },
modifier = Modifier.fillMaxWidth(),
singleLine = true
)
Spacer(modifier = Modifier.height(8.dp))
// Button zum Hinzufügen
Button(
onClick = {
val trimmed = textInput.trim()
if (trimmed.isNotEmpty()) {
wordList.add(trimmed)
saveWords()
updateWidget(context)
textInput = ""
}
},
modifier = Modifier.fillMaxWidth()
) {
Text(stringResource(R.string.hint_add_word))
}
Spacer(modifier = Modifier.height(24.dp))
Text(
text = stringResource(R.string.title_saved_words),
style = MaterialTheme.typography.titleMedium
)
Spacer(modifier = Modifier.height(8.dp))
// Liste der Wörter
if (wordList.isEmpty()) {
Text(
text = stringResource(R.string.msg_no_words_yet),
style = MaterialTheme.typography.bodyMedium
)
} else {
LazyColumn {
items(wordList) { word ->
Text(
text = "• $word",
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(vertical = 4.dp)
text = title,
style = MaterialTheme.typography.headlineMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
}
}
}
// Hilfsfunktion zum Aktualisieren des Widgets
/**
* Bleibt als Top-Level-Funktion erhalten, damit WordListScreen unverändert weiter funktioniert.
*/
fun updateWidget(context: Context) {
val appWidgetManager = AppWidgetManager.getInstance(context)
val componentName = ComponentName(context, SimpleWidget::class.java)
val appWidgetIds = appWidgetManager.getAppWidgetIds(componentName)
for (appWidgetId in appWidgetIds) {
SimpleWidget.updateAppWidget(context, appWidgetManager, appWidgetId)
}
SimpleWidget.updateAllWidgets(context)
}
@@ -1,14 +1,35 @@
package de.schanbro.weekfocus
import android.app.AlarmManager
import android.app.PendingIntent
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.widget.RemoteViews
import java.util.Calendar
import java.util.Random
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.ZoneId
import java.time.temporal.ChronoUnit
import java.time.temporal.IsoFields
import java.time.temporal.TemporalAdjusters
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(
context: Context,
appWidgetManager: AppWidgetManager,
@@ -17,40 +38,141 @@ class SimpleWidget : AppWidgetProvider() {
for (appWidgetId in appWidgetIds) {
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 {
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(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetId: Int
) {
// 1. SharedPreferences auslesen
val sharedPrefs = context.getSharedPreferences("WeekFocusPrefs", Context.MODE_PRIVATE)
val savedSet = sharedPrefs.getStringSet("words_key", emptySet()) ?: emptySet()
val wordList = savedSet.toList()
val displayText = resolveWordOfWeek(context)
?: context.getString(R.string.msg_no_words)
// 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 {
"Keine Wörter"
}
// 4. RemoteViews aktualisieren
val views = RemoteViews(context.packageName, R.layout.widget_main)
views.setTextViewText(R.id.appwidget_text, displayText)
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
)
}
}
}
@@ -0,0 +1,328 @@
package de.schanbro.weekfocus.screens
import android.content.Context
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp
import de.schanbro.weekfocus.R
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(stringResource(R.string.dialog_delete_title)) },
text = { Text(stringResource(R.string.dialog_delete_message, word)) },
confirmButton = {
TextButton(onClick = onConfirm) { Text(stringResource(R.string.action_delete)) }
},
dismissButton = {
TextButton(onClick = onDismiss) { Text(stringResource(R.string.action_cancel)) }
}
)
}
@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(stringResource(R.string.dialog_edit_title)) },
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(stringResource(R.string.action_save)) }
},
dismissButton = {
TextButton(onClick = onDismiss) { Text(stringResource(R.string.action_cancel)) }
}
)
}
@Composable
fun WordListScreen(modifier: Modifier = Modifier) {
val context = LocalContext.current
val focusManager = LocalFocusManager.current // FocusManager holen
val sharedPrefs = remember {
context.getSharedPreferences("WeekFocusPrefs", Context.MODE_PRIVATE)
}
var textInput by remember { mutableStateOf("") }
val wordList = remember {
mutableStateListOf<String>().apply {
val savedSet = sharedPrefs.getStringSet("words_key", emptySet()) ?: emptySet()
addAll(savedSet)
}
}
val haptic = LocalHapticFeedback.current
var wordToDelete by remember { mutableStateOf<String?>(null) }
var wordToEdit by remember { mutableStateOf<String?>(null) }
fun saveWords() {
sharedPrefs.edit().putStringSet("words_key", wordList.toSet()).apply()
}
fun addCurrentWord() {
val trimmed = textInput.trim()
if (trimmed.isNotEmpty() && trimmed !in wordList) {
wordList.add(0, trimmed)
saveWords()
updateWidget(context)
textInput = ""
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(
modifier = modifier
.fillMaxSize()
// Auf Klicks im leeren Bereich reagieren → Fokus aufheben
.pointerInput(Unit) {
detectTapGestures(onTap = {
focusManager.clearFocus()
})
}
.padding(horizontal = 16.dp)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
OutlinedTextField(
value = textInput,
onValueChange = { textInput = it },
label = { Text(stringResource(R.string.hint_new_word)) },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
shape = MaterialTheme.shapes.medium,
// "Fertig" / "Hinzufügen" Taste auf der Tastatur konfigurieren
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(
onDone = { addCurrentWord() }
)
)
Button(
onClick = { addCurrentWord() },
modifier = Modifier
.fillMaxWidth()
.height(50.dp),
shape = MaterialTheme.shapes.medium
) {
Icon(Icons.Default.Add, contentDescription = null)
Spacer(Modifier.width(8.dp))
Text(stringResource(R.string.hint_add_word))
}
}
Spacer(modifier = Modifier.height(16.dp))
AnimatedVisibility(
visible = wordList.isEmpty(),
enter = fadeIn(),
exit = fadeOut()
) {
Box(
modifier = Modifier
.fillMaxWidth()
.padding(top = 32.dp),
contentAlignment = Alignment.Center
) {
Text(
text = stringResource(R.string.msg_no_words_yet),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(bottom = 16.dp)
) {
items(items = wordList, key = { it }) { word ->
SwipeableWordItem(
word = word,
onDeleteRequest = { wordToDelete = word },
onEditRequest = { wordToEdit = word },
modifier = Modifier.animateItem() // ältere Compose-Versionen: animateItemPlacement()
)
}
}
wordToDelete?.let { word ->
DeleteWordDialog(
word = word,
onConfirm = {
wordList.remove(word)
saveWords()
updateWidget(context)
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
wordToDelete = null
},
onDismiss = { wordToDelete = null }
)
}
wordToEdit?.let { word ->
EditWordDialog(
word = word,
onSave = { new ->
updateWord(word, new)
wordToEdit = null
},
onDismiss = { wordToEdit = null }
)
}
}
}
@@ -0,0 +1,77 @@
package de.schanbro.weekfocus.update
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import androidx.core.content.FileProvider
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.withContext
import java.io.File
import java.io.IOException
import java.net.HttpURLConnection
import java.net.URL
object ApkInstaller {
fun canInstall(context: Context): Boolean =
context.packageManager.canRequestPackageInstalls()
fun openInstallPermissionSettings(context: Context) {
val intent = Intent(
Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES,
Uri.parse("package:${context.packageName}")
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}
suspend fun download(
context: Context,
url: String,
onProgress: (Float) -> Unit
): File = withContext(Dispatchers.IO) {
val dir = File(context.cacheDir, "updates").apply {
mkdirs()
listFiles()?.forEach { it.delete() } // alte Downloads aufräumen
}
val file = File(dir, "update.apk")
val conn = URL(url).openConnection() as HttpURLConnection
conn.connectTimeout = 15_000
conn.readTimeout = 15_000
try {
if (conn.responseCode != HttpURLConnection.HTTP_OK) {
throw IOException("HTTP ${conn.responseCode}")
}
val total = conn.contentLengthLong
conn.inputStream.use { input ->
file.outputStream().use { output ->
val buffer = ByteArray(16 * 1024)
var done = 0L
var read: Int
while (input.read(buffer).also { read = it } != -1) {
ensureActive() // macht den Abbruch möglich
output.write(buffer, 0, read)
done += read
if (total > 0) onProgress(done.toFloat() / total)
}
}
}
file
} finally {
conn.disconnect()
}
}
fun install(context: Context, apk: File) {
val uri = FileProvider.getUriForFile(
context, "${context.packageName}.fileprovider", apk
)
val intent = Intent(Intent.ACTION_VIEW).apply {
setDataAndType(uri, "application/vnd.android.package-archive")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
}
}
@@ -0,0 +1,82 @@
package de.schanbro.weekfocus.update
import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.provider.Settings
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.*
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.core.content.ContextCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleEventEffect
import de.schanbro.weekfocus.R
private const val KEY_HINT_DISMISSED = "network_hint_dismissed"
/** Zeigt [content] nur, wenn die App Netzwerkzugriff hat. Fragt sonst einmal danach. */
@Composable
fun NetworkPermissionGate(content: @Composable () -> Unit) {
val context = LocalContext.current
val prefs = remember {
context.getSharedPreferences("WeekFocusPrefs", Context.MODE_PRIVATE)
}
fun isGranted() = ContextCompat.checkSelfPermission(
context, Manifest.permission.INTERNET
) == PackageManager.PERMISSION_GRANTED
var granted by remember { mutableStateOf(isGranted()) }
var showDialog by remember {
mutableStateOf(!isGranted() && !prefs.getBoolean(KEY_HINT_DISMISSED, false))
}
val launcher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) { result ->
granted = result || isGranted()
if (!granted) openAppSettings(context) // kein System-Dialog möglich → Einstellungen
}
// Nach Rückkehr aus den Einstellungen neu prüfen
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) {
granted = isGranted()
}
if (granted) {
content()
} else if (showDialog) {
AlertDialog(
onDismissRequest = {},
title = { Text(stringResource(R.string.permission_network_title)) },
text = { Text(stringResource(R.string.permission_network_message)) },
confirmButton = {
TextButton(onClick = {
showDialog = false
launcher.launch(Manifest.permission.INTERNET)
}) { Text(stringResource(R.string.permission_allow)) }
},
dismissButton = {
TextButton(onClick = {
prefs.edit().putBoolean(KEY_HINT_DISMISSED, true).apply()
showDialog = false
}) { Text(stringResource(R.string.permission_not_now)) }
}
)
}
}
private fun openAppSettings(context: Context) {
val intent = Intent(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", context.packageName, null)
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}
@@ -0,0 +1,71 @@
package de.schanbro.weekfocus.update
import android.content.Context
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.json.JSONObject
import java.net.HttpURLConnection
import java.net.URL
data class ReleaseInfo(
val version: String,
val notes: String,
val apkUrl: String
)
object UpdateChecker {
private const val LATEST_RELEASE_URL =
"https://git.schamagusa.de/api/v1/repos/robin/WeekFocus/releases/latest"
/** Liefert das neueste stabile Release oder null (bei Fehler / ohne APK). */
suspend fun fetchLatestRelease(): ReleaseInfo? = withContext(Dispatchers.IO) {
try {
val conn = URL(LATEST_RELEASE_URL).openConnection() as HttpURLConnection
conn.connectTimeout = 10_000
conn.readTimeout = 10_000
conn.setRequestProperty("Accept", "application/json")
try {
if (conn.responseCode != HttpURLConnection.HTTP_OK) return@withContext null
val json = JSONObject(conn.inputStream.bufferedReader().use { it.readText() })
val assets = json.getJSONArray("assets")
val apk = (0 until assets.length())
.map { assets.getJSONObject(it) }
.firstOrNull { it.getString("name").endsWith(".apk", ignoreCase = true) }
?: return@withContext null
ReleaseInfo(
version = json.getString("tag_name"),
notes = json.optString("body", ""),
apkUrl = apk.getString("browser_download_url")
)
} finally {
conn.disconnect()
}
} catch (e: Exception) {
null // Netzwerk- oder Parse-Fehler: still ignorieren
}
}
@Suppress("DEPRECATION")
fun currentVersion(context: Context): String =
context.packageManager.getPackageInfo(context.packageName, 0).versionName ?: "0"
/** Numerischer Vergleich pro Segment, damit 1.2.11 > 1.2.9 gilt. */
fun isNewer(remote: String, local: String): Boolean {
val r = parse(remote)
val l = parse(local)
for (i in 0 until maxOf(r.size, l.size)) {
val a = r.getOrElse(i) { 0 }
val b = l.getOrElse(i) { 0 }
if (a != b) return a > b
}
// Gleiche Nummer: stabiles Release ist neuer als eine installierte Beta
return local.contains("-") && !remote.contains("-")
}
private fun parse(version: String): List<Int> =
version.trim().removePrefix("v").substringBefore("-")
.split(".").map { it.toIntOrNull() ?: 0 }
}
@@ -0,0 +1,121 @@
package de.schanbro.weekfocus.update
import android.content.Context
import android.widget.Toast
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import de.schanbro.weekfocus.R
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
private const val CHECK_INTERVAL_MS = 24L * 60 * 60 * 1000
@Composable
fun UpdateHandler() {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val prefs = remember {
context.getSharedPreferences("WeekFocusPrefs", Context.MODE_PRIVATE)
}
var release by remember { mutableStateOf<ReleaseInfo?>(null) }
var progress by remember { mutableStateOf<Float?>(null) } // null = kein Download
var downloadJob by remember { mutableStateOf<Job?>(null) }
// Einmal pro Start, höchstens alle 24 Stunden
LaunchedEffect(Unit) {
val now = System.currentTimeMillis()
if (now - prefs.getLong("last_update_check", 0L) < CHECK_INTERVAL_MS) return@LaunchedEffect
val latest = UpdateChecker.fetchLatestRelease() ?: return@LaunchedEffect
prefs.edit().putLong("last_update_check", now).apply()
if (UpdateChecker.isNewer(latest.version, UpdateChecker.currentVersion(context))) {
release = latest
}
}
release?.let { info ->
val downloading = progress != null
AlertDialog(
onDismissRequest = { if (!downloading) release = null },
title = { Text(stringResource(R.string.update_title)) },
text = {
Column(Modifier.verticalScroll(rememberScrollState())) {
Text(stringResource(R.string.update_message, info.version.removePrefix("v")))
if (info.notes.isNotBlank()) {
Spacer(Modifier.height(12.dp))
Text(
text = info.notes,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
progress?.let { p ->
Spacer(Modifier.height(16.dp))
LinearProgressIndicator(
progress = { p },
modifier = Modifier.fillMaxWidth()
)
}
}
},
confirmButton = {
TextButton(
enabled = !downloading,
onClick = {
if (!ApkInstaller.canInstall(context)) {
Toast.makeText(
context, R.string.update_permission_hint, Toast.LENGTH_LONG
).show()
ApkInstaller.openInstallPermissionSettings(context)
} else {
downloadJob = scope.launch {
progress = 0f
try {
val apk = ApkInstaller.download(context, info.apkUrl) {
progress = it
}
progress = null
release = null
ApkInstaller.install(context, apk)
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
progress = null
Toast.makeText(
context, R.string.update_failed, Toast.LENGTH_LONG
).show()
}
}
}
}
) { Text(stringResource(R.string.update_action)) }
},
dismissButton = {
TextButton(
onClick = {
downloadJob?.cancel()
progress = null
release = null
}
) {
Text(
stringResource(
if (downloading) R.string.action_cancel else R.string.update_later
)
)
}
}
)
}
}
+2 -3
View File
@@ -11,10 +11,9 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WOCHENFOKUS"
android:text="@string/title_weekly_focus"
android:textSize="11sp"
android:letterSpacing="0.1"
android:textAllCaps="true"
android:textColor="?android:attr/textColorSecondary"
android:textStyle="bold" />
@@ -24,7 +23,7 @@
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="Hallo"
android:text="@string/msg_no_words"
android:textColor="?android:attr/textColorPrimary"
android:textSize="22sp"
android:textStyle="bold" />
+26 -3
View File
@@ -1,8 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">WeekFocus</string>
<string name="hint_new_word">Enter new Word</string>
<string name="hint_new_word">Enter new word</string>
<string name="hint_add_word">Add word</string>
<string name="title_saved_words">Saved words:</string>
<string name="msg_no_words_yet">No words yet.</string>
<string name="msg_no_words">No words</string>
<string name="title_weekly_focus">Weekly focus</string>
<string name="title_settings">Settings</string>
<string name="title_words">Words</string>
<string name="title_home">Home</string>
<string name="action_delete">Delete</string>
<string name="action_cancel">Cancel</string>
<string name="action_save">Save</string>
<string name="dialog_delete_title">Delete word?</string>
<string name="dialog_delete_message">“%1$s” will be permanently removed.</string>
<string name="dialog_edit_title">Edit word</string>
<string name="update_title">Update available</string>
<string name="update_message">Version %1$s is available. Download and install now?</string>
<string name="update_action">Update</string>
<string name="update_later">Later</string>
<string name="update_failed">Update failed. Please try again later.</string>
<string name="update_permission_hint">Please allow installs from this source, then tap “Update” again.</string>
<string name="permission_network_title">Network access needed</string>
<string name="permission_network_message">WeekFocus needs network access to check for updates. Without it the app keeps working, but won’t look for new versions.</string>
<string name="permission_allow">Allow</string>
<string name="permission_not_now">Not now</string>
</resources>
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="splash_background">#121212</color>
</resources>
+1
View File
@@ -7,4 +7,5 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="splash_background">#FFFFFF</color>
</resources>
+30 -2
View File
@@ -1,8 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">WeekFocus</string>
<string name="app_name" translatable="false">WeekFocus</string>
<string name="hint_new_word">Neues Wort eingeben</string>
<string name="hint_add_word">Wort hinzufügen</string>
<string name="title_saved_words">Gespeicherte Wörter:</string>
<string name="msg_no_words_yet">Noch keine Wörter vorhanden.</string>
<string name="msg_no_words">Keine Wörter</string>
<string name="title_weekly_focus">Wochenfokus</string>
<string name="title_settings">Einstellungen</string>
<string name="title_words">Wörter</string>
<string name="title_home">Start</string>
<!-- Aktionen -->
<string name="action_delete">Löschen</string>
<string name="action_cancel">Abbrechen</string>
<string name="action_save">Speichern</string>
<!-- Dialoge -->
<string name="dialog_delete_title">Wort löschen?</string>
<string name="dialog_delete_message">„%1$s“ wird dauerhaft entfernt.</string>
<string name="dialog_edit_title">Wort bearbeiten</string>
<!-- Auto-Update -->
<string name="update_title">Update verfügbar</string>
<string name="update_message">Version %1$s ist verfügbar. Jetzt herunterladen und installieren?</string>
<string name="update_action">Aktualisieren</string>
<string name="update_later">Später</string>
<string name="update_failed">Update fehlgeschlagen. Bitte später erneut versuchen.</string>
<string name="update_permission_hint">Bitte die Installation aus dieser Quelle erlauben und danach erneut auf „Aktualisieren“ tippen.</string>
<!-- Berechntigungen -->
<string name="permission_network_title">Netzwerkzugriff benötigt</string>
<string name="permission_network_message">WeekFocus braucht Netzwerkzugriff, um nach Updates zu suchen. Ohne Zugriff funktioniert die App weiterhin, sucht aber nicht nach neuen Versionen.</string>
<string name="permission_allow">Erlauben</string>
<string name="permission_not_now">Nicht jetzt</string>
</resources>
+5 -1
View File
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.WeekFocus" parent="android:Theme.Material.Light.NoActionBar" />
<style name="Theme.WeekFocus.Splash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/splash_background</item>
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
<item name="postSplashScreenTheme">@style/Theme.WeekFocus</item>
</style>
</resources>
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path name="updates" path="updates/" />
</paths>
+1 -1
View File
@@ -7,5 +7,5 @@
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen"
android:targetCellWidth="2"
android:targetCellHeight="2">
android:targetCellHeight="1">
</appwidget-provider>
-12
View File
@@ -1,12 +0,0 @@
#This file is generated by updateDaemonJvm
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c2dd35c9d0aaf0ba6ad0791320f99dfc/redirect
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/e5810bd7fd1f8a586644409d395a7e55/redirect
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/7b3c4877c0749019e6805bb61e421497/redirect
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/d76df094a9cbbabd3b08251f9e61444a/redirect
toolchainVersion=25
+10 -7
View File
@@ -1,13 +1,14 @@
[versions]
agp = "9.4.1"
coreKtx = "1.10.1"
coreKtx = "1.19.1"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
lifecycleRuntimeKtx = "2.6.1"
activityCompose = "1.8.0"
kotlin = "2.2.10"
composeBom = "2026.02.01"
junitVersion = "1.3.0"
espressoCore = "3.7.0"
lifecycleRuntimeKtx = "2.11.0"
activityCompose = "1.13.0"
kotlin = "2.4.20"
composeBom = "2026.09.00"
animation = "1.12.1"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -24,6 +25,8 @@ androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "u
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
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]
android-application = { id = "com.android.application", version.ref = "agp" }