Implement more task filtering options

This commit is contained in:
Phillip Thelen 2017-04-03 19:36:44 +02:00
parent 1b5dec0c16
commit e79bd18c3a
24 changed files with 517 additions and 427 deletions

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/brand_400"/>
<corners android:radius="20dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<corners android:radius="20dip"/>
<stroke android:color="@color/days_gray" android:width="1dp" />
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/pill_bg_radio_selected" android:state_checked="true" />
<item android:drawable="@drawable/pill_bg_radio_unselected" android:state_checked="false" />
</selector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/white"/>
<item android:color="@color/days_gray"/>
</selector>

View file

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/pill_gray" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical">
<TextView
android:id="@+id/task_type_title"
style="@style/Caption3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="@string/habits"
android:textAllCaps="true"/>
<RadioGroup
android:id="@+id/task_filter_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="12dp"
android:layout_marginBottom="24dp"
>
<RadioButton
android:id="@+id/all_task_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/all"
style="@style/TaskFilterRadioButton"
android:checked="true"
/>
<RadioButton
android:id="@+id/second_task_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/weak"
style="@style/TaskFilterRadioButton"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" />
<RadioButton
android:id="@+id/third_task_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/strong"
style="@style/TaskFilterRadioButton"/>
</RadioGroup>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/pill_gray" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tags_title"
style="@style/Caption3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:text="@string/tags"
android:textAllCaps="true"/>
<Button
android:id="@+id/challenge_filter_button_done"
style="@style/Body1_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/edit_tag_btn_edit"
android:textColor="#6133b4"
android:textSize="16sp" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/tags_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:orientation="vertical"/>
</ScrollView>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/pill_gray" />
</LinearLayout>

View file

@ -551,4 +551,9 @@ To start, which parts of your life do you want to improve?</string>
<string name="avatar_hair_ponytail">Ponytail</string>
<string name="avatar_glasses">Glasses</string>
<string name="avatar_wheelchair">Wheelchair</string>
<string name="weak">Weak</string>
<string name="strong">Strong</string>
<string name="gray">Gray</string>
<string name="dated">Dated</string>
<string name="completed">Complated</string>
</resources>

View file

@ -329,4 +329,13 @@
<item name="android:textAllCaps">false</item>
<item name="android:shadowColor">@color/transparent</item>
</style>
<style name="TaskFilterRadioButton">
<item name="android:layout_weight">1</item>
<item name="android:button">@color/transparent</item>
<item name="android:background">@drawable/pill_radio_button</item>
<item name="android:gravity">center</item>
<item name="android:padding">8dp</item>
<item name="android:textColor">@drawable/radio_button_text_color</item>
</style>
</resources>

View file

@ -1,49 +0,0 @@
package com.habitrpg.android.habitica.helpers;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
import java.util.ArrayList;
import java.util.List;
/**
* Created by magicmicky on 02/10/15.
*/
public class TagsHelper {
private List<String> tagsId;
public TagsHelper() {
tagsId = new ArrayList<String>();
}
public void addTags(String tags) {
this.tagsId.add(tags);
}
public int howMany() {
return this.tagsId.size();
}
public List<String> getTags() {
return this.tagsId;
}
public void setTags(List<String> tagsId) {
this.tagsId = tagsId;
}
public boolean isTagChecked(String tagID) {
return this.tagsId.contains(tagID);
}
public List<Task> filter(List<Task> tasks) {
List<Task> filtered = new ArrayList<Task>();
for (Task t : tasks) {
if (t.containsAllTagIds(this.tagsId)) {
filtered.add(t);
}
}
return filtered;
}
}

View file

@ -0,0 +1,81 @@
package com.habitrpg.android.habitica.helpers;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
import java.util.ArrayList;
import java.util.List;
/**
* Created by magicmicky on 02/10/15.
*/
public class TaskFilterHelper {
private List<String> tagsId;
private String activeFilter;
public TaskFilterHelper() {
tagsId = new ArrayList<>();
}
public void addTags(String tags) {
this.tagsId.add(tags);
}
public int howMany() {
return this.tagsId.size() + (activeFilter != null ? 1 : 0);
}
public List<String> getTags() {
return this.tagsId;
}
public void setTags(List<String> tagsId) {
this.tagsId = tagsId;
}
public boolean isTagChecked(String tagID) {
return this.tagsId.contains(tagID);
}
public List<Task> filter(List<Task> tasks) {
List<Task> filtered = new ArrayList<Task>();
for (Task task : tasks) {
if (isFiltered(task)) {
filtered.add(task);
}
}
return filtered;
}
private boolean isFiltered(Task task) {
if (!task.containsAllTagIds(tagsId)) {
return false;
}
if (activeFilter != null && !activeFilter.equals(Task.FILTER_ALL)) {
switch (activeFilter) {
case Task.FILTER_ACTIVE:
if (task.type.equals(Task.TYPE_DAILY)) {
return task.isDisplayedActive(0);
} else {
return !task.completed;
}
case Task.FILTER_GRAY:
return task.completed || !task.isDisplayedActive(0);
case Task.FILTER_WEAK:
return task.value < 0;
case Task.FILTER_STRONG:
return task.value >= 0;
case Task.FILTER_DATED:
return task.duedate != null;
case Task.FILTER_COMPLETED:
return task.completed;
}
}
return true;
}
public void setActiveFilter(String activeFilter) {
this.activeFilter = activeFilter;
}
}

View file

