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

Document how to use package with Jetpack Glance #181

Merged
merged 1 commit into from
Dec 13, 2023
Merged

Conversation

tenhobi
Copy link
Contributor

@tenhobi tenhobi commented Nov 16, 2023

When trying to update my Jetpack Glance from Flutter app, it does not trigger the update. I therefore did update this package so it works with Glance.

Firstly I wanted to make a superclass that would my glance widget had to import, but that did not work. So I changed the code so it uses config where I "register" the Glance widget so the plugin can use the concrete widget class to trigger updates.

This is partially related to #134

//
Btw. while trying out this package, I tested that initial launch as well as widget clicked listener works. 👍 (other things I did not try)

@ABausG
Copy link
Owner

ABausG commented Nov 16, 2023

Thank you so much for this!
Do you know if it is possible to use Glance and the old Provider Way side by side? I'm not sure if that is possible with your current approach? If at all possible in Android..

Would you have time to work on this a bit more? I think we should definitely check that also interactivity is working with Glance.
Also it would be great if you could add some documentation to the readme how to use the features like initialLaunch, Clicked, Interactivity
If it is possible to use Glance Side by Side with the old way it would be great to also show that in the example

@tenhobi
Copy link
Contributor Author

tenhobi commented Nov 16, 2023

@ABausG hi, I am not really sure about that. Glance makes a lot of things and even the current widget update does not work. Now I discovered that the update using intent actually works, but still we have to update Preferences to make it work, so Glance probably only refresh widget when the state actually changes? That however does not modify the code since we need to update the Glance state first...

We could probably make custom provider/receiver that extends GlanceAppWidgetReceiver and automatically initializes the glance widget (GlanceAppWidget) to the config? But that still would not work in cases when you have multiple providers/receivers and want to have different widgets for them...

So I am not really sure how to improve that...

@tenhobi
Copy link
Contributor Author

tenhobi commented Nov 16, 2023

LMAO I figured it out! It seems using HomeWidget.updateWidget the glance receiver's onUpdate is called and there I can iterate through all the widgets and update them.

... seems as a Glance way of doing example/android/app/src/main/kotlin/es/antonborri/home_widget_example/HomeWidgetExampleProvider.kt:56 (appWidgetManager.updateAppWidget(widgetId, views))

^^ which is also not mentioned that you have to do btw... So we should probably also mention it? Because w/o it even regular widgets won't update.

@tenhobi tenhobi changed the title Add Jetpack Glance updateWidget support Document how to use package with Jetpack Glance Nov 16, 2023
@tenhobi
Copy link
Contributor Author

tenhobi commented Nov 16, 2023

That's all @ABausG. This is what I tried/know about Jetpack Glance and this package:

  • ❔ saveWidgetData -- should work since Flutter's Shared Preferences do
  • ✅ updateWidget
  • ❔ getWidgetData -- should work since Flutter's Shared Preferences do
  • ⚫ setAppGroupId (iOS)
  • ✅ initiallyLaunchedFromHomeWidget
  • ✅ widgetClicked
  • ❔ registerBackgroundCallback
  • ❔ renderFlutterWidget

@tenhobi
Copy link
Contributor Author

tenhobi commented Nov 20, 2023

@ABausG what do you think about these changes?

@tenhobi
Copy link
Contributor Author

tenhobi commented Nov 21, 2023

Could you also review this getIntent method I need? Since in Jetpack Glance, we can use context.startActivity, which takes Intent, not PendingIntent, I need this method to create just the Intent.

Note I tried to use getActivity and then .send() on it, which does not work. 🤔

Copy link

codecov bot commented Dec 2, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (59e596a) 100.00% compared to head (e24b2a5) 100.00%.
Report is 7 commits behind head on dev.

❗ Current head e24b2a5 differs from pull request most recent head f1fcd9d. Consider uploading reports for the commit f1fcd9d to get more accurate results

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #181   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines           67        67           
=========================================
  Hits            67        67           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Musta-Pollo
Copy link

Musta-Pollo commented Dec 2, 2023

So you can use glance widgets without a problem? Or you are going to work on it again?

@tenhobi
Copy link
Contributor Author

tenhobi commented Dec 2, 2023

Yes, we are using Jetpack Glance for our Flutter app with no problem (we are almost production ready). And we are using this home_widget package to help us with widget updating from an app, handling app initial opening and widget clicks etc. (we are not using that get/save widget data helper since we decided to use shared preferences and secure storage for that directly)

We plan to write (hopefully till the end of the year) an article on our blog, as mentioned in my tweet https://twitter.com/tenhobi/status/1729969425057567149. So I hope that will help people with making a home widget for Flutter apps 👍

@Musta-Pollo
Copy link

Thank you for your quick response 👍 And good luck with your project :)

@ABausG
Copy link
Owner

ABausG commented Dec 2, 2023

Thanks for this contribution @tenhobi here is my plan:

I am preparing right now the release of 0.3.1 which will include some general fixes for Android.
Also probably today or tomorrow I will finish Version 0.4.0 which will make the Interactive iOS stuff transition to a stable release.
My plan would then be to merge the changes from this onto dev channel and finish all this up for Jetpack Compose as Version 0.5.0. My optimistic goal for this would be to get it out in the next week

Copy link
Owner

@ABausG ABausG left a comment

Choose a reason for hiding this comment

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

