Compare commits

..
3 Commits
Author SHA1 Message Date
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
6 changed files with 100 additions and 204 deletions

No files matched your search

+46 -28
View File
@@ -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;37.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
@@ -66,38 +64,46 @@ jobs:
echo "$KEYSTORE_BASE64" | base64 -d > "$RUNNER_TEMP/release.keystore" echo "$KEYSTORE_BASE64" | base64 -d > "$RUNNER_TEMP/release.keystore"
echo "KEYSTORE_PATH=$RUNNER_TEMP/release.keystore" >> $GITHUB_ENV echo "KEYSTORE_PATH=$RUNNER_TEMP/release.keystore" >> $GITHUB_ENV
- name: Android Release APK bauen - name: Android Release APKs bauen
run: | run: |
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 \
-PversionNameOverride="$VERSION" -PversionNameOverride="$VERSION"
echo "Erzeugte APK-Dateien:"
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)"
if [ -z "$APK_SOURCE" ]; then
echo "Keine Release-APK gefunden."
exit 1
fi
APK_DIR="app/build/outputs/apk/release" APK_DIR="app/build/outputs/apk/release"
APK_NAME="WeekFocus-${VERSION}.apk"
APK_TARGET="$APK_DIR/$APK_NAME"
mv "$APK_SOURCE" "$APK_TARGET" echo "Gefundene Original-APKs in $APK_DIR:"
"$ANDROID_HOME/build-tools/36.0.0/apksigner" verify --verbose "$APK_TARGET"
echo "APK erstellt: $APK_TARGET"
ls -lh "$APK_DIR" ls -lh "$APK_DIR"
for APK in "$APK_DIR"/*.apk; do
[ -e "$APK" ] || continue
if [[ "$APK" == *"unsigned"* || "$APK" == *"WeekFocus-"* ]]; then
continue
fi
FILENAME=$(basename "$APK")
VARIANT=$(echo "$FILENAME" | sed -E 's/^app-(.*)-release\.apk$/\1/')
if [ "$VARIANT" = "$FILENAME" ]; then
VARIANT="release"
fi
TARGET_NAME="WeekFocus-${VERSION}-${VARIANT}.apk"
TARGET_PATH="$APK_DIR/$TARGET_NAME"
mv "$APK" "$TARGET_PATH"
echo "Signatur prüfen für $TARGET_NAME..."
"$ANDROID_HOME/build-tools/35.0.0/apksigner" verify --verbose "$TARGET_PATH"
done
echo "Finale Release-APKs:"
ls -lh "$APK_DIR"/WeekFocus-*.apk
env: env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }} KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
@@ -134,21 +140,29 @@ jobs:
echo "Release-Notes:" echo "Release-Notes:"
cat "$NOTES_FILE" cat "$NOTES_FILE"
- name: Release in Gitea erstellen und APK hochladen - name: Release in Gitea erstellen und APKs hochladen
env: env:
TOKEN: ${{ secrets.GITHUB_TOKEN }} TOKEN: ${{ secrets.GITHUB_TOKEN }}
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
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 +170,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
+11 -5
View File
@@ -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,9 +15,7 @@ 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"
@@ -30,6 +27,15 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
} }
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")
@@ -79,5 +85,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("androidx.compose.material:material-icons-extended") implementation(libs.androidx.material.icons.extended)
} }
+2 -8
View File
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?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" />
<application <application
android:allowBackup="true" android:allowBackup="true"
@@ -30,10 +28,6 @@
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.DATE_CHANGED" />
<action android:name="android.intent.action.TIME_SET" />
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
</intent-filter> </intent-filter>
<meta-data <meta-data
android:name="android.appwidget.provider" android:name="android.appwidget.provider"
@@ -1,5 +1,7 @@
package de.schanbro.weekfocus package de.schanbro.weekfocus
import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
@@ -33,13 +35,6 @@ class MainActivity : ComponentActivity() {
} }
} }
} }
override fun onResume() {
super.onResume()
// Falls das Widget (z.B. durch Energiesparmodus) nicht rechtzeitig aktualisiert
// wurde, wird es beim Öffnen der App nachgezogen.
updateWidget(this)
}
} }
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@@ -138,9 +133,12 @@ fun PlaceholderScreen(title: String) {
} }
} }
/**
* Bleibt als Top-Level-Funktion erhalten, damit WordListScreen unverändert weiter funktioniert.
*/
fun updateWidget(context: Context) { fun updateWidget(context: Context) {
SimpleWidget.updateAllWidgets(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)
}
} }
@@ -1,35 +1,15 @@
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.time.DayOfWeek import androidx.compose.ui.res.stringResource
import java.time.LocalDate import java.util.Calendar
import java.time.ZoneId import java.util.Random
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,
@@ -38,141 +18,40 @@ 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
) { ) {
val displayText = resolveWordOfWeek(context) // 1. SharedPreferences auslesen
?: context.getString(R.string.msg_no_words) val sharedPrefs = context.getSharedPreferences("WeekFocusPrefs", Context.MODE_PRIVATE)
val savedSet = sharedPrefs.getStringSet("words_key", emptySet()) ?: emptySet()
val wordList = savedSet.toList()
// 2. Aktuelle Kalenderwoche & Jahr bestimmen
val calendar = Calendar.getInstance()
val weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR)
val year = calendar.get(Calendar.YEAR)
// 3. Wort für die aktuelle Kalenderwoche auswählen
val displayText = if (wordList.isNotEmpty()) {
// Kombinierter Seed aus Jahr und Kalenderwoche
val seed = (year * 100 + weekOfYear).toLong()
val random = Random(seed)
val randomIndex = random.nextInt(wordList.size)
wordList[randomIndex]
} else {
context.getString(R.string.msg_no_words)
}
// 4. RemoteViews aktualisieren
val views = RemoteViews(context.packageName, R.layout.widget_main) val views = RemoteViews(context.packageName, R.layout.widget_main)
views.setTextViewText(R.id.appwidget_text, displayText) views.setTextViewText(R.id.appwidget_text, displayText)
appWidgetManager.updateAppWidget(appWidgetId, views) appWidgetManager.updateAppWidget(appWidgetId, views)
} }
/**
* ISO-Kalenderwoche (Montag = Wochenbeginn, unabhängig von der Geräte-Locale)
* kombiniert mit dem zugehörigen Wochenjahr, z.B. 202641.
*
* Das Wochenjahr (nicht das Kalenderjahr!) verhindert, dass sich der Wert
* um Neujahr mitten in der Woche ändert.
*/
internal fun weekKeyFor(date: LocalDate): Int {
val weekBasedYear = date.get(IsoFields.WEEK_BASED_YEAR)
val week = date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR)
return weekBasedYear * 100 + week
}
/**
* Liefert das Wort der aktuellen Woche.
*
* - Die Liste wird sortiert, damit die Reihenfolge deterministisch ist
* (ein Set hat keine garantierte Reihenfolge).
* - Das gewählte Wort wird pro Woche gespeichert. Dadurch ändert sich das Wort
* nicht, wenn Wörter hinzugefügt oder gelöscht werden. Nur wenn das aktuelle
* Wort selbst gelöscht wird, wird neu gewählt.
*/
private fun resolveWordOfWeek(context: Context): String? {
val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
val words = (prefs.getStringSet(KEY_WORDS, emptySet()) ?: emptySet()).sorted()
if (words.isEmpty()) {
prefs.edit().remove(KEY_WEEK).remove(KEY_WORD).apply()
return null
}
val weekKey = weekKeyFor(LocalDate.now())
val storedWord = prefs.getString(KEY_WORD, null)
if (prefs.getInt(KEY_WEEK, -1) == weekKey && storedWord != null && storedWord in words) {
return storedWord
}
val currentMonday = LocalDate.now().with(DayOfWeek.MONDAY)
val weeksSinceEpoch = ChronoUnit.WEEKS.between(LocalDate.ofEpochDay(4), currentMonday) // 5.1.1970 war ein Montag
val word = words[(weeksSinceEpoch % words.size).toInt()]
prefs.edit()
.putInt(KEY_WEEK, weekKey)
.putString(KEY_WORD, word)
.apply()
return word
}
/**
* Plant einen Alarm für den nächsten Montag, 00:00 Uhr (lokale Zeit).
* Bewusst ohne Exact-Alarm-Berechtigung: Eine Verzögerung von wenigen Minuten
* ist für ein Wochenwort unkritisch.
*/
private fun scheduleNextWeekChange(context: Context) {
val alarmManager = context.getSystemService(AlarmManager::class.java) ?: return
val triggerAtMillis = LocalDate.now()
.with(TemporalAdjusters.next(DayOfWeek.MONDAY)) // "next" schließt heute aus
.atStartOfDay(ZoneId.systemDefault())
.toInstant()
.toEpochMilli()
alarmManager.setAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
triggerAtMillis,
weekChangePendingIntent(context)
)
}
private fun cancelWeekChange(context: Context) {
val alarmManager = context.getSystemService(AlarmManager::class.java) ?: return
alarmManager.cancel(weekChangePendingIntent(context))
}
private fun weekChangePendingIntent(context: Context): PendingIntent {
val intent = Intent(context, SimpleWidget::class.java).apply {
action = ACTION_WEEK_CHANGED
}
return PendingIntent.getBroadcast(
context,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
}
} }
} }
+8 -7
View File
@@ -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" }