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

Widget that opens a group #397

Open
TheLastProject opened this issue Sep 17, 2021 · 18 comments
Open

Widget that opens a group #397

TheLastProject opened this issue Sep 17, 2021 · 18 comments
Assignees
Labels
common: uncommon Most users are unlikely to come across this or unexpected workflow good first issue Good for newcomers hacktoberfest severity: tolerable Low/no impact on users type: enhancement New feature or request

Comments

@TheLastProject
Copy link
Member

A widget that opens the MainActivity with a specific group selected would be pretty awesome.

So, for example, I use Groups to make a group of "Coupons". I would like to be able to create a widget to not just open a specific card but open Catima with the Coupons group selected.

This would requiring adding an extractIntentFields to MainActivity (like LoyaltyCardViewActivity has) which supports entering a requested group and an extra Shortcut activity in the manifest: https://github.com/TheLastProject/Catima/blob/110b3bcef3aa5e63531c706934ef0674dd0d51cf/app/src/main/AndroidManifest.xml#L92-L100

@TheLastProject TheLastProject added type: enhancement New feature or request good first issue Good for newcomers hacktoberfest labels Sep 17, 2021
@theyup12
Copy link

Can I try to work on it ?

@TheLastProject
Copy link
Member Author

Yeah, sure! Go for it :)

@theyup12
Copy link

For this issue, do you want me to display a group of coupons on the main page instead of each separate coupon on the main page as it is now?

@TheLastProject
Copy link
Member Author

The idea is that instead of creating a widget on your home screen that opens the chosen card, it open Catima's main screen with your chosen group.

I think that is what you meant too, so yes :)

@theyup12
Copy link

any tips for this issues? :(

@TheLastProject
Copy link
Member Author

TheLastProject commented Sep 21, 2021

Let's do things one step at a time.

Step 1: Make sure you can find the widget to create a shortcut

video_2021-09-21_23-51-52.mp4

Step 2: Make a copy of CardShortcutConfigure.java to a logical name (something like GroupShortcutConfigure.java)

Step 3: Copy the widget stuff in AndroidManifest.xml but change .CardShortcutConfigure.java to .GroupShortcutConfigure.java
https://github.com/TheLastProject/Catima/blob/fa33cdaca4397f22651f9b64bdba77a907d2f3df/app/src/main/AndroidManifest.xml#L102-L111

Step 4: Test if you now have 2 widgets

Step 5: Modify GroupShortcutConfigure.java until you no longer have a list of cards, but a list of groups

Step 6: Modify GroupShortcutConfigure.java to create an Intent pointing at MainActivity instead of LoyaltyCardViewActivity and put the group somewhere in the intent extra data (like CardShortcutConfigure creates one which puts the loyaltyCard id in the bundle, see https://github.com/TheLastProject/Catima/blob/fa33cdaca4397f22651f9b64bdba77a907d2f3df/app/src/main/java/protect/card_locker/ShortcutHelper.java#L122-L130)

Step 7: Create an extractIntentFields on MainActivity like LoyaltyCardViewActivity has one: https://github.com/TheLastProject/Catima/blob/fa33cdaca4397f22651f9b64bdba77a907d2f3df/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java#L185-L190 and make it read however you named the field for the group name and display that group

It sounds really big and complex like this, but for the most part it is standard Android widget handling, there is not really any Catima "secret sauce" over it (which, I admit, can be a bit confusing if you've never worked with Android widgets before, but basically, a widget just starts an activity with an intent, the same way launchers start apps or apps switch between screens).

@theyup12
Copy link

Thank you so much for your help. I will work on it

@TheLastProject
Copy link
Member Author

Hey @theyup12, I haven't heard from you on this for a while. If you still want to work on this, please tell me. Otherwise I will free this up for someone else to work on.

@Altonss
Copy link
Contributor

Altonss commented Dec 9, 2021

I'm currently trying to work on this :)

@Altonss
Copy link
Contributor

Altonss commented Dec 9, 2021

As an id for the group should the group._id string be used or the hashCode?

@TheLastProject
Copy link
Member Author

I would recommend using group._id, as otherwise it'll break when you reorder a group and the names are unique

@Altonss
Copy link
Contributor

Altonss commented Dec 9, 2021

Ah yes your right, that's what I did anyway. But as these ids are just strings and I don't know if they are unique, my fear was to introduce conflicts ^^ Are group._id unique? What is the group._id of the "All" tab?

@TheLastProject
Copy link
Member Author

Yeah, group._id is an unique string per group (it's the group name).

The "All" tab has no group ID, it's not a real group. Guess you could use like null or something for all

@Altonss
Copy link
Contributor

Altonss commented Dec 9, 2021

Ok because I was wondering what to put here:

private void extractIntentFields(Intent intent)
    {
        final Bundle b = intent.getExtras();
        groupId = b != null ? b.getString("id") : "";
        Log.d(TAG, "View activity: id=" + groupId);
    }

@Altonss
Copy link
Contributor

Altonss commented Dec 10, 2021

I managed to progress pretty far, but I have a bug now: when I have the app opened on the All tab, then leave the app open in the background and then tap on the widget, the all tab opens up instead of the group I chose. Do you have an idea of where in the code this error comes from?

@TheLastProject
Copy link
Member Author

Please make a PR, mark it as "Draft" with the note of that issue and I will take a look at your code when I have time :)

@Altonss
Copy link
Contributor

Altonss commented Dec 10, 2021

All right, I still need to make some tweaks, but will make the draft PR probably in a few hours :)

@Altonss
Copy link
Contributor

Altonss commented Dec 10, 2021

I'm finally done with the work and it is now a real PR!

@TheLastProject TheLastProject added common: uncommon Most users are unlikely to come across this or unexpected workflow severity: tolerable Low/no impact on users labels Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common: uncommon Most users are unlikely to come across this or unexpected workflow good first issue Good for newcomers hacktoberfest severity: tolerable Low/no impact on users type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants