2018-04-20 17:27:31 +02:00
|
|
|
package info.nightscout.androidaps.startupwizard;
|
|
|
|
|
2018-04-23 16:03:22 +02:00
|
|
|
import android.content.Intent;
|
2018-04-20 17:27:31 +02:00
|
|
|
import android.os.Bundle;
|
2018-05-03 16:04:56 +02:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2018-04-20 17:27:31 +02:00
|
|
|
import android.view.View;
|
2018-04-23 14:58:27 +02:00
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2018-04-25 10:03:33 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2018-04-25 14:29:20 +02:00
|
|
|
import java.util.ArrayList;
|
2018-04-23 14:58:27 +02:00
|
|
|
import java.util.List;
|
2018-04-20 17:27:31 +02:00
|
|
|
|
2018-04-26 15:59:56 +02:00
|
|
|
import info.nightscout.androidaps.MainActivity;
|
2018-04-30 15:41:40 +02:00
|
|
|
import info.nightscout.androidaps.MainApp;
|
2018-04-20 17:27:31 +02:00
|
|
|
import info.nightscout.androidaps.R;
|
2018-04-30 15:41:40 +02:00
|
|
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
|
|
|
import info.nightscout.utils.LocaleHelper;
|
2018-04-26 14:59:08 +02:00
|
|
|
import info.nightscout.utils.SP;
|
2018-04-20 17:27:31 +02:00
|
|
|
|
|
|
|
public class SetupWizardActivity extends AppCompatActivity {
|
2018-05-03 16:04:56 +02:00
|
|
|
private List<String> labels = new ArrayList<>();
|
|
|
|
private List<String> comments = new ArrayList<>();
|
2018-04-25 14:29:20 +02:00
|
|
|
|
2018-04-23 14:58:27 +02:00
|
|
|
private TextView screenName;
|
2018-05-03 16:04:56 +02:00
|
|
|
|
|
|
|
//logging
|
2018-04-25 10:03:33 +02:00
|
|
|
private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class);
|
2018-05-03 16:04:56 +02:00
|
|
|
|
2018-04-25 14:29:20 +02:00
|
|
|
private int currentWizardPage = 0;
|
2018-04-23 16:03:22 +02:00
|
|
|
public static final String INTENT_MESSAGE = "WIZZARDPAGE";
|
2018-04-20 17:27:31 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_setupwizard);
|
2018-04-23 14:58:27 +02:00
|
|
|
|
2018-04-23 16:03:22 +02:00
|
|
|
Intent intent = getIntent();
|
2018-05-03 16:04:56 +02:00
|
|
|
int showPage = intent.getIntExtra(SetupWizardActivity.INTENT_MESSAGE, 0);
|
2018-04-23 14:58:27 +02:00
|
|
|
SWDefinition swDefinition = SWDefinition.getInstance();
|
|
|
|
List<SWScreen> screens = swDefinition.getScreens();
|
2018-05-03 16:04:56 +02:00
|
|
|
if (screens.size() > 0 && showPage < screens.size()) {
|
2018-04-23 16:03:22 +02:00
|
|
|
SWScreen currentScreen = screens.get(showPage);
|
2018-04-25 16:02:10 +02:00
|
|
|
currentWizardPage = showPage;
|
2018-04-23 16:03:22 +02:00
|
|
|
// show/hide prev/next buttons if we are at the beninning/end
|
2018-04-26 15:59:56 +02:00
|
|
|
//showNextButton(showPage, screens.size()-1);
|
|
|
|
|
2018-05-03 16:04:56 +02:00
|
|
|
if (showPage == 0)
|
2018-04-23 16:03:22 +02:00
|
|
|
((Button) findViewById(R.id.previous_button)).setVisibility(View.GONE);
|
2018-04-23 14:58:27 +02:00
|
|
|
//Set screen name
|
|
|
|
screenName = (TextView) findViewById(R.id.fullscreen_content);
|
|
|
|
screenName.setText(currentScreen.getHeader());
|
|
|
|
|
2018-04-27 12:30:45 +02:00
|
|
|
//Generate layout first
|
|
|
|
LinearLayout layout = info.nightscout.androidaps.startupwizard.SWItem.generateLayout(this.findViewById(R.id.fullscreen_content_fields));
|
2018-05-03 16:04:56 +02:00
|
|
|
for (int i = 0; i < currentScreen.items.size(); i++) {
|
2018-04-23 14:58:27 +02:00
|
|
|
SWItem currentItem = currentScreen.items.get(i);
|
2018-05-03 16:04:56 +02:00
|
|
|
labels.add(i, currentItem.getLabel());
|
|
|
|
comments.add(i, currentItem.getComment());
|
2018-04-27 12:30:45 +02:00
|
|
|
currentItem.setOptions(labels, comments);
|
|
|
|
currentItem.generateDialog(this.findViewById(R.id.fullscreen_content_fields), layout);
|
|
|
|
}
|
|
|
|
// Check if input isValid or screen is sckippable
|
2018-05-03 16:04:56 +02:00
|
|
|
if (currentScreen.validator.isValid() || currentScreen.skippable) {
|
2018-04-27 12:30:45 +02:00
|
|
|
showNextButton(showPage, screens.size() - 1);
|
2018-04-23 14:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-20 17:27:31 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 15:41:40 +02:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
|
|
|
|
super.onResume();
|
|
|
|
// check is current locale is different from the one in preferences
|
|
|
|
// log.debug("Current: "+LocaleHelper.getLanguage(this)+" preferences: "+SP.getString("language", "en"));
|
2018-05-03 16:04:56 +02:00
|
|
|
if (!LocaleHelper.getLanguage(this).equals(SP.getString("language", "en"))) {
|
2018-04-30 15:41:40 +02:00
|
|
|
// it is so change it in locale and restart SetupWizard
|
|
|
|
// log.debug("Setting locale to: "+SP.getString("language", "en")+" and restarting");
|
|
|
|
LocaleHelper.setLocale(this, SP.getString(R.string.key_language, "en"));
|
|
|
|
MainApp.bus().post(new EventRefreshGui(true));
|
|
|
|
Intent intent = getIntent();
|
|
|
|
this.finish();
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-03 16:04:56 +02:00
|
|
|
private void showNextButton(int currentPage, int maxPages) {
|
|
|
|
if (currentPage == maxPages) {
|
2018-04-26 15:59:56 +02:00
|
|
|
((Button) findViewById(R.id.finish_button)).setVisibility(View.VISIBLE);
|
|
|
|
((Button) findViewById(R.id.next_button)).setVisibility(View.GONE);
|
|
|
|
} else
|
|
|
|
((Button) findViewById(R.id.next_button)).setVisibility(View.VISIBLE);
|
|
|
|
}
|
2018-04-23 14:58:27 +02:00
|
|
|
|
2018-04-23 16:03:22 +02:00
|
|
|
public void showNextPage(View view) {
|
|
|
|
Intent intent = new Intent(this, SetupWizardActivity.class);
|
2018-04-25 14:29:20 +02:00
|
|
|
intent.putExtra(INTENT_MESSAGE, currentWizardPage + 1);
|
2018-04-23 16:03:22 +02:00
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showPreviousPage(View view) {
|
|
|
|
Intent intent = new Intent(this, SetupWizardActivity.class);
|
2018-05-03 16:04:56 +02:00
|
|
|
if (currentWizardPage > 0)
|
2018-04-25 14:29:20 +02:00
|
|
|
intent.putExtra(INTENT_MESSAGE, currentWizardPage - 1);
|
2018-04-23 16:03:22 +02:00
|
|
|
else
|
|
|
|
intent.putExtra(INTENT_MESSAGE, 0);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2018-04-26 15:59:56 +02:00
|
|
|
// Go back to overview
|
2018-05-03 16:04:56 +02:00
|
|
|
public void finishSetupWizard(View view) {
|
|
|
|
Intent intent = new Intent(this, MainActivity.class);
|
|
|
|
startActivity(intent);
|
2018-04-26 15:59:56 +02:00
|
|
|
}
|
2018-04-30 15:41:40 +02:00
|
|
|
|
2018-05-03 16:04:56 +02:00
|
|
|
}
|