mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-23 23:48:51 -05:00
implement sticky preferences
This commit is contained in:
parent
5d87872245
commit
cf5fadae76
@ -84,6 +84,9 @@ public final class Constants {
|
||||
public static final String SEARCH_KEYBASE = "search_keybase_pref";
|
||||
public static final String USE_DEFAULT_YUBIKEY_PIN = "useDefaultYubikeyPin";
|
||||
public static final String USE_NUMKEYPAD_FOR_YUBIKEY_PIN = "useNumKeypadForYubikeyPin";
|
||||
public static final String ENCRYPT_FILENAMES = "encryptFilenames";
|
||||
public static final String USE_COMPRESSION = "useCompression";
|
||||
public static final String USE_ARMOR = "useArmor";
|
||||
}
|
||||
|
||||
public static final class Defaults {
|
||||
|
@ -73,12 +73,10 @@ public class EncryptFilesActivity extends EncryptActivity {
|
||||
uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
}
|
||||
|
||||
boolean useArmor = extras.getBoolean(EXTRA_ASCII_ARMOR, false);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
|
||||
EncryptFilesFragment encryptFragment = EncryptFilesFragment.newInstance(uris, useArmor);
|
||||
EncryptFilesFragment encryptFragment = EncryptFilesFragment.newInstance(uris);
|
||||
transaction.replace(R.id.encrypt_file_container, encryptFragment);
|
||||
transaction.commit();
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nispok.snackbar.Snackbar;
|
||||
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
@ -58,9 +59,12 @@ import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.ShareHelper;
|
||||
|
||||
import java.io.File;
|
||||
@ -99,11 +103,10 @@ public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEnc
|
||||
/**
|
||||
* Creates new instance of this fragment
|
||||
*/
|
||||
public static EncryptFilesFragment newInstance(ArrayList<Uri> uris, boolean useArmor) {
|
||||
public static EncryptFilesFragment newInstance(ArrayList<Uri> uris) {
|
||||
EncryptFilesFragment frag = new EncryptFilesFragment();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean(ARG_USE_ASCII_ARMOR, useArmor);
|
||||
args.putParcelableArrayList(ARG_URIS, uris);
|
||||
frag.setArguments(args);
|
||||
|
||||
@ -167,11 +170,28 @@ public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEnc
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Preferences prefs = Preferences.getPreferences(getActivity());
|
||||
|
||||
Bundle args = savedInstanceState == null ? getArguments() : savedInstanceState;
|
||||
mDeleteAfterEncrypt = args.getBoolean(ARG_DELETE_AFTER_ENCRYPT, false);
|
||||
mUseArmor = args.getBoolean(ARG_USE_ASCII_ARMOR, false);
|
||||
mUseCompression = args.getBoolean(ARG_USE_COMPRESSION, true);
|
||||
mEncryptFilenames = args.getBoolean(ARG_ENCRYPT_FILENAMES, true);
|
||||
|
||||
if (args.containsKey(ARG_USE_ASCII_ARMOR)) {
|
||||
mUseArmor = args.getBoolean(ARG_USE_ASCII_ARMOR, false);
|
||||
} else {
|
||||
mUseArmor = prefs.getUseArmor();
|
||||
}
|
||||
|
||||
if (args.containsKey(ARG_USE_COMPRESSION)) {
|
||||
mUseCompression = args.getBoolean(ARG_USE_COMPRESSION, true);
|
||||
} else {
|
||||
mUseCompression = prefs.getUseCompression();
|
||||
}
|
||||
|
||||
if (args.containsKey(ARG_ENCRYPT_FILENAMES)) {
|
||||
mEncryptFilenames = args.getBoolean(ARG_ENCRYPT_FILENAMES, true);
|
||||
} else {
|
||||
mEncryptFilenames = prefs.getEncryptFilenames();
|
||||
}
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
@ -262,9 +282,7 @@ public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEnc
|
||||
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();
|
||||
toggleUseArmor(item, !item.isChecked());
|
||||
break;
|
||||
}
|
||||
case R.id.check_delete_after_encrypt: {
|
||||
@ -273,13 +291,11 @@ public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEnc
|
||||
break;
|
||||
}
|
||||
case R.id.check_enable_compression: {
|
||||
item.setChecked(!item.isChecked());
|
||||
mUseCompression = item.isChecked();
|
||||
toggleEnableCompression(item, !item.isChecked());
|
||||
break;
|
||||
}
|
||||
case R.id.check_encrypt_filenames: {
|
||||
item.setChecked(!item.isChecked());
|
||||
mEncryptFilenames = item.isChecked();
|
||||
toggleEncryptFilenamesCheck(item, !item.isChecked());
|
||||
break;
|
||||
}
|
||||
// case R.id.check_hidden_recipients: {
|
||||
@ -294,6 +310,72 @@ public class EncryptFilesFragment extends CachingCryptoOperationFragment<SignEnc
|
||||
return true;
|
||||
}
|
||||
|
||||
public void toggleUseArmor(MenuItem item, final boolean useArmor) {
|
||||
|
||||
mUseArmor = useArmor;
|
||||
item.setChecked(useArmor);
|
||||
|
||||
Notify.create(getActivity(), useArmor
|
||||
? R.string.snack_armor_on
|
||||
: R.string.snack_armor_off,
|
||||
Notify.LENGTH_LONG, Style.OK, new ActionListener() {
|
||||
@Override
|
||||
public void onAction() {
|
||||
Preferences.getPreferences(getActivity()).setUseArmor(useArmor);
|
||||
Notify.create(getActivity(), useArmor
|
||||
? R.string.snack_armor_on
|
||||
: R.string.snack_armor_off,
|
||||
Notify.LENGTH_SHORT, Style.OK, null, R.string.btn_saved)
|
||||
.show(EncryptFilesFragment.this, false);
|
||||
}
|
||||
}, R.string.btn_save_default).show(this);
|
||||
|
||||
}
|
||||
|
||||
public void toggleEnableCompression(MenuItem item, final boolean compress) {
|
||||
|
||||
mUseCompression = compress;
|
||||
item.setChecked(compress);
|
||||
|
||||
Notify.create(getActivity(), compress
|
||||
? R.string.snack_compression_on
|
||||
: R.string.snack_compression_off,
|
||||
Notify.LENGTH_LONG, Style.OK, new ActionListener() {
|
||||
@Override
|
||||
public void onAction() {
|
||||
Preferences.getPreferences(getActivity()).setUseCompression(compress);
|
||||
Notify.create(getActivity(), compress
|
||||
? R.string.snack_compression_on
|
||||
: R.string.snack_compression_off,
|
||||
Notify.LENGTH_SHORT, Style.OK, null, R.string.btn_saved)
|
||||
.show(EncryptFilesFragment.this, false);
|
||||
}
|
||||
}, R.string.btn_save_default).show(this);
|
||||
|
||||
}
|
||||
|
||||
public void toggleEncryptFilenamesCheck(MenuItem item, final boolean encryptFilenames) {
|
||||
|
||||
mEncryptFilenames = encryptFilenames;
|
||||
item.setChecked(encryptFilenames);
|
||||
|
||||
Notify.create(getActivity(), encryptFilenames
|
||||
? R.string.snack_encrypt_filenames_on
|
||||
: R.string.snack_encrypt_filenames_off,
|
||||
Notify.LENGTH_LONG, Style.OK, new ActionListener() {
|
||||
@Override
|
||||
public void onAction() {
|
||||
Preferences.getPreferences(getActivity()).setEncryptFilenames(encryptFilenames);
|
||||
Notify.create(getActivity(), encryptFilenames
|
||||
? R.string.snack_encrypt_filenames_on
|
||||
: R.string.snack_encrypt_filenames_off,
|
||||
Notify.LENGTH_SHORT, Style.OK, null, R.string.btn_saved)
|
||||
.show(EncryptFilesFragment.this, false);
|
||||
}
|
||||
}, R.string.btn_save_default).show(this);
|
||||
|
||||
}
|
||||
|
||||
public void onEncryptSuccess(final SignEncryptResult result) {
|
||||
if (mDeleteAfterEncrypt) {
|
||||
DeleteFileDialogFragment deleteFileDialog =
|
||||
|
@ -47,7 +47,10 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.ShareHelper;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -131,8 +134,16 @@ public class EncryptTextFragment extends CachingCryptoOperationFragment<SignEncr
|
||||
mMessage = getArguments().getString(ARG_TEXT);
|
||||
}
|
||||
|
||||
Preferences prefs = Preferences.getPreferences(getActivity());
|
||||
|
||||
Bundle args = savedInstanceState == null ? getArguments() : savedInstanceState;
|
||||
|
||||
mUseCompression = args.getBoolean(ARG_USE_COMPRESSION, true);
|
||||
if (args.containsKey(ARG_USE_COMPRESSION)) {
|
||||
mUseCompression = args.getBoolean(ARG_USE_COMPRESSION, true);
|
||||
} else {
|
||||
mUseCompression = prefs.getUseCompression();
|
||||
}
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
@ -147,12 +158,9 @@ public class EncryptTextFragment extends CachingCryptoOperationFragment<SignEncr
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.isCheckable()) {
|
||||
item.setChecked(!item.isChecked());
|
||||
}
|
||||
switch (item.getItemId()) {
|
||||
case R.id.check_enable_compression: {
|
||||
mUseCompression = item.isChecked();
|
||||
toggleEnableCompression(item, !item.isChecked());
|
||||
break;
|
||||
}
|
||||
// case R.id.check_hidden_recipients: {
|
||||
@ -175,6 +183,28 @@ public class EncryptTextFragment extends CachingCryptoOperationFragment<SignEncr
|
||||
return true;
|
||||
}
|
||||
|
||||
public void toggleEnableCompression(MenuItem item, final boolean compress) {
|
||||
|
||||
mUseCompression = compress;
|
||||
item.setChecked(compress);
|
||||
|
||||
Notify.create(getActivity(), compress
|
||||
? R.string.snack_compression_on
|
||||
: R.string.snack_compression_off,
|
||||
Notify.LENGTH_LONG, Style.OK, new ActionListener() {
|
||||
@Override
|
||||
public void onAction() {
|
||||
Preferences.getPreferences(getActivity()).setUseCompression(compress);
|
||||
Notify.create(getActivity(), compress
|
||||
? R.string.snack_compression_on
|
||||
: R.string.snack_compression_off,
|
||||
Notify.LENGTH_SHORT, Style.OK, null, R.string.btn_saved)
|
||||
.show(EncryptTextFragment.this, false);
|
||||
}
|
||||
}, R.string.btn_save_default).show(this);
|
||||
|
||||
}
|
||||
|
||||
protected void onEncryptSuccess(SignEncryptResult result) {
|
||||
if (mShareAfterEncrypt) {
|
||||
// Share encrypted message/file
|
||||
|
@ -62,9 +62,10 @@ public class Notify {
|
||||
|
||||
public static final int LENGTH_INDEFINITE = 0;
|
||||
public static final int LENGTH_LONG = 3500;
|
||||
public static final int LENGTH_SHORT = 1500;
|
||||
|
||||
public static Showable create(final Activity activity, String text, int duration, Style style,
|
||||
final ActionListener actionListener, int actionResId) {
|
||||
final ActionListener actionListener, Integer actionResId) {
|
||||
final Snackbar snackbar = Snackbar.with(activity)
|
||||
.type(SnackbarType.MULTI_LINE)
|
||||
.text(text);
|
||||
@ -77,14 +78,16 @@ public class Notify {
|
||||
|
||||
style.applyToBar(snackbar);
|
||||
|
||||
if (actionResId != null) {
|
||||
snackbar.actionLabel(actionResId);
|
||||
}
|
||||
if (actionListener != null) {
|
||||
snackbar.actionLabel(actionResId)
|
||||
.actionListener(new ActionClickListener() {
|
||||
@Override
|
||||
public void onActionClicked(Snackbar snackbar) {
|
||||
actionListener.onAction();
|
||||
}
|
||||
});
|
||||
snackbar.actionListener(new ActionClickListener() {
|
||||
@Override
|
||||
public void onActionClicked(Snackbar snackbar) {
|
||||
actionListener.onAction();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (activity instanceof FabContainer) {
|
||||
@ -107,6 +110,13 @@ public class Notify {
|
||||
SnackbarManager.show(snackbar, activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(Fragment fragment, boolean animate) {
|
||||
snackbar.animation(animate);
|
||||
snackbar.dismissOnActionClicked(animate);
|
||||
show(fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(Fragment fragment) {
|
||||
if (fragment != null) {
|
||||
@ -134,7 +144,7 @@ public class Notify {
|
||||
}
|
||||
|
||||
public static Showable create(Activity activity, String text, int duration, Style style) {
|
||||
return create(activity, text, duration, style, null, -1);
|
||||
return create(activity, text, duration, style, null, null);
|
||||
}
|
||||
|
||||
public static Showable create(Activity activity, String text, Style style) {
|
||||
@ -159,24 +169,26 @@ public class Notify {
|
||||
/**
|
||||
* Shows the notification on the bottom of the Activity.
|
||||
*/
|
||||
public void show();
|
||||
void show();
|
||||
|
||||
void show(Fragment fragment, boolean animate);
|
||||
|
||||
/**
|
||||
* Shows the notification on the bottom of the Fragment.
|
||||
*/
|
||||
public void show(Fragment fragment);
|
||||
void show(Fragment fragment);
|
||||
|
||||
/**
|
||||
* Shows the notification on the given ViewGroup.
|
||||
* The viewGroup should be either a RelativeLayout or FrameLayout.
|
||||
*/
|
||||
public void show(ViewGroup viewGroup);
|
||||
void show(ViewGroup viewGroup);
|
||||
|
||||
}
|
||||
|
||||
public interface ActionListener {
|
||||
|
||||
public void onAction();
|
||||
void onAction();
|
||||
|
||||
}
|
||||
|
||||
|
@ -182,6 +182,36 @@ public class Preferences {
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public void setUseCompression(boolean compress) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putBoolean(Pref.USE_COMPRESSION, compress);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public boolean getUseCompression() {
|
||||
return mSharedPreferences.getBoolean(Pref.USE_COMPRESSION, true);
|
||||
}
|
||||
|
||||
public void setUseArmor(boolean useArmor) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putBoolean(Pref.USE_ARMOR, useArmor);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public boolean getUseArmor() {
|
||||
return mSharedPreferences.getBoolean(Pref.USE_ARMOR, false);
|
||||
}
|
||||
|
||||
public void setEncryptFilenames(boolean encryptFilenames) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putBoolean(Pref.ENCRYPT_FILENAMES, encryptFilenames);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public boolean getEncryptFilenames() {
|
||||
return mSharedPreferences.getBoolean(Pref.ENCRYPT_FILENAMES, true);
|
||||
}
|
||||
|
||||
public CloudSearchPrefs getCloudSearchPrefs() {
|
||||
return new CloudSearchPrefs(mSharedPreferences.getBoolean(Pref.SEARCH_KEYSERVER, true),
|
||||
mSharedPreferences.getBoolean(Pref.SEARCH_KEYBASE, true),
|
||||
|
@ -88,6 +88,8 @@
|
||||
<string name="btn_add_email">"Add additional email address"</string>
|
||||
<string name="btn_unlock">"Unlock"</string>
|
||||
<string name="btn_add_keyserver">"Add"</string>
|
||||
<string name="btn_save_default">"Save as default"</string>
|
||||
<string name="btn_saved">"Saved!"</string>
|
||||
|
||||
<!-- menu -->
|
||||
<string name="menu_preferences">"Settings"</string>
|
||||
@ -1308,5 +1310,11 @@
|
||||
<string name="error_nfc">"NFC Error: %s"</string>
|
||||
<string name="error_pin_nodefault">Default PIN was rejected!</string>
|
||||
<string name="error_bluetooth_file">Error creating temporary file. Bluetooth sharing will fail.</string>
|
||||
<string name="snack_encrypt_filenames_on">"Filenames <b>are</b> encrypted."</string>
|
||||
<string name="snack_encrypt_filenames_off">"Filenames <b>are not</b> encrypted."</string>
|
||||
<string name="snack_armor_on">"Output encoded as Text."</string>
|
||||
<string name="snack_armor_off">"Output encoded as Binary."</string>
|
||||
<string name="snack_compression_on">"Compression <b>enabled</b>."</string>
|
||||
<string name="snack_compression_off">"Compression <b>disabled</b>."</string>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user