@ -7,7 +7,7 @@ import com.habitrpg.android.habitica.executors.ThreadExecutor;
import com.habitrpg.android.habitica.executors.UIThread;
import com.habitrpg.android.habitica.helpers.SoundFileLoader;
import com.habitrpg.android.habitica.helpers.SoundManager;
import com.habitrpg.android.habitica.helpers.TagsHelper;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import android.app.Application;
import android.content.Context;
@ -50,8 +50,8 @@ public class AppModule {
@Provides
@Singleton
public TagsHelper providesTagsHelper() {
return new TagsHelper();
public TaskFilterHelper providesTagsHelper() {
return new TaskFilterHelper();
}
@Provides

View file

@ -235,7 +235,6 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
// endregion
private Drawer drawer;
private Drawer filterDrawer;
private AccountHeader accountHeader;
private BaseMainFragment activeFragment;
private AvatarWithBarsViewModel avatarInHeader;
@ -303,14 +302,6 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
drawer.setSelectionAtPosition(1, false);
sideAvatarView = new AvatarView(this, true, false, false);
if (this.filterDrawer == null) {
filterDrawer = new DrawerBuilder()
.withActivity(this)
.withDrawerGravity(Gravity.END)
.withCloseOnClick(false)
.append(this.drawer);
}
EventBus.getDefault().register(this);
}
@ -1518,44 +1509,14 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
}
public void closeDrawer(int gravity) {
Drawer drawer;
if (gravity == GravityCompat.START) {
drawer = this.drawer;
} else {
drawer = this.filterDrawer;
}
if (drawer != null) {
drawer.closeDrawer();
}
this.drawer.closeDrawer();
}
public void openDrawer(int gravity) {
Drawer drawer;
if (gravity == GravityCompat.START) {
drawer = this.drawer;
} else {
drawer = this.filterDrawer;
}
if (drawer != null) {
EventBus.getDefault().post(new ToggledEditTagsEvent(false));
drawer.openDrawer();
}
EventBus.getDefault().post(new ToggledEditTagsEvent(false));
this.drawer.openDrawer();
}
public void fillFilterDrawer(List<IDrawerItem> items) {
if (this.filterDrawer != null) {
this.filterDrawer.removeAllItems();
for (IDrawerItem item : items) {
this.filterDrawer.addItem(item);
}
}
}
public void addFilterDrawerItem(IDrawerItem item) {
this.filterDrawer.addItem(item);
}
@Subscribe
public void onEvent(OpenFullProfileCommand cmd) {
if (cmd.MemberId.equals("system"))
@ -1569,13 +1530,4 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
}
public void removeFilterDrawerItem(int position) {
this.filterDrawer.removeItemByPosition(position);
}
public void updateFilterDrawerItem(IDrawerItem item, int position) {
this.filterDrawer.removeItemByPosition(position);
this.filterDrawer.addItemAtPosition(item, position);
}
}

View file

@ -6,7 +6,7 @@ import com.habitrpg.android.habitica.events.TaskSaveEvent;
import com.habitrpg.android.habitica.events.commands.DeleteTaskCommand;
import com.habitrpg.android.habitica.helpers.FirstDayOfTheWeekHelper;
import com.habitrpg.android.habitica.helpers.RemindersManager;
import com.habitrpg.android.habitica.helpers.TagsHelper;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import com.habitrpg.android.habitica.helpers.TaskAlarmManager;
import com.habitrpg.android.habitica.ui.WrapContentRecyclerViewLayoutManager;
import com.habitrpg.android.habitica.ui.adapter.tasks.CheckListAdapter;
@ -194,7 +194,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
LinearLayout tagsContainerLinearLayout;
@Inject
TagsHelper tagsHelper;
TaskFilterHelper taskFilterHelper;
EmojiPopup popup;
@ -526,7 +526,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
}
}
});
checkbox.setChecked(tagsHelper.isTagChecked(tag.getId()));
checkbox.setChecked(taskFilterHelper.isTagChecked(tag.getId()));
tagsContainerLinearLayout.addView(row);
tagCheckBoxList.add(checkbox);
position++;

View file

