fix crashing at start

This commit is contained in:
Milos Kozak 2017-06-04 01:15:11 +02:00
parent 1702ce7702
commit 013025b750
5 changed files with 22 additions and 19 deletions

View file

@ -162,7 +162,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
if (!pm.isIgnoringBatteryOptimizations(packageName)) {
log.debug("Requesting ignore battery optimization");
OKDialog.show(this, getString(R.string.pleaseallowpermission), String.format(getString(R.string.needwhitelisting), getString(R.string.app_name)), new Runnable() {
OKDialog.show(getParent(), getString(R.string.pleaseallowpermission), String.format(getString(R.string.needwhitelisting), getString(R.string.app_name)), new Runnable() {
@Override
public void run() {

View file

@ -129,6 +129,8 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() == null)
return;
boolean allowProfileSwitch = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getProfileList().size() > 1;
if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !allowProfileSwitch)
profileSwitch.setVisibility(View.GONE);

View file

@ -1016,6 +1016,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
}
}
// Unable to determine profile, failover to default
if (activeProfile.getProfile() == null)
return null; //app not initialized
Profile defaultProfile = activeProfile.getProfile().getDefaultProfile();
if (defaultProfile != null)
return defaultProfile;

View file

@ -274,7 +274,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
showCobView = (CheckBox) view.findViewById(R.id.overview_showcob);
showDeviationsView = (CheckBox) view.findViewById(R.id.overview_showdeviations);
showPredictionView.setChecked(SP.getBoolean("showprediction", false));
showBasalsView.setChecked(SP.getBoolean("showbasals", false));
showBasalsView.setChecked(SP.getBoolean("showbasals", true));
showIobView.setChecked(SP.getBoolean("showiob", false));
showCobView.setChecked(SP.getBoolean("showcob", false));
showDeviationsView.setChecked(SP.getBoolean("showdeviations", false));
@ -891,27 +891,27 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
@SuppressLint("SetTextI18n")
public void updateGUI(String from) {
log.debug("updateGUI entered from: " + from);
if (MainApp.getConfigBuilder().getProfile() == null) {// app not initialized yet
pumpStatusView.setText(R.string.noprofileset);
pumpStatusLayout.setVisibility(View.VISIBLE);
loopStatusLayout.setVisibility(View.GONE);
return;
}
pumpStatusLayout.setVisibility(View.GONE);
loopStatusLayout.setVisibility(View.VISIBLE);
updateNotifications();
CareportalFragment.updateAge(getActivity(), sage, iage, cage, pbage);
BgReading actualBG = DatabaseHelper.actualBg();
BgReading lastBG = DatabaseHelper.lastBg();
// if (MainApp.getConfigBuilder().getActiveProfile().getProfile() == null) {// app not initialized yet
// pumpStatusView.setText(R.string.noprofileset);
// pumpStatusLayout.setVisibility(View.VISIBLE);
// loopStatusLayout.setVisibility(View.GONE);
// return;
// } else {
pumpStatusLayout.setVisibility(View.GONE);
loopStatusLayout.setVisibility(View.VISIBLE);
// }
PumpInterface pump = MainApp.getConfigBuilder();
// Skip if not initialized yet
if (bgGraph == null)
return;
Profile profile = MainApp.getConfigBuilder().getProfile();
if (getActivity() == null)
return;
@ -950,7 +950,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
// temp target
Profile profile = MainApp.getConfigBuilder().getProfile();
TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(new Date().getTime());
if (tempTarget != null) {
tempTargetView.setTextColor(Color.BLACK);

View file

@ -75,12 +75,12 @@ public class NSProfileFragment extends Fragment {
}
private void updateGUI() {
// if (nsProfilePlugin.profile == null) {
// noProfile.setVisibility(View.VISIBLE);
// return;
// } else {
// noProfile.setVisibility(View.GONE);
// }
if (MainApp.getConfigBuilder().getProfile() == null) {
noProfile.setVisibility(View.VISIBLE);
return;
} else {
noProfile.setVisibility(View.GONE);
}
Profile profile = MainApp.getConfigBuilder().getProfile();
units.setText(profile.getUnits());