Objectives: remove static code, cleanup
This commit is contained in:
parent
c380b3dcc7
commit
6f53afbbe3
13 changed files with 45 additions and 36 deletions
|
@ -55,7 +55,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
||||||
enableFake.setOnClickListener(v -> updateGUI());
|
enableFake.setOnClickListener(v -> updateGUI());
|
||||||
reset.setOnClickListener(v -> {
|
reset.setOnClickListener(v -> {
|
||||||
ObjectivesPlugin.getPlugin().reset();
|
ObjectivesPlugin.getPlugin().reset();
|
||||||
ObjectivesPlugin.saveProgress();
|
ObjectivesPlugin.getPlugin().saveProgress();
|
||||||
recyclerView.getAdapter().notifyDataSetChanged();
|
recyclerView.getAdapter().notifyDataSetChanged();
|
||||||
scrollToCurrentObjective();
|
scrollToCurrentObjective();
|
||||||
});
|
});
|
||||||
|
@ -77,7 +77,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
||||||
|
|
||||||
private void startUpdateTimer() {
|
private void startUpdateTimer() {
|
||||||
handler.removeCallbacks(objectiveUpdater);
|
handler.removeCallbacks(objectiveUpdater);
|
||||||
for (Objective objective : ObjectivesPlugin.getObjectives()) {
|
for (Objective objective : ObjectivesPlugin.getPlugin().getObjectives()) {
|
||||||
if (objective.isStarted() && !objective.isAccomplished()) {
|
if (objective.isStarted() && !objective.isAccomplished()) {
|
||||||
long timeTillNextMinute = (System.currentTimeMillis() - objective.getStartedOn().getTime()) % (60 * 1000);
|
long timeTillNextMinute = (System.currentTimeMillis() - objective.getStartedOn().getTime()) % (60 * 1000);
|
||||||
handler.postDelayed(objectiveUpdater, timeTillNextMinute);
|
handler.postDelayed(objectiveUpdater, timeTillNextMinute);
|
||||||
|
@ -87,8 +87,8 @@ public class ObjectivesFragment extends SubscriberFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollToCurrentObjective() {
|
private void scrollToCurrentObjective() {
|
||||||
for (int i = 0; i < ObjectivesPlugin.getObjectives().size(); i++) {
|
for (int i = 0; i < ObjectivesPlugin.getPlugin().getObjectives().size(); i++) {
|
||||||
Objective objective = ObjectivesPlugin.getObjectives().get(i);
|
Objective objective = ObjectivesPlugin.getPlugin().getObjectives().get(i);
|
||||||
if (!objective.isStarted() || !objective.isAccomplished()) {
|
if (!objective.isStarted() || !objective.isAccomplished()) {
|
||||||
RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) {
|
RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,7 +118,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
Objective objective = ObjectivesPlugin.getObjectives().get(position);
|
Objective objective = ObjectivesPlugin.getPlugin().getObjectives().get(position);
|
||||||
holder.title.setText(MainApp.gs(R.string.nth_objective, position + 1));
|
holder.title.setText(MainApp.gs(R.string.nth_objective, position + 1));
|
||||||
if (objective.getObjective() != 0) {
|
if (objective.getObjective() != 0) {
|
||||||
holder.objective.setVisibility(View.VISIBLE);
|
holder.objective.setVisibility(View.VISIBLE);
|
||||||
|
@ -132,7 +132,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
||||||
holder.gate.setTextColor(0xFFFFFFFF);
|
holder.gate.setTextColor(0xFFFFFFFF);
|
||||||
holder.verify.setVisibility(View.GONE);
|
holder.verify.setVisibility(View.GONE);
|
||||||
holder.progress.setVisibility(View.GONE);
|
holder.progress.setVisibility(View.GONE);
|
||||||
if (position == 0 || ObjectivesPlugin.getObjectives().get(position - 1).isAccomplished())
|
if (position == 0 || ObjectivesPlugin.getPlugin().getObjectives().get(position - 1).isAccomplished())
|
||||||
holder.start.setVisibility(View.VISIBLE);
|
holder.start.setVisibility(View.VISIBLE);
|
||||||
else holder.start.setVisibility(View.GONE);
|
else holder.start.setVisibility(View.GONE);
|
||||||
} else if (objective.isAccomplished()) {
|
} else if (objective.isAccomplished()) {
|
||||||
|
@ -173,7 +173,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return ObjectivesPlugin.getObjectives().size();
|
return ObjectivesPlugin.getPlugin().getObjectives().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
|
@ -37,10 +37,10 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
|
||||||
|
|
||||||
private static ObjectivesPlugin objectivesPlugin;
|
private static ObjectivesPlugin objectivesPlugin;
|
||||||
|
|
||||||
public static List<Objective> objectives = new ArrayList<>();
|
public List<Objective> objectives = new ArrayList<>();
|
||||||
public static boolean bgIsAvailableInNS = false;
|
public boolean bgIsAvailableInNS = false;
|
||||||
public static boolean pumpStatusIsAvailableInNS = false;
|
public boolean pumpStatusIsAvailableInNS = false;
|
||||||
public static Integer manualEnacts = 0;
|
public Integer manualEnacts = 0;
|
||||||
|
|
||||||
public static ObjectivesPlugin getPlugin() {
|
public static ObjectivesPlugin getPlugin() {
|
||||||
if (objectivesPlugin == null) {
|
if (objectivesPlugin == null) {
|
||||||
|
@ -91,7 +91,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
|
||||||
saveProgress();
|
saveProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveProgress() {
|
public void saveProgress() {
|
||||||
SP.putBoolean("Objectives" + "bgIsAvailableInNS", bgIsAvailableInNS);
|
SP.putBoolean("Objectives" + "bgIsAvailableInNS", bgIsAvailableInNS);
|
||||||
SP.putBoolean("Objectives" + "pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS);
|
SP.putBoolean("Objectives" + "pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS);
|
||||||
SP.putString("Objectives" + "manualEnacts", Integer.toString(manualEnacts));
|
SP.putString("Objectives" + "manualEnacts", Integer.toString(manualEnacts));
|
||||||
|
@ -112,7 +112,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
|
||||||
log.debug("Objectives loaded");
|
log.debug("Objectives loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Objective> getObjectives() {
|
public List<Objective> getObjectives() {
|
||||||
return objectives;
|
return objectives;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
import info.nightscout.utils.T;
|
||||||
|
|
||||||
public abstract class Objective {
|
public abstract class Objective {
|
||||||
|
|
||||||
|
@ -128,9 +129,9 @@ public abstract class Objective {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDurationText(long duration) {
|
private String getDurationText(long duration) {
|
||||||
int days = (int) Math.floor((double) duration / (24D * 60D * 60D * 1000D));
|
int days = (int) Math.floor((double) duration / T.days(1).msecs());
|
||||||
int hours = (int) Math.floor((double) duration / (60D * 60D * 1000D));
|
int hours = (int) Math.floor((double) duration / T.hours(1).msecs());
|
||||||
int minutes = (int) Math.floor((double) duration / (60D * 1000D));
|
int minutes = (int) Math.floor((double) duration / T.mins(1).msecs());
|
||||||
if (days > 0) return MainApp.gq(R.plurals.objective_days, days, days);
|
if (days > 0) return MainApp.gq(R.plurals.objective_days, days, days);
|
||||||
else if (hours > 0) return MainApp.gq(R.plurals.objective_hours, hours, hours);
|
else if (hours > 0) return MainApp.gq(R.plurals.objective_hours, hours, hours);
|
||||||
else return MainApp.gq(R.plurals.objective_minutes, minutes, minutes);
|
else return MainApp.gq(R.plurals.objective_minutes, minutes, minutes);
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class Objective1 extends Objective {
|
||||||
tasks.add(new Task(R.string.objectives_bgavailableinns) {
|
tasks.add(new Task(R.string.objectives_bgavailableinns) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isCompleted() {
|
public boolean isCompleted() {
|
||||||
return ObjectivesPlugin.bgIsAvailableInNS;
|
return ObjectivesPlugin.getPlugin().bgIsAvailableInNS;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tasks.add(new Task(R.string.nsclienthaswritepermission) {
|
tasks.add(new Task(R.string.nsclienthaswritepermission) {
|
||||||
|
@ -50,7 +50,7 @@ public class Objective1 extends Objective {
|
||||||
tasks.add(new Task(R.string.objectives_pumpstatusavailableinns) {
|
tasks.add(new Task(R.string.objectives_pumpstatusavailableinns) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isCompleted() {
|
public boolean isCompleted() {
|
||||||
return ObjectivesPlugin.pumpStatusIsAvailableInNS;
|
return ObjectivesPlugin.getPlugin().pumpStatusIsAvailableInNS;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tasks.add(new Task(R.string.hasbgdata) {
|
tasks.add(new Task(R.string.hasbgdata) {
|
||||||
|
|
|
@ -5,10 +5,11 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
|
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
|
||||||
|
import info.nightscout.utils.T;
|
||||||
|
|
||||||
public class Objective2 extends Objective {
|
public class Objective2 extends Objective {
|
||||||
|
|
||||||
public static final int MANUAL_ENACTS_NEEDED = 20;
|
public final int MANUAL_ENACTS_NEEDED = 20;
|
||||||
|
|
||||||
public Objective2() {
|
public Objective2() {
|
||||||
super(1, R.string.objectives_1_objective, R.string.objectives_1_gate);
|
super(1, R.string.objectives_1_objective, R.string.objectives_1_gate);
|
||||||
|
@ -16,17 +17,19 @@ public class Objective2 extends Objective {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupTasks(List<Task> tasks) {
|
protected void setupTasks(List<Task> tasks) {
|
||||||
tasks.add(new MinimumDurationTask(7L * 24L * 60L * 60L * 1000L));
|
tasks.add(new MinimumDurationTask(T.days(7).msecs()));
|
||||||
tasks.add(new Task(R.string.objectives_manualenacts) {
|
tasks.add(new Task(R.string.objectives_manualenacts) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isCompleted() {
|
public boolean isCompleted() {
|
||||||
return ObjectivesPlugin.manualEnacts >= MANUAL_ENACTS_NEEDED;
|
return ObjectivesPlugin.getPlugin().manualEnacts >= MANUAL_ENACTS_NEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProgress() {
|
public String getProgress() {
|
||||||
if (ObjectivesPlugin.manualEnacts >= MANUAL_ENACTS_NEEDED) return MainApp.gs(R.string.completed_well_done);
|
if (ObjectivesPlugin.getPlugin().manualEnacts >= MANUAL_ENACTS_NEEDED)
|
||||||
else return ObjectivesPlugin.manualEnacts + " / " + MANUAL_ENACTS_NEEDED;
|
return MainApp.gs(R.string.completed_well_done);
|
||||||
|
else
|
||||||
|
return ObjectivesPlugin.getPlugin().manualEnacts + " / " + MANUAL_ENACTS_NEEDED;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
|
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
|
||||||
|
import info.nightscout.utils.T;
|
||||||
|
|
||||||
public class Objective4 extends Objective {
|
public class Objective4 extends Objective {
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ public class Objective4 extends Objective {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupTasks(List<Task> tasks) {
|
protected void setupTasks(List<Task> tasks) {
|
||||||
tasks.add(new MinimumDurationTask(5L * 24L * 60L * 60L * 1000L));
|
tasks.add(new MinimumDurationTask(T.days(5).msecs()));
|
||||||
tasks.add(new Task(R.string.closedmodeenabled) {
|
tasks.add(new Task(R.string.closedmodeenabled) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isCompleted() {
|
public boolean isCompleted() {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.utils.T;
|
||||||
|
|
||||||
public class Objective5 extends Objective {
|
public class Objective5 extends Objective {
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ public class Objective5 extends Objective {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupTasks(List<Task> tasks) {
|
protected void setupTasks(List<Task> tasks) {
|
||||||
tasks.add(new MinimumDurationTask(24L * 60L * 60L * 1000L));
|
tasks.add(new MinimumDurationTask(T.days(1).msecs()));
|
||||||
tasks.add(new Task(R.string.maxiobset) {
|
tasks.add(new Task(R.string.maxiobset) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isCompleted() {
|
public boolean isCompleted() {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.utils.T;
|
||||||
|
|
||||||
public class Objective6 extends Objective {
|
public class Objective6 extends Objective {
|
||||||
|
|
||||||
|
@ -12,6 +13,6 @@ public class Objective6 extends Objective {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupTasks(List<Task> tasks) {
|
protected void setupTasks(List<Task> tasks) {
|
||||||
tasks.add(new MinimumDurationTask(7L * 24L * 60L * 60L * 1000L));
|
tasks.add(new MinimumDurationTask(T.days(7).msecs()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.utils.T;
|
||||||
|
|
||||||
public class Objective7 extends Objective {
|
public class Objective7 extends Objective {
|
||||||
|
|
||||||
|
@ -12,6 +13,6 @@ public class Objective7 extends Objective {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupTasks(List<Task> tasks) {
|
protected void setupTasks(List<Task> tasks) {
|
||||||
tasks.add(new MinimumDurationTask(28L * 24L * 60L * 60L * 1000L));
|
tasks.add(new MinimumDurationTask(T.days(28).msecs()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.utils.T;
|
||||||
|
|
||||||
public class Objective8 extends Objective {
|
public class Objective8 extends Objective {
|
||||||
|
|
||||||
|
@ -12,6 +13,6 @@ public class Objective8 extends Objective {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupTasks(List<Task> tasks) {
|
protected void setupTasks(List<Task> tasks) {
|
||||||
tasks.add(new MinimumDurationTask(28L * 24L * 60L * 60L * 1000L));
|
tasks.add(new MinimumDurationTask(T.days(28).msecs()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -464,8 +464,8 @@ public class LoopPlugin extends PluginBase {
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class);
|
ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class);
|
||||||
if (objectivesPlugin != null) {
|
if (objectivesPlugin != null) {
|
||||||
ObjectivesPlugin.manualEnacts++;
|
ObjectivesPlugin.getPlugin().manualEnacts++;
|
||||||
ObjectivesPlugin.saveProgress();
|
ObjectivesPlugin.getPlugin().saveProgress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventAcceptOpenLoopChange());
|
MainApp.bus().post(new EventAcceptOpenLoopChange());
|
||||||
|
|
|
@ -108,8 +108,8 @@ public class NSDeviceStatus {
|
||||||
setData(devicestatusJson);
|
setData(devicestatusJson);
|
||||||
if (devicestatusJson.has("pump")) {
|
if (devicestatusJson.has("pump")) {
|
||||||
// Objectives 0
|
// Objectives 0
|
||||||
ObjectivesPlugin.pumpStatusIsAvailableInNS = true;
|
ObjectivesPlugin.getPlugin().pumpStatusIsAvailableInNS = true;
|
||||||
ObjectivesPlugin.saveProgress();
|
ObjectivesPlugin.getPlugin().saveProgress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bundle.containsKey("devicestatuses")) {
|
if (bundle.containsKey("devicestatuses")) {
|
||||||
|
@ -120,8 +120,8 @@ public class NSDeviceStatus {
|
||||||
setData(devicestatusJson);
|
setData(devicestatusJson);
|
||||||
if (devicestatusJson.has("pump")) {
|
if (devicestatusJson.has("pump")) {
|
||||||
// Objectives 0
|
// Objectives 0
|
||||||
ObjectivesPlugin.pumpStatusIsAvailableInNS = true;
|
ObjectivesPlugin.getPlugin().pumpStatusIsAvailableInNS = true;
|
||||||
ObjectivesPlugin.saveProgress();
|
ObjectivesPlugin.getPlugin().saveProgress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,8 +86,8 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac
|
||||||
}
|
}
|
||||||
|
|
||||||
// Objectives 0
|
// Objectives 0
|
||||||
ObjectivesPlugin.bgIsAvailableInNS = true;
|
ObjectivesPlugin.getPlugin().bgIsAvailableInNS = true;
|
||||||
ObjectivesPlugin.saveProgress();
|
ObjectivesPlugin.getPlugin().saveProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeSgv(JSONObject sgvJson) {
|
private void storeSgv(JSONObject sgvJson) {
|
||||||
|
|
Loading…
Reference in a new issue