Compare commits

..
12 Commits
Author SHA1 Message Date
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
12 changed files with 505 additions and 152 deletions

No files matched your search

+6
View File
@@ -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
+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"> <img src="https://raw.githubusercontent.com/ImranR98/Obtainium/main/assets/graphics/badge_obtainium.png" alt="Get it on Obtainium" height="64">
</a> </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) [![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)](LICENSE) [![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/) <!--[![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)
![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> </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!
+6 -1
View File
@@ -24,7 +24,7 @@ android {
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"
@@ -43,6 +43,10 @@ android {
} }
buildTypes { buildTypes {
debug {
applicationIdSuffix = ".debug"
versionNameSuffix = "-dev"
}
release { release {
signingConfig = signingConfigs.getByName("release") signingConfig = signingConfigs.getByName("release")
optimization { optimization {
@@ -75,4 +79,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")
} }
+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>
+8 -2
View File
@@ -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
)
}
}
}
}
}
}
}
+2 -3
View File
@@ -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" />
+5 -2
View File
@@ -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>
+6 -2
View File
@@ -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>
+1 -1
View File
@@ -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>