|
17 | 17 |
|
18 | 18 | package org.gnucash.android.export; |
19 | 19 |
|
20 | | -import android.annotation.TargetApi; |
21 | 20 | import android.app.Activity; |
22 | 21 | import android.app.ProgressDialog; |
23 | 22 | import android.content.Context; |
|
27 | 26 | import android.database.sqlite.SQLiteDatabase; |
28 | 27 | import android.net.Uri; |
29 | 28 | import android.os.AsyncTask; |
30 | | -import android.os.Build; |
31 | 29 | import android.preference.PreferenceManager; |
32 | 30 | import android.support.annotation.NonNull; |
33 | 31 | import android.support.v4.content.FileProvider; |
|
79 | 77 | import java.util.Date; |
80 | 78 | import java.util.List; |
81 | 79 | import java.util.concurrent.TimeUnit; |
| 80 | +import java.util.zip.ZipEntry; |
| 81 | +import java.util.zip.ZipOutputStream; |
82 | 82 |
|
83 | 83 | /** |
84 | 84 | * Asynchronous task for exporting transactions. |
@@ -280,21 +280,38 @@ private void moveExportToUri() throws Exporter.ExporterException { |
280 | 280 | return; |
281 | 281 | } |
282 | 282 |
|
283 | | - //we only support exporting to a single file |
284 | | - String exportedFile = mExportedFiles.get(0); |
285 | | - try { |
286 | | - moveFile(exportedFile, mContext.getContentResolver().openOutputStream(exportUri)); |
287 | | - } catch (IOException e) { |
288 | | - e.printStackTrace(); |
289 | | - Log.e(TAG, "Error moving export file to: " + exportUri); |
290 | | - Crashlytics.logException(e); |
| 283 | + if (mExportedFiles.size() > 0){ |
| 284 | + try { |
| 285 | + OutputStream outputStream = mContext.getContentResolver().openOutputStream(exportUri); |
| 286 | + ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream); |
| 287 | + byte[] buffer = new byte[1024]; |
| 288 | + for (String exportedFile : mExportedFiles) { |
| 289 | + File file = new File(exportedFile); |
| 290 | + FileInputStream fileInputStream = new FileInputStream(file); |
| 291 | + zipOutputStream.putNextEntry(new ZipEntry(file.getName())); |
| 292 | + |
| 293 | + int length; |
| 294 | + while ((length = fileInputStream.read(buffer)) > 0) { |
| 295 | + zipOutputStream.write(buffer, 0, length); |
| 296 | + } |
| 297 | + zipOutputStream.closeEntry(); |
| 298 | + fileInputStream.close(); |
| 299 | + } |
| 300 | + zipOutputStream.close(); |
| 301 | + } catch (IOException ex) { |
| 302 | + Log.e(TAG, "Error when zipping QIF files for export"); |
| 303 | + ex.printStackTrace(); |
| 304 | + Crashlytics.logException(ex); |
| 305 | + } |
291 | 306 | } |
292 | 307 | } |
293 | 308 |
|
294 | 309 | /** |
295 | 310 | * Move the exported files to a GnuCash folder on Google Drive |
296 | 311 | * @throws Exporter.ExporterException |
| 312 | + * @deprecated Explicit Google Drive integration is deprecated, use Storage Access Framework. See {@link #moveExportToUri()} |
297 | 313 | */ |
| 314 | + @Deprecated |
298 | 315 | private void moveExportToGoogleDrive() throws Exporter.ExporterException { |
299 | 316 | Log.i(TAG, "Moving exported file to Google Drive"); |
300 | 317 | final GoogleApiClient googleApiClient = BackupPreferenceFragment.getGoogleApiClient(GnuCashApplication.getAppContext()); |
@@ -421,7 +438,9 @@ private void moveExportToOwnCloud() throws Exporter.ExporterException { |
421 | 438 | * Moves the exported files from the internal storage where they are generated to |
422 | 439 | * external storage, which is accessible to the user. |
423 | 440 | * @return The list of files moved to the SD card. |
| 441 | + * @deprecated Use the Storage Access Framework to save to SD card. See {@link #moveExportToUri()} |
424 | 442 | */ |
| 443 | + @Deprecated |
425 | 444 | private List<String> moveExportToSDCard() throws Exporter.ExporterException { |
426 | 445 | Log.i(TAG, "Moving exported file to external storage"); |
427 | 446 | new File(Exporter.getExportFolderPath(mExporter.mBookUID)); |
|
0 commit comments