Android icon indicating copy to clipboard operation
Android copied to clipboard

Widget that opens a group

Open TheLastProject opened this issue 4 years ago • 18 comments

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 avatar Sep 17 '21 10:09 TheLastProject

Can I try to work on it ?

theyup12 avatar Sep 18 '21 19:09 theyup12

Yeah, sure! Go for it :)

TheLastProject avatar Sep 18 '21 19:09 TheLastProject

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?

theyup12 avatar Sep 20 '21 19:09 theyup12

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 :)

TheLastProject avatar Sep 20 '21 19:09 TheLastProject

any tips for this issues? :(

theyup12 avatar Sep 21 '21 21:09 theyup12

Let's do things one step at a time.

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

https://user-images.githubusercontent.com/1885159/134252819-b8a92a7b-fcf4-4d9d-825c-c66d0cd29757.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).

TheLastProject avatar Sep 21 '21 22:09 TheLastProject

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

theyup12 avatar Sep 22 '21 05:09 theyup12

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.

TheLastProject avatar Oct 17 '21 20:10 TheLastProject

I'm currently trying to work on this :)

Altonss avatar Dec 09 '21 20:12 Altonss

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

Altonss avatar Dec 09 '21 21:12 Altonss

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

TheLastProject avatar Dec 09 '21 21:12 TheLastProject

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?

Altonss avatar Dec 09 '21 21:12 Altonss

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

TheLastProject avatar Dec 09 '21 21:12 TheLastProject

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 avatar Dec 09 '21 21:12 Altonss

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?

Altonss avatar Dec 10 '21 12:12 Altonss

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 :)

TheLastProject avatar Dec 10 '21 12:12 TheLastProject

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

Altonss avatar Dec 10 '21 12:12 Altonss

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

Altonss avatar Dec 10 '21 18:12 Altonss