@ -2,7 +2,7 @@ package com.habitrpg.android.habitica.ui.adapter.tasks;
import com.habitrpg.android.habitica.HabiticaBaseApplication;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.helpers.TagsHelper;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import com.habitrpg.android.habitica.proxy.ifce.CrashlyticsProxy;
import com.habitrpg.android.habitica.ui.helpers.MarkdownParser;
import com.habitrpg.android.habitica.ui.viewHolders.tasks.BaseTaskViewHolder;
@ -37,14 +37,14 @@ public abstract class BaseTasksRecyclerViewAdapter<VH extends BaseTaskViewHolder
protected List<Task> filteredContent;
int layoutResource;
Context context;
private TagsHelper tagsHelper;
private TaskFilterHelper taskFilterHelper;
public BaseTasksRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource,
public BaseTasksRecyclerViewAdapter(String taskType, TaskFilterHelper taskFilterHelper, int layoutResource,
Context newContext, String userID) {
this.setHasStableIds(true);
this.taskType = taskType;
this.context = newContext.getApplicationContext();
this.tagsHelper = tagsHelper;
this.taskFilterHelper = taskFilterHelper;
this.userID = userID;
this.filteredContent = new ArrayList<>();
injectThis(HabiticaBaseApplication.getComponent());
@ -105,11 +105,11 @@ public abstract class BaseTasksRecyclerViewAdapter<VH extends BaseTaskViewHolder
}
public void filter() {
if (this.tagsHelper == null || this.tagsHelper.howMany() == 0) {
if (this.taskFilterHelper == null || this.taskFilterHelper.howMany() == 0) {
filteredContent = content;
} else {
filteredContent = new ObservableArrayList<>();
filteredContent.addAll(this.tagsHelper.filter(content));
filteredContent.addAll(this.taskFilterHelper.filter(content));
}
this.notifyDataSetChanged();

View file

@ -2,7 +2,7 @@ package com.habitrpg.android.habitica.ui.adapter.tasks;
import com.habitrpg.android.habitica.HabiticaBaseApplication;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.helpers.TagsHelper;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import com.habitrpg.android.habitica.ui.viewHolders.tasks.DailyViewHolder;
import android.content.Context;
@ -13,10 +13,10 @@ public class DailiesRecyclerViewHolder extends SortableTasksRecyclerViewAdapter<
public int dailyResetOffset;
public DailiesRecyclerViewHolder(String taskType, TagsHelper tagsHelper, int layoutResource,
public DailiesRecyclerViewHolder(String taskType, TaskFilterHelper taskFilterHelper, int layoutResource,
Context newContext, String userID, int dailyResetOffset,
@Nullable SortTasksCallback sortTasksCallback) {
super(taskType, tagsHelper, layoutResource, newContext, userID, sortTasksCallback);
super(taskType, taskFilterHelper, layoutResource, newContext, userID, sortTasksCallback);
this.dailyResetOffset = dailyResetOffset;
}

View file

@ -2,7 +2,7 @@ package com.habitrpg.android.habitica.ui.adapter.tasks;
import com.habitrpg.android.habitica.HabiticaBaseApplication;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.helpers.TagsHelper;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import com.habitrpg.android.habitica.ui.viewHolders.tasks.HabitViewHolder;
import android.content.Context;
@ -12,8 +12,8 @@ import android.view.ViewGroup;
public class HabitsRecyclerViewAdapter extends SortableTasksRecyclerViewAdapter<HabitViewHolder> {
public HabitsRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource, Context newContext, String userID, @Nullable SortTasksCallback sortCallback) {
super(taskType, tagsHelper, layoutResource, newContext, userID, sortCallback);
public HabitsRecyclerViewAdapter(String taskType, TaskFilterHelper taskFilterHelper, int layoutResource, Context newContext, String userID, @Nullable SortTasksCallback sortCallback) {
super(taskType, taskFilterHelper, layoutResource, newContext, userID, sortCallback);
}
@Override

View file

@ -5,7 +5,7 @@ import com.habitrpg.android.habitica.ContentCache;
import com.habitrpg.android.habitica.HabiticaBaseApplication;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.helpers.TagsHelper;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import com.habitrpg.android.habitica.ui.viewHolders.tasks.RewardViewHolder;
import com.magicmicky.habitrpgwrapper.lib.api.ApiClient;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
@ -28,8 +28,8 @@ public class RewardsRecyclerViewAdapter extends BaseTasksRecyclerViewAdapter<Rew
private final HabitRPGUser user;
private ApiClient apiClient;
public RewardsRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource, Context newContext, HabitRPGUser user, ApiClient apiClient) {
super(taskType, tagsHelper, layoutResource, newContext, user.getId());
public RewardsRecyclerViewAdapter(String taskType, TaskFilterHelper taskFilterHelper, int layoutResource, Context newContext, HabitRPGUser user, ApiClient apiClient) {
super(taskType, taskFilterHelper, layoutResource, newContext, user.getId());
this.user = user;
this.apiClient = apiClient;
this.contentCache = new ContentCache(apiClient);

View file

@ -1,6 +1,6 @@
package com.habitrpg.android.habitica.ui.adapter.tasks;
import com.habitrpg.android.habitica.helpers.TagsHelper;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import com.habitrpg.android.habitica.ui.helpers.ItemTouchHelperAdapter;
import com.habitrpg.android.habitica.ui.helpers.ItemTouchHelperDropCallback;
import com.habitrpg.android.habitica.ui.viewHolders.tasks.BaseTaskViewHolder;
@ -19,9 +19,9 @@ public abstract class SortableTasksRecyclerViewAdapter<VH extends BaseTaskViewHo
private SortTasksCallback sortCallback;
public SortableTasksRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource,
public SortableTasksRecyclerViewAdapter(String taskType, TaskFilterHelper taskFilterHelper, int layoutResource,
Context newContext, String userID, @Nullable SortTasksCallback sortCallback) {
super(taskType, tagsHelper, layoutResource, newContext, userID);
super(taskType, taskFilterHelper, layoutResource, newContext, userID);
this.sortCallback = sortCallback;
}

View file

@ -2,7 +2,7 @@ package com.habitrpg.android.habitica.ui.adapter.tasks;
import com.habitrpg.android.habitica.HabiticaBaseApplication;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.helpers.TagsHelper;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import com.habitrpg.android.habitica.ui.viewHolders.tasks.TodoViewHolder;
import android.content.Context;
@ -11,9 +11,9 @@ import android.view.ViewGroup;
public class TodosRecyclerViewAdapter extends SortableTasksRecyclerViewAdapter<TodoViewHolder> {
public TodosRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource,
public TodosRecyclerViewAdapter(String taskType, TaskFilterHelper taskFilterHelper, int layoutResource,
Context newContext, String userID, @Nullable SortTasksCallback sortCallback) {
super(taskType, tagsHelper, layoutResource, newContext, userID, sortCallback);
super(taskType, taskFilterHelper, layoutResource, newContext, userID, sortCallback);
}
@Override

View file

@ -1,10 +1,10 @@
package com.habitrpg.android.habitica.ui.fragments.social.challenges;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import com.magicmicky.habitrpgwrapper.lib.api.ApiClient;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.helpers.TagsHelper;
import com.habitrpg.android.habitica.ui.adapter.tasks.BaseTasksRecyclerViewAdapter;
import com.habitrpg.android.habitica.ui.adapter.tasks.SortableTasksRecyclerViewAdapter;
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
@ -146,8 +146,8 @@ public class ChallengeTasksRecyclerViewFragment extends BaseFragment {
private int dailyResetOffset = 0;
public ChallengeTasksRecyclerViewAdapter(TagsHelper tagsHelper, int layoutResource, Context newContext, String userID, SortTasksCallback sortCallback) {
super("", tagsHelper, layoutResource, newContext, userID, sortCallback);
public ChallengeTasksRecyclerViewAdapter(TaskFilterHelper taskFilterHelper, int layoutResource, Context newContext, String userID, SortTasksCallback sortCallback) {
super("", taskFilterHelper, layoutResource, newContext, userID, sortCallback);
if (user != null) {
dailyResetOffset = user.getPreferences().getDayStart();

View file

@ -20,7 +20,7 @@ import com.habitrpg.android.habitica.events.TaskUpdatedEvent;
import com.habitrpg.android.habitica.events.commands.AddNewTaskCommand;
import com.habitrpg.android.habitica.events.commands.FilterTasksByTagsCommand;
import com.habitrpg.android.habitica.events.commands.TaskCheckedCommand;
import com.habitrpg.android.habitica.helpers.TagsHelper;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import com.habitrpg.android.habitica.ui.activities.MainActivity;
import com.habitrpg.android.habitica.ui.adapter.tasks.BaseTasksRecyclerViewAdapter;
import com.habitrpg.android.habitica.ui.adapter.tasks.DailiesRecyclerViewHolder;
@ -59,7 +59,7 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
@Inject
ApiClient apiClient;
@Inject
TagsHelper tagsHelper;
TaskFilterHelper taskFilterHelper;
LinearLayoutManager layoutManager = null;
@ -68,20 +68,22 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
@BindView(R.id.recyclerView)
public RecyclerView recyclerView;
private String classType;
String classType;
private HabitRPGUser user;
private View view;
@Nullable
private SortableTasksRecyclerViewAdapter.SortTasksCallback sortCallback;
private ItemTouchHelper.Callback mItemTouchCallback;
private String activeFilter;
public static TaskRecyclerViewFragment newInstance(HabitRPGUser user, String classType,
public static TaskRecyclerViewFragment newInstance(HabitRPGUser user, String classType, @Nullable String activeFilter,
@Nullable SortableTasksRecyclerViewAdapter.SortTasksCallback sortCallback) {
TaskRecyclerViewFragment fragment = new TaskRecyclerViewFragment();
fragment.setRetainInstance(true);
fragment.user = user;
fragment.classType = classType;
fragment.sortCallback = sortCallback;
fragment.activeFilter = activeFilter;
return fragment;
}
@ -92,7 +94,7 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
switch (this.classType) {
case Task.TYPE_HABIT:
layoutOfType = R.layout.habit_item_card;
this.recyclerAdapter = new HabitsRecyclerViewAdapter(Task.TYPE_HABIT, tagsHelper, layoutOfType, getContext(), userID, sortCallback);
this.recyclerAdapter = new HabitsRecyclerViewAdapter(Task.TYPE_HABIT, taskFilterHelper, layoutOfType, getContext(), userID, sortCallback);
allowReordering();
break;
case Task.TYPE_DAILY:
@ -101,17 +103,17 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
if (user != null) {
dailyResetOffset = user.getPreferences().getDayStart();
}
this.recyclerAdapter = new DailiesRecyclerViewHolder(Task.TYPE_DAILY, tagsHelper, layoutOfType, getContext(), userID, dailyResetOffset, sortCallback);
this.recyclerAdapter = new DailiesRecyclerViewHolder(Task.TYPE_DAILY, taskFilterHelper, layoutOfType, getContext(), userID, dailyResetOffset, sortCallback);
allowReordering();
break;
case Task.TYPE_TODO:
layoutOfType = R.layout.todo_item_card;
this.recyclerAdapter = new TodosRecyclerViewAdapter(Task.TYPE_TODO, tagsHelper, layoutOfType, getContext(), userID, sortCallback);
this.recyclerAdapter = new TodosRecyclerViewAdapter(Task.TYPE_TODO, taskFilterHelper, layoutOfType, getContext(), userID, sortCallback);
allowReordering();
return;
case Task.TYPE_REWARD:
layoutOfType = R.layout.reward_item_card;
this.recyclerAdapter = new RewardsRecyclerViewAdapter(Task.TYPE_REWARD, tagsHelper, layoutOfType, getContext(), user, apiClient);
this.recyclerAdapter = new RewardsRecyclerViewAdapter(Task.TYPE_REWARD, taskFilterHelper, layoutOfType, getContext(), user, apiClient);
break;
}
}
@ -125,6 +127,9 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
taskFilterHelper.setActiveFilter(activeFilter);
mItemTouchCallback = new ItemTouchHelper.Callback() {
private Integer mFromPosition = null;
@ -284,4 +289,10 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
throwable -> {}
);
}
public void setActiveFilter(String activeFilter) {
this.activeFilter = activeFilter;
taskFilterHelper.setActiveFilter(activeFilter);
recyclerAdapter.filter();
}
}

View file

@ -26,7 +26,6 @@ import com.github.clans.fab.FloatingActionButton;
import com.github.clans.fab.FloatingActionMenu;
import com.habitrpg.android.habitica.HabiticaApplication;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.events.TaskSaveEvent;
import com.habitrpg.android.habitica.events.TaskTappedEvent;
@ -36,10 +35,9 @@ import com.habitrpg.android.habitica.events.commands.CreateTagCommand;
import com.habitrpg.android.habitica.events.commands.DeleteTagCommand;
import com.habitrpg.android.habitica.events.commands.EditTagCommand;
import com.habitrpg.android.habitica.events.commands.FilterTasksByTagsCommand;
import com.habitrpg.android.habitica.events.commands.RefreshTasksCommand;
import com.habitrpg.android.habitica.events.commands.RefreshUserCommand;
import com.habitrpg.android.habitica.events.commands.UpdateTagCommand;
import com.habitrpg.android.habitica.helpers.TagsHelper;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import com.habitrpg.android.habitica.ui.activities.MainActivity;
import com.habitrpg.android.habitica.ui.activities.TaskFormActivity;
import com.habitrpg.android.habitica.ui.adapter.tasks.BaseTasksRecyclerViewAdapter;
@ -49,14 +47,11 @@ import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
import com.habitrpg.android.habitica.ui.helpers.Debounce;
import com.habitrpg.android.habitica.ui.helpers.UiUtils;
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
import com.habitrpg.android.habitica.ui.menu.EditTagsDrawerItem;
import com.habitrpg.android.habitica.ui.menu.EditTagsSectionDrawer;
import com.habitrpg.android.habitica.ui.menu.EditTextDrawer;
import com.habitrpg.android.habitica.ui.views.tasks.TaskFilterDialog;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import com.magicmicky.habitrpgwrapper.lib.models.Tag;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
import com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener;
import com.mikepenz.materialdrawer.model.SwitchDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import org.greenrobot.eventbus.EventBus;
@ -70,38 +65,20 @@ import java.util.Map;
import javax.inject.Inject;
public class TasksFragment extends BaseMainFragment implements OnCheckedChangeListener {
public class TasksFragment extends BaseMainFragment {
private static final int TASK_CREATED_RESULT = 1;
private static final int TASK_UPDATED_RESULT = 2;
public ViewPager viewPager;
@Inject
public TagsHelper tagsHelper; // This will be used for this fragment. Currently being used to help filtering
public TaskFilterHelper taskFilterHelper; // This will be used for this fragment. Currently being used to help filtering
MenuItem refreshItem;
FloatingActionMenu floatingMenu;
Map<Integer, TaskRecyclerViewFragment> ViewFragmentsDictionary = new HashMap<>();
Map<String, String> activeTaskFilters = new HashMap<>();
private boolean displayingTaskForm;
private boolean editingTags;
private List<Tag> tags;
private HashMap<String, Boolean> tagFilterMap = new HashMap<>();
private Debounce filterChangedHandler = new Debounce(1500, 1000) {
@Override
public void execute() {
ArrayList<String> tagList = new ArrayList<>();
for (Map.Entry<String, Boolean> f : tagFilterMap.entrySet()) {
if (f.getValue()) {
tagList.add(f.getKey());
}
}
tagsHelper.setTags(tagList);
TasksFragment.this.activity.runOnUiThread(() -> EventBus.getDefault().post(new FilterTasksByTagsCommand()));
}
};
public void setActivity(MainActivity activity) {
super.setActivity(activity);
@ -114,7 +91,6 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
this.usesTabLayout = false;
this.usesBottomNavigation = true;
this.displayingTaskForm = false;
this.editingTags = false;
super.onCreateView(inflater, container, savedInstanceState);
View v = inflater.inflate(R.layout.fragment_fading_viewpager, container, false);
@ -164,16 +140,6 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
return true;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (user != null) {
tags = user.getTags();
fillTagFilterDrawer(tags);
}
}
@Override
public void injectFragment(AppComponent component) {
component.inject(this);
@ -190,7 +156,7 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
switch (id) {
case R.id.action_search:
this.activity.openDrawer(GravityCompat.END);
showFilterDialog();
return true;
case R.id.action_reload:
refreshItem = item;
@ -201,8 +167,22 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
return super.onOptionsItemSelected(item);
}
private void showFilterDialog() {
TaskFilterDialog dialog = new TaskFilterDialog(getContext());
dialog.setTags(user.getTags());
dialog.setActiveTags(taskFilterHelper.getTags());
String taskType = getActiveFragment().classType;
dialog.setTaskType(taskType, activeTaskFilters.get(taskType));
dialog.setListener((activeTaskFilter, activeTags) -> {
activeTaskFilters.put(taskType, activeTaskFilter);
getActiveFragment().setActiveFilter(activeTaskFilter);
taskFilterHelper.setTags(activeTags);
});
dialog.show();
}
public void refresh() {
ViewFragmentsDictionary.get(viewPager.getCurrentItem()).onRefresh();
getActiveFragment().onRefresh();
}
public void loadTaskLists() {
@ -217,7 +197,6 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
(task, from, to) -> {
if (apiClient != null){
apiClient.postTaskNewPosition(task.getId(), String.valueOf(to))
.subscribe(aVoid -> {
}, e -> {
});
@ -226,16 +205,16 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
switch (position) {
case 0:
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_HABIT, sortCallback);
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_HABIT, activeTaskFilters.get(Task.TYPE_HABIT), sortCallback);
break;
case 1:
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_DAILY, sortCallback);
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_DAILY, activeTaskFilters.get(Task.TYPE_DAILY), sortCallback);
break;
case 3:
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_REWARD, null);
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_REWARD, null, null);
break;
default:
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_TODO, sortCallback);
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_TODO, activeTaskFilters.get(Task.TYPE_TODO),sortCallback);
}
ViewFragmentsDictionary.put(position, fragment);
@ -270,7 +249,6 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
public void updateUserData(HabitRPGUser user) {
super.updateUserData(user);
if (this.user != null) {
fillTagFilterDrawer(tags);
for (TaskRecyclerViewFragment fragm : ViewFragmentsDictionary.values()) {
if (fragm != null) {
BaseTasksRecyclerViewAdapter adapter = fragm.recyclerAdapter;
@ -308,63 +286,13 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
}
}
@Subscribe
public void onEvent(final CreateTagCommand event) {
UiUtils.dismissKeyboard(activity);
final Tag t = new Tag();
t.setName(event.tagName);
if (apiClient != null) {
apiClient.createTag(t)
.subscribe(tag -> {
// Since we get a list of all tags, we just save them all
tag.user_id = user.getId();
tag.async().save();
tags.add(tag);
addTagFilterDrawerItem(tag);
}, throwable -> UiUtils.showSnackbar(activity, activity.getFloatingMenuWrapper(), "Error: " + throwable.getMessage(), UiUtils.SnackbarDisplayType.FAILURE));
}
}
@Subscribe
public void onEvent(final DeleteTagCommand event) {
final Tag t = event.tag;
if (apiClient != null) {
apiClient.deleteTag(t.getId())
.subscribe(tag -> {
tagFilterMap.remove(t.getId());
filterChangedHandler.hit();
removeTagFilterDrawerItem(t);
EventBus.getDefault().post(new RefreshUserCommand());
}, throwable -> UiUtils.showSnackbar(activity, activity.getFloatingMenuWrapper(), "Error: " + throwable.getMessage(), UiUtils.SnackbarDisplayType.FAILURE));
}
}
@Subscribe
public void onEvent(final EditTagCommand event) {
showEditTagDialog(event.tag);
}
@Subscribe
public void onEvent(final UpdateTagCommand event) {
final Tag t = event.tag;
final String uuid = event.uuid;
if (apiClient != null) {
apiClient.updateTag(uuid,t)
.subscribe(tag -> {
UiUtils.dismissKeyboard(this.activity);
updateTagFilterDrawerItem(tag);
EventBus.getDefault().post(new RefreshUserCommand());
}, throwable -> UiUtils.showSnackbar(activity, activity.getFloatingMenuWrapper(), "Error: " + throwable.getMessage(), UiUtils.SnackbarDisplayType.FAILURE));
}
}
@Subscribe
public void onEvent(RefreshUserCommand event) {
ViewFragmentsDictionary.get(viewPager.getCurrentItem()).onRefresh();
getActiveFragment().onRefresh();
}
private TaskRecyclerViewFragment getActiveFragment() {
return ViewFragmentsDictionary.get(viewPager.getCurrentItem());
}
@Subscribe
@ -402,115 +330,8 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
floatingMenu.close(true);
}
@Subscribe
public void onEvent(ToggledEditTagsEvent event) {
if (user != null) {
if (this.editingTags == event.editing) {
return;
}
this.editingTags = event.editing;
fillTagFilterDrawer(tags);
}
}
//endregion Events
public void fillTagFilterDrawer(List<Tag> tagList) {
if (this.tagsHelper != null) {
List<IDrawerItem> items = new ArrayList<>();
if (this.editingTags) {
items.add(new EditTagsSectionDrawer().withEditing(this.editingTags).withName(getString(R.string.filter_drawer_edit_tags)));
items.add(new EditTextDrawer());
if (tagList != null) {
for (Tag t : tagList) {
items.add(new EditTagsDrawerItem()
.withName(t.getName())
.withTag(t)
);
}
}
if (isAdded()) {
this.activity.fillFilterDrawer(items);
}
} else {
items.add(new EditTagsSectionDrawer().withEditing(this.editingTags).withName(getString(R.string.filter_drawer_filter_tags)));
items.add(new EditTextDrawer());
if (tagList != null) {
for (Tag t : tagList) {
items.add(new SwitchDrawerItem()
.withName(t.getName())
.withTag(t)
.withChecked(this.tagsHelper.isTagChecked(t.getId()))
.withOnCheckedChangeListener(this)
);
}
}
if (isAdded()) {
this.activity.fillFilterDrawer(items);
}
}
}
}
public void addTagFilterDrawerItem(Tag tag) {
if (this.tagsHelper != null) {
if (this.editingTags) {
IDrawerItem item = new EditTagsDrawerItem()
.withName(tag.getName())
.withTag(tag);
this.activity.addFilterDrawerItem(item);
} else {
IDrawerItem item = new SwitchDrawerItem()
.withName(tag.getName())
.withTag(tag)
.withChecked(this.tagsHelper.isTagChecked(tag.getId()))
.withOnCheckedChangeListener(this);
this.activity.addFilterDrawerItem(item);
}
}
}
public void removeTagFilterDrawerItem(Tag t) {
//Have to add 2 for the Drawer components that reside above the actual tags' ui component.
int pos = tags.indexOf(t) + 2;
tags.remove(t);
this.activity.removeFilterDrawerItem(pos);
}
public void updateTagFilterDrawerItem(Tag t) {
if (this.tagsHelper != null) {
//Add 2 for the same reason as above
int pos = tags.indexOf(t) + 2;
IDrawerItem item;
if (this.editingTags) {
item = new EditTagsDrawerItem()
.withName(t.getName())
.withTag(t);
} else {
item = new SwitchDrawerItem()
.withName(t.getName())
.withTag(t)
.withChecked(this.tagsHelper.isTagChecked(t.getId()))
.withOnCheckedChangeListener(this);
}
this.activity.updateFilterDrawerItem(item, pos);
}
}
@Override
public void onCheckedChanged(IDrawerItem iDrawerItem, CompoundButton compoundButton, boolean b) {
Tag t = (Tag) iDrawerItem.getTag();
if (t != null) {
tagFilterMap.put(t.getId(), b);
filterChangedHandler.hit();
}
}
@Override
public void onDestroyView() {
this.activity.lockDrawer(GravityCompat.END);
@ -554,88 +375,9 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
return null;
}
public void showEditTagDialog(Tag tag) {
Button btnDelete = null;
final View editTagDialogView = this.activity.getLayoutInflater().inflate(R.layout.dialog_edit_tag, null);
if (editTagDialogView != null) {
EditText tagEditText = (EditText) editTagDialogView.findViewById(R.id.tagEditText);
tagEditText.setText(tag.getName());
btnDelete = (Button) editTagDialogView.findViewById(R.id.btnDelete);
ViewHelper.SetBackgroundTint(btnDelete, ContextCompat.getColor(this.activity, R.color.worse_10));
}
AlertDialog alert = new AlertDialog.Builder(this.activity)
.setTitle(getString(R.string.edit_tag_title))
.setPositiveButton(getString(R.string.save_changes), null)
.setNeutralButton(getString(R.string.dialog_go_back), (dialog, which) -> {
EditText tagEditText = null;
if (editTagDialogView != null) {
tagEditText = (EditText) editTagDialogView.findViewById(R.id.tagEditText);
}
UiUtils.dismissKeyboard(this.activity, tagEditText);
dialog.cancel();
})
.create();
if (btnDelete != null) {
btnDelete.setOnClickListener((View v) -> showDeleteTagDialog(alert, tag));
}
alert.setView(editTagDialogView);
alert.show();
alert.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(view -> {
if (editTagDialogView != null) {
EditText tagEditText = (EditText) editTagDialogView.findViewById(R.id.tagEditText);
if (attemptUpdateTag(tagEditText, tag)) {
alert.dismiss();
}
} else {
alert.dismiss();
}
});
}
public boolean attemptUpdateTag(EditText tagEditText, Tag tag) {
String newTagName = tagEditText.getText().toString();
if (newTagName.equals("")) {
return false;
}
UiUtils.dismissKeyboard(activity, tagEditText);
if (newTagName.equals(tag.getName())) {
return true;
}
String uuid = tag.getId();
tag.setName(newTagName);
EventBus.getDefault().post(new UpdateTagCommand(tag, uuid));
return true;
}
public void showDeleteTagDialog(AlertDialog d, Tag tag) {
AlertDialog confirmDeleteAlert = new AlertDialog.Builder(this.activity)
.setTitle(getString(R.string.confirm_delete_tag_title)).setMessage(getString(R.string.confirm_delete_tag_message))
.setPositiveButton(getString(R.string.yes), (dialog, which) -> {
EventBus.getDefault().post(new DeleteTagCommand(tag));
UiUtils.dismissKeyboard(this.activity, d.getCurrentFocus());
//dismiss both dialogs
dialog.dismiss();
d.dismiss();
})
.setNegativeButton(getString(R.string.no), (dialog, which) -> dialog.dismiss())
.create();
confirmDeleteAlert.show();
}
@Nullable
@Override
public String customTitle() {
return null;
}
}
}

View file

@ -5,6 +5,7 @@ import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
public class FadingViewPager extends ViewPager {
@ -25,9 +26,12 @@ public class FadingViewPager extends ViewPager {
if(position <= -1.0F || position >= 1.0F) {
page.setAlpha(0.0F);
page.setVisibility(View.INVISIBLE);
} else if( position == 0.0F ) {
page.setVisibility(View.VISIBLE);
page.setAlpha(1.0F);
} else {
page.setVisibility(View.VISIBLE);
// position is between -1.0F & 0.0F OR 0.0F & 1.0F
page.setAlpha(1.0F - Math.abs(position));
}

View file

@ -0,0 +1,203 @@
package com.habitrpg.android.habitica.ui.views.tasks;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.IdRes;
import android.support.annotation.StringDef;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.habitrpg.android.habitica.R;
import com.magicmicky.habitrpgwrapper.lib.models.Tag;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import butterknife.BindView;
import butterknife.ButterKnife;
public class TaskFilterDialog extends AlertDialog implements RadioGroup.OnCheckedChangeListener {
@BindView(R.id.task_type_title)
TextView taskTypeTitle;
@BindView(R.id.task_filter_wrapper)
RadioGroup taskFilters;
@BindView(R.id.all_task_filter)
RadioButton allTaskFilter;
@BindView(R.id.second_task_filter)
RadioButton secondTaskFilter;
@BindView(R.id.third_task_filter)
RadioButton thirdTaskFilter;
@BindView(R.id.tags_list)
LinearLayout tagsList;
private String taskType;
private OnFilterCompletedListener listener;
private String filterType;
private List<String> tagIds;
private List<String> activeTags;
public TaskFilterDialog(Context context) {
super(context);
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.dialog_task_filter, null);
ButterKnife.bind(this, view);
taskFilters.setOnCheckedChangeListener(this);
setTitle(R.string.filters);
setView(view);
this.setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.close), (dialog, which) -> {
if (listener != null) {
listener.onFilterCompleted(filterType, activeTags);
}
this.dismiss();
});
}
public void setTags(List<Tag> tags) {
tagIds = new ArrayList<>();
for (Tag tag : tags) {
tagIds.add(tag.getId());
CheckBox tagCheckbox = new CheckBox(getContext());
tagCheckbox.setText(tag.getName());
tagCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
if (!activeTags.contains(tag.getId())) {
activeTags.add(tag.getId());
}
} else {
if (activeTags.contains(tag.getId())) {
activeTags.remove(tag.getId());
}
}
});
tagsList.addView(tagCheckbox);
}
}
public void setActiveTags(List<String> tagIds) {
this.activeTags = tagIds;
for (String tagId : tagIds) {
((CheckBox)tagsList.getChildAt(this.tagIds.indexOf(tagId))).setChecked(true);
}
}
public void setTaskType(String taskType, String activeFilter) {
this.taskType = taskType;
switch (taskType) {
case Task.TYPE_HABIT: {
taskTypeTitle.setText(R.string.habits);
allTaskFilter.setText(R.string.all);
secondTaskFilter.setText(R.string.weak);
thirdTaskFilter.setText(R.string.strong);
break;
}
case Task.TYPE_DAILY: {
taskTypeTitle.setText(R.string.dailies);
allTaskFilter.setText(R.string.all);
secondTaskFilter.setText(R.string.active);
thirdTaskFilter.setText(R.string.gray);
break;
}
case Task.TYPE_TODO: {
taskTypeTitle.setText(R.string.todos);
allTaskFilter.setText(R.string.active);
secondTaskFilter.setText(R.string.dated);
thirdTaskFilter.setText(R.string.completed);
break;
}
}
setActiveFilter(activeFilter);
}
private void setActiveFilter(String activeFilter) {
filterType = activeFilter;
int checkedId = -1;
if (activeFilter == null) {
checkedId = R.id.all_task_filter;
} else {
switch (activeFilter) {
case Task.FILTER_ALL:
checkedId = R.id.all_task_filter;
break;
case Task.FILTER_WEAK:
case Task.FILTER_DATED:
checkedId = R.id.second_task_filter;
break;
case Task.FILTER_STRONG:
case Task.FILTER_GRAY:
case Task.FILTER_COMPLETED:
checkedId = R.id.third_task_filter;
break;
case Task.FILTER_ACTIVE:
if (taskType.equals(Task.TYPE_DAILY)) {
checkedId = R.id.second_task_filter;
} else {
checkedId = R.id.all_task_filter;
}
break;
}
}
taskFilters.check(checkedId);
}
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
if (checkedId == R.id.all_task_filter) {
if (!taskType.equals(Task.TYPE_TODO)) {
filterType = Task.FILTER_ALL;
} else {
filterType = Task.FILTER_ACTIVE;
}
} else if (checkedId == R.id.second_task_filter) {
switch (taskType) {
case Task.TYPE_HABIT:
filterType = Task.FILTER_WEAK;
break;
case Task.FREQUENCY_DAILY:
filterType = Task.FILTER_ACTIVE;
break;
case Task.TYPE_TODO:
filterType = Task.FILTER_DATED;
break;
}
} else if (checkedId == R.id.third_task_filter) {
switch (taskType) {
case Task.TYPE_HABIT:
filterType = Task.FILTER_STRONG;
break;
case Task.FREQUENCY_DAILY:
filterType = Task.FILTER_GRAY;
break;
case Task.TYPE_TODO:
filterType = Task.FILTER_COMPLETED;
break;
}
}
}
public void setListener(OnFilterCompletedListener listener) {
this.listener = listener;
}
public interface OnFilterCompletedListener {
void onFilterCompleted(String activeTaskFilter, List<String> activeTags);
}
}

View file

@ -38,6 +38,13 @@ public class Task extends BaseModel {
public static final String TYPE_TODO = "todo";
public static final String TYPE_DAILY = "daily";
public static final String TYPE_REWARD = "reward";
public static final String FILTER_ALL = "all";
public static final String FILTER_WEAK = "weak";
public static final String FILTER_STRONG = "strong";
public static final String FILTER_ACTIVE = "active";
public static final String FILTER_GRAY = "gray";
public static final String FILTER_DATED = "dated";
public static final String FILTER_COMPLETED = "completed";
public static final String FREQUENCY_WEEKLY = "weekly";
public static final String FREQUENCY_DAILY = "daily";
public static final String ATTRIBUTE_STRENGTH = "str";