mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Finish implementation of habit archival
This commit is contained in:
@@ -69,7 +69,7 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||
<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/jniLibs" />
|
||||
<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/tmp" />
|
||||
</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="library" exported="" name="ActiveAndroid" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -38,18 +38,21 @@ public class MainActivity extends ReplayableActivity
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.main_activity, menu);
|
||||
getMenuInflater().inflate(R.menu.list_habits_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_settings)
|
||||
return true;
|
||||
switch(item.getItemId())
|
||||
{
|
||||
case R.id.action_settings:
|
||||
return true;
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import org.isoron.uhabits.dialogs.ListHabitsFragment;
|
||||
import org.isoron.uhabits.dialogs.ShowHabitFragment;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -35,7 +33,7 @@ public class ShowHabitActivity extends Activity
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.show_habit, menu);
|
||||
getMenuInflater().inflate(R.menu.show_habit_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
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.DropListener;
|
||||
|
||||
import org.isoron.helpers.ColorHelper;
|
||||
import org.isoron.helpers.Command;
|
||||
import org.isoron.helpers.DateHelper;
|
||||
import org.isoron.helpers.DialogHelper.OnSavedListener;
|
||||
@@ -153,30 +155,51 @@ public class ListHabitsFragment extends Fragment
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater 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
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo 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
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.action_add)
|
||||
switch(item.getItemId())
|
||||
{
|
||||
EditHabitFragment frag = EditHabitFragment.createHabitFragment();
|
||||
frag.setOnSavedListener(this);
|
||||
frag.show(getFragmentManager(), "dialog");
|
||||
return true;
|
||||
}
|
||||
case R.id.action_add:
|
||||
{
|
||||
EditHabitFragment frag = EditHabitFragment.createHabitFragment();
|
||||
frag.setOnSavedListener(this);
|
||||
frag.show(getFragmentManager(), "dialog");
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
case R.id.action_show_archived:
|
||||
{
|
||||
Habit.setIncludeArchived(!Habit.isIncludeArchived());
|
||||
notifyDataSetChanged();
|
||||
activity.invalidateOptionsMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -193,12 +216,16 @@ public class ListHabitsFragment extends Fragment
|
||||
frag.show(getFragmentManager(), "dialog");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (id == R.id.action_archive_habit)
|
||||
else if (id == R.id.action_archive_habit)
|
||||
{
|
||||
Command c = habit.new ArchiveCommand();
|
||||
executeCommand(c);
|
||||
}
|
||||
else if (id == R.id.action_unarchive_habit)
|
||||
{
|
||||
Command c = habit.new UnarchiveCommand();
|
||||
executeCommand(c);
|
||||
}
|
||||
|
||||
return super.onContextItemSelected(menuItem);
|
||||
}
|
||||
@@ -353,24 +380,36 @@ public class ListHabitsFragment extends Fragment
|
||||
tvName.setText(habit.name);
|
||||
tvName.setTextColor(activeColor);
|
||||
|
||||
int score = habit.getScore();
|
||||
if(habit.isArchived())
|
||||
{
|
||||
activeColor = ColorHelper.palette[12];
|
||||
tvName.setTextColor(activeColor);
|
||||
|
||||
if (score < Habit.HALF_STAR_CUTOFF)
|
||||
{
|
||||
tvStar.setText(context.getString(R.string.fa_star_o));
|
||||
tvStar.setTextColor(inactiveColor);
|
||||
}
|
||||
else if (score < Habit.FULL_STAR_CUTOFF)
|
||||
{
|
||||
tvStar.setText(context.getString(R.string.fa_star_half_o));
|
||||
tvStar.setTextColor(inactiveColor);
|
||||
tvStar.setText(context.getString(R.string.fa_archive));
|
||||
tvStar.setTextColor(activeColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
tvStar.setText(context.getString(R.string.fa_star));
|
||||
tvStar.setTextColor(activeColor);
|
||||
int score = habit.getScore();
|
||||
|
||||
if (score < Habit.HALF_STAR_CUTOFF)
|
||||
{
|
||||
tvStar.setText(context.getString(R.string.fa_star_o));
|
||||
tvStar.setTextColor(inactiveColor);
|
||||
}
|
||||
else if (score < Habit.FULL_STAR_CUTOFF)
|
||||
{
|
||||
tvStar.setText(context.getString(R.string.fa_star_half_o));
|
||||
tvStar.setTextColor(inactiveColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
tvStar.setText(context.getString(R.string.fa_star));
|
||||
tvStar.setTextColor(activeColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LinearLayout llButtons = (LinearLayout) view.findViewById(R.id.llButtons);
|
||||
int m = llButtons.getChildCount();
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.isoron.helpers.Command;
|
||||
import org.isoron.helpers.DateHelper;
|
||||
import org.isoron.uhabits.R;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Table(name = "Habits")
|
||||
@@ -32,6 +31,8 @@ public class Habit extends Model
|
||||
public static final int FULL_STAR_CUTOFF = 12973000;
|
||||
public static final int MAX_SCORE = 19259500;
|
||||
|
||||
private static boolean includeArchived = false;
|
||||
|
||||
@Column(name = "name")
|
||||
public String name;
|
||||
|
||||
@@ -88,7 +89,20 @@ public class Habit extends Model
|
||||
|
||||
protected static From select()
|
||||
{
|
||||
return new Select().from(Habit.class).where("archived = 0").orderBy("position");
|
||||
if(includeArchived)
|
||||
return new Select().from(Habit.class).orderBy("position");
|
||||
else
|
||||
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()
|
||||
@@ -298,6 +312,11 @@ public class Habit extends Model
|
||||
save();
|
||||
}
|
||||
|
||||
public boolean isArchived()
|
||||
{
|
||||
return archived != 0;
|
||||
}
|
||||
|
||||
public void toggleRepetitionToday()
|
||||
{
|
||||
toggleRepetition(DateHelper.getStartOfToday());
|
||||
@@ -595,4 +614,31 @@ public class Habit extends Model
|
||||
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:title="@string/edit">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_archive_habit"
|
||||
android:title="@string/archive">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_unarchive_habit"
|
||||
android:title="@string/unarchive">
|
||||
</item>
|
||||
|
||||
</menu>
|
||||
@@ -2,6 +2,11 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="org.isoron.uhabits.MainActivity" >
|
||||
|
||||
<item android:id="@+id/action_show_archived"
|
||||
android:title="Show archived"
|
||||
android:enabled="true"
|
||||
android:checkable="true" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
@@ -2,6 +2,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="org.isoron.uhabits.ShowHabitActivity" >
|
||||
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
@@ -9,6 +9,10 @@
|
||||
<item name="android:windowContentTransitions">true</item>
|
||||
<item name="android:windowAllowEnterTransitionOverlap">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 name="MyDialogStyle" parent="android:Theme.Material.Light.Dialog">
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<string name="edit">Edit</string>
|
||||
<string name="delete">Delete</string>
|
||||
<string name="archive">Archive</string>
|
||||
<string name="unarchive">Unarchive</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>
|
||||
|
||||
Reference in New Issue
Block a user