implement saving of files
This commit is contained in:
@@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -220,8 +221,7 @@ public class DecryptListFragment
|
|||||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||||
Uri saveUri = data.getData();
|
Uri saveUri = data.getData();
|
||||||
Uri outputUri = mOutputUris.get(mCurrentInputUri);
|
Uri outputUri = mOutputUris.get(mCurrentInputUri);
|
||||||
// TODO save from outputUri to saveUri
|
saveFile(saveUri, outputUri);
|
||||||
|
|
||||||
mCurrentInputUri = null;
|
mCurrentInputUri = null;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -233,6 +233,21 @@ public class DecryptListFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveFile(Uri outputUri, Uri saveUri) {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileHelper.copyUriData(activity, outputUri, saveUri);
|
||||||
|
Notify.create(activity, R.string.file_saved, Style.ERROR).show();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(Constants.TAG, "error saving file", e);
|
||||||
|
Notify.create(activity, R.string.error_saving_file, Style.ERROR).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
|
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
|
||||||
super.cryptoOperation(cryptoInput, false);
|
super.cryptoOperation(cryptoInput, false);
|
||||||
@@ -448,6 +463,12 @@ public class DecryptListFragment
|
|||||||
if (mAdapter.mMenuClickedModel == null || !mAdapter.mMenuClickedModel.hasResult()) {
|
if (mAdapter.mMenuClickedModel == null || !mAdapter.mMenuClickedModel.hasResult()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// don't process menu items until all items are done!
|
||||||
|
if (!mPendingInputUris.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity == null) {
|
if (activity == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.util;
|
|||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
@@ -41,8 +42,11 @@ import org.sufficientlysecure.keychain.R;
|
|||||||
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
|
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
@@ -267,6 +271,33 @@ public class FileHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void copyUriData(Context context, Uri fromUri, Uri toUri) throws IOException {
|
||||||
|
BufferedInputStream bis = null;
|
||||||
|
BufferedOutputStream bos = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
ContentResolver resolver = context.getContentResolver();
|
||||||
|
bis = new BufferedInputStream(resolver.openInputStream(fromUri));
|
||||||
|
bos = new BufferedOutputStream(resolver.openOutputStream(toUri));
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ( (len = bis.read(buf)) > 0) {
|
||||||
|
bos.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (bis != null) {
|
||||||
|
bis.close();
|
||||||
|
}
|
||||||
|
if (bos != null) {
|
||||||
|
bos.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// ignore, it's just stream closin'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface FileDialogCallback {
|
public interface FileDialogCallback {
|
||||||
void onFileSelected(File file, boolean checked);
|
void onFileSelected(File file, boolean checked);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1342,5 +1342,7 @@
|
|||||||
<string name="error_preparing_data">"Error preparing data!"</string>
|
<string name="error_preparing_data">"Error preparing data!"</string>
|
||||||
<string name="label_clip_title">"Encrypted Data"</string>
|
<string name="label_clip_title">"Encrypted Data"</string>
|
||||||
<string name="progress_processing">Processing…</string>
|
<string name="progress_processing">Processing…</string>
|
||||||
|
<string name="error_saving_file">Error saving file!</string>
|
||||||
|
<string name="file_saved">File saved!</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user