move synchronous encryption into activity, and preserve checkbox state

This commit is contained in:
Vincent Breitmoser 2015-05-27 22:33:14 +02:00
parent fed0e7db8d
commit 8dc9773c1e
6 changed files with 42 additions and 25 deletions

View File

@ -21,6 +21,8 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.MenuItem;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
@ -56,9 +58,33 @@ public class EncryptActivity extends BaseActivity {
}
}
public void toggleModeFragment() {
boolean symmetric = getModeFragment() instanceof EncryptModeAsymmetricFragment;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.check_use_symmetric: {
item.setChecked(!item.isChecked());
setModeFragment(item.isChecked());
return true;
}
default: {
return super.onOptionsItemSelected(item);
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.encrypt_activity, menu);
Fragment frag =
getSupportFragmentManager().findFragmentById(R.id.encrypt_mode_container);
boolean isSymmetric = frag instanceof EncryptModeSymmetricFragment;
menu.findItem(R.id.check_use_symmetric).setChecked(isSymmetric);
return super.onCreateOptionsMenu(menu);
}
private void setModeFragment(boolean symmetric) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.encrypt_mode_container,
symmetric

View File

@ -250,9 +250,6 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.isCheckable()) {
item.setChecked(!item.isChecked());
}
switch (item.getItemId()) {
case R.id.encrypt_save: {
encryptClicked(false);
@ -262,24 +259,24 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
encryptClicked(true);
break;
}
case R.id.check_use_symmetric: {
EncryptActivity encryptActivity = (EncryptActivity) getActivity();
encryptActivity.toggleModeFragment();
break;
}
case R.id.check_use_armor: {
// we can NOT do this for every item, others might care!
item.setChecked(!item.isChecked());
mUseArmor = item.isChecked();
break;
}
case R.id.check_delete_after_encrypt: {
item.setChecked(!item.isChecked());
mDeleteAfterEncrypt = item.isChecked();
break;
}
case R.id.check_enable_compression: {
item.setChecked(!item.isChecked());
mUseCompression = item.isChecked();
break;
}
case R.id.check_encrypt_filenames: {
item.setChecked(!item.isChecked());
mEncryptFilenames = item.isChecked();
break;
}

View File

@ -137,11 +137,6 @@ public class EncryptTextFragment extends CryptoOperationFragment {
item.setChecked(!item.isChecked());
}
switch (item.getItemId()) {
case R.id.check_use_symmetric: {
EncryptActivity modeInterface = (EncryptActivity) getActivity();
modeInterface.toggleModeFragment();
break;
}
case R.id.check_enable_compression: {
mUseCompression = item.isChecked();
break;

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/check_use_symmetric"
android:title="@string/label_symmetric"
android:checkable="true" />
</menu>

View File

@ -14,11 +14,6 @@
android:icon="@drawable/ic_action_encrypt_share_24dp"
app:showAsAction="always" />
<item
android:id="@+id/check_use_symmetric"
android:title="@string/label_symmetric"
android:checkable="true" />
<item
android:id="@+id/check_delete_after_encrypt"
android:title="@string/label_delete_after_encryption"

View File

@ -14,11 +14,6 @@
android:icon="@drawable/ic_action_encrypt_share_24dp"
app:showAsAction="always" />
<item
android:id="@+id/check_use_symmetric"
android:title="@string/label_symmetric"
android:checkable="true" />
<item
android:id="@+id/check_enable_compression"
android:title="@string/label_enable_compression"