From a051391f3d0ba7b28231b98cbf18d8a9135a9ee4 Mon Sep 17 00:00:00 2001 From: Maary <24504742+Steve-Mr@users.noreply.github.com> Date: Wed, 15 May 2024 21:40:31 +0800 Subject: [PATCH] change to string resource and blank widget --- app/src/main/AndroidManifest.xml | 16 ++++++++-- .../blankwidget/BlankWidget.kt | 23 +++++++++++++ .../blankwidget/BlankWidgetProvider.kt | 9 ++++++ .../{ => calenderwidget}/Widget.kt | 32 ++++++++----------- .../{ => calenderwidget}/WidgetReceiver.kt | 4 +-- app/src/main/res/values-zh-rCN/strings.xml | 16 ++++++++++ app/src/main/res/values/strings.xml | 12 +++++++ app/src/main/res/xml/blank_widget_info.xml | 10 ++++++ 8 files changed, 100 insertions(+), 22 deletions(-) create mode 100644 app/src/main/java/com/maary/yetanothercalendarwidget/blankwidget/BlankWidget.kt create mode 100644 app/src/main/java/com/maary/yetanothercalendarwidget/blankwidget/BlankWidgetProvider.kt rename app/src/main/java/com/maary/yetanothercalendarwidget/{ => calenderwidget}/Widget.kt (85%) rename app/src/main/java/com/maary/yetanothercalendarwidget/{ => calenderwidget}/WidgetReceiver.kt (89%) create mode 100644 app/src/main/res/values-zh-rCN/strings.xml create mode 100644 app/src/main/res/xml/blank_widget_info.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b26e837..fe112aa 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,8 +22,9 @@ android:theme="@style/Theme.YetAnotherCalendarWidget"> - + @@ -32,6 +33,17 @@ android:resource="@xml/widget_info" /> + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/maary/yetanothercalendarwidget/blankwidget/BlankWidget.kt b/app/src/main/java/com/maary/yetanothercalendarwidget/blankwidget/BlankWidget.kt new file mode 100644 index 0000000..40c3d86 --- /dev/null +++ b/app/src/main/java/com/maary/yetanothercalendarwidget/blankwidget/BlankWidget.kt @@ -0,0 +1,23 @@ +package com.maary.yetanothercalendarwidget.blankwidget + +import android.content.Context +import androidx.compose.runtime.Composable +import androidx.glance.GlanceId +import androidx.glance.GlanceTheme +import androidx.glance.appwidget.GlanceAppWidget +import androidx.glance.appwidget.provideContent + +class BlankWidget: GlanceAppWidget() { + override suspend fun provideGlance(context: Context, id: GlanceId) { + provideContent { + GlanceTheme { + Content() + } + } + } +} + +@Composable +private fun Content() { + +} \ No newline at end of file diff --git a/app/src/main/java/com/maary/yetanothercalendarwidget/blankwidget/BlankWidgetProvider.kt b/app/src/main/java/com/maary/yetanothercalendarwidget/blankwidget/BlankWidgetProvider.kt new file mode 100644 index 0000000..4467e74 --- /dev/null +++ b/app/src/main/java/com/maary/yetanothercalendarwidget/blankwidget/BlankWidgetProvider.kt @@ -0,0 +1,9 @@ +package com.maary.yetanothercalendarwidget.blankwidget + +import androidx.glance.appwidget.GlanceAppWidget +import androidx.glance.appwidget.GlanceAppWidgetReceiver + +class BlankWidgetProvider : GlanceAppWidgetReceiver() { + override val glanceAppWidget: GlanceAppWidget + get() = BlankWidget() +} \ No newline at end of file diff --git a/app/src/main/java/com/maary/yetanothercalendarwidget/Widget.kt b/app/src/main/java/com/maary/yetanothercalendarwidget/calenderwidget/Widget.kt similarity index 85% rename from app/src/main/java/com/maary/yetanothercalendarwidget/Widget.kt rename to app/src/main/java/com/maary/yetanothercalendarwidget/calenderwidget/Widget.kt index 8c6003a..43c21a0 100644 --- a/app/src/main/java/com/maary/yetanothercalendarwidget/Widget.kt +++ b/app/src/main/java/com/maary/yetanothercalendarwidget/calenderwidget/Widget.kt @@ -1,9 +1,7 @@ -package com.maary.yetanothercalendarwidget +package com.maary.yetanothercalendarwidget.calenderwidget import android.content.Context -import android.content.Intent import android.icu.text.SimpleDateFormat -import android.util.Log import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue @@ -38,6 +36,9 @@ import androidx.glance.layout.wrapContentWidth import androidx.glance.text.Text import androidx.glance.text.TextStyle import androidx.glance.unit.ColorProvider +import com.maary.yetanothercalendarwidget.CalendarContentResolver +import com.maary.yetanothercalendarwidget.MainActivity +import com.maary.yetanothercalendarwidget.R import java.util.Calendar import java.util.Date import java.util.Locale @@ -142,13 +143,13 @@ class Widget : GlanceAppWidget() { } val widgetItemStates = listOf( - WidgetItemState(eventsByDay["SUN"]?: emptyList(), "Sunday", GlanceTheme.colors.primaryContainer), - WidgetItemState(eventsByDay["MON"]?: emptyList(), "Monday", GlanceTheme.colors.primaryContainer), - WidgetItemState(eventsByDay["TUE"]?: emptyList(), "Tuesday", GlanceTheme.colors.secondaryContainer), - WidgetItemState(eventsByDay["WED"]?: emptyList(), "Wednesday", GlanceTheme.colors.tertiaryContainer), - WidgetItemState(eventsByDay["THU"]?: emptyList(), "Thursday", GlanceTheme.colors.primaryContainer), - WidgetItemState(eventsByDay["FRI"]?: emptyList(), "Friday", GlanceTheme.colors.secondaryContainer), - WidgetItemState(eventsByDay["SAT"]?: emptyList(), "Saturday", GlanceTheme.colors.tertiaryContainer) + WidgetItemState(eventsByDay["SUN"]?: emptyList(), LocalContext.current.getString(R.string.sunday), GlanceTheme.colors.primaryContainer), + WidgetItemState(eventsByDay["MON"]?: emptyList(), LocalContext.current.getString(R.string.monday), GlanceTheme.colors.primaryContainer), + WidgetItemState(eventsByDay["TUE"]?: emptyList(), LocalContext.current.getString(R.string.tuesday), GlanceTheme.colors.secondaryContainer), + WidgetItemState(eventsByDay["WED"]?: emptyList(), LocalContext.current.getString(R.string.wednesday), GlanceTheme.colors.tertiaryContainer), + WidgetItemState(eventsByDay["THU"]?: emptyList(), LocalContext.current.getString(R.string.thursday), GlanceTheme.colors.primaryContainer), + WidgetItemState(eventsByDay["FRI"]?: emptyList(), LocalContext.current.getString(R.string.friday), GlanceTheme.colors.secondaryContainer), + WidgetItemState(eventsByDay["SAT"]?: emptyList(), LocalContext.current.getString(R.string.saturday), GlanceTheme.colors.tertiaryContainer) ) LazyColumn (modifier = GlanceModifier.padding(8.dp)) { @@ -162,11 +163,6 @@ class Widget : GlanceAppWidget() { } } - @Composable - private fun WeekItem() { - - } - @Composable private fun DayView( modifier: GlanceModifier, @@ -185,9 +181,9 @@ class Widget : GlanceAppWidget() { } val widgetItemStates = listOf( - WidgetItemState(yesterdayEvents, "Yesterday", GlanceTheme.colors.secondaryContainer), - WidgetItemState(todayEvents, "Today", GlanceTheme.colors.primaryContainer), - WidgetItemState(tomorrowEvents, "Tomorrow", GlanceTheme.colors.tertiaryContainer) + WidgetItemState(yesterdayEvents, LocalContext.current.getString(R.string.yesterday), GlanceTheme.colors.secondaryContainer), + WidgetItemState(todayEvents, LocalContext.current.getString(R.string.today), GlanceTheme.colors.primaryContainer), + WidgetItemState(tomorrowEvents, LocalContext.current.getString(R.string.tomorrow), GlanceTheme.colors.tertiaryContainer) ) LazyColumn(modifier = GlanceModifier.padding(8.dp)) { diff --git a/app/src/main/java/com/maary/yetanothercalendarwidget/WidgetReceiver.kt b/app/src/main/java/com/maary/yetanothercalendarwidget/calenderwidget/WidgetReceiver.kt similarity index 89% rename from app/src/main/java/com/maary/yetanothercalendarwidget/WidgetReceiver.kt rename to app/src/main/java/com/maary/yetanothercalendarwidget/calenderwidget/WidgetReceiver.kt index 9a9af1a..0972b69 100644 --- a/app/src/main/java/com/maary/yetanothercalendarwidget/WidgetReceiver.kt +++ b/app/src/main/java/com/maary/yetanothercalendarwidget/calenderwidget/WidgetReceiver.kt @@ -1,15 +1,15 @@ -package com.maary.yetanothercalendarwidget +package com.maary.yetanothercalendarwidget.calenderwidget import android.appwidget.AppWidgetManager import android.content.Context import androidx.glance.appwidget.GlanceAppWidget import androidx.glance.appwidget.GlanceAppWidgetReceiver import androidx.glance.appwidget.updateAll +import com.maary.yetanothercalendarwidget.CalendarContentResolver import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import javax.inject.Inject @AndroidEntryPoint diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml new file mode 100644 index 0000000..a42a869 --- /dev/null +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -0,0 +1,16 @@ + + + Yet Another Calendar Widget + 日历微件 + 空微件 + 周日 + 周一 + 周二 + 周三 + 周四 + 周五 + 周六 + 昨天 + 今天 + 明天 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9a867b3..13c295f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,15 @@ Yet Another Calendar Widget + Calendar Widget + Blank Widget + Sunday + Monday + Tuesday + Wednesday + Thursday + Friday + Saturday + Yesterday + Today + Tomorrow \ No newline at end of file diff --git a/app/src/main/res/xml/blank_widget_info.xml b/app/src/main/res/xml/blank_widget_info.xml new file mode 100644 index 0000000..e8a48b9 --- /dev/null +++ b/app/src/main/res/xml/blank_widget_info.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file