mirror of https://github.com/M66B/FairEmail.git
Save export view model
This commit is contained in:
parent
3056949a92
commit
1b488aed5b
|
@ -463,10 +463,12 @@ dependencies {
|
||||||
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-runtime
|
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-runtime
|
||||||
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-livedata
|
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-livedata
|
||||||
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-livedata-core
|
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-livedata-core
|
||||||
|
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-viewmodel-savedstate
|
||||||
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-compiler
|
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-compiler
|
||||||
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
|
||||||
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
|
||||||
implementation "androidx.lifecycle:lifecycle-livedata-core:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-livedata-core:$lifecycle_version"
|
||||||
|
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
|
||||||
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
|
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-extensions
|
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-extensions
|
||||||
|
|
|
@ -73,6 +73,7 @@ import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
import androidx.lifecycle.Lifecycle;
|
import androidx.lifecycle.Lifecycle;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
|
@ -132,14 +133,6 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||||
private RecyclerView rvMenu;
|
private RecyclerView rvMenu;
|
||||||
|
|
||||||
private boolean hasAccount;
|
private boolean hasAccount;
|
||||||
private String password;
|
|
||||||
private boolean import_accounts;
|
|
||||||
private boolean import_delete;
|
|
||||||
private boolean import_rules;
|
|
||||||
private boolean import_contacts;
|
|
||||||
private boolean import_answers;
|
|
||||||
private boolean import_searches;
|
|
||||||
private boolean import_settings;
|
|
||||||
|
|
||||||
static final int REQUEST_SOUND_INBOUND = 1;
|
static final int REQUEST_SOUND_INBOUND = 1;
|
||||||
static final int REQUEST_SOUND_OUTBOUND = 2;
|
static final int REQUEST_SOUND_OUTBOUND = 2;
|
||||||
|
@ -359,14 +352,6 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
drawerToggle.setDrawerIndicatorEnabled(savedInstanceState.getBoolean("fair:toggle"));
|
drawerToggle.setDrawerIndicatorEnabled(savedInstanceState.getBoolean("fair:toggle"));
|
||||||
password = savedInstanceState.getString("fair:password");
|
|
||||||
import_accounts = savedInstanceState.getBoolean("fair:import_accounts");
|
|
||||||
import_delete = savedInstanceState.getBoolean("fair:import_delete");
|
|
||||||
import_rules = savedInstanceState.getBoolean("fair:import_rules");
|
|
||||||
import_contacts = savedInstanceState.getBoolean("fair:import_contacts");
|
|
||||||
import_answers = savedInstanceState.getBoolean("fair:import_answers");
|
|
||||||
import_searches = savedInstanceState.getBoolean("fair:import_searches");
|
|
||||||
import_settings = savedInstanceState.getBoolean("fair:import_settings");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DB db = DB.getInstance(this);
|
DB db = DB.getInstance(this);
|
||||||
|
@ -382,14 +367,6 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
outState.putBoolean("fair:toggle", drawerToggle == null || drawerToggle.isDrawerIndicatorEnabled());
|
outState.putBoolean("fair:toggle", drawerToggle == null || drawerToggle.isDrawerIndicatorEnabled());
|
||||||
outState.putString("fair:password", password);
|
|
||||||
outState.putBoolean("fair:import_accounts", import_accounts);
|
|
||||||
outState.putBoolean("fair:import_delete", import_delete);
|
|
||||||
outState.putBoolean("fair:import_rules", import_rules);
|
|
||||||
outState.putBoolean("fair:import_contacts", import_contacts);
|
|
||||||
outState.putBoolean("fair:import_answers", import_answers);
|
|
||||||
outState.putBoolean("fair:import_searches", import_searches);
|
|
||||||
outState.putBoolean("fair:import_settings", import_settings);
|
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,9 +626,11 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleExport(Intent data) {
|
private void handleExport(Intent data) {
|
||||||
|
ViewModelExport vme = new ViewModelProvider(this).get(ViewModelExport.class);
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putParcelable("uri", data.getData());
|
args.putParcelable("uri", data.getData());
|
||||||
args.putString("password", this.password);
|
args.putString("password", vme.getPassword());
|
||||||
|
|
||||||
new SimpleTask<Void>() {
|
new SimpleTask<Void>() {
|
||||||
private Toast toast = null;
|
private Toast toast = null;
|
||||||
|
@ -971,16 +950,18 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||||
Button ok = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
Button ok = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
ok.setEnabled(false);
|
ok.setEnabled(false);
|
||||||
|
|
||||||
|
ViewModelExport vme = new ViewModelProvider(this).get(ViewModelExport.class);
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putParcelable("uri", uri);
|
args.putParcelable("uri", uri);
|
||||||
args.putString("password", this.password);
|
args.putString("password", vme.getPassword());
|
||||||
args.putBoolean("import_accounts", this.import_accounts);
|
args.putBoolean("import_accounts", vme.getOption("accounts"));
|
||||||
args.putBoolean("import_delete", this.import_delete);
|
args.putBoolean("import_delete", vme.getOption("delete"));
|
||||||
args.putBoolean("import_rules", this.import_rules);
|
args.putBoolean("import_rules", vme.getOption("rules"));
|
||||||
args.putBoolean("import_contacts", this.import_contacts);
|
args.putBoolean("import_contacts", vme.getOption("contacts"));
|
||||||
args.putBoolean("import_answers", this.import_answers);
|
args.putBoolean("import_answers", vme.getOption("answers"));
|
||||||
args.putBoolean("import_searches", this.import_searches);
|
args.putBoolean("import_searches", vme.getOption("searches"));
|
||||||
args.putBoolean("import_settings", this.import_settings);
|
args.putBoolean("import_settings", vme.getOption("settings"));
|
||||||
|
|
||||||
new SimpleTask<Void>() {
|
new SimpleTask<Void>() {
|
||||||
private SpannableStringBuilder ssb = new SpannableStringBuilder();
|
private SpannableStringBuilder ssb = new SpannableStringBuilder();
|
||||||
|
@ -2005,8 +1986,8 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||||
.setPositiveButton(R.string.title_save_file, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.title_save_file, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
((ActivitySetup) getActivity()).password =
|
ViewModelExport vme = new ViewModelProvider(getActivity()).get(ViewModelExport.class);
|
||||||
tilPassword1.getEditText().getText().toString();
|
vme.setPassword(tilPassword1.getEditText().getText().toString());
|
||||||
getActivity().startActivityForResult(
|
getActivity().startActivityForResult(
|
||||||
Helper.getChooser(context, getIntentExport()), REQUEST_EXPORT);
|
Helper.getChooser(context, getIntentExport()), REQUEST_EXPORT);
|
||||||
}
|
}
|
||||||
|
@ -2114,15 +2095,15 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||||
if (TextUtils.isEmpty(password1) && !(debug || BuildConfig.DEBUG))
|
if (TextUtils.isEmpty(password1) && !(debug || BuildConfig.DEBUG))
|
||||||
ToastEx.makeText(context, R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
|
ToastEx.makeText(context, R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
|
||||||
else {
|
else {
|
||||||
ActivitySetup activity = (ActivitySetup) getActivity();
|
ViewModelExport vme = new ViewModelProvider(getActivity()).get(ViewModelExport.class);
|
||||||
activity.password = password1;
|
vme.setPassword(password1);
|
||||||
activity.import_accounts = cbAccounts.isChecked();
|
vme.setOptions("accounts", cbAccounts.isChecked());
|
||||||
activity.import_delete = cbDelete.isChecked();
|
vme.setOptions("delete", cbDelete.isChecked());
|
||||||
activity.import_rules = cbRules.isChecked();
|
vme.setOptions("rules", cbRules.isChecked());
|
||||||
activity.import_contacts = cbContacts.isChecked();
|
vme.setOptions("contacts", cbContacts.isChecked());
|
||||||
activity.import_answers = cbAnswers.isChecked();
|
vme.setOptions("answers", cbAnswers.isChecked());
|
||||||
activity.import_searches = cbSearches.isChecked();
|
vme.setOptions("searches", cbSearches.isChecked());
|
||||||
activity.import_settings = cbSettings.isChecked();
|
vme.setOptions("settings", cbSettings.isChecked());
|
||||||
getActivity().startActivityForResult(
|
getActivity().startActivityForResult(
|
||||||
Helper.getChooser(context, getIntentImport()), REQUEST_IMPORT);
|
Helper.getChooser(context, getIntentImport()), REQUEST_IMPORT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of FairEmail.
|
||||||
|
|
||||||
|
FairEmail is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
FairEmail is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Copyright 2018-2023 by Marcel Bokhorst (M66B)
|
||||||
|
*/
|
||||||
|
|
||||||
|
import androidx.lifecycle.SavedStateHandle;
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ViewModelExport extends ViewModel {
|
||||||
|
private SavedStateHandle state;
|
||||||
|
|
||||||
|
public ViewModelExport(SavedStateHandle state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
state.set("password", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOptions(String name, boolean value) {
|
||||||
|
state.set(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return state.get("password");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getOption(String name) {
|
||||||
|
Boolean value = state.get("name");
|
||||||
|
return (value != null && value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue