Compare commits
33
Commits
v1.1.3
..
98ffa47fa4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98ffa47fa4 | ||
|
|
dfd0b75521 | ||
|
|
d9c1942f2a | ||
|
|
bc6edc4a04 | ||
|
|
d03f9eee67 | ||
|
|
7eff7300d0 | ||
|
|
8458f0fce5 | ||
|
|
e444abecae | ||
|
|
3bac488893 | ||
|
|
b8195b74f1 | ||
|
|
f431fb272d | ||
|
|
107f1c3955 | ||
|
|
ce1eba6b83 | ||
|
|
4b8e2bc88d | ||
|
|
c71851702f | ||
|
|
4c04a5260c | ||
|
|
90e477cb04 | ||
|
|
82d4fa331b | ||
|
|
6206a47fc7 | ||
|
|
ff78c71ab5 | ||
|
|
c6d6ac359b | ||
|
|
7cc3245b97 | ||
|
|
8cacb6f582 | ||
|
|
86882fafcb | ||
|
|
edb11b360b | ||
|
|
18c375979c | ||
|
|
2545498dc2 | ||
|
|
fd20b5d91e | ||
|
|
76cf592cd1 | ||
|
|
d134b0cd0a | ||
|
|
4a62373992 | ||
|
|
e589693c67 | ||
|
|
f5568cf211 |
No files matched your search
@@ -1,4 +1,3 @@
|
|||||||
# .gitea/workflows/build-release.yml
|
|
||||||
name: Build & Release Android App
|
name: Build & Release Android App
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@@ -19,6 +18,7 @@ jobs:
|
|||||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
||||||
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
|
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
|
||||||
|
|
||||||
- name: Code auschecken
|
- name: Code auschecken
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -46,14 +46,12 @@ jobs:
|
|||||||
rm /tmp/tools.zip
|
rm /tmp/tools.zip
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Lizenzen korrekt akzeptieren (kein "yes |", wegen pipefail/SIGPIPE)
|
|
||||||
"$SDKMANAGER" --sdk_root="$SDK_PATH" --licenses < <(yes) > /dev/null
|
"$SDKMANAGER" --sdk_root="$SDK_PATH" --licenses < <(yes) > /dev/null
|
||||||
|
|
||||||
# Benötigte Pakete direkt installieren
|
|
||||||
"$SDKMANAGER" --sdk_root="$SDK_PATH" \
|
"$SDKMANAGER" --sdk_root="$SDK_PATH" \
|
||||||
"platform-tools" \
|
"platform-tools" \
|
||||||
"platforms;android-37.0" \
|
"platforms;android-37" \
|
||||||
"build-tools;36.0.0"
|
"build-tools;35.0.0"
|
||||||
|
|
||||||
echo "ANDROID_HOME=$SDK_PATH" >> $GITHUB_ENV
|
echo "ANDROID_HOME=$SDK_PATH" >> $GITHUB_ENV
|
||||||
echo "ANDROID_SDK_ROOT=$SDK_PATH" >> $GITHUB_ENV
|
echo "ANDROID_SDK_ROOT=$SDK_PATH" >> $GITHUB_ENV
|
||||||
@@ -71,33 +69,33 @@ jobs:
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
VERSION="${GITHUB_REF_NAME#v}"
|
VERSION="${GITHUB_REF_NAME#v}"
|
||||||
|
|
||||||
echo "Baue Version: $VERSION"
|
echo "Baue Version: $VERSION"
|
||||||
|
|
||||||
./gradlew assembleRelease \
|
./gradlew assembleRelease \
|
||||||
--no-daemon \
|
--no-daemon \
|
||||||
|
-Dorg.gradle.java.home="$JAVA_HOME" \
|
||||||
|
-Porg.gradle.java.installations.auto-download=false \
|
||||||
-PversionNameOverride="$VERSION"
|
-PversionNameOverride="$VERSION"
|
||||||
|
|
||||||
echo "Erzeugte APK-Dateien:"
|
APK_DIR="app/build/outputs/apk/release"
|
||||||
find app/build/outputs -type f -name "*.apk" -print
|
|
||||||
|
|
||||||
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
|
SRC="$APK_DIR/app-release.apk"
|
||||||
echo "Keine Release-APK gefunden."
|
if [ ! -f "$SRC" ]; then
|
||||||
|
echo "app-release.apk nicht gefunden (evtl. unsigniert oder anderer Name)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
APK_DIR="app/build/outputs/apk/release"
|
TARGET_PATH="$APK_DIR/WeekFocus-${VERSION}.apk"
|
||||||
APK_NAME="WeekFocus-${VERSION}.apk"
|
mv "$SRC" "$TARGET_PATH"
|
||||||
APK_TARGET="$APK_DIR/$APK_NAME"
|
|
||||||
|
|
||||||
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 "Finale Release-APK:"
|
||||||
|
ls -lh "$TARGET_PATH"
|
||||||
echo "APK erstellt: $APK_TARGET"
|
|
||||||
ls -lh "$APK_DIR"
|
|
||||||
env:
|
env:
|
||||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
||||||
@@ -141,14 +139,22 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
TAG="$GITHUB_REF_NAME"
|
TAG="$GITHUB_REF_NAME"
|
||||||
|
VERSION="${TAG#v}"
|
||||||
NOTES_FILE="$RUNNER_TEMP/release_notes.md"
|
NOTES_FILE="$RUNNER_TEMP/release_notes.md"
|
||||||
AUTH="Authorization: token $TOKEN"
|
AUTH="Authorization: token $TOKEN"
|
||||||
|
|
||||||
# Release holen oder neu anlegen
|
|
||||||
CODE=$(curl -sS -o release.json -w '%{http_code}' -H "$AUTH" "$API/releases/tags/$TAG")
|
CODE=$(curl -sS -o release.json -w '%{http_code}' -H "$AUTH" "$API/releases/tags/$TAG")
|
||||||
if [ "$CODE" = "404" ]; then
|
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" \
|
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" \
|
curl -fsS -X POST -H "$AUTH" -H "Content-Type: application/json" \
|
||||||
-d @payload.json "$API/releases" -o release.json
|
-d @payload.json "$API/releases" -o release.json
|
||||||
elif [ "$CODE" != "200" ]; then
|
elif [ "$CODE" != "200" ]; then
|
||||||
@@ -156,14 +162,18 @@ jobs:
|
|||||||
cat release.json
|
cat release.json
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RELEASE_ID=$(jq -r .id release.json)
|
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
|
for APK in app/build/outputs/apk/release/WeekFocus-*.apk; do
|
||||||
|
[ -e "$APK" ] || continue
|
||||||
NAME=$(basename "$APK")
|
NAME=$(basename "$APK")
|
||||||
|
echo "Lade Hoch: $NAME"
|
||||||
|
|
||||||
for ID in $(jq -r --arg n "$NAME" '.assets[]? | select(.name==$n) | .id' release.json); do
|
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"
|
curl -fsS -X DELETE -H "$AUTH" "$API/releases/$RELEASE_ID/assets/$ID"
|
||||||
done
|
done
|
||||||
|
|
||||||
curl -fsS -X POST -H "$AUTH" -F "attachment=@$APK" \
|
curl -fsS -X POST -H "$AUTH" -F "attachment=@$APK" \
|
||||||
"$API/releases/$RELEASE_ID/assets?name=$NAME"
|
"$API/releases/$RELEASE_ID/assets?name=$NAME"
|
||||||
done
|
done
|
||||||
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_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" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.2.0] - 2026-10-04
|
||||||
|
### New
|
||||||
|
* navigation
|
||||||
|
* ability to delete words
|
||||||
|
* better layout
|
||||||
|
|
||||||
## [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
|
||||||
|
|||||||
@@ -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">
|
<img src="https://raw.githubusercontent.com/ImranR98/Obtainium/main/assets/graphics/badge_obtainium.png" alt="Get it on Obtainium" height="64">
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
[](https://git.schamagusa.de/Schanbro/WeekFocus/releases)
|
[](https://git.schamagusa.de/Schanbro/WeekFocus/releases)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
[](https://weblate.schamagusa.de/engage/weekfocus/)
|
<!--[](https://weblate.schamagusa.de/engage/weekfocus/)-->
|
||||||
|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
<!--[](https://git.schamagusa.de/Schanbro/WeekFocus)
|
||||||
|
[](https://git.schamagusa.de/Schanbro/WeekFocus)-->
|
||||||
|
[](https://git.schamagusa.de/Schanbro/WeekFocus/issues)
|
||||||
|
[](https://git.schamagusa.de/Schanbro/WeekFocus)
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -35,9 +34,9 @@
|
|||||||
- [About](#about)
|
- [About](#about)
|
||||||
- [How It Works](#how-it-works)
|
- [How It Works](#how-it-works)
|
||||||
- [Features](#features)
|
- [Features](#features)
|
||||||
- [Screenshots](#screenshots)
|
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Building from Source](#building-from-source)
|
- [Building from Source](#building-from-source)
|
||||||
|
- [Releases](#releases)
|
||||||
- [Contributing](#contributing)
|
- [Contributing](#contributing)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
- [Translations](#translations)
|
- [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
|
- 🔒 No ads, no tracking, no unnecessary permissions
|
||||||
- ⚡ Lightweight and battery-friendly
|
- ⚡ 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
|
## Installation
|
||||||
|
|
||||||
### Recommended: Obtainium
|
### 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.
|
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.
|
1. Install Obtainium on your Android device.
|
||||||
2. Tap the badge above or open this link:
|
2. Tap the badge above.
|
||||||
[Add WeekFocus to Obtainium](https://apps.obtainium.imranr.dev/redirect?r=obtainium://add/https://git.schamagusa.de/Schanbro/WeekFocus)
|
|
||||||
3. Confirm and install the app.
|
3. Confirm and install the app.
|
||||||
|
|
||||||
Alternatively, tap **Add App** in Obtainium and paste this URL:
|
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)
|
- [Android Studio](https://developer.android.com/studio) (latest stable)
|
||||||
- JDK 17 or newer
|
- JDK 17 or newer
|
||||||
|
- Android SDK platform 37 (`minSdk` 29, `targetSdk` 37)
|
||||||
|
|
||||||
**Steps**
|
**Steps**
|
||||||
|
|
||||||
@@ -115,6 +104,34 @@ cd WeekFocus
|
|||||||
|
|
||||||
The resulting APK is located in `app/build/outputs/apk/debug/`.
|
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
|
## Contributing
|
||||||
|
|
||||||
Contributions are welcome!
|
Contributions are welcome!
|
||||||
|
|||||||
+23
-6
@@ -5,7 +5,6 @@ plugins {
|
|||||||
|
|
||||||
val tagVersion = (project.findProperty("versionNameOverride") as String?) ?: "0.0.0-dev"
|
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
|
val core = tagVersion
|
||||||
.removePrefix("v")
|
.removePrefix("v")
|
||||||
.substringBefore("-")
|
.substringBefore("-")
|
||||||
@@ -16,20 +15,28 @@ val patch = parts.getOrElse(2) { 0 }
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "de.schanbro.weekfocus"
|
namespace = "de.schanbro.weekfocus"
|
||||||
compileSdk {
|
compileSdk = 37
|
||||||
version = release(37)
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "de.schanbro.weekfocus"
|
applicationId = "de.schanbro.weekfocus"
|
||||||
minSdk = 29
|
minSdk = 29
|
||||||
targetSdk = 37
|
targetSdk = 37
|
||||||
versionCode = major * 10000 + minor * 100 + patch
|
versionCode = (major * 10000 + minor * 100 + patch).coerceAtLeast(1)
|
||||||
versionName = tagVersion
|
versionName = tagVersion
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// not necessary
|
||||||
|
/*splits {
|
||||||
|
abi {
|
||||||
|
isEnable = true
|
||||||
|
reset()
|
||||||
|
include("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
|
||||||
|
isUniversalApk = true
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
create("release") {
|
create("release") {
|
||||||
val ksPath = System.getenv("KEYSTORE_PATH")
|
val ksPath = System.getenv("KEYSTORE_PATH")
|
||||||
@@ -43,11 +50,20 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
debug {
|
||||||
|
applicationIdSuffix = ".debug"
|
||||||
|
versionNameSuffix = "-dev"
|
||||||
|
}
|
||||||
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 {
|
||||||
@@ -75,4 +91,5 @@ dependencies {
|
|||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
||||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||||
|
implementation(libs.androidx.material.icons.extended)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="app_name" translatable="false">WeekFocus-dev</string>
|
||||||
|
</resources>
|
||||||
@@ -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"
|
||||||
|
|||||||
@@ -6,17 +6,22 @@ import androidx.activity.ComponentActivity
|
|||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.foundation.lazy.items
|
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.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
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.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import de.schanbro.weekfocus.ui.theme.WeekFocusTheme
|
||||||
|
|
||||||
|
import de.schanbro.weekfocus.screens.WordListScreen
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@@ -24,105 +29,118 @@ class MainActivity : ComponentActivity() {
|
|||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
WeekFocusTheme {
|
WeekFocusTheme {
|
||||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
MainScreen()
|
||||||
WordListScreen(
|
}
|
||||||
modifier = Modifier.padding(innerPadding)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
@Composable
|
||||||
fun WordListScreen(modifier: Modifier = Modifier) {
|
fun PlaceholderScreen(title: String) {
|
||||||
val context = LocalContext.current
|
Box(
|
||||||
val sharedPrefs = remember {
|
modifier = Modifier.fillMaxSize(),
|
||||||
context.getSharedPreferences("WeekFocusPrefs", Context.MODE_PRIVATE)
|
contentAlignment = Alignment.Center
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
) {
|
) {
|
||||||
// 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(
|
||||||
text = stringResource(R.string.title_saved_words),
|
text = title,
|
||||||
style = MaterialTheme.typography.titleMedium
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
|
|
||||||
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)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hilfsfunktion zum Aktualisieren des Widgets
|
/**
|
||||||
|
* 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,14 +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 java.util.Calendar
|
import java.time.DayOfWeek
|
||||||
import java.util.Random
|
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() {
|
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,
|
||||||
@@ -17,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 {
|
|
||||||
"Keine Wörter"
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
package de.schanbro.weekfocus.screens
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.fadeIn
|
||||||
|
import androidx.compose.animation.fadeOut
|
||||||
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
|
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.material3.*
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
|
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
|
||||||
|
|
||||||
|
@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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveWords() {
|
||||||
|
sharedPrefs.edit().putStringSet("words_key", wordList.toSet()).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addCurrentWord() {
|
||||||
|
val trimmed = textInput.trim()
|
||||||
|
if (trimmed.isNotEmpty()) {
|
||||||
|
wordList.add(0, trimmed)
|
||||||
|
saveWords()
|
||||||
|
updateWidget(context)
|
||||||
|
textInput = ""
|
||||||
|
focusManager.clearFocus() // Fokus aufheben & Tastatur schließen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
) {
|
||||||
|
itemsIndexed(wordList) { index, word ->
|
||||||
|
ElevatedCard(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
shape = MaterialTheme.shapes.medium,
|
||||||
|
colors = CardDefaults.elevatedCardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainerLow
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = word,
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
)
|
||||||
|
IconButton(
|
||||||
|
onClick = {
|
||||||
|
wordList.removeAt(index)
|
||||||
|
saveWords()
|
||||||
|
updateWidget(context)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Delete,
|
||||||
|
contentDescription = "Entfernen",
|
||||||
|
tint = MaterialTheme.colorScheme.error
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,10 +11,9 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="WOCHENFOKUS"
|
android:text="@string/title_weekly_focus"
|
||||||
android:textSize="11sp"
|
android:textSize="11sp"
|
||||||
android:letterSpacing="0.1"
|
android:letterSpacing="0.1"
|
||||||
android:textAllCaps="true"
|
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@
|
|||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="Hallo"
|
android:text="@string/msg_no_words"
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
android:textSize="22sp"
|
android:textSize="22sp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<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="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_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>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<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_new_word">Neues Wort eingeben</string>
|
||||||
<string name="hint_add_word">Wort hinzufügen</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_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>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -7,5 +7,5 @@
|
|||||||
android:resizeMode="horizontal|vertical"
|
android:resizeMode="horizontal|vertical"
|
||||||
android:widgetCategory="home_screen"
|
android:widgetCategory="home_screen"
|
||||||
android:targetCellWidth="2"
|
android:targetCellWidth="2"
|
||||||
android:targetCellHeight="2">
|
android:targetCellHeight="1">
|
||||||
</appwidget-provider>
|
</appwidget-provider>
|
||||||
@@ -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
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
[versions]
|
[versions]
|
||||||
agp = "9.4.1"
|
agp = "9.4.1"
|
||||||
coreKtx = "1.10.1"
|
coreKtx = "1.19.1"
|
||||||
junit = "4.13.2"
|
junit = "4.13.2"
|
||||||
junitVersion = "1.1.5"
|
junitVersion = "1.3.0"
|
||||||
espressoCore = "3.5.1"
|
espressoCore = "3.7.0"
|
||||||
lifecycleRuntimeKtx = "2.6.1"
|
lifecycleRuntimeKtx = "2.11.0"
|
||||||
activityCompose = "1.8.0"
|
activityCompose = "1.13.0"
|
||||||
kotlin = "2.2.10"
|
kotlin = "2.4.20"
|
||||||
composeBom = "2026.02.01"
|
composeBom = "2026.09.00"
|
||||||
|
|
||||||
[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" }
|
||||||
@@ -24,6 +24,7 @@ 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-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
||||||
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" }
|
||||||
|
|
||||||
[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