mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 00:37:03 +05:30
feat(android): basic widget implementation
This needs a Glance version of LobstersCard to function
This commit is contained in:
parent
e740ddb7cc
commit
62f512e319
5 changed files with 103 additions and 0 deletions
|
@ -65,6 +65,8 @@ dependencies {
|
||||||
implementation(platform(libs.androidx.compose.bom))
|
implementation(platform(libs.androidx.compose.bom))
|
||||||
implementation(platform(libs.okhttp.bom))
|
implementation(platform(libs.okhttp.bom))
|
||||||
implementation(libs.androidx.activity.compose)
|
implementation(libs.androidx.activity.compose)
|
||||||
|
implementation(libs.androidx.compose.glance)
|
||||||
|
implementation(libs.androidx.compose.glance.m3)
|
||||||
implementation(libs.androidx.compose.material)
|
implementation(libs.androidx.compose.material)
|
||||||
implementation(libs.androidx.compose.material.icons.extended)
|
implementation(libs.androidx.compose.material.icons.extended)
|
||||||
implementation(libs.androidx.compose.material3)
|
implementation(libs.androidx.compose.material3)
|
||||||
|
|
|
@ -155,6 +155,15 @@
|
||||||
<action android:name="androidx.profileinstaller.action.BENCHMARK_OPERATION" />
|
<action android:name="androidx.profileinstaller.action.BENCHMARK_OPERATION" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
<receiver android:name=".glance.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/saved_posts_widget_info" />
|
||||||
|
</receiver>
|
||||||
<!-- Required: set your sentry.io project identifier (DSN) -->
|
<!-- Required: set your sentry.io project identifier (DSN) -->
|
||||||
<meta-data android:name="io.sentry.dsn" android:value="${sentryDsn}" />
|
<meta-data android:name="io.sentry.dsn" android:value="${sentryDsn}" />
|
||||||
<!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->
|
<!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2023 Harsh Shandilya.
|
||||||
|
* Use of this source code is governed by an MIT-style
|
||||||
|
* license that can be found in the LICENSE file or at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*/
|
||||||
|
package dev.msfjarvis.claw.android.glance
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.glance.GlanceId
|
||||||
|
import androidx.glance.GlanceModifier
|
||||||
|
import androidx.glance.appwidget.GlanceAppWidget
|
||||||
|
import androidx.glance.appwidget.lazy.LazyColumn
|
||||||
|
import androidx.glance.appwidget.lazy.items
|
||||||
|
import androidx.glance.appwidget.provideContent
|
||||||
|
import androidx.glance.layout.Alignment
|
||||||
|
import androidx.glance.layout.fillMaxSize
|
||||||
|
import androidx.glance.text.Text
|
||||||
|
import androidx.glance.text.TextStyle
|
||||||
|
import dev.msfjarvis.claw.database.local.SavedPost
|
||||||
|
import java.time.Month
|
||||||
|
import kotlinx.collections.immutable.ImmutableMap
|
||||||
|
import kotlinx.collections.immutable.persistentMapOf
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
class SavedPostsWidget(
|
||||||
|
private val savedPosts: Flow<ImmutableMap<Month, List<SavedPost>>>,
|
||||||
|
) : GlanceAppWidget() {
|
||||||
|
override suspend fun provideGlance(context: Context, id: GlanceId) {
|
||||||
|
provideContent { MyContent() }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun MyContent() {
|
||||||
|
val posts by savedPosts.collectAsState(persistentMapOf())
|
||||||
|
|
||||||
|
LazyColumn(
|
||||||
|
modifier = GlanceModifier.fillMaxSize(),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
items(posts.values.flatten()) { post -> Text(post.title, style = TextStyle()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2023 Harsh Shandilya.
|
||||||
|
* Use of this source code is governed by an MIT-style
|
||||||
|
* license that can be found in the LICENSE file or at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*/
|
||||||
|
package dev.msfjarvis.claw.android.glance
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.glance.appwidget.GlanceAppWidget
|
||||||
|
import androidx.glance.appwidget.GlanceAppWidgetReceiver
|
||||||
|
import com.deliveryhero.whetstone.Whetstone
|
||||||
|
import com.deliveryhero.whetstone.broadcastreceiver.ContributesBroadcastReceiverInjector
|
||||||
|
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ContributesBroadcastReceiverInjector
|
||||||
|
class WidgetReceiver : GlanceAppWidgetReceiver() {
|
||||||
|
|
||||||
|
@Inject lateinit var viewModel: ClawViewModel
|
||||||
|
|
||||||
|
override val glanceAppWidget: GlanceAppWidget
|
||||||
|
get() = SavedPostsWidget(viewModel.savedPosts)
|
||||||
|
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
Whetstone.inject(this, context)
|
||||||
|
super.onReceive(context, intent)
|
||||||
|
}
|
||||||
|
}
|
15
android/src/main/res/xml/saved_posts_widget_info.xml
Normal file
15
android/src/main/res/xml/saved_posts_widget_info.xml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<!--
|
||||||
|
~ Copyright © 2023 Harsh Shandilya.
|
||||||
|
~ Use of this source code is governed by an MIT-style
|
||||||
|
~ license that can be found in the LICENSE file or at
|
||||||
|
~ https://opensource.org/licenses/MIT.
|
||||||
|
-->
|
||||||
|
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:initialLayout="@layout/glance_default_loading_layout"
|
||||||
|
android:minWidth="250dp"
|
||||||
|
android:minHeight="110dp"
|
||||||
|
android:minResizeWidth="250dp"
|
||||||
|
android:minResizeHeight="110dp"
|
||||||
|
android:resizeMode="vertical|horizontal"
|
||||||
|
android:updatePeriodMillis="1800000"
|
||||||
|
android:widgetCategory="home_screen" />
|
Loading…
Add table
Add a link
Reference in a new issue