diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-09-16 19:33:43 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-09-16 19:52:26 +0200 |
commit | ece06b1933c26688d2eb6b7fa8657acbb8833728 (patch) | |
tree | 426b596e7a5e6748ac027d540a8780b96c2bcc57 | |
parent | 9ac7b33a4e15aea3f685a1713142aafcf1895195 (diff) | |
download | open-keychain-ece06b1933c26688d2eb6b7fa8657acbb8833728.tar.gz open-keychain-ece06b1933c26688d2eb6b7fa8657acbb8833728.tar.bz2 open-keychain-ece06b1933c26688d2eb6b7fa8657acbb8833728.zip |
multidecrypt: use bottom sheet for longclick options
6 files changed, 108 insertions, 10 deletions
diff --git a/OpenKeychain/build.gradle b/OpenKeychain/build.gradle index c8b095eac..9d29d0a98 100644 --- a/OpenKeychain/build.gradle +++ b/OpenKeychain/build.gradle @@ -61,6 +61,7 @@ dependencies { compile 'org.apache.james:apache-mime4j-core:0.7.2' compile 'org.apache.james:apache-mime4j-dom:0.7.2' compile 'org.thoughtcrime.ssl.pinning:AndroidPinning:1.0.0' + compile 'com.cocosw:bottomsheet:1.1.1@aar' // libs as submodules compile project(':extern:openpgp-api-lib:openpgp-api') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java index 14f711df0..a5208e05b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java @@ -156,7 +156,6 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> { if (mFilename != null) { 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()); 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!"); } - int len; + int len, totalLength = 0; while ((len = is.read(buf)) > 0) { + totalLength += 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(); outputUris.add(uri); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java index 5f6089fd9..98d8c1ba8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java @@ -44,7 +44,9 @@ import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; +import android.view.View.OnLongClickListener; import android.view.ViewGroup; +import android.webkit.MimeTypeMap; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupMenu; @@ -54,6 +56,7 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.ViewAnimator; +import com.cocosw.bottomsheet.BottomSheet; import org.openintents.openpgp.OpenPgpMetadata; import org.openintents.openpgp.OpenPgpSignatureResult; import org.sufficientlysecure.keychain.Constants; @@ -97,6 +100,7 @@ public class DecryptListFragment private Uri mCurrentInputUri; private DecryptFilesAdapter mAdapter; + private Uri mCurrentSaveFileUri; /** * Creates new instance of this fragment @@ -222,9 +226,8 @@ public class DecryptListFragment case REQUEST_CODE_OUTPUT: { // This happens after output file was selected, so start our operation if (resultCode == Activity.RESULT_OK && data != null) { - Uri decryptedFileUri = mInputDataResults.get(mCurrentInputUri).getOutputUris().get(0); Uri saveUri = data.getData(); - saveFile(decryptedFileUri, saveUri); + saveFile(saveUri); mCurrentInputUri = null; } 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(); if (activity == null) { 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) { Activity activity = getActivity(); if (activity == null) { @@ -698,6 +758,18 @@ public class DecryptListFragment // save index closure-style :) 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() { @Override public void onClick(View view) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java index de90d48fd..88351b6b7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java @@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui.base; +import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Parcelable; @@ -116,14 +117,15 @@ public abstract class CryptoOperationFragment<T extends Parcelable, S extends Op } public void hideKeyboard() { - if (getActivity() == null) { + Activity activity = getActivity(); + if (activity == null) { return; } - InputMethodManager inputManager = (InputMethodManager) getActivity() + InputMethodManager inputManager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); // check if no view has focus - View v = getActivity().getCurrentFocus(); + View v = activity.getCurrentFocus(); if (v == null) return; diff --git a/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml b/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml index 47a8d85c4..577d825b7 100644 --- a/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml +++ b/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml @@ -131,7 +131,9 @@ android:layout_height="wrap_content" android:clickable="true" android:background="?android:selectableItemBackground" - android:orientation="horizontal"> + android:orientation="horizontal" + style="?listPreferredItemHeight" + > <LinearLayout android:layout_width="0dp" diff --git a/OpenKeychain/src/main/res/menu/decrypt_bottom_sheet.xml b/OpenKeychain/src/main/res/menu/decrypt_bottom_sheet.xml new file mode 100644 index 000000000..e38acd591 --- /dev/null +++ b/OpenKeychain/src/main/res/menu/decrypt_bottom_sheet.xml @@ -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> |