Skip to content

Commit

Permalink
change to string resource and blank widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-Mr committed May 15, 2024
1 parent 0dfadb4 commit a051391
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 22 deletions.
16 changes: 14 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
android:theme="@style/Theme.YetAnotherCalendarWidget">
</activity>

<receiver android:name=".WidgetReceiver"
android:exported="true">
<receiver android:name=".calenderwidget.WidgetReceiver"
android:exported="true"
android:label="@string/calendar_widget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -32,6 +33,17 @@
android:resource="@xml/widget_info" />
</receiver>

<receiver android:name=".blankwidget.BlankWidgetProvider"
android:exported="true"
android:label="@string/blank_widget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/blank_widget_info" />
</receiver>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -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() {

}
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand All @@ -162,11 +163,6 @@ class Widget : GlanceAppWidget() {
}
}

@Composable
private fun WeekItem() {

}

@Composable
private fun DayView(
modifier: GlanceModifier,
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Yet Another Calendar Widget</string>
<string name="calendar_widget">日历微件</string>
<string name="blank_widget">空微件</string>
<string name="sunday">周日</string>
<string name="monday">周一</string>
<string name="tuesday">周二</string>
<string name="wednesday">周三</string>
<string name="thursday">周四</string>
<string name="friday">周五</string>
<string name="saturday">周六</string>
<string name="yesterday">昨天</string>
<string name="today">今天</string>
<string name="tomorrow">明天</string>
</resources>
12 changes: 12 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
<resources>
<string name="app_name">Yet Another Calendar Widget</string>
<string name="calendar_widget">Calendar Widget</string>
<string name="blank_widget">Blank Widget</string>
<string name="sunday">Sunday</string>
<string name="monday">Monday</string>
<string name="tuesday">Tuesday</string>
<string name="wednesday">Wednesday</string>
<string name="thursday">Thursday</string>
<string name="friday">Friday</string>
<string name="saturday">Saturday</string>
<string name="yesterday">Yesterday</string>
<string name="today">Today</string>
<string name="tomorrow">Tomorrow</string>
</resources>
10 changes: 10 additions & 0 deletions app/src/main/res/xml/blank_widget_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/glance_default_loading_layout"
android:minWidth="40dp"
android:minHeight="40dp"
android:targetCellWidth="1"
android:targetCellHeight="1"
android:updatePeriodMillis="0"
android:resizeMode="none"
android:widgetCategory="home_screen">
</appwidget-provider>

0 comments on commit a051391

Please sign in to comment.