Add simple filter to menu

pull/145/head
Alinson S. Xavier 9 years ago
parent 3d53812d7f
commit dbe268b8e9

@ -95,4 +95,6 @@ public interface BaseComponent
void inject(BaseWidget baseWidget); void inject(BaseWidget baseWidget);
void inject(WidgetUpdater widgetManager); void inject(WidgetUpdater widgetManager);
void inject(ListHabitsMenu listHabitsMenu);
} }

@ -61,17 +61,6 @@ public class ListHabitsActivity extends BaseActivity
system = new BaseSystem(this); system = new BaseSystem(this);
adapter = new HabitCardListAdapter(habits, checkmarkCount); adapter = new HabitCardListAdapter(habits, checkmarkCount);
// List<Integer> colors = new ArrayList<>();
// colors.add(0);
// colors.add(1);
// colors.add(2);
//
// HabitMatcher matcher = new HabitMatcherBuilder()
// .setArchivedAllowed(false)
// .setAllowedColors(colors)
// .build();
// adapter.setFilter(matcher);
rootView = new ListHabitsRootView(this, adapter); rootView = new ListHabitsRootView(this, adapter);
screen = new ListHabitsScreen(this, rootView); screen = new ListHabitsScreen(this, rootView);
menu = new ListHabitsMenu(this, screen, adapter); menu = new ListHabitsMenu(this, screen, adapter);

@ -19,32 +19,43 @@
package org.isoron.uhabits.ui.habits.list; package org.isoron.uhabits.ui.habits.list;
import android.support.annotation.NonNull; import android.support.annotation.*;
import android.view.Menu; import android.view.*;
import android.view.MenuItem;
import org.isoron.uhabits.R; import org.isoron.uhabits.*;
import org.isoron.uhabits.ui.BaseActivity; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.ui.BaseMenu; import org.isoron.uhabits.ui.*;
import org.isoron.uhabits.ui.habits.list.model.*; import org.isoron.uhabits.ui.habits.list.model.*;
import org.isoron.uhabits.utils.InterfaceUtils; import org.isoron.uhabits.utils.*;
import javax.inject.*;
public class ListHabitsMenu extends BaseMenu public class ListHabitsMenu extends BaseMenu
{ {
@NonNull @NonNull
private final ListHabitsScreen screen; private final ListHabitsScreen screen;
private final HabitCardListAdapter adapter;
private boolean showArchived; private boolean showArchived;
private final HabitCardListAdapter adapter; private boolean showCompleted;
@Inject
Preferences preferences;
public ListHabitsMenu(@NonNull BaseActivity activity, public ListHabitsMenu(@NonNull BaseActivity activity,
@NonNull ListHabitsScreen screen, @NonNull ListHabitsScreen screen,
@NonNull HabitCardListAdapter adapter) @NonNull HabitCardListAdapter adapter)
{ {
super(activity); super(activity);
HabitsApplication.getComponent().inject(this);
this.screen = screen; this.screen = screen;
this.adapter = adapter; this.adapter = adapter;
showCompleted = preferences.getShowCompleted();
showArchived = preferences.getShowArchived();
updateAdapterFilter();
} }
@Override @Override
@ -55,6 +66,9 @@ public class ListHabitsMenu extends BaseMenu
MenuItem showArchivedItem = menu.findItem(R.id.action_show_archived); MenuItem showArchivedItem = menu.findItem(R.id.action_show_archived);
showArchivedItem.setChecked(showArchived); showArchivedItem.setChecked(showArchived);
MenuItem showCompletedItem = menu.findItem(R.id.actionShowCompleted);
showCompletedItem.setChecked(showCompleted);
} }
@Override @Override
@ -83,8 +97,12 @@ public class ListHabitsMenu extends BaseMenu
return true; return true;
case R.id.action_show_archived: case R.id.action_show_archived:
showArchived = !showArchived; toggleShowArchived();
adapter.setShowArchived(showArchived); invalidate();
return true;
case R.id.actionShowCompleted:
toggleShowCompleted();
invalidate(); invalidate();
return true; return true;
@ -96,6 +114,28 @@ public class ListHabitsMenu extends BaseMenu
@Override @Override
protected int getMenuResourceId() protected int getMenuResourceId()
{ {
return R.menu.main_activity; return R.menu.list_habits;
}
private void toggleShowArchived()
{
showArchived = !showArchived;
preferences.setShowArchived(showArchived);
updateAdapterFilter();
}
private void toggleShowCompleted()
{
showCompleted = !showCompleted;
preferences.setShowCompleted(showCompleted);
updateAdapterFilter();
}
private void updateAdapterFilter()
{
adapter.setFilter(new HabitMatcherBuilder()
.setArchivedAllowed(showArchived)
.setCompletedAllowed(showCompleted)
.build());
} }
} }

@ -172,6 +172,7 @@ public class HabitCardListCache implements CommandRunner.Listener
public void setFilter(HabitMatcher matcher) public void setFilter(HabitMatcher matcher)
{ {
filteredHabits = allHabits.getFiltered(matcher); filteredHabits = allHabits.getFiltered(matcher);
refreshAllHabits(true);
} }
public void setListener(@Nullable Listener listener) public void setListener(@Nullable Listener listener)

