Skip to content

Commit

Permalink
Closes #78
Browse files Browse the repository at this point in the history
Merge branch 'feature/link-date' into develop

* feature/link-date:
  Links planted action with plant date
  • Loading branch information
7LPdWcaW committed May 18, 2019
2 parents dc1b992 + d60cc13 commit 5720add
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import me.anon.model.EmptyAction;
import me.anon.model.NoteAction;
import me.anon.model.Plant;
import me.anon.model.PlantStage;
import me.anon.model.StageChange;
import me.anon.model.Water;
import me.anon.view.ActionHolder;
Expand Down Expand Up @@ -152,6 +153,12 @@ public void setActions(@Nullable Plant plant, ArrayList<Action> actions, ArrayLi
Collections.reverse(actions);
for (Action item : actions)
{
// force planted stage to use plant date
if (item instanceof StageChange && ((StageChange)item).getNewStage() == PlantStage.PLANTED)
{
item.setDate(plant.getPlantDate());
}

if (plant != null)
{
ArrayList<String> groupedImages = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import me.anon.model.EmptyAction;
import me.anon.model.NoteAction;
import me.anon.model.Plant;
import me.anon.model.PlantStage;
import me.anon.model.StageChange;
import me.anon.model.Water;
import me.anon.view.ActionHolder;
Expand Down Expand Up @@ -436,6 +437,11 @@ else if (action instanceof StageChange)
{
@Override public void onStageUpdated(final StageChange action)
{
if (action.getNewStage() == PlantStage.PLANTED)
{
plant.setPlantDate(action.getDate());
}

plant.getActions().set(originalIndex, action);
PlantManager.getInstance().upsert(plantIndex, plant);
setActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import me.anon.lib.manager.PlantManager;
import me.anon.lib.task.AsyncCallback;
import me.anon.lib.task.EncryptTask;
import me.anon.model.Action;
import me.anon.model.EmptyAction;
import me.anon.model.NoteAction;
import me.anon.model.Plant;
Expand Down Expand Up @@ -277,6 +278,14 @@ private void setUi()
{
@Override public void onDateSelected(Calendar newDate)
{
for (Action action : plant.getActions())
{
if (action instanceof StageChange && ((StageChange)action).getNewStage() == PlantStage.PLANTED)
{
action.setDate(newDate.getTimeInMillis());
}
}

plant.setPlantDate(newDate.getTimeInMillis());
String dateStr = dateFormat.format(new Date(plant.getPlantDate())) + " " + timeFormat.format(new Date(plant.getPlantDate()));
date.setText(dateStr);
Expand Down

0 comments on commit 5720add

Please sign in to comment.