Merge pull request #49 from AdrianLxM/disableLoopLongpress

Disable loop on Longpress on Loop-Status in Overview
This commit is contained in:
Milos Kozak 2016-11-07 10:14:14 +01:00 committed by GitHub
commit 925b5612fc
5 changed files with 40 additions and 6 deletions

View file

@ -76,7 +76,7 @@ public class MainActivity extends AppCompatActivity {
LocaleHelper.setLocale(getApplicationContext(), lang); LocaleHelper.setLocale(getApplicationContext(), lang);
recreate(); recreate();
try { // activity may be destroyed try { // activity may be destroyed
setUpTabs(true); setUpTabs(ev.isSwitchToLast());
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -37,7 +37,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
String lang = sharedPreferences.getString("language", "en"); String lang = sharedPreferences.getString("language", "en");
LocaleHelper.setLocale(getApplicationContext(), lang); LocaleHelper.setLocale(getApplicationContext(), lang);
recreate(); recreate();
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui(true));
} }
updatePrefSummary(myPreferenceFragment.getPreference(key)); updatePrefSummary(myPreferenceFragment.getPreference(key));
} }
@ -105,4 +105,4 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
return findPreference(key); return findPreference(key);
} }
} }
} }

View file

@ -4,4 +4,15 @@ package info.nightscout.androidaps.events;
* Created by mike on 13.06.2016. * Created by mike on 13.06.2016.
*/ */
public class EventRefreshGui { public class EventRefreshGui {
public boolean isSwitchToLast() {
return switchToLast;
}
private final boolean switchToLast;
public EventRefreshGui(boolean switchToLast){
this.switchToLast = switchToLast;
}
} }

View file

@ -178,7 +178,7 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase {
plugin.setFragmentVisible(type, cb.isChecked()); plugin.setFragmentVisible(type, cb.isChecked());
onEnabledCategoryChanged(plugin, type); onEnabledCategoryChanged(plugin, type);
configBuilderPlugin.storeSettings(); configBuilderPlugin.storeSettings();
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui(true));
} }
}); });
@ -188,7 +188,7 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase {
PluginBase plugin = (PluginBase) cb.getTag(); PluginBase plugin = (PluginBase) cb.getTag();
plugin.setFragmentVisible(type, cb.isChecked()); plugin.setFragmentVisible(type, cb.isChecked());
configBuilderPlugin.storeSettings(); configBuilderPlugin.storeSettings();
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui(true));
} }
}); });
} else { } else {

View file

@ -53,6 +53,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
@ -404,7 +405,7 @@ public class OverviewFragment extends Fragment {
if (Config.APS) { if (Config.APS) {
apsModeView.setVisibility(View.VISIBLE); apsModeView.setVisibility(View.VISIBLE);
apsModeView.setBackgroundResource(R.drawable.loopmodeborder); apsModeView.setBackgroundResource(R.drawable.loopmodeborder);
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
if(activeloop != null && activeloop.isEnabled(activeloop.getType())) { if(activeloop != null && activeloop.isEnabled(activeloop.getType())) {
if (MainApp.getConfigBuilder().isClosedModeEnabled()) { if (MainApp.getConfigBuilder().isClosedModeEnabled()) {
apsModeView.setText(MainApp.sResources.getString(R.string.closedloop)); apsModeView.setText(MainApp.sResources.getString(R.string.closedloop));
@ -415,6 +416,28 @@ public class OverviewFragment extends Fragment {
apsModeView.setBackgroundResource(R.drawable.loopmodedisabledborder); apsModeView.setBackgroundResource(R.drawable.loopmodedisabledborder);
apsModeView.setText(MainApp.sResources.getString(R.string.disabledloop)); apsModeView.setText(MainApp.sResources.getString(R.string.disabledloop));
} }
apsModeView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (activeloop == null){
log.error("no active loop?");
return true;
} else if (activeloop.isEnabled(PluginBase.LOOP)){
activeloop.setFragmentEnabled(PluginBase.LOOP, false);
activeloop.setFragmentVisible(PluginBase.LOOP, false);
} else {
activeloop.setFragmentEnabled(PluginBase.LOOP, true);
activeloop.setFragmentVisible(PluginBase.LOOP, true);
}
MainApp.getConfigBuilder().storeSettings();
MainApp.bus().post(new EventRefreshGui(false));
return true;
}
});
apsModeView.setLongClickable(true);
} else { } else {
apsModeView.setVisibility(View.GONE); apsModeView.setVisibility(View.GONE);
} }