mirror of https://github.com/iSoron/uhabits.git
parent
373f21e247
commit
0a5622c78e
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.core.commands;
|
|
||||||
|
|
||||||
import androidx.annotation.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.core.models.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Command to change the color of a list of habits.
|
|
||||||
*/
|
|
||||||
public class ChangeHabitColorCommand implements Command
|
|
||||||
{
|
|
||||||
@NonNull
|
|
||||||
final HabitList habitList;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
final List<Habit> selected;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
final PaletteColor newColor;
|
|
||||||
|
|
||||||
public ChangeHabitColorCommand(@NonNull HabitList habitList,
|
|
||||||
@NonNull List<Habit> selected,
|
|
||||||
@NonNull PaletteColor newColor)
|
|
||||||
{
|
|
||||||
this.habitList = habitList;
|
|
||||||
this.selected = selected;
|
|
||||||
this.newColor = newColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
for (Habit h : selected) h.setColor(newColor);
|
|
||||||
habitList.update(selected);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.core.commands;
|
|
||||||
|
|
||||||
import androidx.annotation.*;
|
|
||||||
|
|
||||||
import com.google.auto.factory.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.core.models.*;
|
|
||||||
|
|
||||||
@AutoFactory
|
|
||||||
public class CreateHabitCommand implements Command
|
|
||||||
{
|
|
||||||
ModelFactory modelFactory;
|
|
||||||
|
|
||||||
HabitList habitList;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
Habit model;
|
|
||||||
|
|
||||||
public CreateHabitCommand(@Provided @NonNull ModelFactory modelFactory,
|
|
||||||
@NonNull HabitList habitList,
|
|
||||||
@NonNull Habit model)
|
|
||||||
{
|
|
||||||
this.modelFactory = modelFactory;
|
|
||||||
this.habitList = habitList;
|
|
||||||
this.model = model;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
Habit habit = modelFactory.buildHabit();
|
|
||||||
habit.copyFrom(model);
|
|
||||||
habitList.add(habit);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.core.commands;
|
|
||||||
|
|
||||||
import androidx.annotation.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.core.models.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class CreateRepetitionCommand implements Command
|
|
||||||
{
|
|
||||||
@NonNull
|
|
||||||
final Habit habit;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
final HabitList habitList;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
final Timestamp timestamp;
|
|
||||||
|
|
||||||
final int value;
|
|
||||||
|
|
||||||
public CreateRepetitionCommand(@NonNull HabitList habitList,
|
|
||||||
@NonNull Habit habit,
|
|
||||||
@NonNull Timestamp timestamp,
|
|
||||||
int value)
|
|
||||||
{
|
|
||||||
this.habitList = habitList;
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
this.habit = habit;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
EntryList entries = habit.getOriginalEntries();
|
|
||||||
entries.add(new Entry(timestamp, value));
|
|
||||||
habit.recompute();
|
|
||||||
habitList.resort();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public Habit getHabit()
|
|
||||||
{
|
|
||||||
return habit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o)
|
|
||||||
{
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
CreateRepetitionCommand that = (CreateRepetitionCommand) o;
|
|
||||||
return value == that.value &&
|
|
||||||
habit.equals(that.habit) &&
|
|
||||||
habitList.equals(that.habitList) &&
|
|
||||||
timestamp.equals(that.timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return Objects.hash(habit, habitList, timestamp, value);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.isoron.uhabits.core.commands
|
||||||
|
|
||||||
|
import org.isoron.uhabits.core.models.*
|
||||||
|
|
||||||
|
data class CreateRepetitionCommand(
|
||||||
|
val habitList: HabitList,
|
||||||
|
val habit: Habit,
|
||||||
|
val timestamp: Timestamp,
|
||||||
|
val value: Int,
|
||||||
|
) : Command {
|
||||||
|
override fun run() {
|
||||||
|
val entries = habit.originalEntries
|
||||||
|
entries.add(Entry(timestamp, value))
|
||||||
|
habit.recompute()
|
||||||
|
habitList.resort()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.isoron.uhabits.core.commands
|
||||||
|
|
||||||
|
import org.isoron.uhabits.core.models.*
|
||||||
|
|
||||||
|
data class DeleteHabitsCommand(
|
||||||
|
val habitList: HabitList,
|
||||||
|
val selected: List<Habit>,
|
||||||
|
) : Command {
|
||||||
|
override fun run() {
|
||||||
|
for (h in selected) habitList.remove(h)
|
||||||
|
}
|
||||||
|
}
|
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.core.commands;
|
|
||||||
|
|
||||||
import androidx.annotation.*;
|
|
||||||
|
|
||||||
import com.google.auto.factory.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.core.models.*;
|
|
||||||
|
|
||||||
@AutoFactory
|
|
||||||
public class EditHabitCommand implements Command
|
|
||||||
{
|
|
||||||
@NonNull
|
|
||||||
final HabitList habitList;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
final Habit original;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
final Habit modified;
|
|
||||||
|
|
||||||
final long savedId;
|
|
||||||
|
|
||||||
final boolean hasFrequencyChanged;
|
|
||||||
|
|
||||||
final boolean hasTargetChanged;
|
|
||||||
|
|
||||||
public EditHabitCommand(@Provided @NonNull ModelFactory modelFactory,
|
|
||||||
@NonNull HabitList habitList,
|
|
||||||
@NonNull Habit original,
|
|
||||||
@NonNull Habit modified)
|
|
||||||
{
|
|
||||||
Long habitId = original.getId();
|
|
||||||
if (habitId == null) throw new RuntimeException("Habit not saved");
|
|
||||||
|
|
||||||
this.savedId = habitId;
|
|
||||||
this.habitList = habitList;
|
|
||||||
this.modified = modelFactory.buildHabit();
|
|
||||||
this.original = modelFactory.buildHabit();
|
|
||||||
|
|
||||||
this.modified.copyFrom(modified);
|
|
||||||
this.original.copyFrom(original);
|
|
||||||
|
|
||||||
Frequency originalFreq = this.original.getFrequency();
|
|
||||||
Frequency modifiedFreq = this.modified.getFrequency();
|
|
||||||
hasFrequencyChanged = (!originalFreq.equals(modifiedFreq));
|
|
||||||
hasTargetChanged =
|
|
||||||
(original.getTargetType() != modified.getTargetType() ||
|
|
||||||
original.getTargetValue() != modified.getTargetValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
copyAttributes(this.modified);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyAttributes(Habit model)
|
|
||||||
{
|
|
||||||
Habit habit = habitList.getById(savedId);
|
|
||||||
if (habit == null) throw new RuntimeException("Habit not found");
|
|
||||||
|
|
||||||
habit.copyFrom(model);
|
|
||||||
habitList.update(habit);
|
|
||||||
habit.getObservable().notifyListeners();
|
|
||||||
|
|
||||||
if (hasFrequencyChanged || hasTargetChanged)
|
|
||||||
habit.recompute();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.isoron.uhabits.core.commands
|
||||||
|
|
||||||
|
import org.isoron.uhabits.core.models.*
|
||||||
|
|
||||||
|
data class EditHabitCommand(
|
||||||
|
val habitList: HabitList,
|
||||||
|
val habitId: Long,
|
||||||
|
val modified: Habit,
|
||||||
|
) : Command {
|
||||||
|
override fun run() {
|
||||||
|
val habit = habitList.getById(habitId) ?: throw HabitNotFoundException()
|
||||||
|
habit.copyFrom(modified)
|
||||||
|
habitList.update(habit)
|
||||||
|
habit.observable.notifyListeners()
|
||||||
|
habit.recompute()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.isoron.uhabits.core.commands
|
||||||
|
|
||||||
|
import org.isoron.uhabits.core.models.*
|
||||||
|
|
||||||
|
data class UnarchiveHabitsCommand(
|
||||||
|
val habitList: HabitList,
|
||||||
|
val selected: List<Habit>,
|
||||||
|
) : Command {
|
||||||
|
override fun run() {
|
||||||
|
for (h in selected) h.isArchived = false
|
||||||
|
habitList.update(selected)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue