Implement habits archival

pull/30/head
Alinson S. Xavier 10 years ago
parent 3e25c81f25
commit 62aaac084a

@ -24,7 +24,7 @@
<meta-data <meta-data
android:name="AA_DB_VERSION" android:name="AA_DB_VERSION"
android:value="6"/> android:value="7"/>
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"

@ -0,0 +1 @@
alter table habits add column archived integer not null default 0;

@ -59,6 +59,9 @@ public class Habit extends Model
@Column(name = "highlight") @Column(name = "highlight")
public Integer highlight; public Integer highlight;
@Column(name = "archived")
public Integer archived;
public Habit(Habit model) public Habit(Habit model)
{ {
copyAttributes(model); copyAttributes(model);
@ -69,6 +72,7 @@ public class Habit extends Model
this.color = ColorHelper.palette[7]; this.color = ColorHelper.palette[7];
this.position = Habit.getCount(); this.position = Habit.getCount();
this.highlight = 0; this.highlight = 0;
this.archived = 0;
} }
public static Habit get(Long id) public static Habit get(Long id)
@ -84,7 +88,7 @@ public class Habit extends Model
protected static From select() protected static From select()
{ {
return new Select().from(Habit.class).orderBy("position"); return new Select().from(Habit.class).where("archived = 0").orderBy("position");
} }
public static int getCount() public static int getCount()
@ -178,7 +182,6 @@ public class Habit extends Model
this.highlight = model.highlight; this.highlight = model.highlight;
} }
public void save(Long id) public void save(Long id)
{ {
save(); save();
@ -282,6 +285,18 @@ public class Habit extends Model
deleteScoresNewerThan(timestamp); deleteScoresNewerThan(timestamp);
} }
public void archive()
{
archived = 1;
save();
}
public void unarchive()
{
archived = 0;
save();
}
public void toggleRepetitionToday() public void toggleRepetitionToday()
{ {
toggleRepetition(DateHelper.getStartOfToday()); toggleRepetition(DateHelper.getStartOfToday());
@ -552,4 +567,31 @@ public class Habit extends Model
execute(); execute();
} }
} }
public class ArchiveCommand extends Command
{
@Override
public void execute()
{
archive();
Habit.rebuildOrder();
}
@Override
public void undo()
{
unarchive();
Habit.rebuildOrder();
}
public Integer getExecuteStringId()
{
return R.string.toast_habit_archived;
}
public Integer getUndoStringId()
{
return R.string.toast_habit_unarchived;
}
}
} }

@ -6,8 +6,8 @@
android:title="@string/edit"> android:title="@string/edit">
</item> </item>
<item <item
android:id="@+id/action_delete_habit" android:id="@+id/action_archive_habit"
android:title="@string/delete"> android:title="@string/archive">
</item> </item>
</menu> </menu>

@ -5,6 +5,7 @@
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="edit">Edit</string> <string name="edit">Edit</string>
<string name="delete">Delete</string> <string name="delete">Delete</string>
<string name="archive">Archive</string>
<string name="add_habit">Add habit</string> <string name="add_habit">Add habit</string>
<string name="color_picker_default_title">Select a Color</string> <string name="color_picker_default_title">Select a Color</string>
<string name="color_swatch_description">Color <xliff:g id="color_index" example="14">%1$d</xliff:g></string> <string name="color_swatch_description">Color <xliff:g id="color_index" example="14">%1$d</xliff:g></string>
@ -16,6 +17,8 @@
<string name="toast_habit_changed">Habit changed.</string> <string name="toast_habit_changed">Habit changed.</string>
<string name="toast_habit_changed_back">Habit changed back.</string> <string name="toast_habit_changed_back">Habit changed back.</string>
<string name="toast_repetition_toggled">Repetition toggled.</string> <string name="toast_repetition_toggled">Repetition toggled.</string>
<string name="toast_habit_archived">Habit archived.</string>
<string name="toast_habit_unarchived">Habit unarchived.</string>
<!-- Date and time picker --> <!-- Date and time picker -->
<string name="done_label">Done</string> <string name="done_label">Done</string>

Loading…
Cancel
Save