diff --git a/res/layout/export_fragment.xml b/res/layout/export_fragment.xml deleted file mode 100644 index c46800eab8..0000000000 --- a/res/layout/export_fragment.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/layout/import_export_fragment.xml b/res/layout/import_export_fragment.xml new file mode 100644 index 0000000000..9c86122cf5 --- /dev/null +++ b/res/layout/import_export_fragment.xml @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/import_fragment.xml b/res/layout/import_fragment.xml deleted file mode 100644 index 25453eb117..0000000000 --- a/res/layout/import_fragment.xml +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 5ede7d4117..35ccff091c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -845,6 +845,9 @@ Nothing found + + Export + Import Could not read the log on your device. You can still use ADB to get a debug log instead. diff --git a/src/org/thoughtcrime/securesms/ExportFragment.java b/src/org/thoughtcrime/securesms/ExportFragment.java deleted file mode 100644 index bf6202cf79..0000000000 --- a/src/org/thoughtcrime/securesms/ExportFragment.java +++ /dev/null @@ -1,196 +0,0 @@ -package org.thoughtcrime.securesms; - -import android.app.Dialog; -import android.app.ProgressDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v7.app.AlertDialog; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Toast; - -import org.thoughtcrime.securesms.crypto.MasterSecret; -import org.thoughtcrime.securesms.database.NoExternalStorageException; -import org.thoughtcrime.securesms.database.PlaintextBackupExporter; - -import java.io.IOException; - - -public class ExportFragment extends Fragment { - - private static final int SUCCESS = 0; - private static final int NO_SD_CARD = 1; - private static final int IO_ERROR = 2; - - private MasterSecret masterSecret; - - public void setMasterSecret(MasterSecret masterSecret) { - this.masterSecret = masterSecret; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { - View layout = inflater.inflate(R.layout.export_fragment, container, false); -// View exportEncryptedView = layout.findViewById(R.id.export_encrypted_backup); - View exportPlaintextView = layout.findViewById(R.id.export_plaintext_backup); - -// exportEncryptedView.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// handleExportEncryptedBackup(); -// } -// }); - - exportPlaintextView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - handleExportPlaintextBackup(); - } - }); - - return layout; - } - -// private void handleExportEncryptedBackup() { -// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); -// builder.setIcon(Dialogs.getDrawable(getActivity(), R.attr.dialog_info_icon)); -// builder.setTitle(getActivity().getString(R.string.ExportFragment_export_to_sd_card)); -// builder.setMessage(getActivity().getString(R.string.ExportFragment_this_will_export_your_encrypted_keys_settings_and_messages)); -// builder.setPositiveButton(getActivity().getString(R.string.ExportFragment_export), new Dialog.OnClickListener() { -// @Override -// public void onClick(DialogInterface dialog, int which) { -// new ExportEncryptedTask().execute(); -// } -// }); -// builder.setNegativeButton(getActivity().getString(R.string.ExportFragment_cancel), null); -// builder.show(); -// } - - private void handleExportPlaintextBackup() { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setIconAttribute(R.attr.dialog_alert_icon); - builder.setTitle(getActivity().getString(R.string.ExportFragment_export_plaintext_to_storage)); - builder.setMessage(getActivity().getString(R.string.ExportFragment_warning_this_will_export_the_plaintext_contents)); - builder.setPositiveButton(getActivity().getString(R.string.ExportFragment_export), new Dialog.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - new ExportPlaintextTask().execute(); - } - }); - builder.setNegativeButton(getActivity().getString(R.string.ExportFragment_cancel), null); - builder.show(); - } - - private class ExportPlaintextTask extends AsyncTask { - private ProgressDialog dialog; - - @Override - protected void onPreExecute() { - dialog = ProgressDialog.show(getActivity(), - getActivity().getString(R.string.ExportFragment_exporting), - getActivity().getString(R.string.ExportFragment_exporting_plaintext_to_storage), - true, false); - } - - @Override - protected Integer doInBackground(Void... params) { - try { - PlaintextBackupExporter.exportPlaintextToSd(getActivity(), masterSecret); - return SUCCESS; - } catch (NoExternalStorageException e) { - Log.w("ExportFragment", e); - return NO_SD_CARD; - } catch (IOException e) { - Log.w("ExportFragment", e); - return IO_ERROR; - } - } - - @Override - protected void onPostExecute(Integer result) { - Context context = getActivity(); - - if (dialog != null) - dialog.dismiss(); - - if (context == null) - return; - - switch (result) { - case NO_SD_CARD: - Toast.makeText(context, - context.getString(R.string.ExportFragment_error_unable_to_write_to_storage), - Toast.LENGTH_LONG).show(); - break; - case IO_ERROR: - Toast.makeText(context, - context.getString(R.string.ExportFragment_error_while_writing_to_storage), - Toast.LENGTH_LONG).show(); - break; - case SUCCESS: - Toast.makeText(context, - context.getString(R.string.ExportFragment_export_successful), - Toast.LENGTH_LONG).show(); - break; - } - } - } - -// private class ExportEncryptedTask extends AsyncTask { -// private ProgressDialog dialog; -// -// @Override -// protected void onPreExecute() { -// dialog = ProgressDialog.show(getActivity(), -// getActivity().getString(R.string.ExportFragment_exporting), -// getActivity().getString(R.string.ExportFragment_exporting_keys_settings_and_messages), -// true, false); -// } -// -// @Override -// protected void onPostExecute(Integer result) { -// Context context = getActivity(); -// -// if (dialog != null) dialog.dismiss(); -// -// if (context == null) return; -// -// switch (result) { -// case NO_SD_CARD: -// Toast.makeText(context, -// context.getString(R.string.ExportFragment_error_unable_to_write_to_storage), -// Toast.LENGTH_LONG).show(); -// break; -// case IO_ERROR: -// Toast.makeText(context, -// context.getString(R.string.ExportFragment_error_while_writing_to_storage), -// Toast.LENGTH_LONG).show(); -// break; -// case SUCCESS: -// Toast.makeText(context, -// context.getString(R.string.ExportFragment_success), -// Toast.LENGTH_LONG).show(); -// break; -// } -// } -// -// @Override -// protected Integer doInBackground(Void... params) { -// try { -// EncryptedBackupExporter.exportToSd(getActivity()); -// return SUCCESS; -// } catch (NoExternalStorageException e) { -// Log.w("ExportFragment", e); -// return NO_SD_CARD; -// } catch (IOException e) { -// Log.w("ExportFragment", e); -// return IO_ERROR; -// } -// } -// } -} \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/ImportExportActivity.java b/src/org/thoughtcrime/securesms/ImportExportActivity.java index 498fd0372c..bf70561af0 100644 --- a/src/org/thoughtcrime/securesms/ImportExportActivity.java +++ b/src/org/thoughtcrime/securesms/ImportExportActivity.java @@ -2,25 +2,17 @@ package org.thoughtcrime.securesms; import android.os.Bundle; import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentStatePagerAdapter; -import android.support.v4.app.FragmentTransaction; -import android.support.v4.view.ViewPager; -import android.support.v7.app.ActionBar; import android.view.MenuItem; import org.thoughtcrime.securesms.crypto.MasterSecret; +import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicTheme; public class ImportExportActivity extends PassphraseRequiredActionBarActivity { - private MasterSecret masterSecret; - private TabPagerAdapter tabPagerAdapter; - private ViewPager viewPager; - - private DynamicTheme dynamicTheme = new DynamicTheme(); + private DynamicTheme dynamicTheme = new DynamicTheme(); + private DynamicLanguage dynamicLanguage = new DynamicLanguage(); @Override protected void onPreCreate() { @@ -29,19 +21,15 @@ public class ImportExportActivity extends PassphraseRequiredActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState, @NonNull MasterSecret masterSecret) { - this.masterSecret = masterSecret; - setContentView(R.layout.import_export_activity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - initializeResources(); - initializeViewPager(); - initializeTabs(); + initFragment(android.R.id.content, new ImportExportFragment(), + masterSecret, dynamicLanguage.getCurrentLocale()); } @Override public void onResume() { - dynamicTheme.onResume(this); - super.onResume(); + dynamicTheme.onResume(this); + super.onResume(); } @Override @@ -54,70 +42,4 @@ public class ImportExportActivity extends PassphraseRequiredActionBarActivity { return false; } - - private void initializeResources() { - this.viewPager = (ViewPager) findViewById(R.id.import_export_pager); - this.tabPagerAdapter = new TabPagerAdapter(getSupportFragmentManager()); - - viewPager.setAdapter(tabPagerAdapter); - } - - private void initializeViewPager() { - viewPager.setAdapter(tabPagerAdapter); - viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { - @Override - public void onPageSelected(int position) { - getSupportActionBar().setSelectedNavigationItem(position); - } - }); - } - - private void initializeTabs() { - final ActionBar actionBar = getSupportActionBar(); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); - - ActionBar.TabListener tabListener = new ActionBar.TabListener() { - public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { - viewPager.setCurrentItem(tab.getPosition()); - } - - public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {} - public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {} - }; - - actionBar.addTab(actionBar.newTab().setText(R.string.ImportExportActivity_import).setTabListener(tabListener)); - actionBar.addTab(actionBar.newTab().setText(R.string.ImportExportActivity_export).setTabListener(tabListener)); - } - - private class TabPagerAdapter extends FragmentStatePagerAdapter { - private final ImportFragment importFragment; - private final ExportFragment exportFragment; - - public TabPagerAdapter(FragmentManager fragmentManager) { - super(fragmentManager); - - this.importFragment = new ImportFragment(); - this.exportFragment = new ExportFragment(); - this.importFragment.setMasterSecret(masterSecret); - this.exportFragment.setMasterSecret(masterSecret); - } - - @Override - public Fragment getItem(int i) { - if (i == 0) return importFragment; - else return exportFragment; - } - - @Override - public int getCount() { - return 2; - } - - @Override - public CharSequence getPageTitle(int i) { - if (i == 0) return getString(R.string.ImportExportActivity_import); - else return getString(R.string.ImportExportActivity_export); - } - } - } diff --git a/src/org/thoughtcrime/securesms/ImportFragment.java b/src/org/thoughtcrime/securesms/ImportExportFragment.java similarity index 75% rename from src/org/thoughtcrime/securesms/ImportFragment.java rename to src/org/thoughtcrime/securesms/ImportExportFragment.java index 3f0663f13e..958be145fc 100644 --- a/src/org/thoughtcrime/securesms/ImportFragment.java +++ b/src/org/thoughtcrime/securesms/ImportExportFragment.java @@ -1,5 +1,6 @@ package org.thoughtcrime.securesms; +import android.app.Dialog; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; @@ -15,35 +16,35 @@ import android.view.ViewGroup; import android.widget.Toast; import org.thoughtcrime.securesms.crypto.MasterSecret; -import org.thoughtcrime.securesms.database.DatabaseFactory; -import org.thoughtcrime.securesms.database.EncryptedBackupExporter; import org.thoughtcrime.securesms.database.NoExternalStorageException; +import org.thoughtcrime.securesms.database.PlaintextBackupExporter; import org.thoughtcrime.securesms.database.PlaintextBackupImporter; import org.thoughtcrime.securesms.service.ApplicationMigrationService; -import org.thoughtcrime.securesms.service.KeyCachingService; import java.io.IOException; -public class ImportFragment extends Fragment { +public class ImportExportFragment extends Fragment { private static final int SUCCESS = 0; private static final int NO_SD_CARD = 1; private static final int ERROR_IO = 2; - private MasterSecret masterSecret; + private MasterSecret masterSecret; private ProgressDialog progressDialog; - public void setMasterSecret(MasterSecret masterSecret) { - this.masterSecret = masterSecret; + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + this.masterSecret = getArguments().getParcelable("master_secret"); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { - View layout = inflater.inflate(R.layout.import_fragment, container, false); + View layout = inflater.inflate(R.layout.import_export_fragment, container, false); View importSmsView = layout.findViewById(R.id.import_sms ); - View importEncryptedView = layout.findViewById(R.id.import_encrypted_backup); View importPlaintextView = layout.findViewById(R.id.import_plaintext_backup); + View exportPlaintextView = layout.findViewById(R.id.export_plaintext_backup); importSmsView.setOnClickListener(new View.OnClickListener() { @Override @@ -52,13 +53,6 @@ public class ImportFragment extends Fragment { } }); - importEncryptedView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - handleImportEncryptedBackup(); - } - }); - importPlaintextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -66,6 +60,13 @@ public class ImportFragment extends Fragment { } }); + exportPlaintextView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + handleExportPlaintextBackup(); + } + }); + return layout; } @@ -103,21 +104,6 @@ public class ImportFragment extends Fragment { builder.show(); } - private void handleImportEncryptedBackup() { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setIconAttribute(R.attr.dialog_alert_icon); - builder.setTitle(getActivity().getString(R.string.ImportFragment_restore_encrypted_backup)); - builder.setMessage(getActivity().getString(R.string.ImportFragment_restoring_an_encrypted_backup_will_completely_replace_your_existing_keys)); - builder.setPositiveButton(getActivity().getString(R.string.ImportFragment_restore), new AlertDialog.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - new ImportEncryptedBackupTask().execute(); - } - }); - builder.setNegativeButton(getActivity().getString(R.string.ImportFragment_cancel), null); - builder.show(); - } - private void handleImportPlaintextBackup() { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setIconAttribute(R.attr.dialog_alert_icon); @@ -133,6 +119,21 @@ public class ImportFragment extends Fragment { builder.show(); } + private void handleExportPlaintextBackup() { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setIconAttribute(R.attr.dialog_alert_icon); + builder.setTitle(getActivity().getString(R.string.ExportFragment_export_plaintext_to_storage)); + builder.setMessage(getActivity().getString(R.string.ExportFragment_warning_this_will_export_the_plaintext_contents)); + builder.setPositiveButton(getActivity().getString(R.string.ExportFragment_export), new Dialog.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + new ExportPlaintextTask().execute(); + } + }); + builder.setNegativeButton(getActivity().getString(R.string.ExportFragment_cancel), null); + builder.show(); + } + private class ImportPlaintextBackupTask extends AsyncTask { @Override @@ -184,23 +185,39 @@ public class ImportFragment extends Fragment { return ERROR_IO; } } -} + } - private class ImportEncryptedBackupTask extends AsyncTask { + private class ExportPlaintextTask extends AsyncTask { + private ProgressDialog dialog; @Override protected void onPreExecute() { - progressDialog = ProgressDialog.show(getActivity(), - getActivity().getString(R.string.ImportFragment_restoring), - getActivity().getString(R.string.ImportFragment_restoring_encrypted_backup), - true, false); + dialog = ProgressDialog.show(getActivity(), + getActivity().getString(R.string.ExportFragment_exporting), + getActivity().getString(R.string.ExportFragment_exporting_plaintext_to_storage), + true, false); } + @Override + protected Integer doInBackground(Void... params) { + try { + PlaintextBackupExporter.exportPlaintextToSd(getActivity(), masterSecret); + return SUCCESS; + } catch (NoExternalStorageException e) { + Log.w("ExportFragment", e); + return NO_SD_CARD; + } catch (IOException e) { + Log.w("ExportFragment", e); + return ERROR_IO; + } + } + + @Override protected void onPostExecute(Integer result) { Context context = getActivity(); - if (progressDialog != null) - progressDialog.dismiss(); + if (dialog != null) + dialog.dismiss(); if (context == null) return; @@ -208,39 +225,22 @@ public class ImportFragment extends Fragment { switch (result) { case NO_SD_CARD: Toast.makeText(context, - context.getString(R.string.ImportFragment_no_encrypted_backup_found), + context.getString(R.string.ExportFragment_error_unable_to_write_to_storage), Toast.LENGTH_LONG).show(); break; case ERROR_IO: Toast.makeText(context, - context.getString(R.string.ImportFragment_error_importing_backup), + context.getString(R.string.ExportFragment_error_while_writing_to_storage), Toast.LENGTH_LONG).show(); break; case SUCCESS: - DatabaseFactory.getInstance(context).reset(context); - Intent intent = new Intent(context, KeyCachingService.class); - intent.setAction(KeyCachingService.CLEAR_KEY_ACTION); - context.startService(intent); - Toast.makeText(context, - context.getString(R.string.ImportFragment_restore_complete), + context.getString(R.string.ExportFragment_export_successful), Toast.LENGTH_LONG).show(); - } - } - - @Override - protected Integer doInBackground(Void... params) { - try { - EncryptedBackupExporter.importFromSd(getActivity()); - return SUCCESS; - } catch (NoExternalStorageException e) { - Log.w("ImportFragment", e); - return NO_SD_CARD; - } catch (IOException e) { - Log.w("ImportFragment", e); - return ERROR_IO; + break; } } } + } \ No newline at end of file