Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JetChat] Add glance widget for JetChat App #1424 #1425

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

shangeethsivan
Copy link

@shangeethsivan shangeethsivan commented Jul 3, 2024

Added an Unreads widget for the JetChat app using Glance. Also has a option to add widget to home screen on the app.

Glance.Widget.Recording.webm

Fixes #1424

@shangeethsivan shangeethsivan requested a review from a team as a code owner July 3, 2024 16:34
@riggaroo riggaroo removed the request for review from arriolac August 14, 2024 14:21
@shangeethsivan shangeethsivan changed the base branch from main to tm/root-project October 17, 2024 06:23
@shangeethsivan shangeethsivan changed the base branch from tm/root-project to main October 17, 2024 06:23
Copy link
Contributor

@mlykotom mlykotom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR!

Jetchat/app/src/main/AndroidManifest.xml Show resolved Hide resolved
Jetchat/app/src/main/res/values/strings.xml Show resolved Hide resolved
@@ -67,5 +67,8 @@
<string name="more_options">More options</string>
<string name="touch_and_hold_to_record">Touch and hold to record</string>
<string name="record_message">Record voice message</string>
<string name="widget_loading_error">Cannot load Widget</string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string name="widget_loading_error">Cannot load Widget</string>
<string name="widget_loading_error">Problem loading the widget</string>
val appWidgetManager = AppWidgetManager.getInstance(context)
val myProvider = ComponentName(context, WidgetReceiver::class.java)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of showing the error only when user clicks the button, can we prevent showing the drawer item at all?
Maybe you can abstract the method to something like widgetAddingIsSupported() that uses the SDK check and uses the isRequestPinAppWidgetSupported and check for that before showing the UI.

@@ -64,6 +64,58 @@ private val initialMessages = listOf(
"8:03 PM"
)
)
val unreadMessages = listOf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest instead of adding bunch of copy pastes, to use something like the initialMessages and filter it for the unread messages. Maybe filter the ones not from the current author?
val unreadMessages = initialMessages.filter { it.author != "me" }

If you don't have enough messages, you can add more (meaningful-ish) messages to the initialMessages

Comment on lines +1 to +13
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black30"
android:text="@string/widget_loading_error" />
</RelativeLayout>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this used? 🤔

Comment on lines +5 to +11
android:background="#ffffff"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black30"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try not to use direct colors, but use the tokens from the Theme

style = TextStyle(fontWeight = FontWeight.Bold)
)
Text(
text = message.content,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of us not being able to format the text in any form. Showing the unformatted font looks unstyled :(

Copy link

@secondsun secondsun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I've added my feedback, and +1 all of @mlykotom's points.

Are you expecting to add live data to the widget too, or only stick with static data?

title = LocalContext.current.getString(R.string.app_name_unreads),
)
}) {
val unreadMessage = unreadMessages

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unreadMessages should be hoisted and passed into MessagesWidget from provideGlance.

Usually in a Glance Widget you will pass to your widget a repository and the widget can access flows in the composable function. Even though this is fakeData we should try to keep as much as possible to this pattern.

Column(modifier = GlanceModifier.clickable(actionStartActivity<NavActivity>()).fillMaxWidth()) {
Text(
text = message.author,
style = TextStyle(fontWeight = FontWeight.Bold)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add color = GlanceTheme.colors.onSurface to the TextStyle. This will make the colors update when you switch to dark mode.

)
Text(
text = message.content,
style = TextStyle(fontWeight = FontWeight.Normal)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add color = GlanceTheme.colors.onSurface to the TextStyle. This will make the colors update when you switch to dark mode.

import androidx.glance.appwidget.GlanceAppWidget
import androidx.glance.appwidget.GlanceAppWidgetReceiver

class WidgetReceiver : GlanceAppWidgetReceiver() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a widget error layout but do not use it. Consider referencing it here with the errorUiLayout property or implementing onCompositionError

@shangeethsivan
Copy link
Author

Thanks for the review @secondsun and @mlykotom will work on these over the weekend and will re-request a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants