diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-05-29 21:38:20 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-05-29 21:38:20 +0200 |
commit | 8be6450a367514216edab62791c5328798556fbf (patch) | |
tree | f2aa730d8315977e0de351d3b65b0f5ceaa17783 | |
parent | c9f9af660345632426662363754af3f656f2f7e6 (diff) | |
download | open-keychain-8be6450a367514216edab62791c5328798556fbf.tar.gz open-keychain-8be6450a367514216edab62791c5328798556fbf.tar.bz2 open-keychain-8be6450a367514216edab62791c5328798556fbf.zip |
preserve state in DecryptFilesActivity/-Fragment
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesActivity.java | 47 | ||||
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java | 16 |
2 files changed, 26 insertions, 37 deletions
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 c9a590c5b..81fb6a392 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesActivity.java @@ -21,7 +21,9 @@ import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.support.v4.app.Fragment; import android.view.View; +import android.widget.Toast; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; @@ -37,8 +39,6 @@ public class DecryptFilesActivity extends BaseActivity { // intern public static final String ACTION_DECRYPT_DATA_OPEN = Constants.INTENT_PREFIX + "DECRYPT_DATA_OPEN"; - DecryptFilesFragment mFragment; - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -62,19 +62,12 @@ public class DecryptFilesActivity extends BaseActivity { /** * Handles all actions with this intent - * - * @param intent */ private void handleActions(Bundle savedInstanceState, Intent intent) { String action = intent.getAction(); String type = intent.getType(); Uri uri = intent.getData(); - Bundle mFileFragmentBundle = new Bundle(); - - /* - * Android's Action - */ if (Intent.ACTION_SEND.equals(action) && type != null) { // When sending to Keychain Decrypt via share menu // Binary via content provider (could also be files) @@ -88,39 +81,27 @@ public class DecryptFilesActivity extends BaseActivity { action = ACTION_DECRYPT_DATA; } - /** - * Main Actions - */ - if (ACTION_DECRYPT_DATA.equals(action) && uri != null) { - mFileFragmentBundle.putParcelable(DecryptFilesFragment.ARG_URI, uri); - - loadFragment(savedInstanceState, uri, false); - } else if (ACTION_DECRYPT_DATA_OPEN.equals(action)) { - loadFragment(savedInstanceState, null, true); - } else if (ACTION_DECRYPT_DATA.equals(action)) { - Log.e(Constants.TAG, - "Include an Uri with setInputData() in your Intent!"); - } - } - - private void loadFragment(Bundle savedInstanceState, Uri uri, boolean openDialog) { - // However, if we're being restored from a previous state, - // then we don't need to do anything and should return or else - // we could end up with overlapping fragments. + // No need to initialize fragments if we are being restored if (savedInstanceState != null) { return; } - // Create an instance of the fragment - mFragment = DecryptFilesFragment.newInstance(uri, openDialog); + // 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(); + } + + boolean showOpenDialog = ACTION_DECRYPT_DATA_OPEN.equals(action); + DecryptFilesFragment frag = DecryptFilesFragment.newInstance(uri, 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, mFragment) + .replace(R.id.decrypt_files_fragment_container, frag) .commitAllowingStateLoss(); - // do it immediately! - getSupportFragmentManager().executePendingTransactions(); + } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java index 234362edc..479b8fd93 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java @@ -112,17 +112,25 @@ public class DecryptFilesFragment extends DecryptFragment { } @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + outState.putParcelable(ARG_URI, mInputUri); + } + + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - setInputUri(getArguments().<Uri>getParcelable(ARG_URI)); + Bundle state = savedInstanceState != null ? savedInstanceState : getArguments(); + setInputUri(state.<Uri>getParcelable(ARG_URI)); - if (getArguments().getBoolean(ARG_OPEN_DIRECTLY, false)) { + // should only come from args + if (state.getBoolean(ARG_OPEN_DIRECTLY, false)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { FileHelper.openDocument(DecryptFilesFragment.this, "*/*", REQUEST_CODE_INPUT); } else { - FileHelper.openFile(DecryptFilesFragment.this, mInputUri, "*/*", - REQUEST_CODE_INPUT); + FileHelper.openFile(DecryptFilesFragment.this, mInputUri, "*/*", REQUEST_CODE_INPUT); } } } |