diff --git a/OpenKeychain/src/main/AndroidManifest.xml b/OpenKeychain/src/main/AndroidManifest.xml index 75d94ae69..19b775149 100644 --- a/OpenKeychain/src/main/AndroidManifest.xml +++ b/OpenKeychain/src/main/AndroidManifest.xml @@ -210,15 +210,6 @@ - - - - - - - - - - + + - + + diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesActivity.java index b56c38d19..672015aaa 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesActivity.java @@ -23,6 +23,8 @@ import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.view.View; import android.widget.Toast; @@ -65,56 +67,83 @@ public class DecryptFilesActivity extends BaseActivity { * Handles all actions with this intent */ private void handleActions(Bundle savedInstanceState, Intent intent) { - String action = intent.getAction(); - String type = intent.getType(); - Uri uri = intent.getData(); - if (Intent.ACTION_SEND.equals(action) && type != null) { - // When sending to Keychain Decrypt via share menu - // Binary via content provider (could also be files) - // override uri to get stream from send - uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); - action = ACTION_DECRYPT_DATA; - } else if (Intent.ACTION_VIEW.equals(action)) { - // Android's Action when opening file associated to Keychain (see AndroidManifest.xml) - - // override action - action = ACTION_DECRYPT_DATA; - } - - // No need to initialize fragments if we are being restored + // No need to initialize fragments if we are just being restored if (savedInstanceState != null) { return; } - // Definitely need a data uri with the decrypt_data intent - if (ACTION_DECRYPT_DATA.equals(action) && uri == null) { - Toast.makeText(this, "No data to decrypt!", Toast.LENGTH_LONG).show(); - setResult(Activity.RESULT_CANCELED); - finish(); + ArrayList uris = new ArrayList<>(); + + String action = intent.getAction(); + + switch (action) { + case Intent.ACTION_SEND: { + // When sending to Keychain Decrypt via share menu + // Binary via content provider (could also be files) + // override uri to get stream from send + action = ACTION_DECRYPT_DATA; + uris.add(intent.getParcelableExtra(Intent.EXTRA_STREAM)); + break; + } + + case Intent.ACTION_SEND_MULTIPLE: { + action = ACTION_DECRYPT_DATA; + uris.addAll(intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM)); + break; + } + + case Intent.ACTION_VIEW: + // Android's Action when opening file associated to Keychain (see AndroidManifest.xml) + action = ACTION_DECRYPT_DATA; + + // fallthrough + default: + uris.add(intent.getData()); + + } + + if (ACTION_DECRYPT_DATA.equals(action)) { + // Definitely need a data uri with the decrypt_data intent + if (uris.isEmpty()) { + Toast.makeText(this, "No data to decrypt!", Toast.LENGTH_LONG).show(); + setResult(Activity.RESULT_CANCELED); + finish(); + } + displayListFragment(uris); + return; } boolean showOpenDialog = ACTION_DECRYPT_DATA_OPEN.equals(action); - DecryptFilesInputFragment frag = DecryptFilesInputFragment.newInstance(uri, showOpenDialog); + displayInputFragment(showOpenDialog); + + } + + public void displayInputFragment(boolean showOpenDialog) { + DecryptFilesInputFragment frag = DecryptFilesInputFragment.newInstance(showOpenDialog); // Add the fragment to the 'fragment_container' FrameLayout // NOTE: We use commitAllowingStateLoss() to prevent weird crashes! getSupportFragmentManager().beginTransaction() .replace(R.id.decrypt_files_fragment_container, frag) .commit(); - } - public void displayListFragment(Uri inputUri) { + public void displayListFragment(ArrayList inputUris) { - ArrayList uris = new ArrayList<>(); - uris.add(inputUri); - DecryptFilesListFragment frag = DecryptFilesListFragment.newInstance(uris); + DecryptFilesListFragment frag = DecryptFilesListFragment.newInstance(inputUris); - getSupportFragmentManager().beginTransaction() - .replace(R.id.decrypt_files_fragment_container, frag) - .addToBackStack("list") - .commit(); + FragmentManager fragMan = getSupportFragmentManager(); + + FragmentTransaction trans = fragMan.beginTransaction(); + trans.replace(R.id.decrypt_files_fragment_container, frag); + + // if there already is a fragment, allow going back to that. otherwise, we're top level! + if (fragMan.getFragments() != null && !fragMan.getFragments().isEmpty()) { + trans.addToBackStack("list"); + } + + trans.commit(); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesInputFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesInputFragment.java index 5b0b191e0..2b9219f49 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesInputFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesInputFragment.java @@ -18,6 +18,8 @@ package org.sufficientlysecure.keychain.ui; +import java.util.ArrayList; + import android.app.Activity; import android.content.Intent; import android.net.Uri; @@ -44,11 +46,10 @@ public class DecryptFilesInputFragment extends Fragment { private Uri mInputUri = null; - public static DecryptFilesInputFragment newInstance(Uri uri, boolean openDirectly) { + public static DecryptFilesInputFragment newInstance(boolean openDirectly) { DecryptFilesInputFragment frag = new DecryptFilesInputFragment(); Bundle args = new Bundle(); - args.putParcelable(ARG_URI, uri); args.putBoolean(ARG_OPEN_DIRECTLY, openDirectly); frag.setArguments(args); @@ -127,7 +128,10 @@ public class DecryptFilesInputFragment extends Fragment { } DecryptFilesActivity activity = (DecryptFilesActivity) getActivity(); - activity.displayListFragment(mInputUri); + + ArrayList uris = new ArrayList<>(); + uris.add(mInputUri); + activity.displayListFragment(uris); } @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesListFragment.java index d3b52fe78..35f534c90 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesListFragment.java @@ -58,6 +58,7 @@ import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; // this import NEEDS to be above the ViewModel one, or it won't compile! (as of 06/06/15) +import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.StatusHolder; import org.sufficientlysecure.keychain.ui.DecryptFilesListFragment.DecryptFilesAdapter.ViewModel; import org.sufficientlysecure.keychain.ui.adapter.SpacesItemDecoration; @@ -187,6 +188,11 @@ public class DecryptFilesListFragment cryptoOperation(); } + @Override + protected void cryptoOperation(CryptoInputParcel cryptoInput) { + super.cryptoOperation(cryptoInput, false); + } + @Override protected boolean onCryptoSetProgress(String msg, int progress, int max) { mAdapter.setProgress(mCurrentInputUri, progress, max, msg); @@ -204,6 +210,8 @@ public class DecryptFilesListFragment mCurrentInputUri = null; mAdapter.addResult(uri, result, null, null, null); + + cryptoOperation(); } @Override @@ -257,6 +265,8 @@ public class DecryptFilesListFragment mAdapter.addResult(uri, result, icon, onFileClick, onKeyClick); + cryptoOperation(); + } @Override 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 5f1097588..764602735 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 @@ -123,6 +123,14 @@ public abstract class CryptoOperationFragment + layout="@layout/toolbar_standalone_white" />