Fix #842
This commit is contained in:
parent
80e81b1c25
commit
42e36ab818
|
@ -85,37 +85,52 @@ public class ObjectivesFragment extends SubscriberFragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Long now = System.currentTimeMillis();
|
long prevObjectiveAccomplishedTime = position > 0 ?
|
||||||
if (position > 0 && objectives.get(position - 1).accomplished.getTime() == 0) {
|
objectives.get(position - 1).accomplished.getTime() : -1;
|
||||||
|
|
||||||
|
int phase = modifyVisibility(position, prevObjectiveAccomplishedTime,
|
||||||
|
o.started.getTime(), o.durationInDays,
|
||||||
|
o.accomplished.getTime(), requirementsMet.done, enableFake.isChecked());
|
||||||
|
|
||||||
|
switch (phase) {
|
||||||
|
case 0:
|
||||||
// Phase 0: previous not completed
|
// Phase 0: previous not completed
|
||||||
holder.startedLayout.setVisibility(View.GONE);
|
holder.startedLayout.setVisibility(View.GONE);
|
||||||
holder.durationLayout.setVisibility(View.GONE);
|
holder.durationLayout.setVisibility(View.GONE);
|
||||||
holder.progressLayout.setVisibility(View.GONE);
|
holder.progressLayout.setVisibility(View.GONE);
|
||||||
holder.verifyLayout.setVisibility(View.GONE);
|
holder.verifyLayout.setVisibility(View.GONE);
|
||||||
} else if (o.started.getTime() == 0) {
|
break;
|
||||||
|
case 1:
|
||||||
// Phase 1: not started
|
// Phase 1: not started
|
||||||
holder.durationLayout.setVisibility(View.GONE);
|
holder.durationLayout.setVisibility(View.GONE);
|
||||||
holder.progressLayout.setVisibility(View.GONE);
|
holder.progressLayout.setVisibility(View.GONE);
|
||||||
holder.verifyLayout.setVisibility(View.GONE);
|
holder.verifyLayout.setVisibility(View.GONE);
|
||||||
holder.started.setVisibility(View.GONE);
|
holder.started.setVisibility(View.GONE);
|
||||||
} else if (o.started.getTime() > 0 && !enableFake.isChecked() && o.accomplished.getTime() == 0 && !(o.started.getTime() + o.durationInDays * 24 * 60 * 60 * 1000 < now && requirementsMet.done)) {
|
break;
|
||||||
|
case 2:
|
||||||
// Phase 2: started, waiting for duration and met requirements
|
// Phase 2: started, waiting for duration and met requirements
|
||||||
holder.startButton.setEnabled(false);
|
holder.startButton.setEnabled(false);
|
||||||
holder.verifyLayout.setVisibility(View.GONE);
|
holder.verifyLayout.setVisibility(View.GONE);
|
||||||
} else if (o.accomplished.getTime() == 0) {
|
break;
|
||||||
|
case 3:
|
||||||
// Phase 3: started, after duration, requirements met
|
// Phase 3: started, after duration, requirements met
|
||||||
holder.startButton.setEnabled(false);
|
holder.startButton.setEnabled(false);
|
||||||
holder.accomplished.setVisibility(View.INVISIBLE);
|
holder.accomplished.setVisibility(View.INVISIBLE);
|
||||||
} else {
|
break;
|
||||||
|
case 4:
|
||||||
// Phase 4: verified
|
// Phase 4: verified
|
||||||
holder.gateLayout.setVisibility(View.GONE);
|
holder.gateLayout.setVisibility(View.GONE);
|
||||||
holder.startedLayout.setVisibility(View.GONE);
|
holder.startedLayout.setVisibility(View.GONE);
|
||||||
holder.durationLayout.setVisibility(View.GONE);
|
holder.durationLayout.setVisibility(View.GONE);
|
||||||
holder.progressLayout.setVisibility(View.GONE);
|
holder.progressLayout.setVisibility(View.GONE);
|
||||||
holder.verifyButton.setVisibility(View.INVISIBLE);
|
holder.verifyButton.setVisibility(View.INVISIBLE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// should not happen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return objectives.size();
|
return objectives.size();
|
||||||
|
@ -164,6 +179,40 @@ public class ObjectivesFragment extends SubscriberFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns an int, which represents the phase the current objective is at.
|
||||||
|
*
|
||||||
|
* this is mainly used for unit-testing the conditions
|
||||||
|
*
|
||||||
|
* @param currentPosition
|
||||||
|
* @param prevObjectiveAccomplishedTime
|
||||||
|
* @param objectiveStartedTime
|
||||||
|
* @param durationInDays
|
||||||
|
* @param objectiveAccomplishedTime
|
||||||
|
* @param requirementsMet
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int modifyVisibility(int currentPosition,
|
||||||
|
long prevObjectiveAccomplishedTime,
|
||||||
|
long objectiveStartedTime, int durationInDays,
|
||||||
|
long objectiveAccomplishedTime, boolean requirementsMet,
|
||||||
|
boolean enableFakeValue) {
|
||||||
|
Long now = System.currentTimeMillis();
|
||||||
|
if (currentPosition > 0 && prevObjectiveAccomplishedTime == 0) {
|
||||||
|
return 0;
|
||||||
|
} else if (objectiveStartedTime == 0) {
|
||||||
|
return 1;
|
||||||
|
} else if (objectiveStartedTime > 0 && !enableFakeValue
|
||||||
|
&& objectiveAccomplishedTime == 0
|
||||||
|
&& !(objectiveStartedTime + durationInDays * 24 * 60 * 60 * 1000 >= now && requirementsMet)) {
|
||||||
|
return 2;
|
||||||
|
} else if (objectiveAccomplishedTime == 0) {
|
||||||
|
return 3;
|
||||||
|
} else {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
@ -205,6 +254,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
||||||
ObjectivesPlugin.objectives.get(3).gate = MainApp.sResources.getString(R.string.objectives_3_gate);
|
ObjectivesPlugin.objectives.get(3).gate = MainApp.sResources.getString(R.string.objectives_3_gate);
|
||||||
ObjectivesPlugin.objectives.get(4).gate = MainApp.sResources.getString(R.string.objectives_4_gate);
|
ObjectivesPlugin.objectives.get(4).gate = MainApp.sResources.getString(R.string.objectives_4_gate);
|
||||||
ObjectivesPlugin.objectives.get(5).gate = MainApp.sResources.getString(R.string.objectives_5_gate);
|
ObjectivesPlugin.objectives.get(5).gate = MainApp.sResources.getString(R.string.objectives_5_gate);
|
||||||
|
|
||||||
updateGUI();
|
updateGUI();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package info.nightscout.androidaps.plugins.ConstraintsObjectives;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class ObjectivesFragmentTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testModifyVisibility() {
|
||||||
|
|
||||||
|
ObjectivesFragment fragment = new ObjectivesFragment();
|
||||||
|
|
||||||
|
int currentPosition = 1;
|
||||||
|
long prevObjectiveAccomplishedTime = 0;
|
||||||
|
long objectiveStartedTime = 0;
|
||||||
|
int durationInDays = 0;
|
||||||
|
long objectiveAccomplishedTime = 0;
|
||||||
|
boolean requirementsMet = false;
|
||||||
|
boolean enableFakeValue = false;
|
||||||
|
|
||||||
|
// previous objective is not accomplished yet
|
||||||
|
assertEquals(0, fragment.modifyVisibility(currentPosition, prevObjectiveAccomplishedTime,
|
||||||
|
objectiveStartedTime, durationInDays, objectiveAccomplishedTime, requirementsMet, enableFakeValue));
|
||||||
|
|
||||||
|
// not started yet
|
||||||
|
prevObjectiveAccomplishedTime = 4711;
|
||||||
|
assertEquals(1, fragment.modifyVisibility(currentPosition, prevObjectiveAccomplishedTime,
|
||||||
|
objectiveStartedTime, durationInDays, objectiveAccomplishedTime, requirementsMet, enableFakeValue));
|
||||||
|
|
||||||
|
// started
|
||||||
|
// time calculation is true, requirements met is false
|
||||||
|
objectiveStartedTime = Long.MAX_VALUE;
|
||||||
|
durationInDays = 0;
|
||||||
|
assertEquals(2, fragment.modifyVisibility(currentPosition, prevObjectiveAccomplishedTime,
|
||||||
|
objectiveStartedTime, durationInDays, objectiveAccomplishedTime, requirementsMet, enableFakeValue));
|
||||||
|
|
||||||
|
// started
|
||||||
|
// time calculation is false, requirements met is false
|
||||||
|
objectiveStartedTime = 10;
|
||||||
|
durationInDays = 0;
|
||||||
|
requirementsMet = true;
|
||||||
|
assertEquals(2, fragment.modifyVisibility(currentPosition, prevObjectiveAccomplishedTime,
|
||||||
|
objectiveStartedTime, durationInDays, objectiveAccomplishedTime, requirementsMet, enableFakeValue));
|
||||||
|
|
||||||
|
// started
|
||||||
|
// time calculation is false, requirements met is true
|
||||||
|
objectiveStartedTime = 10;
|
||||||
|
durationInDays = 999999;
|
||||||
|
requirementsMet = true;
|
||||||
|
assertEquals(2, fragment.modifyVisibility(currentPosition, prevObjectiveAccomplishedTime,
|
||||||
|
objectiveStartedTime, durationInDays, objectiveAccomplishedTime, requirementsMet, enableFakeValue));
|
||||||
|
|
||||||
|
// started, after duration, requirements met --> show verify
|
||||||
|
objectiveStartedTime = Long.MAX_VALUE;
|
||||||
|
durationInDays = 0;
|
||||||
|
requirementsMet = true;
|
||||||
|
assertEquals(3, fragment.modifyVisibility(currentPosition, prevObjectiveAccomplishedTime,
|
||||||
|
objectiveStartedTime, durationInDays, objectiveAccomplishedTime, requirementsMet, enableFakeValue));
|
||||||
|
|
||||||
|
// finished
|
||||||
|
objectiveStartedTime = Long.MAX_VALUE;
|
||||||
|
durationInDays = 0;
|
||||||
|
requirementsMet = true;
|
||||||
|
objectiveAccomplishedTime = Long.MAX_VALUE;
|
||||||
|
assertEquals(4, fragment.modifyVisibility(currentPosition, prevObjectiveAccomplishedTime,
|
||||||
|
objectiveStartedTime, durationInDays, objectiveAccomplishedTime, requirementsMet, enableFakeValue));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue