forked from k3b/privacy-friendly-finance-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from k3b/ExportCsv
SecUSo#42: created fileUtils
- Loading branch information
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
app/src/main/java/org/secuso/privacyfriendlyfinance/activities/helper/FileHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
app/src/main/java/org/secuso/privacyfriendlyfinance/csv/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|