Add simple filter to menu
@@ -95,4 +95,6 @@ public interface BaseComponent
|
||||
void inject(BaseWidget baseWidget);
|
||||
|
||||
void inject(WidgetUpdater widgetManager);
|
||||
|
||||
void inject(ListHabitsMenu listHabitsMenu);
|
||||
}
|
||||
|
||||
@@ -61,17 +61,6 @@ public class ListHabitsActivity extends BaseActivity
|
||||
system = new BaseSystem(this);
|
||||
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);
|
||||
screen = new ListHabitsScreen(this, rootView);
|
||||
menu = new ListHabitsMenu(this, screen, adapter);
|
||||
|
||||
@@ -19,32 +19,43 @@
|
||||
|
||||
package org.isoron.uhabits.ui.habits.list;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.support.annotation.*;
|
||||
import android.view.*;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.ui.BaseActivity;
|
||||
import org.isoron.uhabits.ui.BaseMenu;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
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
|
||||
{
|
||||
@NonNull
|
||||
private final ListHabitsScreen screen;
|
||||
|
||||
private final HabitCardListAdapter adapter;
|
||||
|
||||
private boolean showArchived;
|
||||
|
||||
private final HabitCardListAdapter adapter;
|
||||
private boolean showCompleted;
|
||||
|
||||
@Inject
|
||||
Preferences preferences;
|
||||
|
||||
public ListHabitsMenu(@NonNull BaseActivity activity,
|
||||
@NonNull ListHabitsScreen screen,
|
||||
@NonNull HabitCardListAdapter adapter)
|
||||
{
|
||||
super(activity);
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
this.screen = screen;
|
||||
this.adapter = adapter;
|
||||
|
||||
showCompleted = preferences.getShowCompleted();
|
||||
showArchived = preferences.getShowArchived();
|
||||
updateAdapterFilter();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,6 +66,9 @@ public class ListHabitsMenu extends BaseMenu
|
||||
|
||||
MenuItem showArchivedItem = menu.findItem(R.id.action_show_archived);
|
||||
showArchivedItem.setChecked(showArchived);
|
||||
|
||||
MenuItem showCompletedItem = menu.findItem(R.id.actionShowCompleted);
|
||||
showCompletedItem.setChecked(showCompleted);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,8 +97,12 @@ public class ListHabitsMenu extends BaseMenu
|
||||
return true;
|
||||
|
||||
case R.id.action_show_archived:
|
||||
showArchived = !showArchived;
|
||||
adapter.setShowArchived(showArchived);
|
||||
toggleShowArchived();
|
||||
invalidate();
|
||||
return true;
|
||||
|
||||
case R.id.actionShowCompleted:
|
||||
toggleShowCompleted();
|
||||
invalidate();
|
||||
return true;
|
||||
|
||||
@@ -96,6 +114,28 @@ public class ListHabitsMenu extends BaseMenu
|
||||
@Override
|
||||
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)
|
||||
{
|
||||
filteredHabits = allHabits.getFiltered(matcher);
|
||||
refreshAllHabits(true);
|
||||
}
|
||||
|
||||
public void setListener(@Nullable Listener listener)
|
||||
|
||||
@@ -61,6 +61,16 @@ public class Preferences
|
||||
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()
|
||||
{
|
||||
int count = prefs.getInt("launch_count", 0);
|
||||
@@ -105,6 +115,16 @@ public class Preferences
|
||||
.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()
|
||||
{
|
||||
return prefs.getBoolean("pref_checkmark_reverse_order", false);
|
||||
|
||||
BIN
app/src/main/res/drawable-hdpi/ic_action_filter_dark.png
Normal file
|
After Width: | Height: | Size: 111 B |
BIN
app/src/main/res/drawable-hdpi/ic_action_filter_light.png
Normal file
|
After Width: | Height: | Size: 107 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_filter_dark.png
Normal file
|
After Width: | Height: | Size: 90 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_filter_light.png
Normal file
|
After Width: | Height: | Size: 89 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_filter_dark.png
Normal file
|
After Width: | Height: | Size: 103 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_filter_light.png
Normal file
|
After Width: | Height: | Size: 103 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_filter_dark.png
Normal file
|
After Width: | Height: | Size: 107 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_filter_light.png
Normal file
|
After Width: | Height: | Size: 112 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_action_filter_dark.png
Normal file
|
After Width: | Height: | Size: 106 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_action_filter_light.png
Normal file
|
After Width: | Height: | Size: 123 B |
31
app/src/main/res/layout/filter.xml
Normal file
@@ -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>
|
||||
@@ -28,20 +28,32 @@
|
||||
android:title="@string/add_habit"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_filter"
|
||||
android:icon="?iconFilter"
|
||||
android:title="@string/filter"
|
||||
app:showAsAction="ifRoom">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/action_show_archived"
|
||||
android:checkable="true"
|
||||
android:enabled="true"
|
||||
android:title="@string/show_archived"
|
||||
android:orderInCategory="0"
|
||||
app:showAsAction="never"/>
|
||||
android:title="@string/show_archived"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/actionShowCompleted"
|
||||
android:checkable="true"
|
||||
android:enabled="true"
|
||||
android:title="@string/show_completed"/>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_night_mode"
|
||||
android:checkable="true"
|
||||
android:enabled="true"
|
||||
android:title="@string/night_mode"
|
||||
android:orderInCategory="50"
|
||||
android:title="@string/night_mode"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
@@ -43,6 +43,7 @@
|
||||
<attr name="dialogIconChangeColor" format="reference"/>
|
||||
<attr name="iconReminder" format="reference"/>
|
||||
<attr name="iconFrequency" format="reference"/>
|
||||
<attr name="iconFilter" format="reference"/>
|
||||
|
||||
<attr name="toolbarPopupTheme" format="reference"/>
|
||||
|
||||
|
||||
@@ -180,4 +180,6 @@
|
||||
<string name="score">Score</string>
|
||||
<string name="reminder_sound">Reminder sound</string>
|
||||
<string name="none">None</string>
|
||||
<string name="filter">Filter</string>
|
||||
<string name="show_completed">Show completed</string>
|
||||
</resources>
|
||||
@@ -56,6 +56,7 @@
|
||||
<item name="iconEdit">@drawable/ic_action_edit_dark</item>
|
||||
<item name="iconUnarchive">@drawable/ic_action_unarchive_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="iconReminder">@drawable/ic_alarm_black</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="iconEdit">@drawable/ic_action_edit_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="dialogIconChangeColor">@drawable/ic_action_color_dark</item>
|
||||
<item name="iconFrequency">@drawable/ic_repeat_white</item>
|
||||
|
||||