-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(androidApp): create widget to see next talks from the agenda.
- Loading branch information
1 parent
f207aa2
commit 46dad40
Showing
30 changed files
with
677 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
androidApp/src/main/java/org/gdglille/devfest/android/widgets/AgendaAppWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.gdglille.devfest.android.widgets | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.core.net.toUri | ||
import androidx.datastore.preferences.core.MutablePreferences | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import androidx.glance.GlanceId | ||
import androidx.glance.GlanceTheme | ||
import androidx.glance.appwidget.GlanceAppWidget | ||
import androidx.glance.appwidget.SizeMode | ||
import androidx.glance.appwidget.action.actionStartActivity | ||
import androidx.glance.appwidget.provideContent | ||
import androidx.glance.currentState | ||
import androidx.glance.state.GlanceStateDefinition | ||
import androidx.glance.state.PreferencesGlanceStateDefinition | ||
import kotlinx.datetime.Clock | ||
import kotlinx.datetime.TimeZone | ||
import kotlinx.datetime.toLocalDateTime | ||
import org.gdglille.devfest.android.R | ||
import org.gdglille.devfest.android.widgets.feature.SessionsWidget | ||
import org.gdglille.devfest.repositories.AgendaRepository | ||
import org.gdglille.devfest.repositories.EventRepository | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
|
||
class AgendaAppWidget : GlanceAppWidget(), KoinComponent { | ||
private val agendaRepository: AgendaRepository by inject() | ||
private val eventRepository: EventRepository by inject() | ||
|
||
override val sizeMode = SizeMode.Exact | ||
|
||
override val stateDefinition: GlanceStateDefinition<*> | ||
get() = PreferencesGlanceStateDefinition | ||
|
||
override suspend fun provideGlance(context: Context, id: GlanceId) { | ||
val date = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).toString() | ||
provideContent { | ||
GlanceTheme { | ||
val prefs = currentState<Preferences>() | ||
SessionsWidget( | ||
eventRepository = eventRepository, | ||
agendaRepository = agendaRepository, | ||
date = prefs.lastUpdate ?: date, | ||
iconId = R.drawable.ic_launcher_foreground, | ||
onUpdate = { | ||
prefs.toMutablePreferences().apply { | ||
this.lastUpdate = | ||
Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()) | ||
.toString() | ||
} | ||
update(context, id) | ||
}, | ||
onItemClick = { | ||
actionStartActivity( | ||
intent = Intent( | ||
Intent.ACTION_VIEW, | ||
"c4h://event/schedules/$it".toUri() | ||
) | ||
) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
var MutablePreferences.lastUpdate: String? | ||
set(value) { | ||
this[stringPreferencesKey("last_update")] = value ?: "" | ||
} | ||
get() = this[stringPreferencesKey("last_update")] | ||
|
||
val Preferences.lastUpdate: String? | ||
get() = this[stringPreferencesKey("last_update")] |
9 changes: 9 additions & 0 deletions
9
androidApp/src/main/java/org/gdglille/devfest/android/widgets/AppWidgetReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.gdglille.devfest.android.widgets | ||
|
||
import androidx.glance.appwidget.GlanceAppWidget | ||
import androidx.glance.appwidget.GlanceAppWidgetReceiver | ||
|
||
class AppWidgetReceiver : GlanceAppWidgetReceiver() { | ||
override val glanceAppWidget: GlanceAppWidget | ||
get() = AgendaAppWidget() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:initialLayout="@layout/glance_default_loading_layout" | ||
android:minWidth="350dp" | ||
android:minHeight="100dp" | ||
android:targetCellWidth="5" | ||
android:targetCellHeight="2" | ||
android:minResizeWidth="350dp" | ||
android:minResizeHeight="100dp" | ||
android:maxResizeWidth="350dp" | ||
android:maxResizeHeight="300dp" | ||
android:resizeMode="vertical" | ||
android:updatePeriodMillis="1800000" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.