mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #961 from deltachat/move_import_export
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,11 @@ 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 final String CONFIG_SHOW_EMAILS = "show_emails";
|
||||
|
||||
public static ApplicationDcContext getContext(Context context) {
|
||||
return ApplicationContext.getInstance(context).dcContext;
|
||||
|
||||
@@ -20,15 +20,17 @@ 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.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 +38,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,9 +51,6 @@ 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");
|
||||
sendAsm.setOnPreferenceClickListener(new SendAsmListener());
|
||||
|
||||
@@ -63,29 +59,26 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
|
||||
inboxWatchCheckbox = (CheckBoxPreference) this.findPreference("pref_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.setOnPreferenceChangeListener((preference, newValue) ->
|
||||
handleImapCheck(preference, newValue, "sentbox_watch")
|
||||
handleImapCheck(preference, newValue, CONFIG_SENTBOX_WATCH)
|
||||
);
|
||||
|
||||
mvboxWatchCheckbox = (CheckBoxPreference) this.findPreference("pref_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.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");
|
||||
manageKeys.setOnPreferenceClickListener(new ManageKeysListener());
|
||||
|
||||
@@ -113,12 +106,6 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
dcContext.eventCenter.removeObservers(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) {
|
||||
addPreferencesFromResource(R.xml.preferences_advanced);
|
||||
@@ -129,22 +116,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 +216,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 +270,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,32 @@
|
||||
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;
|
||||
import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_SHOW_EMAILS;
|
||||
|
||||
public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
private static final String TAG = ChatsPreferenceFragment.class.getSimpleName();
|
||||
|
||||
private ApplicationDcContext dcContext;
|
||||
|
||||
ListPreferenceWithSummary showEmails;
|
||||
|
||||
@@ -35,21 +35,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());
|
||||
.setOnPreferenceChangeListener(new ListSummaryListener());
|
||||
|
||||
showEmails = (ListPreferenceWithSummary) this.findPreference("pref_show_emails");
|
||||
showEmails.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
updateListSummary(preference, newValue);
|
||||
dcContext.setConfigInt("show_emails", Util.objectToInt(newValue));
|
||||
dcContext.setConfigInt(CONFIG_SHOW_EMAILS, Util.objectToInt(newValue));
|
||||
return true;
|
||||
});
|
||||
|
||||
Preference backup = this.findPreference("pref_backup");
|
||||
backup.setOnPreferenceClickListener(new BackupListener());
|
||||
|
||||
// trimEnabledCheckbox = (CheckBoxPreference) findPreference("pref_trim_threads");
|
||||
// trimEnabledCheckbox.setOnPreferenceChangeListener(new TrimEnabledListener());
|
||||
//
|
||||
@@ -59,6 +61,7 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
// .setOnPreferenceClickListener(new TrimNowClickListener());
|
||||
|
||||
initializeListSummary((ListPreference) findPreference(Prefs.MESSAGE_BODY_TEXT_SIZE_PREF));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +76,7 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
|
||||
initializeListSummary((ListPreferenceWithSummary) findPreference("pref_compression"));
|
||||
|
||||
String value = Integer.toString(dcContext.getConfigInt("show_emails"));
|
||||
String value = Integer.toString(dcContext.getConfigInt("pref_show_emails"));
|
||||
showEmails.setValue(value);
|
||||
updateListSummary(showEmails, value);
|
||||
|
||||
@@ -81,13 +84,18 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
||||
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 {
|
||||
@@ -151,4 +159,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,40 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
dcContext.eventCenter.removeObservers(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
protected class ListSummaryListener implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
@@ -30,4 +56,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user