Thank you again so much for this. Apart from the comments some wishes/questions:

  1. Could you please make this target the dev branch? As I described I plan to release this as 0.5.0 after iOS Interactivity is released (should be beginning of this week) and there are some changes to the README Structure that might affect this PR
  2. I think it would be great if we could add an example Widget using Glance to the example App on top of the available Widget. This does not need to be in this PR. Let me know if you would have time for that. Otherwise I should be able to do this as well.
  3. Regarding updating the Glance Widget. Have you played around at all if it is somehow possible to detect that whatever class is being found in the updateWidget method in the Plugin and update the state from there? https://developer.android.com/jetpack/compose/glance/glance-app-widget#update-glanceappwidget

README.md Outdated
Comment on lines 77 to 79
// Shared Preferences used by Flutter
context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE)
```
Copy link
Owner

Choose a reason for hiding this comment

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

I know that you are using the default SharedPreferences however I think this might be confusing for people as I think the default should be for people to simply use the data from HomeWidget.

Not sure if maybe an extension exposed by the package that has a getter for the HomeWidget Data might make sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, you are probably right! I will delete this note then. :)

README.md Outdated
@@ -133,6 +153,58 @@ This Name needs to be equal to the Classname of the [WidgetProvider](#Write-your
The name for iOS will be chosen by checking `iOSName` if that was not provided it will fallback to `name`.
This name needs to be equal to the Kind specified in you Widget

#### Standard widgets
Copy link
Owner

Choose a reason for hiding this comment

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

This might need an ### Android Title

@@ -79,13 +79,16 @@ class HomeWidgetPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
"updateWidget" -> {
val qualifiedName = call.argument<String>("qualifiedAndroidName")
val className = call.argument<String>("android") ?: call.argument<String>("name")
val androidIsUsingGlance = call.argument<Boolean>("androidIsUsingGlance") ?: false
Copy link
Owner

Choose a reason for hiding this comment

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

This is not needed anymore is it?

@tenhobi tenhobi changed the base branch from main to dev December 4, 2023 08:21
@tenhobi
Copy link
Contributor Author

tenhobi commented Dec 4, 2023

  1. done
  2. I can do that, but I am not sure whether I will have time for that tho.
  3. I think thats the same thing as I do in https://github.com/ABausG/home_widget/pull/181/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R192-R201

@ABausG
Copy link
Owner

ABausG commented Dec 4, 2023

  1. I can do that, but I am not sure whether I will have time for that tho.

No worries. Let's sync before starting it and we'll get that added 👍

  1. I think thats the same thing as I do in https://github.com/ABausG/home_widget/pull/181/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R192-R201

Yes! And I think it would be enough if my idea doesn't work.
If it would be possible to do that on the Plugin side somewhere here: https://github.com/ABausG/home_widget/pull/181/files?diff=unified&w=0#diff-c93199852bce9e39c15fd5f53ad09ed739b949fe5ccb7166786e91915afd1f41R85-R91
This would mean that users of the plugin would not have to do the state updating on their side which is a thing people might forget to do so if we manage to get it working on the plugin side I think it would be great. Given that we have the reference to the class name we might be able to check if it is a GlanceWidget and perform the updates with the ids?

@tenhobi
Copy link
Contributor Author

tenhobi commented Dec 4, 2023

I am not sure if you can, since the provider/receiver should probable handle that (the same way as for regular android widget here https://github.com/ABausG/home_widget/blob/main/example/android/app/src/main/kotlin/es/antonborri/home_widget_example/HomeWidgetExampleProvider.kt#L54).

And you need that update anyway. The regular 30 minute refresh triggers this method on provider/receiver, not the plugin. And it might be contraproductive to doing it automatically (if somehow possible) for updates from Flutter, and not for this. And what more: for Glance, as shown in the initial draft, you must use the YourWidget class and call updates on that. And I was only able to do that using some static variable and adding an initializer (which I wrongly put in Flutter activity, not to the Flutter App itself and therefore if no app is ran and only widget is running it might fail hah).

@ABausG ABausG merged commit f1fcd9d into ABausG:dev Dec 13, 2023
3 of 6 checks passed
@ABausG
Copy link
Owner

ABausG commented Dec 13, 2023

@tenhobi Not sure what happened here. But for some reason the PR got closed. Says it is merged however it not really is merged. Would you mind reopening the PR? Think this is mergeable to the dev branch now!

@tenhobi
Copy link
Contributor Author

tenhobi commented Dec 13, 2023

Interesting. Sure, will do that all on Friday probably

@ABausG
Copy link
Owner

ABausG commented Jan 7, 2024

@tenhobi would you mind reopening this (against main)?
I will now work on adding a Glance Widget to the Example App based on the documentation you wrote. That way we should also be able to see which areas could benefit from changes

@tenhobi
Copy link
Contributor Author

tenhobi commented Jan 9, 2024

I will reopen this from a new branch. I have to recover the changes from the PR.

@bhoomikshetty
Copy link

@tenhobi would you mind reopening this (against main)? I will now work on adding a Glance Widget to the Example App based on the documentation you wrote. That way we should also be able to see which areas could benefit from changes

Hello @tenhobi, thankyou so much for this great plugin. Any update on the example app using Glance.

@ABausG
Copy link
Owner

ABausG commented Jan 30, 2024

@tenhobi would you mind reopening this (against main)? I will now work on adding a Glance Widget to the Example App based on the documentation you wrote. That way we should also be able to see which areas could benefit from changes

Hello @tenhobi, thankyou so much for this great plugin. Any update on the example app using Glance.

I'm working on it! Hope to get it done soon!!

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

Successfully merging this pull request may close these issues.

4 participants