Finish implementation of habit archival

pull/30/head
Alinson S. Xavier 10 years ago
parent d4152f6b7e
commit d6d7798ae7

@ -69,7 +69,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.0.0/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
@ -83,10 +83,10 @@
<excludeFolder url="file://$MODULE_DIR$/build/outputs" /> <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" /> <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content> </content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" /> <orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="ActiveAndroid" level="project" /> <orderEntry type="library" exported="" name="ActiveAndroid" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" /> <orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" /> <orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
</component> </component>
</module> </module>

@ -38,19 +38,22 @@ public class MainActivity extends ReplayableActivity
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) public boolean onCreateOptionsMenu(Menu menu)
{ {
getMenuInflater().inflate(R.menu.main_activity, menu); getMenuInflater().inflate(R.menu.list_habits_menu, menu);
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) public boolean onOptionsItemSelected(MenuItem item)
{ {
int id = item.getItemId(); switch(item.getItemId())
if (id == R.id.action_settings) {
case R.id.action_settings:
return true; return true;
default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
}
@Override @Override
public void onHabitClicked(Habit habit) public void onHabitClicked(Habit habit)

@ -1,7 +1,5 @@
package org.isoron.uhabits; package org.isoron.uhabits;
import org.isoron.uhabits.dialogs.ListHabitsFragment;
import org.isoron.uhabits.dialogs.ShowHabitFragment;
import org.isoron.uhabits.models.Habit; import org.isoron.uhabits.models.Habit;
import android.app.Activity; import android.app.Activity;
@ -35,7 +33,7 @@ public class ShowHabitActivity extends Activity
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) public boolean onCreateOptionsMenu(Menu menu)
{ {
getMenuInflater().inflate(R.menu.show_habit, menu); getMenuInflater().inflate(R.menu.show_habit_menu, menu);
return true; return true;
} }

@ -9,6 +9,7 @@ import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Vibrator; import android.os.Vibrator;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.Display; import android.view.Display;
@ -34,6 +35,7 @@ import com.mobeta.android.dslv.DragSortController;
import com.mobeta.android.dslv.DragSortListView; import com.mobeta.android.dslv.DragSortListView;
import com.mobeta.android.dslv.DragSortListView.DropListener; import com.mobeta.android.dslv.DragSortListView.DropListener;
import org.isoron.helpers.ColorHelper;
import org.isoron.helpers.Command; import org.isoron.helpers.Command;
import org.isoron.helpers.DateHelper; import org.isoron.helpers.DateHelper;
import org.isoron.helpers.DialogHelper.OnSavedListener; import org.isoron.helpers.DialogHelper.OnSavedListener;
@ -153,22 +155,33 @@ public class ListHabitsFragment extends Fragment
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{ {
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.show_habits_options, menu); inflater.inflate(R.menu.list_habits_options, menu);
MenuItem showArchivedItem = menu.findItem(R.id.action_show_archived);
showArchivedItem.setChecked(Habit.isIncludeArchived());
} }
@Override @Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo)
{ {
super.onCreateContextMenu(menu, view, menuInfo); super.onCreateContextMenu(menu, view, menuInfo);
getActivity().getMenuInflater().inflate(R.menu.show_habits_context, menu); getActivity().getMenuInflater().inflate(R.menu.list_habits_context, menu);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
final Habit habit = Habit.get(info.id);
if(habit.isArchived())
menu.findItem(R.id.action_archive_habit).setVisible(false);
else
menu.findItem(R.id.action_unarchive_habit).setVisible(false);
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) public boolean onOptionsItemSelected(MenuItem item)
{ {
int id = item.getItemId(); switch(item.getItemId())
{
if (id == R.id.action_add) case R.id.action_add:
{ {
EditHabitFragment frag = EditHabitFragment.createHabitFragment(); EditHabitFragment frag = EditHabitFragment.createHabitFragment();
frag.setOnSavedListener(this); frag.setOnSavedListener(this);
@ -176,8 +189,18 @@ public class ListHabitsFragment extends Fragment
return true; return true;
} }
case R.id.action_show_archived:
{
Habit.setIncludeArchived(!Habit.isIncludeArchived());
notifyDataSetChanged();
activity.invalidateOptionsMenu();
return true;
}
default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
}
@Override @Override
public boolean onContextItemSelected(MenuItem menuItem) public boolean onContextItemSelected(MenuItem menuItem)
@ -193,12 +216,16 @@ public class ListHabitsFragment extends Fragment
frag.show(getFragmentManager(), "dialog"); frag.show(getFragmentManager(), "dialog");
return true; return true;
} }
else if (id == R.id.action_archive_habit)
if (id == R.id.action_archive_habit)
{ {
Command c = habit.new ArchiveCommand(); Command c = habit.new ArchiveCommand();
executeCommand(c); executeCommand(c);
} }
else if (id == R.id.action_unarchive_habit)
{
Command c = habit.new UnarchiveCommand();
executeCommand(c);
}
return super.onContextItemSelected(menuItem); return super.onContextItemSelected(menuItem);
} }
@ -353,6 +380,16 @@ public class ListHabitsFragment extends Fragment
tvName.setText(habit.name); tvName.setText(habit.name);
tvName.setTextColor(activeColor); tvName.setTextColor(activeColor);
if(habit.isArchived())
{
activeColor = ColorHelper.palette[12];
tvName.setTextColor(activeColor);
tvStar.setText(context.getString(R.string.fa_archive));
tvStar.setTextColor(activeColor);
}
else
{
int score = habit.getScore(); int score = habit.getScore();
if (score < Habit.HALF_STAR_CUTOFF) if (score < Habit.HALF_STAR_CUTOFF)
@ -370,6 +407,8 @@ public class ListHabitsFragment extends Fragment
tvStar.setText(context.getString(R.string.fa_star)); tvStar.setText(context.getString(R.string.fa_star));
tvStar.setTextColor(activeColor); tvStar.setTextColor(activeColor);
} }
}
LinearLayout llButtons = (LinearLayout) view.findViewById(R.id.llButtons); LinearLayout llButtons = (LinearLayout) view.findViewById(R.id.llButtons);
int m = llButtons.getChildCount(); int m = llButtons.getChildCount();

