Add favorites widget

This commit is contained in:
MM20
2022-03-30 22:29:20 +02:00
parent a86d453f4e
commit 0b7704cdf2
7 changed files with 82 additions and 2 deletions
@@ -24,6 +24,7 @@ sealed class Widget {
"weather" -> WeatherWidget
"music" -> MusicWidget
"calendar" -> CalendarWidget
"favorites" -> FavoritesWidget
else -> null
}
} else {
@@ -132,6 +133,24 @@ object CalendarWidget : Widget() {
}
}
object FavoritesWidget : Widget() {
override fun loadLabel(context: Context): String {
return context.getString(R.string.widget_name_favorites)
}
override fun toDatabaseEntity(position: Int): WidgetEntity {
return WidgetEntity(
type = WidgetType.INTERNAL.value,
data = "favorites",
height = -1,
position = position
)
}
override val isConfigurable: Boolean = false
}
class ExternalWidget(
var height: Int,
val widgetId: Int,
@@ -14,6 +14,7 @@ interface WidgetRepository {
fun removeWidget(widget: Widget)
fun setWidgetHeight(widget: Widget, newHeight: Int)
fun isCalendarWidgetEnabled(): Flow<Boolean>
fun isFavoritesWidgetEnabled(): Flow<Boolean>
}
internal class WidgetRepositoryImpl(
@@ -30,7 +31,7 @@ internal class WidgetRepositoryImpl(
}
override fun getInternalWidgets(): List<Widget> {
return listOf(WeatherWidget, MusicWidget, CalendarWidget)
return listOf(WeatherWidget, MusicWidget, CalendarWidget, FavoritesWidget)
}
@@ -81,4 +82,8 @@ internal class WidgetRepositoryImpl(
return database.widgetDao().exists("internal", "calendar")
}
override fun isFavoritesWidgetEnabled(): Flow<Boolean> {
return database.widgetDao().exists("internal", "favorites")
}
}