wizard & SP improvements

This commit is contained in:
Milos Kozak 2019-12-03 15:29:14 +01:00
parent cca5fca86c
commit e4a5616298
6 changed files with 40 additions and 67 deletions

View file

@ -42,7 +42,6 @@ import info.nightscout.androidaps.activities.HistoryBrowseActivity;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.activities.PreferencesActivity; import info.nightscout.androidaps.activities.PreferencesActivity;
import info.nightscout.androidaps.activities.SingleFragmentActivity; import info.nightscout.androidaps.activities.SingleFragmentActivity;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRebuildTabs; import info.nightscout.androidaps.events.EventRebuildTabs;
@ -51,7 +50,6 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtilsKt; import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtilsKt;
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
import info.nightscout.androidaps.setupwizard.SetupWizardActivity; import info.nightscout.androidaps.setupwizard.SetupWizardActivity;
@ -59,7 +57,6 @@ import info.nightscout.androidaps.tabs.TabPageAdapter;
import info.nightscout.androidaps.utils.AndroidPermission; import info.nightscout.androidaps.utils.AndroidPermission;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.LocaleHelper; import info.nightscout.androidaps.utils.LocaleHelper;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.PasswordProtection; import info.nightscout.androidaps.utils.PasswordProtection;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
@ -141,7 +138,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
.subscribe(this::processPreferenceChange, FabricPrivacy::logException) .subscribe(this::processPreferenceChange, FabricPrivacy::logException)
); );
if (!SP.getBoolean(R.string.key_setupwizard_processed, false)) { if (!SP.getBoolean(R.string.key_setupwizard_processed, false) || !SP.contains(R.string.key_units)) {
Intent intent = new Intent(this, SetupWizardActivity.class); Intent intent = new Intent(this, SetupWizardActivity.class);
startActivity(intent); startActivity(intent);
} else { } else {
@ -255,11 +252,6 @@ public class MainActivity extends NoSplashAppCompatActivity {
SP.remove(R.string.key_pump_unreachable_threshold); SP.remove(R.string.key_pump_unreachable_threshold);
if (unreachable_threshold < 30) unreachable_threshold = 30; if (unreachable_threshold < 30) unreachable_threshold = 30;
SP.putString(R.string.key_pump_unreachable_threshold, Integer.toString(unreachable_threshold)); SP.putString(R.string.key_pump_unreachable_threshold, Integer.toString(unreachable_threshold));
if (!SP.contains(R.string.key_units)) {
Intent intent = new Intent(this, SetupWizardActivity.class);
startActivity(intent);
}
} }

View file

@ -30,6 +30,7 @@ import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.utils.OKDialog; import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.ToastUtils; import info.nightscout.androidaps.utils.ToastUtils;
/** /**
@ -113,27 +114,24 @@ public class ImportExportPrefs {
.setMessage(MainApp.gs(R.string.import_from) + " " + file + " ?") .setMessage(MainApp.gs(R.string.import_from) + " " + file + " ?")
.setPositiveButton(android.R.string.yes, (dialog, which) -> { .setPositiveButton(android.R.string.yes, (dialog, which) -> {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
String line; String line;
String[] lineParts; String[] lineParts;
try { try {
editor.clear(); SP.clear();
editor.commit();
BufferedReader reader = new BufferedReader(new FileReader(file)); BufferedReader reader = new BufferedReader(new FileReader(file));
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
lineParts = line.split("::"); lineParts = line.split("::");
if (lineParts.length == 2) { if (lineParts.length == 2) {
if (lineParts[1].equals("true") || lineParts[1].equals("false")) { if (lineParts[1].equals("true") || lineParts[1].equals("false")) {
editor.putBoolean(lineParts[0], Boolean.parseBoolean(lineParts[1])); SP.putBoolean(lineParts[0], Boolean.parseBoolean(lineParts[1]));
} else { } else {
editor.putString(lineParts[0], lineParts[1]); SP.putString(lineParts[0], lineParts[1]);
} }
} }
} }
reader.close(); reader.close();
editor.commit(); SP.putBoolean(R.string.key_setupwizard_processed, true);
OKDialog.show(context, MainApp.gs(R.string.setting_imported), MainApp.gs(R.string.restartingapp), () -> { OKDialog.show(context, MainApp.gs(R.string.setting_imported), MainApp.gs(R.string.restartingapp), () -> {
log.debug("Exiting"); log.debug("Exiting");
MainApp.instance().stopKeepAliveService(); MainApp.instance().stopKeepAliveService();

View file

@ -72,18 +72,6 @@ public class SetupWizardActivity extends NoSplashAppCompatActivity {
} }
} }
@Override
public void onBackPressed() {
if (currentWizardPage == 0)
OKDialog.showConfirmation(this, MainApp.gs(R.string.exitwizard), this::finish);
else showPreviousPage(null);
}
public void exitPressed(View view) {
SP.putBoolean(R.string.key_setupwizard_processed, true);
OKDialog.showConfirmation(this, MainApp.gs(R.string.exitwizard), this::finish);
}
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
@ -157,6 +145,18 @@ public class SetupWizardActivity extends NoSplashAppCompatActivity {
}); });
} }
@Override
public void onBackPressed() {
if (currentWizardPage == 0)
OKDialog.showConfirmation(this, MainApp.gs(R.string.exitwizard), this::finish);
else showPreviousPage(null);
}
public void exitPressed(View view) {
SP.putBoolean(R.string.key_setupwizard_processed, true);
OKDialog.showConfirmation(this, MainApp.gs(R.string.exitwizard), this::finish);
}
public void showNextPage(View view) { public void showNextPage(View view) {
this.finish(); this.finish();
Intent intent = new Intent(this, SetupWizardActivity.class); Intent intent = new Intent(this, SetupWizardActivity.class);

View file

@ -3,6 +3,8 @@ package info.nightscout.androidaps.setupwizard.elements;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.annotation.StringRes;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -67,12 +69,12 @@ public class SWItem {
return type; return type;
} }
public SWItem label(int label) { public SWItem label(@StringRes int label) {
this.label = label; this.label = label;
return this; return this;
} }
public SWItem comment(int comment) { public SWItem comment(@StringRes int comment) {
this.comment = comment; this.comment = comment;
return this; return this;
} }

View file

@ -10,7 +10,11 @@ import info.nightscout.androidaps.MainApp;
*/ */
public class SP { public class SP {
static SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); private static SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
static public void clear() {
sharedPreferences.edit().clear().apply();
}
static public boolean contains(String key) { static public boolean contains(String key) {
return sharedPreferences.contains(key); return sharedPreferences.contains(key);
@ -85,75 +89,51 @@ public class SP {
} }
static public void putBoolean(String key, boolean value) { static public void putBoolean(String key, boolean value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); sharedPreferences.edit().putBoolean(key, value).apply();
editor.putBoolean(key, value);
editor.apply();
} }
static public void putBoolean(int resourceID, boolean value) { static public void putBoolean(int resourceID, boolean value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); sharedPreferences.edit().putBoolean(MainApp.gs(resourceID), value).apply();
editor.putBoolean(MainApp.gs(resourceID), value);
editor.apply();
} }
static public void putDouble(String key, double value) { static public void putDouble(String key, double value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); sharedPreferences.edit().putString(key, Double.toString(value)).apply();
editor.putString(key, Double.toString(value));
editor.apply();
} }
static public void putLong(String key, long value) { static public void putLong(String key, long value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); sharedPreferences.edit().putLong(key, value).apply();
editor.putLong(key, value);
editor.apply();
} }
static public void putLong(int resourceID, long value) { static public void putLong(int resourceID, long value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); sharedPreferences.edit().putLong(MainApp.gs(resourceID), value).apply();
editor.putLong(MainApp.gs(resourceID), value);
editor.apply();
} }
static public void putInt(String key, int value) { static public void putInt(String key, int value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); sharedPreferences.edit().putInt(key, value).apply();
editor.putInt(key, value);
editor.apply();
} }
static public void putInt(int resourceID, int value) { static public void putInt(int resourceID, int value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); sharedPreferences.edit().putInt(MainApp.gs(resourceID), value).apply();
editor.putInt(MainApp.gs(resourceID), value);
editor.apply();
} }
static public void incInt(int resourceID) { static public void incInt(int resourceID) {
SharedPreferences.Editor editor = sharedPreferences.edit();
int value = SP.getInt(resourceID, 0) + 1; int value = SP.getInt(resourceID, 0) + 1;
editor.putInt(MainApp.gs(resourceID), value); sharedPreferences.edit().putInt(MainApp.gs(resourceID), value).apply();
editor.apply();
} }
static public void putString(int resourceID, String value) { static public void putString(int resourceID, String value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); sharedPreferences.edit().putString(MainApp.gs(resourceID), value).apply();
editor.putString(MainApp.gs(resourceID), value);
editor.apply();
} }
static public void putString(String key, String value) { static public void putString(String key, String value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); sharedPreferences.edit().putString(key, value).apply();
editor.putString(key, value);
editor.apply();
} }
static public void remove(int resourceID) { static public void remove(int resourceID) {
SharedPreferences.Editor editor = sharedPreferences.edit(); sharedPreferences.edit().remove(MainApp.gs(resourceID)).apply();
editor.remove(MainApp.gs(resourceID));
editor.apply();
} }
static public void remove(String key) { static public void remove(String key) {
SharedPreferences.Editor editor = sharedPreferences.edit(); sharedPreferences.edit().remove(key).apply();
editor.remove(key);
editor.apply();
} }
} }

View file

@ -29,6 +29,7 @@
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/exit" android:text="@string/exit"
android:onClick="exitPressed"
android:textAppearance="@android:style/TextAppearance.Material.Medium" android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:textStyle="bold" /> android:textStyle="bold" />
</LinearLayout> </LinearLayout>