@ -21,7 +21,6 @@ import org.isoron.helpers.Command;
import org.isoron.helpers.DateHelper; import org.isoron.helpers.DateHelper;
import org.isoron.uhabits.R; import org.isoron.uhabits.R;
import java.util.Date;
import java.util.List; import java.util.List;
@Table(name = "Habits") @Table(name = "Habits")
@ -32,6 +31,8 @@ public class Habit extends Model
public static final int FULL_STAR_CUTOFF = 12973000; public static final int FULL_STAR_CUTOFF = 12973000;
public static final int MAX_SCORE = 19259500; public static final int MAX_SCORE = 19259500;
private static boolean includeArchived = false;
@Column(name = "name") @Column(name = "name")
public String name; public String name;
@ -88,9 +89,22 @@ public class Habit extends Model
protected static From select() protected static From select()
{ {
if(includeArchived)
return new Select().from(Habit.class).orderBy("position");
else
return new Select().from(Habit.class).where("archived = 0").orderBy("position"); return new Select().from(Habit.class).where("archived = 0").orderBy("position");
} }
public static void setIncludeArchived(boolean includeArchived)
{
Habit.includeArchived = includeArchived;
}
public static boolean isIncludeArchived()
{
return Habit.includeArchived;
}
public static int getCount() public static int getCount()
{ {
return select().count(); return select().count();
@ -298,6 +312,11 @@ public class Habit extends Model
save(); save();
} }
public boolean isArchived()
{
return archived != 0;
}
public void toggleRepetitionToday() public void toggleRepetitionToday()
{ {
toggleRepetition(DateHelper.getStartOfToday()); toggleRepetition(DateHelper.getStartOfToday());
@ -595,4 +614,31 @@ public class Habit extends Model
return R.string.toast_habit_unarchived; return R.string.toast_habit_unarchived;
} }
} }
public class UnarchiveCommand extends Command
{
@Override
public void execute()
{
unarchive();
Habit.rebuildOrder();
}
@Override
public void undo()
{
archive();
Habit.rebuildOrder();
}
public Integer getExecuteStringId()
{
return R.string.toast_habit_unarchived;
}
public Integer getUndoStringId()
{
return R.string.toast_habit_archived;
}
}
} }

@ -5,9 +5,15 @@
android:id="@+id/action_edit_habit" android:id="@+id/action_edit_habit"
android:title="@string/edit"> android:title="@string/edit">
</item> </item>
<item <item
android:id="@+id/action_archive_habit" android:id="@+id/action_archive_habit"
android:title="@string/archive"> android:title="@string/archive">
</item> </item>
<item
android:id="@+id/action_unarchive_habit"
android:title="@string/unarchive">
</item>
</menu> </menu>

@ -2,6 +2,11 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
tools:context="org.isoron.uhabits.MainActivity" > tools:context="org.isoron.uhabits.MainActivity" >
<item android:id="@+id/action_show_archived"
android:title="Show archived"
android:enabled="true"
android:checkable="true" />
<item <item
android:id="@+id/action_settings" android:id="@+id/action_settings"
android:orderInCategory="100" android:orderInCategory="100"

@ -2,6 +2,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
tools:context="org.isoron.uhabits.ShowHabitActivity" > tools:context="org.isoron.uhabits.ShowHabitActivity" >
<item <item
android:id="@+id/action_settings" android:id="@+id/action_settings"
android:orderInCategory="100" android:orderInCategory="100"

@ -9,6 +9,10 @@
<item name="android:windowContentTransitions">true</item> <item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item> <item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item> <item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:actionBarPopupTheme">@style/actionBarStyle</item>
</style>
<style name="actionBarStyle" parent="android:ThemeOverlay.Material.Light">
</style> </style>
<style name="MyDialogStyle" parent="android:Theme.Material.Light.Dialog"> <style name="MyDialogStyle" parent="android:Theme.Material.Light.Dialog">

@ -6,6 +6,7 @@
<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="archive">Archive</string>
<string name="unarchive">Unarchive</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>

Loading…
Cancel
Save