mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
move backup option to settings -> chats (#957)
This commit is contained in:
@@ -54,14 +54,10 @@
|
||||
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_other">
|
||||
<Preference android:key="pref_backup"
|
||||
android:title="@string/pref_backup"
|
||||
android:summary="@string/pref_backup_explain"/>
|
||||
|
||||
<Preference android:key="pref_manage_keys"
|
||||
android:title="@string/pref_manage_keys"/>
|
||||
|
||||
|
||||
<Preference android:key="pref_view_log"
|
||||
android:title="@string/pref_view_log"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:layout="@layout/preference_divider"/>
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_email_interaction_title">
|
||||
|
||||
<org.thoughtcrime.securesms.preferences.widgets.ListPreferenceWithSummary
|
||||
@@ -44,6 +46,13 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:layout="@layout/preference_divider"/>
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_other">
|
||||
<Preference android:key="pref_backup"
|
||||
android:title="@string/pref_backup"
|
||||
android:summary="@string/pref_backup_explain"/>
|
||||
</PreferenceCategory>
|
||||
<!--
|
||||
<PreferenceCategory android:layout="@layout/preference_divider"/>
|
||||
|
||||
|
||||
@@ -23,6 +23,10 @@ public class DcHelper {
|
||||
public static final String CONFIG_SELF_AVATAR = "selfavatar";
|
||||
public static final String CONFIG_E2EE_ENABLED = "e2ee_enabled";
|
||||
public static final String CONFIG_QR_OVERLAY_LOGO = "qr_overlay_logo";
|
||||
public static final String CONFIG_INBOX_WATCH = "inbox_watch";
|
||||
public static final String CONFIG_SENTBOX_WATCH = "sentbox_watch";
|
||||
public static final String CONFIG_MVBOX_WATCH = "mvbox_watch";
|
||||
public static final String CONFIG_MVBOX_MOVE = "mvbox_move";
|
||||
|
||||
public static ApplicationDcContext getContext(Context context) {
|
||||
return ApplicationContext.getInstance(context).dcContext;
|
||||
|
||||
@@ -20,15 +20,18 @@ import com.b44t.messenger.DcEventCenter;
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.LogViewActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.preferences.widgets.ListPreferenceWithSummary;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.ScreenLockUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.views.ProgressDialog;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_E2EE_ENABLED;
|
||||
import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_INBOX_WATCH;
|
||||
import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_MVBOX_MOVE;
|
||||
import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_MVBOX_WATCH;
|
||||
import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_SENTBOX_WATCH;
|
||||
|
||||
|
||||
public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
@@ -36,11 +39,8 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
{
|
||||
private static final String TAG = AdvancedPreferenceFragment.class.getSimpleName();
|
||||
|
||||
private static final int REQUEST_CODE_CONFIRM_CREDENTIALS_BACKUP = ScreenLockUtil.REQUEST_CODE_CONFIRM_CREDENTIALS + 1;
|
||||
|
||||
private static final int REQUEST_CODE_CONFIRM_CREDENTIALS_KEYS = REQUEST_CODE_CONFIRM_CREDENTIALS_BACKUP + 1;
|
||||
|
||||
private ApplicationDcContext dcContext;
|
||||
|
||||
CheckBoxPreference preferE2eeCheckbox;
|
||||
CheckBoxPreference inboxWatchCheckbox;
|
||||
@@ -52,44 +52,38 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
public void onCreate(Bundle paramBundle) {
|
||||
super.onCreate(paramBundle);
|
||||
|
||||
dcContext = DcHelper.getContext(getContext());
|
||||
dcContext.eventCenter.addObserver(this, DcContext.DC_EVENT_IMEX_PROGRESS);
|
||||
|
||||
Preference sendAsm = this.findPreference("pref_send_autocrypt_setup_message");
|
||||
Preference sendAsm = this.findPreference(Prefs.AUTOCRYPT_SETUP_MESSAGE);
|
||||
sendAsm.setOnPreferenceClickListener(new SendAsmListener());
|
||||
|
||||
preferE2eeCheckbox = (CheckBoxPreference) this.findPreference("pref_prefer_e2ee");
|
||||
preferE2eeCheckbox = (CheckBoxPreference) this.findPreference(Prefs.PREFER_E2EE);
|
||||
preferE2eeCheckbox.setOnPreferenceChangeListener(new PreferE2eeListener());
|
||||
|
||||
inboxWatchCheckbox = (CheckBoxPreference) this.findPreference("pref_inbox_watch");
|
||||
inboxWatchCheckbox = (CheckBoxPreference) this.findPreference(Prefs.INBOX_WATCH);
|
||||
inboxWatchCheckbox.setOnPreferenceChangeListener((preference, newValue) ->
|
||||
handleImapCheck(preference, newValue, "inbox_watch")
|
||||
handleImapCheck(preference, newValue, CONFIG_INBOX_WATCH)
|
||||
);
|
||||
|
||||
sentboxWatchCheckbox = (CheckBoxPreference) this.findPreference("pref_sentbox_watch");
|
||||
sentboxWatchCheckbox = (CheckBoxPreference) this.findPreference(Prefs.SENTBOX_WATCH);
|
||||
sentboxWatchCheckbox.setOnPreferenceChangeListener((preference, newValue) ->
|
||||
handleImapCheck(preference, newValue, "sentbox_watch")
|
||||
handleImapCheck(preference, newValue, CONFIG_SENTBOX_WATCH)
|
||||
);
|
||||
|
||||
mvboxWatchCheckbox = (CheckBoxPreference) this.findPreference("pref_mvbox_watch");
|
||||
mvboxWatchCheckbox = (CheckBoxPreference) this.findPreference(Prefs.MVBOX_WATCH);
|
||||
mvboxWatchCheckbox.setOnPreferenceChangeListener((preference, newValue) ->
|
||||
handleImapCheck(preference, newValue, "mvbox_watch")
|
||||
handleImapCheck(preference, newValue, CONFIG_MVBOX_WATCH)
|
||||
);
|
||||
|
||||
mvboxMoveCheckbox = (CheckBoxPreference) this.findPreference("pref_mvbox_move");
|
||||
mvboxMoveCheckbox = (CheckBoxPreference) this.findPreference(Prefs.MVBOX_MOVE);
|
||||
mvboxMoveCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt("mvbox_move", enabled? 1 : 0);
|
||||
dcContext.setConfigInt(CONFIG_MVBOX_MOVE, enabled? 1 : 0);
|
||||
return true;
|
||||
});
|
||||
|
||||
Preference backup = this.findPreference("pref_backup");
|
||||
backup.setOnPreferenceClickListener(new BackupListener());
|
||||
|
||||
Preference manageKeys = this.findPreference("pref_manage_keys");
|
||||
Preference manageKeys = this.findPreference(Prefs.MANAGE_KEYS);
|
||||
manageKeys.setOnPreferenceClickListener(new ManageKeysListener());
|
||||
|
||||
Preference submitDebugLog = this.findPreference("pref_view_log");
|
||||
Preference submitDebugLog = this.findPreference(Prefs.VIEW_LOG);
|
||||
submitDebugLog.setOnPreferenceClickListener(new ViewLogListener());
|
||||
}
|
||||
|
||||
@@ -129,22 +123,18 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
super.onResume();
|
||||
((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.menu_advanced);
|
||||
|
||||
preferE2eeCheckbox.setChecked(0!=dcContext.getConfigInt("e2ee_enabled"));
|
||||
inboxWatchCheckbox.setChecked(0!=dcContext.getConfigInt("inbox_watch"));
|
||||
sentboxWatchCheckbox.setChecked(0!=dcContext.getConfigInt("sentbox_watch"));
|
||||
mvboxWatchCheckbox.setChecked(0!=dcContext.getConfigInt("mvbox_watch"));
|
||||
mvboxMoveCheckbox.setChecked(0!=dcContext.getConfigInt("mvbox_move"));
|
||||
preferE2eeCheckbox.setChecked(0!=dcContext.getConfigInt(CONFIG_E2EE_ENABLED));
|
||||
inboxWatchCheckbox.setChecked(0!=dcContext.getConfigInt(CONFIG_INBOX_WATCH));
|
||||
sentboxWatchCheckbox.setChecked(0!=dcContext.getConfigInt(CONFIG_SENTBOX_WATCH));
|
||||
mvboxWatchCheckbox.setChecked(0!=dcContext.getConfigInt(CONFIG_MVBOX_WATCH));
|
||||
mvboxMoveCheckbox.setChecked(0!=dcContext.getConfigInt(CONFIG_MVBOX_MOVE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == REQUEST_CODE_CONFIRM_CREDENTIALS_BACKUP) {
|
||||
performBackup();
|
||||
} else if (requestCode == REQUEST_CODE_CONFIRM_CREDENTIALS_KEYS) {
|
||||
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_CONFIRM_CREDENTIALS_KEYS) {
|
||||
exportKeys();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.screenlock_authentication_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@@ -233,42 +223,14 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
@Override
|
||||
public boolean onPreferenceChange(final Preference preference, Object newValue) {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt("e2ee_enabled", enabled? 1 : 0);
|
||||
dcContext.setConfigInt(CONFIG_E2EE_ENABLED, enabled? 1 : 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************************************
|
||||
* Import/Export
|
||||
* Key Import/Export
|
||||
**********************************************************************************************/
|
||||
|
||||
private class BackupListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
boolean result = ScreenLockUtil.applyScreenLock(getActivity(), REQUEST_CODE_CONFIRM_CREDENTIALS_BACKUP);
|
||||
if (!result) {
|
||||
performBackup();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void performBackup() {
|
||||
Permissions.with(getActivity())
|
||||
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
.ifNecessary()
|
||||
.withRationaleDialog(getActivity().getString(R.string.perm_explain_need_for_storage_access), R.drawable.ic_folder_white_48dp)
|
||||
.onAllGranted(() -> {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.pref_backup)
|
||||
.setMessage(R.string.pref_backup_export_explain)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.pref_backup_export_start_button, (dialogInterface, i) -> startImex(DcContext.DC_IMEX_EXPORT_BACKUP))
|
||||
.show();
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
private class ManageKeysListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
@@ -315,67 +277,4 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
private ProgressDialog progressDialog = null;
|
||||
private int progressWhat = 0;
|
||||
private String imexDir = "";
|
||||
private void startImex(int what)
|
||||
{
|
||||
if( progressDialog!=null ) {
|
||||
progressDialog.dismiss();
|
||||
progressDialog = null;
|
||||
}
|
||||
progressWhat = what;
|
||||
progressDialog = new ProgressDialog(getActivity());
|
||||
progressDialog.setMessage(getActivity().getString(R.string.one_moment));
|
||||
progressDialog.setCanceledOnTouchOutside(false);
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), (dialog, which) -> dcContext.stopOngoingProcess());
|
||||
progressDialog.show();
|
||||
|
||||
imexDir = dcContext.getImexDir().getAbsolutePath();
|
||||
dcContext.captureNextError();
|
||||
dcContext.imex(progressWhat, imexDir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEvent(int eventId, Object data1, Object data2) {
|
||||
if (eventId== DcContext.DC_EVENT_IMEX_PROGRESS) {
|
||||
long progress = (Long)data1;
|
||||
if (progress==0/*error/aborted*/) {
|
||||
dcContext.endCaptureNextError();
|
||||
progressDialog.dismiss();
|
||||
progressDialog = null;
|
||||
if (dcContext.hasCapturedError()) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(dcContext.getCapturedError())
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
else if (progress<1000/*progress in permille*/) {
|
||||
int percent = (int)progress / 10;
|
||||
progressDialog.setMessage(getResources().getString(R.string.one_moment)+String.format(" %d%%", percent));
|
||||
}
|
||||
else if (progress==1000/*done*/) {
|
||||
dcContext.endCaptureNextError();
|
||||
progressDialog.dismiss();
|
||||
progressDialog = null;
|
||||
String msg = "";
|
||||
if (progressWhat==DcContext.DC_IMEX_EXPORT_BACKUP) {
|
||||
msg = getActivity().getString(R.string.pref_backup_written_to_x, imexDir);
|
||||
}
|
||||
else if (progressWhat==DcContext.DC_IMEX_EXPORT_SELF_KEYS) {
|
||||
msg = getActivity().getString(R.string.pref_managekeys_secret_keys_exported_to_x, imexDir);
|
||||
}
|
||||
else if (progressWhat==DcContext.DC_IMEX_IMPORT_SELF_KEYS) {
|
||||
msg = getActivity().getString(R.string.pref_managekeys_secret_keys_imported_from_x, imexDir);
|
||||
}
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(msg)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,31 @@
|
||||
package org.thoughtcrime.securesms.preferences;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.preference.CheckBoxPreference;
|
||||
import android.support.v7.preference.EditTextPreference;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.preferences.widgets.ListPreferenceWithSummary;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.ScreenLockUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
private static final String TAG = ChatsPreferenceFragment.class.getSimpleName();
|
||||
|
||||
private ApplicationDcContext dcContext;
|
||||
|
||||
ListPreferenceWithSummary showEmails;
|
||||
|
||||
@@ -35,21 +34,23 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle paramBundle) {
|
||||
super.onCreate(paramBundle);
|
||||
dcContext = DcHelper.getContext(getContext());
|
||||
|
||||
findPreference(Prefs.MESSAGE_BODY_TEXT_SIZE_PREF)
|
||||
.setOnPreferenceChangeListener(new ListSummaryListener());
|
||||
.setOnPreferenceChangeListener(new ListSummaryListener());
|
||||
|
||||
findPreference("pref_compression")
|
||||
.setOnPreferenceChangeListener(new ListSummaryListener());
|
||||
findPreference(Prefs.COMPRESSION)
|
||||
.setOnPreferenceChangeListener(new ListSummaryListener());
|
||||
|
||||
showEmails = (ListPreferenceWithSummary) this.findPreference("pref_show_emails");
|
||||
showEmails = (ListPreferenceWithSummary) this.findPreference(Prefs.SHOW_EMAILS);
|
||||
showEmails.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
updateListSummary(preference, newValue);
|
||||
dcContext.setConfigInt("show_emails", Util.objectToInt(newValue));
|
||||
return true;
|
||||
});
|
||||
|
||||
Preference backup = this.findPreference(Prefs.BACKUP);
|
||||
backup.setOnPreferenceClickListener(new BackupListener());
|
||||
|
||||
// trimEnabledCheckbox = (CheckBoxPreference) findPreference("pref_trim_threads");
|
||||
// trimEnabledCheckbox.setOnPreferenceChangeListener(new TrimEnabledListener());
|
||||
//
|
||||
@@ -59,6 +60,7 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
// .setOnPreferenceClickListener(new TrimNowClickListener());
|
||||
|
||||
initializeListSummary((ListPreference) findPreference(Prefs.MESSAGE_BODY_TEXT_SIZE_PREF));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,9 +73,9 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
super.onResume();
|
||||
((ApplicationPreferencesActivity)getActivity()).getSupportActionBar().setTitle(R.string.pref_chats_and_media);
|
||||
|
||||
initializeListSummary((ListPreferenceWithSummary) findPreference("pref_compression"));
|
||||
initializeListSummary((ListPreferenceWithSummary) findPreference(Prefs.COMPRESSION));
|
||||
|
||||
String value = Integer.toString(dcContext.getConfigInt("show_emails"));
|
||||
String value = Integer.toString(dcContext.getConfigInt(Prefs.SHOW_EMAILS));
|
||||
showEmails.setValue(value);
|
||||
updateListSummary(showEmails, value);
|
||||
|
||||
@@ -90,7 +92,17 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
// private class TrimEnabledListener implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_CONFIRM_CREDENTIALS_BACKUP) {
|
||||
performBackup();
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.screenlock_authentication_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
// private class TrimEnabledListener implements Preference.OnPreferenceChangeListener {
|
||||
// @Override
|
||||
// public boolean onPreferenceChange(final Preference preference, Object newValue) {
|
||||
// boolean enabled = (Boolean) newValue;
|
||||
@@ -151,4 +163,35 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
public static CharSequence getSummary(Context context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/***********************************************************************************************
|
||||
* Backup
|
||||
**********************************************************************************************/
|
||||
|
||||
private class BackupListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
boolean result = ScreenLockUtil.applyScreenLock(getActivity(), REQUEST_CODE_CONFIRM_CREDENTIALS_BACKUP);
|
||||
if (!result) {
|
||||
performBackup();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void performBackup() {
|
||||
Permissions.with(getActivity())
|
||||
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
.ifNecessary()
|
||||
.withRationaleDialog(getActivity().getString(R.string.perm_explain_need_for_storage_access), R.drawable.ic_folder_white_48dp)
|
||||
.onAllGranted(() -> {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.pref_backup)
|
||||
.setMessage(R.string.pref_backup_export_explain)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.pref_backup_export_start_button, (dialogInterface, i) -> startImex(DcContext.DC_IMEX_EXPORT_BACKUP))
|
||||
.show();
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
package org.thoughtcrime.securesms.preferences;
|
||||
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcEventCenter;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.util.ScreenLockUtil;
|
||||
import org.thoughtcrime.securesms.util.views.ProgressDialog;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceFragment {
|
||||
public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceFragment implements DcEventCenter.DcEventDelegate {
|
||||
protected static final int REQUEST_CODE_CONFIRM_CREDENTIALS_BACKUP = ScreenLockUtil.REQUEST_CODE_CONFIRM_CREDENTIALS + 1;
|
||||
protected static final int REQUEST_CODE_CONFIRM_CREDENTIALS_KEYS = REQUEST_CODE_CONFIRM_CREDENTIALS_BACKUP + 1;
|
||||
protected ApplicationDcContext dcContext;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
dcContext = DcHelper.getContext(getContext());
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_IMEX_PROGRESS, this);
|
||||
|
||||
}
|
||||
|
||||
protected class ListSummaryListener implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
@@ -30,4 +51,68 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
|
||||
protected void initializeListSummary(ListPreference pref) {
|
||||
pref.setSummary(pref.getEntry());
|
||||
}
|
||||
|
||||
protected ProgressDialog progressDialog = null;
|
||||
protected int progressWhat = 0;
|
||||
protected String imexDir = "";
|
||||
protected void startImex(int what)
|
||||
{
|
||||
if( progressDialog!=null ) {
|
||||
progressDialog.dismiss();
|
||||
progressDialog = null;
|
||||
}
|
||||
progressWhat = what;
|
||||
progressDialog = new ProgressDialog(getActivity());
|
||||
progressDialog.setMessage(getActivity().getString(R.string.one_moment));
|
||||
progressDialog.setCanceledOnTouchOutside(false);
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), (dialog, which) -> dcContext.stopOngoingProcess());
|
||||
progressDialog.show();
|
||||
|
||||
imexDir = dcContext.getImexDir().getAbsolutePath();
|
||||
dcContext.captureNextError();
|
||||
dcContext.imex(progressWhat, imexDir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEvent(int eventId, Object data1, Object data2) {
|
||||
if (eventId== DcContext.DC_EVENT_IMEX_PROGRESS) {
|
||||
long progress = (Long)data1;
|
||||
if (progress==0/*error/aborted*/) {
|
||||
dcContext.endCaptureNextError();
|
||||
progressDialog.dismiss();
|
||||
progressDialog = null;
|
||||
if (dcContext.hasCapturedError()) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(dcContext.getCapturedError())
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
else if (progress<1000/*progress in permille*/) {
|
||||
int percent = (int)progress / 10;
|
||||
progressDialog.setMessage(getResources().getString(R.string.one_moment)+String.format(" %d%%", percent));
|
||||
}
|
||||
else if (progress==1000/*done*/) {
|
||||
dcContext.endCaptureNextError();
|
||||
progressDialog.dismiss();
|
||||
progressDialog = null;
|
||||
String msg = "";
|
||||
if (progressWhat==DcContext.DC_IMEX_EXPORT_BACKUP) {
|
||||
msg = getActivity().getString(R.string.pref_backup_written_to_x, imexDir);
|
||||
}
|
||||
else if (progressWhat==DcContext.DC_IMEX_EXPORT_SELF_KEYS) {
|
||||
msg = getActivity().getString(R.string.pref_managekeys_secret_keys_exported_to_x, imexDir);
|
||||
}
|
||||
else if (progressWhat==DcContext.DC_IMEX_IMPORT_SELF_KEYS) {
|
||||
msg = getActivity().getString(R.string.pref_managekeys_secret_keys_imported_from_x, imexDir);
|
||||
}
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(msg)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
@@ -55,6 +54,18 @@ public class Prefs {
|
||||
private static final String IN_THREAD_NOTIFICATION_PREF = "pref_key_inthread_notifications";
|
||||
public static final String MESSAGE_BODY_TEXT_SIZE_PREF = "pref_message_body_text_size";
|
||||
|
||||
public static final String SHOW_EMAILS = "pref_show_emails";
|
||||
public static final String COMPRESSION = "pref_compression";
|
||||
public static final String BACKUP = "pref_backup";
|
||||
public static final String AUTOCRYPT_SETUP_MESSAGE = "pref_send_autocrypt_setup_message";
|
||||
public static final String PREFER_E2EE = "pref_prefer_e2ee";
|
||||
public static final String INBOX_WATCH = "pref_inbox_watch";
|
||||
public static final String SENTBOX_WATCH = "pref_sentbox_watch";
|
||||
public static final String MVBOX_WATCH = "pref_mvbox_watch";
|
||||
public static final String MVBOX_MOVE = "pref_mvbox_move";
|
||||
public static final String MANAGE_KEYS = "pref_manage_keys";
|
||||
public static final String VIEW_LOG = "pref_view_log";
|
||||
|
||||
public static final String NOTIFICATION_PRIVACY_PREF = "pref_notification_privacy";
|
||||
public static final String NOTIFICATION_PRIORITY_PREF = "pref_notification_priority";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user