forked from Schanbro/WeekFocus
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16dc1626f7 | ||
|
|
73e4fd2957 |
No files matched your search
@@ -12,22 +12,19 @@ jobs:
|
||||
- name: Code auschecken
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Java/JDK 17 einrichten
|
||||
uses: actions/setup-java@v4
|
||||
- name: Java/JDK einrichten
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
|
||||
- name: Gradle einrichten
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
|
||||
- name: Android Release APK bauen
|
||||
run: |
|
||||
chmod +x gradlew
|
||||
./gradlew assembleRelease -Porg.gradle.java.installations.auto-download=false
|
||||
./gradlew assembleRelease
|
||||
|
||||
- name: Release in Gitea erstellen
|
||||
uses: softprops/action-gh-release@v2
|
||||
uses: gitea/action-gitea-release@v1
|
||||
with:
|
||||
files: app/build/outputs/apk/release/*.apk
|
||||
env:
|
||||
|
||||
@@ -27,18 +27,14 @@ android {
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
buildFeatures {
|
||||
compose = true
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
implementation(libs.androidx.activity.compose)
|
||||
|
||||
@@ -23,6 +23,16 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<receiver
|
||||
android:name=".SimpleWidget"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_info" />
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -1,16 +1,20 @@
|
||||
package de.schanbro.weekfocus
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.ComponentName
|
||||
import de.schanbro.weekfocus.ui.theme.WeekFocusTheme
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
@@ -20,8 +24,7 @@ class MainActivity : ComponentActivity() {
|
||||
setContent {
|
||||
WeekFocusTheme {
|
||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
||||
Greeting(
|
||||
name = "Android",
|
||||
WordListScreen(
|
||||
modifier = Modifier.padding(innerPadding)
|
||||
)
|
||||
}
|
||||
@@ -31,17 +34,94 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Greeting(name: String, modifier: Modifier = Modifier) {
|
||||
Text(
|
||||
text = "Hello $name!",
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
fun WordListScreen(modifier: Modifier = Modifier) {
|
||||
val context = LocalContext.current
|
||||
val sharedPrefs = remember {
|
||||
context.getSharedPreferences("WeekFocusPrefs", Context.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun GreetingPreview() {
|
||||
WeekFocusTheme {
|
||||
Greeting("Android")
|
||||
// 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("Neues Wort eingeben...") },
|
||||
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("Wort hinzufügen")
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
Text(
|
||||
text = "Gespeicherte Wörter:",
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
// Liste der Wörter
|
||||
if (wordList.isEmpty()) {
|
||||
Text(
|
||||
text = "Noch keine Wörter vorhanden.",
|
||||
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
|
||||
fun updateWidget(context: Context) {
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
val componentName = ComponentName(context, SimpleWidget::class.java)
|
||||
val appWidgetIds = appWidgetManager.getAppWidgetIds(componentName)
|
||||
|
||||
for (appWidgetId in appWidgetIds) {
|
||||
SimpleWidget.updateAppWidget(context, appWidgetManager, appWidgetId)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.schanbro.weekfocus
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.Context
|
||||
import android.widget.RemoteViews
|
||||
import java.util.Calendar
|
||||
import java.util.Random
|
||||
|
||||
class SimpleWidget : AppWidgetProvider() {
|
||||
|
||||
override fun onUpdate(
|
||||
context: Context,
|
||||
appWidgetManager: AppWidgetManager,
|
||||
appWidgetIds: IntArray
|
||||
) {
|
||||
for (appWidgetId in appWidgetIds) {
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun updateAppWidget(
|
||||
context: Context,
|
||||
appWidgetManager: AppWidgetManager,
|
||||
appWidgetId: Int
|
||||
) {
|
||||
// 1. SharedPreferences auslesen
|
||||
val sharedPrefs = context.getSharedPreferences("WeekFocusPrefs", Context.MODE_PRIVATE)
|
||||
val savedSet = sharedPrefs.getStringSet("words_key", emptySet()) ?: emptySet()
|
||||
val wordList = savedSet.toList()
|
||||
|
||||
// 2. Aktuelle Kalenderwoche & Jahr bestimmen
|
||||
val calendar = Calendar.getInstance()
|
||||
val weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR)
|
||||
val year = calendar.get(Calendar.YEAR)
|
||||
|
||||
// 3. Wort für die aktuelle Kalenderwoche auswählen
|
||||
val displayText = if (wordList.isNotEmpty()) {
|
||||
// Kombinierter Seed aus Jahr und Kalenderwoche
|
||||
val seed = (year * 100 + weekOfYear).toLong()
|
||||
val random = Random(seed)
|
||||
val randomIndex = random.nextInt(wordList.size)
|
||||
wordList[randomIndex]
|
||||
} else {
|
||||
"Keine Wörter"
|
||||
}
|
||||
|
||||
// 4. RemoteViews aktualisieren
|
||||
val views = RemoteViews(context.packageName, R.layout.widget_main)
|
||||
views.setTextViewText(R.id.appwidget_text, displayText)
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="28dp" />
|
||||
<solid android:color="?android:attr/colorBackgroundFloating" />
|
||||
</shape>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:theme="@android:style/Theme.DeviceDefault.DayNight"
|
||||
android:background="@drawable/widget_background"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="WOCHENFOKUS"
|
||||
android:textSize="11sp"
|
||||
android:letterSpacing="0.1"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appwidget_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="Hallo"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minWidth="130dp"
|
||||
android:minHeight="80dp"
|
||||
android:updatePeriodMillis="86400000"
|
||||
android:initialLayout="@layout/widget_main"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:widgetCategory="home_screen"
|
||||
android:targetCellWidth="2"
|
||||
android:targetCellHeight="2">
|
||||
</appwidget-provider>
|
||||
@@ -11,6 +11,9 @@ pluginManagement {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
|
||||
Reference in new issue
Block a user