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

Offer import when users click on supported import files #1025

Closed
TheLastProject opened this issue Sep 15, 2022 · 14 comments · Fixed by #1096
Closed

Offer import when users click on supported import files #1025

TheLastProject opened this issue Sep 15, 2022 · 14 comments · Fixed by #1096
Assignees
Labels
common: uncommon Most users are unlikely to come across this or unexpected workflow good first issue Good for newcomers severity: tolerable Low/no impact on users type: enhancement New feature or request

Comments

@TheLastProject
Copy link
Member

We want to register Catima as an opener for common import file names so that users can easily start an import.

For Catima: catima.zip
For Fidme: fidme-export-request-*.zip
For Loyalty Card Keychain: LoyaltyCardKeychain.csv
For Stocard: *-sync.zip
For Voucher Vault: vouchervault.json

When the user opens such a file, Android should offer "Import data into Catima" as option. Catima should select the correct importer based on the filename.

@TheLastProject TheLastProject added type: enhancement New feature or request good first issue Good for newcomers severity: tolerable Low/no impact on users common: uncommon Most users are unlikely to come across this or unexpected workflow labels Sep 15, 2022
@TomerPacific
Copy link
Contributor

Hey @TheLastProject , would you need assistance with this issue? I'd like to help out and get any background details needed to start working on this.

@TheLastProject
Copy link
Member Author

It's mostly a time issue for me, just too many issues, so help would be great :)

