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.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2018-05-03 20:06:13 +02:00
|
|
|
import com.squareup.otto.Subscribe;
|
|
|
|
|
2018-04-25 10:03:33 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
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-05-03 20:06:13 +02:00
|
|
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
|
|
|
|
import info.nightscout.androidaps.startupwizard.events.EventSWUpdate;
|
2018-04-30 15:41:40 +02:00
|
|
|
import info.nightscout.utils.LocaleHelper;
|
2018-04-20 17:27:31 +02:00
|
|
|
|
|
|
|
public class SetupWizardActivity extends AppCompatActivity {
|
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-05-03 20:06:13 +02:00
|
|
|
private TextView screenName;
|
|
|
|
|
|
|
|
SWDefinition swDefinition = SWDefinition.getInstance();
|
|
|
|
List<SWScreen> screens = swDefinition.getScreens();
|
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);
|
2018-05-03 20:06:13 +02:00
|
|
|
LocaleHelper.onCreate(this, "en");
|
2018-04-20 17:27:31 +02:00
|
|
|
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 20:06:13 +02:00
|
|
|
currentWizardPage = intent.getIntExtra(SetupWizardActivity.INTENT_MESSAGE, 0);
|
|
|
|
if (screens.size() > 0 && currentWizardPage < screens.size()) {
|
|
|
|
SWScreen currentScreen = screens.get(currentWizardPage);
|
|
|
|
|
2018-04-23 14:58:27 +02:00
|
|
|
//Set screen name
|
2018-05-03 21:29:34 +02:00
|
|
|
screenName = (TextView) findViewById(R.id.sw_content);
|
2018-04-23 14:58:27 +02:00
|
|
|
screenName.setText(currentScreen.getHeader());
|
|
|
|
|
2018-04-27 12:30:45 +02:00
|
|
|
//Generate layout first
|
2018-05-04 10:17:50 +02:00
|
|
|
generateLayout();
|
2018-05-03 20:06:13 +02:00
|
|
|
updateButtons();
|
2018-04-23 14:58:27 +02:00
|
|
|
}
|
2018-05-03 20:06:13 +02:00
|
|
|
}
|
2018-04-23 14:58:27 +02:00
|
|
|
|
2018-05-03 20:06:13 +02:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
MainApp.bus().unregister(this);
|
2018-04-20 17:27:31 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 15:41:40 +02:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2018-05-03 20:06:13 +02:00
|
|
|
MainApp.bus().register(this);
|
2018-04-30 15:41:40 +02:00
|
|
|
}
|
|
|
|
|
2018-05-03 20:06:13 +02:00
|
|
|
@Subscribe
|
|
|
|
public void onContentUpdate(EventSWUpdate ev) {
|
2018-05-04 10:17:50 +02:00
|
|
|
if (ev.redraw)
|
|
|
|
generateLayout();
|
2018-05-03 20:06:13 +02:00
|
|
|
updateButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Subscribe
|
|
|
|
public void onContentUpdate(EventNSClientStatus ev) {
|
|
|
|
updateButtons();
|
|
|
|
}
|
|
|
|
|
2018-05-04 10:17:50 +02:00
|
|
|
private void generateLayout() {
|
|
|
|
SWScreen currentScreen = screens.get(currentWizardPage);
|
|
|
|
LinearLayout layout = SWItem.generateLayout(this.findViewById(R.id.sw_content_fields));
|
|
|
|
for (int i = 0; i < currentScreen.items.size(); i++) {
|
|
|
|
SWItem currentItem = currentScreen.items.get(i);
|
|
|
|
currentItem.generateDialog(this.findViewById(R.id.sw_content_fields), layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-03 20:06:13 +02:00
|
|
|
private void updateButtons() {
|
|
|
|
SWScreen currentScreen = screens.get(currentWizardPage);
|
2018-05-09 11:55:21 +02:00
|
|
|
if (currentScreen.validator == null || currentScreen.validator.isValid() || currentScreen.skippable) {
|
2018-05-03 20:06:13 +02:00
|
|
|
if (currentWizardPage == screens.size() - 1) {
|
|
|
|
findViewById(R.id.finish_button).setVisibility(View.VISIBLE);
|
|
|
|
findViewById(R.id.next_button).setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
findViewById(R.id.finish_button).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.next_button).setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
findViewById(R.id.finish_button).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.next_button).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (currentWizardPage == 0)
|
|
|
|
findViewById(R.id.previous_button).setVisibility(View.GONE);
|
|
|
|
else
|
|
|
|
findViewById(R.id.previous_button).setVisibility(View.VISIBLE);
|
2018-04-26 15:59:56 +02:00
|
|
|
}
|
2018-04-23 14:58:27 +02:00
|
|
|
|
2018-04-23 16:03:22 +02:00
|
|
|
public void showNextPage(View view) {
|
2018-05-03 20:06:13 +02:00
|
|
|
this.finish();
|
2018-04-23 16:03:22 +02:00
|
|
|
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) {
|
2018-05-03 20:06:13 +02:00
|
|
|
this.finish();
|
2018-04-23 16:03:22 +02:00
|
|
|
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
|
|
|
}
|