Skip to content

Commit

Permalink
widget wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yamin8000 committed Sep 26, 2024
1 parent 14f48bf commit 5a222b4
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,7 @@ dependencies {
implementation(libs.hilt.android)
ksp(libs.hilt.android.compiler)
implementation(libs.androidx.hilt.navigation.compose)
//glance
implementation(libs.androidx.glance.appwidget)
implementation(libs.androidx.glance.material3)
}
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="false"
android:theme="@style/Theme.Owl.Splash">

<receiver
android:name=".widget.WidgetReceiver"
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>

<activity
android:name="io.github.yamin8000.owl.ui.MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard|locale|screenLayout|screenSize"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* freeDictionaryApp/freeDictionaryApp.app.main
* RandomWordWidget.kt Copyrighted by Yamin Siahmargooei at 2024/9/26
* RandomWordWidget.kt Last modified at 2024/9/26
* This file is part of freeDictionaryApp/freeDictionaryApp.app.main.
* Copyright (C) 2024 Yamin Siahmargooei
*
* freeDictionaryApp/freeDictionaryApp.app.main is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* freeDictionaryApp/freeDictionaryApp.app.main is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with freeDictionaryApp. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.yamin8000.owl.widget

import android.content.Context
import androidx.glance.GlanceId
import androidx.glance.GlanceTheme
import androidx.glance.appwidget.GlanceAppWidget
import androidx.glance.appwidget.provideContent
import androidx.glance.material3.ColorProviders
import androidx.glance.text.Text
import io.github.yamin8000.owl.common.ui.theme.darkColors
import io.github.yamin8000.owl.common.ui.theme.lightColors

class RandomWordWidget : GlanceAppWidget() {

override suspend fun provideGlance(context: Context, id: GlanceId) {
provideContent {
GlanceTheme(
colors = ColorProviders(
light = lightColors,
dark = darkColors
),
content = {
Text("Hello There!")
}
)
}
}
}
28 changes: 28 additions & 0 deletions app/src/main/java/io/github/yamin8000/owl/widget/WidgetReceiver.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* freeDictionaryApp/freeDictionaryApp.app.main
* WidgetReceiver.kt Copyrighted by Yamin Siahmargooei at 2024/9/26
* WidgetReceiver.kt Last modified at 2024/9/26
* This file is part of freeDictionaryApp/freeDictionaryApp.app.main.
* Copyright (C) 2024 Yamin Siahmargooei
*
* freeDictionaryApp/freeDictionaryApp.app.main is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* freeDictionaryApp/freeDictionaryApp.app.main is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with freeDictionaryApp. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.yamin8000.owl.widget

import androidx.glance.appwidget.GlanceAppWidgetReceiver

class WidgetReceiver : GlanceAppWidgetReceiver() {
override val glanceAppWidget = RandomWordWidget()
}
27 changes: 27 additions & 0 deletions app/src/main/res/xml/widget_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ freeDictionaryApp/freeDictionaryApp.app.main
~ widget_info.xml Copyrighted by Yamin Siahmargooei at 2024/9/26
~ widget_info.xml Last modified at 2024/9/26
~ This file is part of freeDictionaryApp/freeDictionaryApp.app.main.
~ Copyright (C) 2024 Yamin Siahmargooei
~
~ freeDictionaryApp/freeDictionaryApp.app.main is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ freeDictionaryApp/freeDictionaryApp.app.main is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with freeDictionaryApp. If not, see <https://www.gnu.org/licenses/>.
-->

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/app_name"
android:initialLayout="@layout/glance_default_loading_layout"
android:minWidth="150dp"
android:minHeight="50dp"
android:widgetCategory="home_screen" />
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import kotlin.random.Random

private val lightColors = lightColorScheme(
val lightColors = lightColorScheme(
primary = md_theme_light_primary,
onPrimary = md_theme_light_onPrimary,
primaryContainer = md_theme_light_primaryContainer,
Expand Down Expand Up @@ -78,7 +78,7 @@ private val lightColors = lightColorScheme(
)


private val darkColors = darkColorScheme(
val darkColors = darkColorScheme(
primary = md_theme_dark_primary,
onPrimary = md_theme_dark_onPrimary,
primaryContainer = md_theme_dark_primaryContainer,
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ composeLibs = "1.7.2"
coreKtx = "1.13.1"
coreSplashscreen = "1.0.1"
datastorePreferences = "1.1.1"
glance = "1.1.0"
hilt = "2.52"
hiltNavigationCompose = "1.2.0"
lifecycleViewmodelCompose = "2.8.6"
Expand Down Expand Up @@ -37,6 +38,8 @@ androidx-navigation-compose = { module = "androidx.navigation:navigation-compose
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
androidx-glance-material3 = { module = "androidx.glance:glance-material3", version.ref = "glance" }
androidx-glance-appwidget = { module = "androidx.glance:glance-appwidget", version.ref = "glance" }
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" }
lottie-compose = { module = "com.airbnb.android:lottie-compose", version.ref = "lottieCompose" }
Expand Down

0 comments on commit 5a222b4

Please sign in to comment.