@ -61,6 +61,16 @@ public class Preferences
return prefs.getLong("last_hint_timestamp", -1); return prefs.getLong("last_hint_timestamp", -1);
} }
public boolean getShowArchived()
{
return prefs.getBoolean("pref_show_archived", false);
}
public boolean getShowCompleted()
{
return prefs.getBoolean("pref_show_completed", true);
}
public void incrementLaunchCount() public void incrementLaunchCount()
{ {
int count = prefs.getInt("launch_count", 0); int count = prefs.getInt("launch_count", 0);
@ -105,6 +115,16 @@ public class Preferences
.apply(); .apply();
} }
public void setShowCompleted(boolean showCompleted)
{
prefs.edit().putBoolean("pref_show_completed", showCompleted).apply();
}
public void setShowArchived(boolean showArchived)
{
prefs.edit().putBoolean("pref_show_archived", showArchived).apply();
}
public boolean shouldReverseCheckmarks() public boolean shouldReverseCheckmarks()
{ {
return prefs.getBoolean("pref_checkmark_reverse_order", false); return prefs.getBoolean("pref_checkmark_reverse_order", false);

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Filter"
android:id="@+id/title"/>
</LinearLayout>

@ -29,19 +29,31 @@
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item <item
android:id="@+id/action_show_archived" android:id="@+id/action_filter"
android:checkable="true" android:icon="?iconFilter"
android:enabled="true" android:title="@string/filter"
android:title="@string/show_archived" app:showAsAction="ifRoom">
android:orderInCategory="0" <menu>
app:showAsAction="never"/> <item
android:id="@+id/action_show_archived"
android:checkable="true"
android:enabled="true"
android:title="@string/show_archived"/>
<item
android:id="@+id/actionShowCompleted"
android:checkable="true"
android:enabled="true"
android:title="@string/show_completed"/>
</menu>
</item>
<item <item
android:id="@+id/action_night_mode" android:id="@+id/action_night_mode"
android:checkable="true" android:checkable="true"
android:enabled="true" android:enabled="true"
android:title="@string/night_mode"
android:orderInCategory="50" android:orderInCategory="50"
android:title="@string/night_mode"
app:showAsAction="never"/> app:showAsAction="never"/>
<item <item

@ -43,6 +43,7 @@
<attr name="dialogIconChangeColor" format="reference"/> <attr name="dialogIconChangeColor" format="reference"/>
<attr name="iconReminder" format="reference"/> <attr name="iconReminder" format="reference"/>
<attr name="iconFrequency" format="reference"/> <attr name="iconFrequency" format="reference"/>
<attr name="iconFilter" format="reference"/>
<attr name="toolbarPopupTheme" format="reference"/> <attr name="toolbarPopupTheme" format="reference"/>

@ -180,4 +180,6 @@
<string name="score">Score</string> <string name="score">Score</string>
<string name="reminder_sound">Reminder sound</string> <string name="reminder_sound">Reminder sound</string>
<string name="none">None</string> <string name="none">None</string>
<string name="filter">Filter</string>
<string name="show_completed">Show completed</string>
</resources> </resources>

@ -56,6 +56,7 @@
<item name="iconEdit">@drawable/ic_action_edit_dark</item> <item name="iconEdit">@drawable/ic_action_edit_dark</item>
<item name="iconUnarchive">@drawable/ic_action_unarchive_dark</item> <item name="iconUnarchive">@drawable/ic_action_unarchive_dark</item>
<item name="iconChangeColor">@drawable/ic_action_color_dark</item> <item name="iconChangeColor">@drawable/ic_action_color_dark</item>
<item name="iconFilter">@drawable/ic_action_filter_dark</item>
<item name="iconFrequency">@drawable/ic_repeat_black</item> <item name="iconFrequency">@drawable/ic_repeat_black</item>
<item name="iconReminder">@drawable/ic_alarm_black</item> <item name="iconReminder">@drawable/ic_alarm_black</item>
<item name="dialogIconChangeColor">@drawable/ic_action_color_light</item> <item name="dialogIconChangeColor">@drawable/ic_action_color_light</item>
@ -106,6 +107,7 @@
<item name="iconArchive">@drawable/ic_action_archive_dark</item> <item name="iconArchive">@drawable/ic_action_archive_dark</item>
<item name="iconEdit">@drawable/ic_action_edit_dark</item> <item name="iconEdit">@drawable/ic_action_edit_dark</item>
<item name="iconUnarchive">@drawable/ic_action_unarchive_dark</item> <item name="iconUnarchive">@drawable/ic_action_unarchive_dark</item>
<item name="iconFilter">@drawable/ic_action_filter_dark</item>
<item name="iconChangeColor">@drawable/ic_action_color_dark</item> <item name="iconChangeColor">@drawable/ic_action_color_dark</item>
<item name="dialogIconChangeColor">@drawable/ic_action_color_dark</item> <item name="dialogIconChangeColor">@drawable/ic_action_color_dark</item>
<item name="iconFrequency">@drawable/ic_repeat_white</item> <item name="iconFrequency">@drawable/ic_repeat_white</item>

Loading…
Cancel
Save