other screens

This commit is contained in:
Roumen Georgiev 2018-05-03 16:59:23 +03:00
parent 083730f476
commit 425ba77200
6 changed files with 163 additions and 29 deletions

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.startupwizard; package info.nightscout.androidaps.startupwizard;
import android.content.Context;
import android.content.Intent;
import android.widget.RadioButton; import android.widget.RadioButton;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -14,7 +16,6 @@ import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin; import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin;
@ -24,7 +25,6 @@ import info.nightscout.utils.SP;
public class SWDefinition { public class SWDefinition {
private static Logger log = LoggerFactory.getLogger(SWDefinition.class); private static Logger log = LoggerFactory.getLogger(SWDefinition.class);
private static SWDefinition swDefinition = null; private static SWDefinition swDefinition = null;
public static SWDefinition getInstance() { public static SWDefinition getInstance() {
if (swDefinition == null) if (swDefinition == null)
swDefinition = new SWDefinition(); swDefinition = new SWDefinition();
@ -43,6 +43,8 @@ public class SWDefinition {
return this; return this;
} }
SWDefinition() { SWDefinition() {
// List all the screens here // List all the screens here
// todo: SWValidator ?!? // todo: SWValidator ?!?
@ -50,21 +52,112 @@ public class SWDefinition {
.skippable(false) .skippable(false)
.add(new SWRadioButton().option(R.array.languagesArray, R.array.languagesValues).preferenceId(R.string.key_language).label(R.string.language).comment(R.string.setupwizard_language_prompt)) .add(new SWRadioButton().option(R.array.languagesArray, R.array.languagesValues).preferenceId(R.string.key_language).label(R.string.language).comment(R.string.setupwizard_language_prompt))
.validator(() -> { .validator(() -> {
context = MainApp.instance().getApplicationContext();
LocaleHelper.setLocale(context, SP.getString(R.string.key_language, "en")); LocaleHelper.setLocale(context, SP.getString(R.string.key_language, "en"));
MainApp.bus().post(new EventRefreshGui(true)); MainApp.bus().post(new EventRefreshGui(true));
if(!SP.getString(R.string.key_language, "en").equals(LocaleHelper.getLanguage(context))) {
Intent intent = new Intent(MainApp.instance().getApplicationContext(), SetupWizardActivity.class);
intent.putExtra("WIZZARDPAGE", 0);
SetupWizardActivity.instance().finish();
SetupWizardActivity.instance().startActivity(intent);
}
return SP.contains(R.string.key_language);} return SP.contains(R.string.key_language);}
)) ))
.add(new SWScreen(R.string.nsclientinternal_title) .add(new SWScreen(R.string.nsclientinternal_title)
.skippable(true) .skippable(true)
.add(new SWUrl().preferenceId(R.string.key_nsclientinternal_url).label(R.string.nsclientinternal_url_title).comment(R.string.nsclientinternal_url_dialogmessage)) .add(new SWUrl().preferenceId(R.string.key_nsclientinternal_url).label(R.string.nsclientinternal_url_title).comment(R.string.nsclientinternal_url_dialogmessage))
.add(new SWString().preferenceId(R.string.key_nsclientinternal_api_secret).label(R.string.nsclientinternal_secret_dialogtitle).comment(R.string.nsclientinternal_secret_dialogmessage)) .add(new SWString().preferenceId(R.string.key_nsclientinternal_api_secret).label(R.string.nsclientinternal_secret_dialogtitle).comment(R.string.nsclientinternal_secret_dialogmessage))
.validator(() -> NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth) .validator(() -> {
// Check for the correct locale set and restart if not
log.debug("key is: "+SP.getString(R.string.key_language,"unset")+" Locale is "+LocaleHelper.getLanguage(context));
if(!SP.getString(R.string.key_language, "en").equals(LocaleHelper.getLanguage(context))) {
LocaleHelper.setLocale(context, SP.getString(R.string.key_language, "en"));
MainApp.bus().post(new EventRefreshGui(true));
Intent intent = new Intent(MainApp.instance().getApplicationContext(), SetupWizardActivity.class);
intent.putExtra("WIZZARDPAGE", 0);
SetupWizardActivity.instance().finish();
SetupWizardActivity.instance().startActivity(intent);
}
return NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth;
})
) )
.add(new SWScreen(R.string.patientage) .add(new SWScreen(R.string.patientage)
.skippable(false) .skippable(false)
.add(new SWRadioButton().option(R.array.ageArray, R.array.ageValues).preferenceId(R.string.key_age).label(R.string.patientage).comment(R.string.patientage_summary)) .add(new SWRadioButton().option(R.array.ageArray, R.array.ageValues).preferenceId(R.string.key_age).label(R.string.patientage).comment(R.string.patientage_summary))
.validator(() -> SP.contains(R.string.key_age)) .validator(() -> {
return SP.contains(R.string.key_age);
})
)
.add(new SWScreen(R.string.configbuilder_insulin)
.skippable(false)
.add(new SWRadioButton().option(R.array.insulinArray, R.array.insulinValues).preferenceId(R.string.configbuilder_insulin).label(R.string.configbuilder_insulin).comment(R.string.configbuilder_insulin))
.validator(() -> {
ArrayList<PluginBase> pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.INSULIN);
ConfigBuilderPlugin configBuilder = ConfigBuilderPlugin.getPlugin();
BgSourceInterface activeSource = configBuilder.getActiveBgSource();
if (activeSource == null) {
activeSource = SourceNSClientPlugin.getPlugin();
configBuilder.setPluginEnabled(PluginType.INSULIN, true);
}
// new plugin selected -> disable others
for (PluginBase p : pluginsInCategory) {
log.debug("Name is: "+ p.getClass().getSimpleName() + " setting is: "+SP.getString(R.string.configbuilder_insulin, "InsulinOrefRapidActingPlugin"));
if (p.getClass().getSimpleName().equals(SP.getString(R.string.configbuilder_insulin, "InsulinOrefRapidActingPlugin"))) {
// this is new selected
p.setPluginEnabled(PluginType.INSULIN, true);
p.setFragmentVisible(PluginType.INSULIN, true);
String settingVisible = "ConfigBuilder_" + PluginType.INSULIN.name() + "_" + p.getClass().getSimpleName() + "_Visible";
String settingEnabled = "ConfigBuilder_" + PluginType.INSULIN.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
log.debug("Setting to: "+settingEnabled);
SP.putBoolean(settingEnabled, true);
SP.putBoolean(settingVisible, true);
} else {
String settingEnabled = "ConfigBuilder_" + PluginType.INSULIN.name() + "_" + p.getName() + "_Enabled";
log.debug("Disable: "+settingEnabled);
p.setPluginEnabled(PluginType.INSULIN, false);
p.setFragmentVisible(PluginType.INSULIN, false);
}
}
String settingVisible = "ConfigBuilder_" + PluginType.INSULIN.name() + "_" + SP.getString(R.string.configbuilder_insulin,"InsulinOrefRapidActingPlugin") + "_Visible";
SP.putBoolean(settingVisible, true);
return SP.contains(R.string.configbuilder_insulin);
})
)
.add(new SWScreen(R.string.configbuilder_aps)
.skippable(false)
.add(new SWRadioButton().option(R.array.apsArray, R.array.apsValues).preferenceId(R.string.configbuilder_aps).label(R.string.configbuilder_aps).comment(R.string.configbuilder_aps))
.validator(() -> {
ArrayList<PluginBase> pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.APS);
ConfigBuilderPlugin configBuilder = ConfigBuilderPlugin.getPlugin();
BgSourceInterface activeSource = configBuilder.getActiveBgSource();
if (activeSource == null) {
activeSource = SourceNSClientPlugin.getPlugin();
configBuilder.setPluginEnabled(PluginType.APS, true);
}
// new plugin selected -> disable others
for (PluginBase p : pluginsInCategory) {
log.debug("Name is: "+ p.getClass().getSimpleName() + " setting is: "+SP.getString(R.string.configbuilder_aps, "OpenAPSMA"));
if (p.getClass().getSimpleName().equals(SP.getString(R.string.configbuilder_aps, "OpenAPSMA"))) {
// this is new selected
p.setPluginEnabled(PluginType.APS, true);
p.setFragmentVisible(PluginType.APS, true);
String settingVisible = "ConfigBuilder_" + PluginType.APS.name() + "_" + p.getClass().getSimpleName() + "_Visible";
String settingEnabled = "ConfigBuilder_" + PluginType.APS.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
log.debug("Setting to: "+settingEnabled);
SP.putBoolean(settingEnabled, true);
SP.putBoolean(settingVisible, true);
} else {
String settingEnabled = "ConfigBuilder_" + PluginType.APS.name() + "_" + p.getName() + "_Enabled";
log.debug("Disable: "+settingEnabled);
p.setPluginEnabled(PluginType.APS, false);
p.setFragmentVisible(PluginType.APS, false);
}
}
String settingVisible = "ConfigBuilder_" + PluginType.APS.name() + "_" + SP.getString(R.string.configbuilder_aps,"OpenAPSMA") + "_Visible";
SP.putBoolean(settingVisible, true);
return SP.contains(settingVisible);
})
) )
.add(new SWScreen(R.string.configbuilder_bgsource) .add(new SWScreen(R.string.configbuilder_bgsource)
.skippable(false) .skippable(false)
@ -77,8 +170,6 @@ public class SWDefinition {
activeSource = SourceNSClientPlugin.getPlugin(); activeSource = SourceNSClientPlugin.getPlugin();
configBuilder.setPluginEnabled(PluginType.BGSOURCE, true); configBuilder.setPluginEnabled(PluginType.BGSOURCE, true);
} }
// this.setFragmentVisiblities(((PluginBase) activeSource).getName(), pluginsInCategory, PluginType.BGSOURCE);
// String settingEnabled = "ConfigBuilder_" + PluginType.BGSOURCE.name() + "_" + SP.getString(R.string.configbuilder_bgsource, "SourceNSClientPlugin") + "_Enabled";
// new plugin selected -> disable others // new plugin selected -> disable others
for (PluginBase p : pluginsInCategory) { for (PluginBase p : pluginsInCategory) {
log.debug("Name is: "+ p.getClass().getSimpleName() + " setting is: "+SP.getString(R.string.configbuilder_bgsource, "SourceNSClient")); log.debug("Name is: "+ p.getClass().getSimpleName() + " setting is: "+SP.getString(R.string.configbuilder_bgsource, "SourceNSClient"));
@ -98,17 +189,12 @@ public class SWDefinition {
p.setFragmentVisible(PluginType.BGSOURCE, false); p.setFragmentVisible(PluginType.BGSOURCE, false);
} }
} }
// Enable plugin
// log.debug("Setting: "+settingEnabled);
// SP.putBoolean(settingEnabled, true);
String settingVisible = "ConfigBuilder_" + PluginType.BGSOURCE.name() + "_" + SP.getString(R.string.configbuilder_bgsource,"SourceNSClientPlugin") + "_Visible"; String settingVisible = "ConfigBuilder_" + PluginType.BGSOURCE.name() + "_" + SP.getString(R.string.configbuilder_bgsource,"SourceNSClientPlugin") + "_Visible";
SP.putBoolean(settingVisible, true); SP.putBoolean(settingVisible, true);
MainApp.bus().post(new EventRefreshGui(true));
return SP.contains(R.string.configbuilder_bgsource); return SP.contains(R.string.configbuilder_bgsource);
}) })
) )
; ;
} }

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.startupwizard; package info.nightscout.androidaps.startupwizard;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RadioButton; import android.widget.RadioButton;
@ -11,8 +12,10 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -29,6 +32,7 @@ public class SWRadioButton extends SWItem {
} }
public SWRadioButton option(int labels, int values) { public SWRadioButton option(int labels, int values) {
this.labelsArray = labels; this.labelsArray = labels;
this.valuesArray = values; this.valuesArray = values;
return this; return this;
@ -45,8 +49,6 @@ public class SWRadioButton extends SWItem {
@Override @Override
public void generateDialog(View view, LinearLayout layout){ public void generateDialog(View view, LinearLayout layout){
Context context = view.getContext(); Context context = view.getContext();
// LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
// layout.removeAllViews();
String[] labels = context.getResources().getStringArray(labelsArray); String[] labels = context.getResources().getStringArray(labelsArray);
String[] values = context.getResources().getStringArray(valuesArray); String[] values = context.getResources().getStringArray(valuesArray);
// Get if there is already value in SP // Get if there is already value in SP
@ -74,6 +76,7 @@ public class SWRadioButton extends SWItem {
@Override @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { public void onCheckedChanged(RadioGroup group, int checkedId) {
save(); save();
MainApp.bus().post(new EventRefreshGui(true));
} }
}); });

View file

@ -1,9 +1,19 @@
package info.nightscout.androidaps.startupwizard; package info.nightscout.androidaps.startupwizard;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.ActivityCompat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.utils.LocaleHelper;
import info.nightscout.utils.SP;
public class SWScreen { public class SWScreen {
@ -40,4 +50,5 @@ public class SWScreen {
return validator.isValid(); return validator.isValid();
return true; return true;
} }
} }

View file

@ -1,6 +1,9 @@
package info.nightscout.androidaps.startupwizard; package info.nightscout.androidaps.startupwizard;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -39,7 +42,7 @@ public class SetupWizardActivity extends AppCompatActivity {
* Whether or not the system UI should be auto-hidden after * Whether or not the system UI should be auto-hidden after
* {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds. * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
*/ */
private static final boolean AUTO_HIDE = true; private static final boolean AUTO_HIDE = false;
/** /**
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
@ -66,7 +69,7 @@ public class SetupWizardActivity extends AppCompatActivity {
private Button skipButton; private Button skipButton;
//logiing //logiing
private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class); private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class);
private static SetupWizardActivity mWizardActivity;
private int currentWizardPage = 0; private int currentWizardPage = 0;
public static final String INTENT_MESSAGE = "WIZZARDPAGE"; public static final String INTENT_MESSAGE = "WIZZARDPAGE";
private final Runnable mHidePart2Runnable = new Runnable() { private final Runnable mHidePart2Runnable = new Runnable() {
@ -124,7 +127,7 @@ public class SetupWizardActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setupwizard); setContentView(R.layout.activity_setupwizard);
mWizardActivity = this;
mVisible = true; mVisible = true;
mControlsView = findViewById(R.id.fullscreen_content_controls); mControlsView = findViewById(R.id.fullscreen_content_controls);
mContentView = findViewById(R.id.fullscreen_content); mContentView = findViewById(R.id.fullscreen_content);
@ -226,8 +229,8 @@ public class SetupWizardActivity extends AppCompatActivity {
if (actionBar != null) { if (actionBar != null) {
actionBar.hide(); actionBar.hide();
} }
mControlsView.setVisibility(View.GONE); mControlsView.setVisibility(View.VISIBLE);
mVisible = false; mVisible = true;
// Schedule a runnable to remove the status and navigation bar after a delay // Schedule a runnable to remove the status and navigation bar after a delay
mHideHandler.removeCallbacks(mShowPart2Runnable); mHideHandler.removeCallbacks(mShowPart2Runnable);
@ -281,8 +284,18 @@ public class SetupWizardActivity extends AppCompatActivity {
// Go back to overview // Go back to overview
public void finishSetupWizard(View view){ public void finishSetupWizard(View view){
Intent intent = new Intent(this, MainActivity.class); // restart app
startActivity(intent); Context context = getApplicationContext();
Intent mStartActivity = new Intent(context, MainActivity.class);
int mPendingIntentId = 123456;
PendingIntent mPendingIntent = PendingIntent.getActivity(context, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
System.exit(0);
}
public static SetupWizardActivity instance(){
return mWizardActivity;
} }
} }

View file

@ -44,6 +44,7 @@
android:layout_gravity="bottom|center_horizontal" android:layout_gravity="bottom|center_horizontal"
android:background="@color/black_overlay" android:background="@color/black_overlay"
android:orientation="horizontal" android:orientation="horizontal"
android:visibility="visible"
tools:ignore="UselessParent"> tools:ignore="UselessParent">
<Button <Button
@ -66,14 +67,14 @@
android:visibility="invisible" /> android:visibility="invisible" />
<Button <Button
android:id="@+id/next_button" android:id="@+id/next_button"
style="?metaButtonBarButtonStyle" style="?metaButtonBarButtonStyle"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:onClick="showNextPage" android:onClick="showNextPage"
android:text="@string/setupwizard_next" android:text="@string/setupwizard_next"
android:visibility="gone" /> android:visibility="gone" />
<Button <Button
android:id="@+id/finish_button" android:id="@+id/finish_button"

View file

@ -119,4 +119,24 @@
<item>SourceMM640gPlugin</item> <item>SourceMM640gPlugin</item>
<item>SourceGlimpPlugin</item> <item>SourceGlimpPlugin</item>
</string-array> </string-array>
<string-array name="insulinArray">
<item>@string/fastactinginsulincomment</item>
<item>@string/ultrafastactinginsulincomment</item>
<item>@string/free_peak_oref</item>
</string-array>
<string-array name="insulinValues" translatable="false">
<item>InsulinOrefRapidActingPlugin</item>
<item>InsulinOrefUltraRapidActingPlugin</item>
<item>InsulinOrefFreePeakPlugin</item>
</string-array>
<string-array name="apsArray">
<item>@string/openapsma</item>
<item>@string/openapsama</item>
<item>@string/openapssmb</item>
</string-array>
<string-array name="apsValues" translatable="false">
<item>OpenAPSMAPlugin</item>
<item>OpenAPSAMAPlugin</item>
<item>OpenAPSSMBPlugin</item>
</string-array>
</resources> </resources>