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.PreferencesActivity;
import info.nightscout.androidaps.activities.SingleFragmentActivity;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange;
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.plugins.aps.loop.LoopPlugin;
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.general.nsclient.data.NSSettingsStatus;
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.FabricPrivacy;
import info.nightscout.androidaps.utils.LocaleHelper;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.PasswordProtection;
import info.nightscout.androidaps.utils.SP;
import io.reactivex.android.schedulers.AndroidSchedulers;
@ -141,7 +138,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
.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);
startActivity(intent);
} else {
@ -255,11 +252,6 @@ public class MainActivity extends NoSplashAppCompatActivity {
SP.remove(R.string.key_pump_unreachable_threshold);
if (unreachable_threshold < 30) unreachable_threshold = 30;
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.plugins.bus.RxBus;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.ToastUtils;
/**
@ -113,27 +114,24 @@ public class ImportExportPrefs {
.setMessage(MainApp.gs(R.string.import_from) + " " + file + " ?")
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
String line;
String[] lineParts;
try {
editor.clear();
editor.commit();
SP.clear();
BufferedReader reader = new BufferedReader(new FileReader(file));
while ((line = reader.readLine()) != null) {
lineParts = line.split("::");
if (lineParts.length == 2) {
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 {
editor.putString(lineParts[0], lineParts[1]);
SP.putString(lineParts[0], lineParts[1]);
}
}
}
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), () -> {
log.debug("Exiting");
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
public void 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) {
this.finish();
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.widget.LinearLayout;
import androidx.annotation.StringRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -67,12 +69,12 @@ public class SWItem {
return type;
}
public SWItem label(int label) {
public SWItem label(@StringRes int label) {
this.label = label;
return this;
}
public SWItem comment(int comment) {
public SWItem comment(@StringRes int comment) {
this.comment = comment;
return this;
}

View file

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

View file

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