Skip to content

Commit

Permalink
Merge pull request #4 from k3b/ExportCsv
Browse files Browse the repository at this point in the history
SecUSo#42: created fileUtils
  • Loading branch information
MaxIsV authored Feb 6, 2023
2 parents 74ad2d6 + 5b36337 commit 42537bb
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@
android:name="org.secuso.privacyfriendlybackup.api.pfa.PFAAuthService" />
</intent-filter>
</service>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="org.secuso.privacyfriendlyfinance"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths"/>
</provider>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Privacy Friendly Finance Manager is licensed under the GPLv3.
Copyright (C) 2023 k3b
This program is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.gnu.org/licenses/.
Additionally icons from Google Design Material Icons are used that are licensed under Apache
License Version 2.0.
*/

package org.secuso.privacyfriendlyfinance.activities.helper;

import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;

import androidx.core.content.FileProvider;

import java.io.File;

/** Android specific file helpers */
public class FileHelper {
private static final String FILENAME = "export.csv";

private static final String MIME_CSV = "text/csv";

private static File getSharedDir(Context context) {
File sharedDir = new File(context.getFilesDir(), "shared");
sharedDir.mkdirs();

return sharedDir;
}

public static File getCsvFile(Context context) {
File outFile = new File(getSharedDir(context), FILENAME);
return outFile;
}

private static Uri getCsvFileUri(Context context) {
return FileProvider.getUriForFile(context, "org.secuso.privacyfriendlyfinance", getCsvFile(context));
}

public static boolean sendCsv(Context context, String chooserLabel) {
Uri outUri = getCsvFileUri(context);

if (outUri != null) {
Intent childSend = new Intent();

childSend
.setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_STREAM, outUri)
.setType(MIME_CSV);

childSend.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ClipData clip = ClipData.newUri(context.getContentResolver(), outUri.toString(), outUri);
childSend.setClipData(clip);
}

final Intent execIntent = Intent.createChooser(childSend, chooserLabel);

context.startActivity(execIntent);
return true;
}
return false;
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/org/secuso/privacyfriendlyfinance/csv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# csv definition

charset = "utf8"
csv-fielddelimiter = ";"
enclose in -"- : only if necessary

Available columns

* date (without time as iso string)
* amount (in euro cent)
* note (transaction name or comment)
* category = name of selected category or empty
* account = name of selected account or empty
23 changes: 23 additions & 0 deletions app/src/main/res/xml/file_provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?><!--
/*
Privacy Friendly Finance Manager is licensed under the GPLv3.
Copyright (C) 2023 k3b
This program is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.gnu.org/licenses/.
Additionally icons from Google Design Material Icons are used that are licensed under Apache
License Version 2.0.
*/
-->
<paths >
<files-path name="shared" path="shared/"/>
</paths>

0 comments on commit 42537bb

Please sign in to comment.