mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Implement habits archival
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
<meta-data
|
||||
android:name="AA_DB_VERSION"
|
||||
android:value="6"/>
|
||||
android:value="7"/>
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
|
||||
1
app/src/main/assets/migrations/7.sql
Normal file
1
app/src/main/assets/migrations/7.sql
Normal file
@@ -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")
|
||||
public Integer highlight;
|
||||
|
||||
@Column(name = "archived")
|
||||
public Integer archived;
|
||||
|
||||
public Habit(Habit model)
|
||||
{
|
||||
copyAttributes(model);
|
||||
@@ -69,6 +72,7 @@ public class Habit extends Model
|
||||
this.color = ColorHelper.palette[7];
|
||||
this.position = Habit.getCount();
|
||||
this.highlight = 0;
|
||||
this.archived = 0;
|
||||
}
|
||||
|
||||
public static Habit get(Long id)
|
||||
@@ -84,7 +88,7 @@ public class Habit extends Model
|
||||
|
||||
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()
|
||||
@@ -178,7 +182,6 @@ public class Habit extends Model
|
||||
this.highlight = model.highlight;
|
||||
}
|
||||
|
||||
|
||||
public void save(Long id)
|
||||
{
|
||||
save();
|
||||
@@ -282,6 +285,18 @@ public class Habit extends Model
|
||||
deleteScoresNewerThan(timestamp);
|
||||
}
|
||||
|
||||
public void archive()
|
||||
{
|
||||
archived = 1;
|
||||
save();
|
||||
}
|
||||
|
||||
public void unarchive()
|
||||
{
|
||||
archived = 0;
|
||||
save();
|
||||
}
|
||||
|
||||
public void toggleRepetitionToday()
|
||||
{
|
||||
toggleRepetition(DateHelper.getStartOfToday());
|
||||
@@ -552,4 +567,31 @@ public class Habit extends Model
|
||||
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">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/action_delete_habit"
|
||||
android:title="@string/delete">
|
||||
android:id="@+id/action_archive_habit"
|
||||
android:title="@string/archive">
|
||||
</item>
|
||||
|
||||
</menu>
|
||||
@@ -5,6 +5,7 @@
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="edit">Edit</string>
|
||||
<string name="delete">Delete</string>
|
||||
<string name="archive">Archive</string>
|
||||
<string name="add_habit">Add habit</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>
|
||||
@@ -16,6 +17,8 @@
|
||||
<string name="toast_habit_changed">Habit changed.</string>
|
||||
<string name="toast_habit_changed_back">Habit changed back.</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 -->
|
||||
<string name="done_label">Done</string>
|
||||
|
||||
Reference in New Issue
Block a user