As I understand it it should basically be about adding a few intent-filters to the AndroidManifest.xml for the ImportExportActivity and then inside the ImportExportActivity respond to the intent (LoyaltyCardEditActivity should show some code about the kind of data that'll be in the intent).

@TomerPacific
Copy link
Contributor

Ok, I'll start working on this and update you on my progress.

@TomerPacific
Copy link
Contributor

TomerPacific commented Oct 3, 2022

@TheLastProject - Any way I can (easily) generate/create/get the different file types so I can test out that my intent filters work?

Also, just to make sure I am in the right direction, you want the functionality to work inside the ImportExportActivity after a user presses the Import From Filesystem button?

@Altonss
Copy link
Contributor

Altonss commented Oct 3, 2022

@TheLastProject - Any way I can (easily) generate/create/get the different file types so I can test out that my intent filters work?

You can maybe have a look at this https://github.com/CatimaLoyalty/Android/tree/master/app/src/test/res/protect/card_locker

@TomerPacific
Copy link
Contributor

@TheLastProject - Would you be able to approve/reject what I have written in my comment above? Want to make sure I am on the right path.

@TheLastProject
Copy link
Member Author

Ah, I didn't get an email notification for your question because you added it after your original message so I missed it :)

Also, just to make sure I am in the right direction, you want the functionality to work inside the ImportExportActivity after a user presses the Import From Filesystem button?

That seems the most logical place yeah, hooking it into the Activity instead of the task means that we you could easily hook into the existing logic for asking for a password and everything too.

@TomerPacific
Copy link
Contributor

TomerPacific commented Oct 10, 2022

@TheLastProject , thanks for the feedback.
I looked at the files @Altonss suggested, but I think I need a more encompassing repository of different files types to test out that the code I added works.

Just as a preview, I added the following for importing zip files:

` <activity
            android:name=".ImportExportActivity"
            android:label="@string/importExport"
            android:exported="false"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:mimeType="application/x-zip-compressed" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data
                    android:scheme="file"
                    android:host="*"
                    android:pathPattern=".*\.zip" />
            </intent-filter>
` 

I'll add a regex to enforce the files names you listed above.
I read that android's pathPattern is "regex-like" and can have a bit of boilerplate code to match things.

@TheLastProject
Copy link
Member Author

I looked at the files @Altonss suggested, but I think I need a more encompassing repository of different files types to test out that the code I added works.

Loyalty Card Keychain / Catima v1 is inlined in the code:

public void importV2CSV() {
String csvText = "2\n" +
"\n" +
"_id\n" +
"Health\n" +
"Food\n" +
"Fashion\n" +
"\n" +
"_id,store,note,expiry,balance,balancetype,cardid,barcodeid,headercolor,barcodetype,starstatus\n" +
"1,Card 1,Note 1,1618053234,100,USD,1234,5432,1,QR_CODE,0,\r\n" +
"8,Clothes Store,Note about store,,0,,a,,-5317,,0,\n" +
"2,Department Store,,1618041729,0,,A,,-9977996,,0,\n" +
"3,Grocery Store,\"Multiline note about grocery store\n" +
"\n" +
"with blank line\",,150,,dhd,,-9977996,,0,\n" +
"4,Pharmacy,,,0,,dhshsvshs,,-10902850,,1,\n" +
"5,Restaurant,Note about restaurant here,,0,,98765432,23456,-10902850,CODE_128,0,\n" +
"6,Shoe Store,,,12.50,EUR,a,-5317,,AZTEC,0,\n" +
"\n" +
"cardId,groupId\n" +
"8,Fashion\n" +
"3,Food\n" +
"4,Health\n" +
"5,Food\n" +
"6,Fashion\n";

same with Voucher Vault:

public void importVoucherVault() throws IOException, FormatException, JSONException, ParseException {
String jsonText = "[\n" +
" {\n" +
" \"uuid\": \"ae1ae525-3f27-481e-853a-8c30b7fa12d8\",\n" +
" \"description\": \"Clothes Store\",\n" +
" \"code\": \"123456\",\n" +
" \"codeType\": \"CODE128\",\n" +
" \"expires\": null,\n" +
" \"removeOnceExpired\": true,\n" +
" \"balance\": null,\n" +
" \"balanceMilliunits\": null,\n" +
" \"color\": \"GREY\"\n" +
" },\n" +
" {\n" +
" \"uuid\": \"29a5d3b3-eace-4311-a15c-4c7e6a010531\",\n" +
" \"description\": \"Department Store\",\n" +
" \"code\": \"26846363\",\n" +
" \"codeType\": \"CODE39\",\n" +
" \"expires\": \"2021-03-26T00:00:00.000\",\n" +
" \"removeOnceExpired\": true,\n" +
" \"balance\": null,\n" +
" \"balanceMilliunits\": 3500,\n" +
" \"color\": \"PURPLE\"\n" +
" }\n" +
"]";

I totally understand that does make it harder to discover though, they should probably be moved to their own files to make the tests easier to understand and the test files easier to re-use.

Just as a preview, I added the following for importing zip files:
I'll add a regex to enforce the files names you listed above.
I read that android's pathPattern is "regex-like" and can have a bit of boilerplate code to match things.

That sounds great :)

@TomerPacific
Copy link
Contributor

@TheLastProject , thanks for your quick response.

I'm a bit confused about something.
In the ImportExportActivity, you have already set up logic to have handlers to deal with every file type you want to import.
I asked you previously if the user flow you want to happen is after a user clicks on the Import From Filesystem button.

So my question is, why do we need the intent filters?

I thought (initially) that you wanted the application to be associated with specific files types, where if a user presses on them in his/her file manager, the Catima application will be presented as an option to open them (similar to an application that can open PDF files).

But as far as I understand from your most recent replies, this isn't the case. Because if a user can choose any file after pressing the Import From Filesystem button, there is no use for the intent filters here.

If I am wrong in my understanding, please correct me.

@TheLastProject
Copy link
Member Author

Ah, sorry for the confusion.

What I meant to say is that the user clicking a file in their file manager should follow the same in-app flow as clicking the "Import from file system" button so Catima's internal logic wouldn't have to care if the file came from the button or from the user clicking a file in the user's file manager. Specifically, I was trying to state that I feel it would be cleaner to attach these intents to the ImportExportActivity instead of inside the ImportExportTask (as that class will need a cleanup at some point for #513 anyway).

I realize now I worded this extremely poorly yeah.

I thought (initially) that you wanted the application to be associated with specific files types, where if a user presses on them in his/her file manager, the Catima application will be presented as an option to open them (similar to an application that can open PDF files).

This is indeed what I would like added in this issue, yeah. My apologies.

@TomerPacific
Copy link
Contributor

TomerPacific commented Oct 16, 2022

Hi @TheLastProject, so I have been pounding my head against the wall for the last couple of days trying to find the correct string to put in the intent filter so it will only open zip/csv/json files according to what you have listed.
I've read through many SO questions and documentation and could not find a complete answer to how to open a specific file name with an intent filter.

I've tried using pathPattern, pathPrefix, but nothing seems to work.

Below is the intent filter for zip files I have now:


 <intent-filter >
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType= "application/zip" />
                <data android:scheme="content"/>
                <data android:host="*"/>
 </intent-filter>

This does offer Catima as an option to open zip files:

qemu-system-x86_64_IXaLTOn7sx

Regardless of that, I have added the following logic in the ImportExportActivity in the onCreate method (a bit rough right now, but it shows the direction):

Intent fileIntent = getIntent();
if (fileIntent != null && fileIntent.getType() != null) {
    String intentType = fileIntent.getType();
    if (intentType.contains("/zip")) {
       // This will have more logic for the different zip files
        importDataFormat = DataFormat.Catima;
    } else if (intentType.contains("/csv")) {
        importDataFormat = DataFormat.Stocard;
    } else if (intentType.contains("/json")) {
        importDataFormat = DataFormat.VoucherVault;
    }

    openFileForImport(fileIntent.getData(), null);
}

If you have any idea how I can overcome the regex issue, I will appreciate it. 🙏
Also, how can I easily create the different file types? You gave me the string equivalent inside the test classes, but I don't know how I can translate them to concrete files so I can try to import them.

@TheLastProject
Copy link
Member Author

I've read through many SO questions and documentation and could not find a complete answer to how to open a specific file name with an intent filter.

I've tried using pathPattern, pathPrefix, but nothing seems to work.

Hmm, it's a shame that's apparently so difficult. I guess just grabbing all .zip, .json and .csv files would be an improvement then at least. In that case it'll be necessary to show all the import options when a file is opened, but that could be fine.

Also, how can I easily create the different file types? You gave me the string equivalent inside the test classes, but I don't know how I can translate them to concrete files so I can try to import them.

Well those strings are the whole files, just with quoting to fit in Java files. Here they are with the quotes removed: files.zip (the Catima one is an old format not in the .zip, but still uses the Catima importer). The others are in https://github.com/CatimaLoyalty/Android/tree/master/app/src/test/res/protect/card_locker. The Catima .zip is missing, but that one is extremely easily generated by just using Export in the app itself.

@TomerPacific
Copy link
Contributor

@TheLastProject - I have opened a PR and am awaiting your review. I left a comment there regarding constants.

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 severity: tolerable Low/no impact on users type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants