multidecrypt: use bottom sheet for longclick options
This commit is contained in:
@@ -61,6 +61,7 @@ dependencies {
|
|||||||
compile 'org.apache.james:apache-mime4j-core:0.7.2'
|
compile 'org.apache.james:apache-mime4j-core:0.7.2'
|
||||||
compile 'org.apache.james:apache-mime4j-dom:0.7.2'
|
compile 'org.apache.james:apache-mime4j-dom:0.7.2'
|
||||||
compile 'org.thoughtcrime.ssl.pinning:AndroidPinning:1.0.0'
|
compile 'org.thoughtcrime.ssl.pinning:AndroidPinning:1.0.0'
|
||||||
|
compile 'com.cocosw:bottomsheet:1.1.1@aar'
|
||||||
|
|
||||||
// libs as submodules
|
// libs as submodules
|
||||||
compile project(':extern:openpgp-api-lib:openpgp-api')
|
compile project(':extern:openpgp-api-lib:openpgp-api')
|
||||||
|
|||||||
@@ -156,7 +156,6 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
|
|||||||
if (mFilename != null) {
|
if (mFilename != null) {
|
||||||
log.add(LogType.MSG_DATA_MIME_FILENAME, 3, mFilename);
|
log.add(LogType.MSG_DATA_MIME_FILENAME, 3, mFilename);
|
||||||
}
|
}
|
||||||
log.add(LogType.MSG_DATA_MIME_LENGTH, 3, bd.getContentLength());
|
|
||||||
|
|
||||||
Uri uri = TemporaryStorageProvider.createFile(mContext, mFilename, bd.getMimeType());
|
Uri uri = TemporaryStorageProvider.createFile(mContext, mFilename, bd.getMimeType());
|
||||||
OutputStream out = mContext.getContentResolver().openOutputStream(uri, "w");
|
OutputStream out = mContext.getContentResolver().openOutputStream(uri, "w");
|
||||||
@@ -165,12 +164,15 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
|
|||||||
throw new IOException("Error getting file for writing!");
|
throw new IOException("Error getting file for writing!");
|
||||||
}
|
}
|
||||||
|
|
||||||
int len;
|
int len, totalLength = 0;
|
||||||
while ((len = is.read(buf)) > 0) {
|
while ((len = is.read(buf)) > 0) {
|
||||||
|
totalLength += len;
|
||||||
out.write(buf, 0, len);
|
out.write(buf, 0, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenPgpMetadata metadata = new OpenPgpMetadata(mFilename, bd.getMimeType(), 0L, bd.getContentLength());
|
log.add(LogType.MSG_DATA_MIME_LENGTH, 3, totalLength);
|
||||||
|
|
||||||
|
OpenPgpMetadata metadata = new OpenPgpMetadata(mFilename, bd.getMimeType(), 0L, totalLength);
|
||||||
|
|
||||||
out.close();
|
out.close();
|
||||||
outputUris.add(uri);
|
outputUris.add(uri);
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.View.OnLongClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.webkit.MimeTypeMap;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.PopupMenu;
|
import android.widget.PopupMenu;
|
||||||
@@ -54,6 +56,7 @@ import android.widget.ProgressBar;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.ViewAnimator;
|
import android.widget.ViewAnimator;
|
||||||
|
|
||||||
|
import com.cocosw.bottomsheet.BottomSheet;
|
||||||
import org.openintents.openpgp.OpenPgpMetadata;
|
import org.openintents.openpgp.OpenPgpMetadata;
|
||||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
@@ -97,6 +100,7 @@ public class DecryptListFragment
|
|||||||
private Uri mCurrentInputUri;
|
private Uri mCurrentInputUri;
|
||||||
|
|
||||||
private DecryptFilesAdapter mAdapter;
|
private DecryptFilesAdapter mAdapter;
|
||||||
|
private Uri mCurrentSaveFileUri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of this fragment
|
* Creates new instance of this fragment
|
||||||
@@ -222,9 +226,8 @@ public class DecryptListFragment
|
|||||||
case REQUEST_CODE_OUTPUT: {
|
case REQUEST_CODE_OUTPUT: {
|
||||||
// This happens after output file was selected, so start our operation
|
// This happens after output file was selected, so start our operation
|
||||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||||
Uri decryptedFileUri = mInputDataResults.get(mCurrentInputUri).getOutputUris().get(0);
|
|
||||||
Uri saveUri = data.getData();
|
Uri saveUri = data.getData();
|
||||||
saveFile(decryptedFileUri, saveUri);
|
saveFile(saveUri);
|
||||||
mCurrentInputUri = null;
|
mCurrentInputUri = null;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -236,7 +239,37 @@ public class DecryptListFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveFile(Uri decryptedFileUri, Uri saveUri) {
|
private void saveFileDialog(InputDataResult result, int index) {
|
||||||
|
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenPgpMetadata metadata = result.mMetadata.get(index);
|
||||||
|
Uri saveUri = Uri.fromFile(activity.getExternalFilesDir(metadata.getMimeType()));
|
||||||
|
mCurrentSaveFileUri = result.getOutputUris().get(index);
|
||||||
|
|
||||||
|
String filename = metadata.getFilename();
|
||||||
|
if (filename == null) {
|
||||||
|
String ext = MimeTypeMap.getSingleton().getExtensionFromMimeType(metadata.getMimeType());
|
||||||
|
filename = "decrypted" + (ext != null ? "."+ext : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
FileHelper.saveDocument(this, filename, saveUri, metadata.getMimeType(),
|
||||||
|
R.string.title_decrypt_to_file, R.string.specify_file_to_decrypt_to, REQUEST_CODE_OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveFile(Uri saveUri) {
|
||||||
|
if (mCurrentSaveFileUri == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uri decryptedFileUri = mCurrentSaveFileUri;
|
||||||
|
mCurrentInputUri = null;
|
||||||
|
|
||||||
|
hideKeyboard();
|
||||||
|
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity == null) {
|
if (activity == null) {
|
||||||
return;
|
return;
|
||||||
@@ -379,6 +412,33 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void displayBottomSheet(final InputDataResult result, final int index) {
|
||||||
|
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new BottomSheet.Builder(activity).sheet(R.menu.decrypt_bottom_sheet).listener(new MenuItem.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.decrypt_open:
|
||||||
|
displayWithViewIntent(result, index, false);
|
||||||
|
break;
|
||||||
|
case R.id.decrypt_share:
|
||||||
|
displayWithViewIntent(result, index, true);
|
||||||
|
break;
|
||||||
|
case R.id.decrypt_save:
|
||||||
|
saveFileDialog(result, index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).grid().show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void displayWithViewIntent(InputDataResult result, int index, boolean share) {
|
public void displayWithViewIntent(InputDataResult result, int index, boolean share) {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity == null) {
|
if (activity == null) {
|
||||||
@@ -698,6 +758,18 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
// save index closure-style :)
|
// save index closure-style :)
|
||||||
final int idx = i;
|
final int idx = i;
|
||||||
|
|
||||||
|
fileHolder.vFile.setOnLongClickListener(new OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View view) {
|
||||||
|
if (model.mResult.success()) {
|
||||||
|
displayBottomSheet(model.mResult, idx);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
fileHolder.vFile.setOnClickListener(new OnClickListener() {
|
fileHolder.vFile.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package org.sufficientlysecure.keychain.ui.base;
|
package org.sufficientlysecure.keychain.ui.base;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -116,14 +117,15 @@ public abstract class CryptoOperationFragment<T extends Parcelable, S extends Op
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void hideKeyboard() {
|
public void hideKeyboard() {
|
||||||
if (getActivity() == null) {
|
Activity activity = getActivity();
|
||||||
|
if (activity == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
InputMethodManager inputManager = (InputMethodManager) getActivity()
|
InputMethodManager inputManager = (InputMethodManager) activity
|
||||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
// check if no view has focus
|
// check if no view has focus
|
||||||
View v = getActivity().getCurrentFocus();
|
View v = activity.getCurrentFocus();
|
||||||
if (v == null)
|
if (v == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -131,7 +131,9 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:background="?android:selectableItemBackground"
|
android:background="?android:selectableItemBackground"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal"
|
||||||
|
style="?listPreferredItemHeight"
|
||||||
|
>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|||||||
19
OpenKeychain/src/main/res/menu/decrypt_bottom_sheet.xml
Normal file
19
OpenKeychain/src/main/res/menu/decrypt_bottom_sheet.xml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/decrypt_open"
|
||||||
|
android:title="Open with…"
|
||||||
|
android:icon="@drawable/ic_apps_black_24dp" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/decrypt_share"
|
||||||
|
android:title="@string/btn_share_decrypted_text"
|
||||||
|
android:icon="@drawable/ic_share_black_24dp" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/decrypt_save"
|
||||||
|
android:title="@string/btn_save"
|
||||||
|
android:icon="@drawable/ic_save_grey_24dp" />
|
||||||
|
|
||||||
|
</menu>
|
||||||
Reference in New Issue
Block a user