"my challenges" - filter

This commit is contained in:
Negue 2017-03-01 13:45:43 +01:00
parent 7e9c70fae8
commit 16e32a7ec3
19 changed files with 559 additions and 103 deletions

View file

@ -103,6 +103,9 @@ dependencies {
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1@aar'
// lodash/underscore
compile 'com.github.javadev:underscore:1.23'
//RxJava
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.2.0'

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

View file

@ -1,98 +0,0 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/overlayFrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activities.MainActivity">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:gravity="center">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="0dp"
tools:context=".ui.activities.MainActivity">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="false">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="false"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="?attr/actionBarSize"
app:expandedTitleMarginStart="0dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="false">
<include
android:id="@+id/avatar_with_bars"
layout="@layout/avatar_with_bars"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/Theme.AppCompat.Light"
/>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/detail_tabs"
android:layout_width="match_parent"
android:layout_height="54dp"
android:layout_gravity="bottom"
android:background="@color/brand_200"
android:elevation="0dp"
android:fillViewport="false"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_anchor="@+id/collapsing_toolbar"
app:layout_anchorGravity="bottom"
app:layout_collapseMode="pin"
app:tabGravity="fill"
app:tabIndicatorColor="@android:color/white"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/floating_menu_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="8dp"
app:layout_behavior="com.habitrpg.android.habitica.ui.helpers.FloatingActionMenuBehavior" />
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>
</FrameLayout>

View file

@ -0,0 +1,163 @@
<?xml version="1.0" encoding="utf-8"?>
<com.habitrpg.android.habitica.ui.MaxHeightLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:maxHeightMultiplier="0.7">
<!-- margins can't be at the first LinearLayout, it has to be the inner one -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/dialog_marginLeftRight"
android:layout_marginLeft="@dimen/dialog_marginLeftRight"
android:layout_marginRight="@dimen/dialog_marginLeftRight"
android:layout_marginStart="@dimen/dialog_marginLeftRight"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:orientation="horizontal">
<TextView
style="@style/Title1_WideLetterSpacing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:text="@string/filters"
android:textColor="#000" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_weight="1"
android:gravity="right">
<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/done"
android:textColor="#6133b4"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#1f000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
style="@style/Caption3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_weight="2"
android:height="20dp"
android:gravity="center_vertical"
android:text="@string/groups"
android:textAllCaps="true" />
<Button
android:id="@+id/challenge_filter_button_all"
style="@style/Body1_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/all"
android:textColor="#6133b4"
android:textSize="16sp" />
<Button
android:id="@+id/challenge_filter_button_none"
style="@style/Body1_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/none"
android:textColor="#6133b4"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/challenge_filter_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/dialog_challenge_filter_group_item"
tools:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
style="@style/Caption3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_weight="2"
android:height="20dp"
android:gravity="center_vertical"
android:text="Ownerchip"
android:textAllCaps="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/challenge_filter_owned"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:checked="true"
android:text="" />
<TextView
style="@style/Subheader2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/owned" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/challenge_filter_not_owned"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:checked="true"
android:text="" />
<TextView
style="@style/Subheader2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/not_owned" />
</LinearLayout>
</LinearLayout>
</com.habitrpg.android.habitica.ui.MaxHeightLinearLayout>

View file

@ -0,0 +1,22 @@
<?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:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/challenge_filter_group_checkbox"
android:layout_width="50dp"
android:checked="true"
android:layout_height="wrap_content"
android:text=""/>
<TextView
android:id="@+id/challenge_filter_group_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Subheader2"
tools:text="Tavern"/>
</LinearLayout>

View file

@ -1,11 +1,43 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical">
<LinearLayout
android:id="@+id/challenge_filter_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f9f9f9"
android:orientation="horizontal"
android:padding="16dp">
<ImageView
android:id="@+id/action_filter_icon"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginRight="13dp"
android:src="@drawable/ic_action_filter_list"
android:tint="#80000000"
android:contentDescription="filter icon" />
<TextView
style="@style/Caption2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filter"
android:textAllCaps="true" />
<ImageView
android:layout_width="18dp"
android:layout_height="18dp"
android:src="@drawable/ic_arrow_drop_down_80000000_24dp"
android:contentDescription="filter icon" />
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/challenges.refresh.layout"
android:layout_width="match_parent"

View file

@ -97,4 +97,7 @@
<dimen name="button_padding">32dp</dimen>
<dimen name="button_padding_small">16dp</dimen>
<dimen name="button_padding_vertical_small">4dp</dimen>
<dimen name="dialog_marginLeftRight">24dp</dimen>
<dimen name="dialog_marginTopBottom">24dp</dimen>
</resources>

View file

@ -521,4 +521,11 @@ To start, which parts of your life do you want to improve?</string>
<string name="notification_mystery_item">You open the box and find %s!</string>
<string name="checkInRewardEarned">You earned a %1$s as a reward for your devotion to improving your life.</string>
<string name="nextPrizeUnlocks" tools:ignore="PluralsCandidate">Your next prize unlocks at %1$d Check-Ins</string>
<string name="filters">Filters</string>
<string name="done">Done</string>
<string name="groups">Groups</string>
<string name="all">All</string>
<string name="none">None</string>
<string name="owned">Owned</string>
<string name="not_owned">Not owned</string>
</resources>

View file

@ -17,6 +17,10 @@
<item name="android:letterSpacing" tools:targetApi="lollipop">0.071</item>
</style>
<style name="Title1_WideLetterSpacing" parent="@style/Title1">
<item name="android:letterSpacing" tools:targetApi="lollipop">0.133</item>
</style>
<style name="Title2">
<item name="android:fontFamily" tools:targetApi="jelly_bean">
@string/font_family_condensed

View file

@ -1,9 +1,12 @@
package com.habitrpg.android.habitica.ui.adapter.social;
import com.github.underscore.$;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.events.commands.ShowChallengeDetailActivityCommand;
import com.habitrpg.android.habitica.events.commands.ShowChallengeDetailDialogCommand;
import com.habitrpg.android.habitica.ui.fragments.social.challenges.ChallengeFilterOptions;
import com.magicmicky.habitrpgwrapper.lib.models.Challenge;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import net.pherth.android.emoji_library.EmojiParser;
import net.pherth.android.emoji_library.EmojiTextView;
@ -33,15 +36,38 @@ public class ChallengesListViewAdapter extends RecyclerView.Adapter<ChallengesLi
private List<Challenge> challenges = new ArrayList<>();
private List<Challenge> challengesSource = new ArrayList<>();
private boolean viewUserChallengesOnly;
private HabitRPGUser user;
public ChallengesListViewAdapter(boolean viewUserChallengesOnly) {
public ChallengesListViewAdapter(boolean viewUserChallengesOnly, HabitRPGUser user) {
this.viewUserChallengesOnly = viewUserChallengesOnly;
this.user = user;
}
public void setChallenges(List<Challenge> challenges) {
this.challenges = challenges;
this.challengesSource = challenges;
this.challenges = new ArrayList<>(challengesSource);
this.notifyDataSetChanged();
}
public void setFilterByGroups(ChallengeFilterOptions filterOptions){
this.challenges = $.filter(challengesSource, arg ->
{
boolean showChallenge = $.find(filterOptions.ShowByGroups, g -> g.id.contains(arg.groupId)).isPresent();
boolean showByOwnership = false;
if(filterOptions.ShowOwned){
showByOwnership |= arg.leaderId == this.user.getId();
}
if(filterOptions.NotOwned){
showByOwnership |= arg.leaderId != this.user.getId();
}
return showChallenge && showByOwnership;
});
this.notifyDataSetChanged();
}

View file

@ -0,0 +1,106 @@
package com.habitrpg.android.habitica.ui.adapter.social.challenges;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import com.github.underscore.$;
import com.habitrpg.android.habitica.R;
import com.magicmicky.habitrpgwrapper.lib.models.Group;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class ChallengesFilterRecyclerViewAdapter extends RecyclerView.Adapter<ChallengesFilterRecyclerViewAdapter.ChallengeViewHolder> {
private List<Group> entries;
private List<ChallengesFilterRecyclerViewAdapter.ChallengeViewHolder> holderList;
public ChallengesFilterRecyclerViewAdapter(Collection<Group> entries) {
this.entries = new ArrayList<>(entries);
this.holderList = new ArrayList<>();
}
@Override
public ChallengesFilterRecyclerViewAdapter.ChallengeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.dialog_challenge_filter_group_item, parent, false);
ChallengeViewHolder challengeViewHolder = new ChallengeViewHolder(view);
holderList.add(challengeViewHolder);
return challengeViewHolder;
}
@Override
public void onBindViewHolder(ChallengesFilterRecyclerViewAdapter.ChallengeViewHolder holder, int position) {
holder.bind(entries.get(position));
}
@Override
public int getItemCount() {
return entries.size();
}
public void deSelectAll(){
for (ChallengeViewHolder h : holderList) {
h.checkbox.setChecked(false);
}
}
public void selectAll(){
for (ChallengeViewHolder h : holderList) {
h.checkbox.setChecked(true);
}
}
public void selectAll(List<Group> groupsToCheck){
for (ChallengeViewHolder h : holderList) {
h.checkbox.setChecked($.find(groupsToCheck, g -> h.group.id == g.id).isPresent());
}
}
public List<Group> getCheckedEntries(){
ArrayList<Group> result = new ArrayList<>();
for (ChallengeViewHolder h : holderList) {
if(h.checkbox.isChecked()){
result.add(h.group);
}
}
return result;
}
public static class ChallengeViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.challenge_filter_group_checkbox)
CheckBox checkbox;
@BindView(R.id.challenge_filter_group_label)
TextView label;
public Group group;
public ChallengeViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
public void bind(Group group) {
this.group = group;
label.setText(group.name);
}
}
}

View file

@ -0,0 +1,143 @@
package com.habitrpg.android.habitica.ui.fragments.social.challenges;
import android.app.Activity;
import android.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import com.habitrpg.android.habitica.APIHelper;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.ui.adapter.social.challenges.ChallengesFilterRecyclerViewAdapter;
import com.magicmicky.habitrpgwrapper.lib.models.Challenge;
import com.magicmicky.habitrpgwrapper.lib.models.Group;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.functions.Action1;
public class ChallegeFilterDialogHolder {
@BindView(R.id.challenge_filter_recycler_view)
RecyclerView groupRecyclerView;
@BindView(R.id.challenge_filter_button_done)
Button doneButton;
@BindView(R.id.challenge_filter_button_all)
Button allButton;
@BindView(R.id.challenge_filter_button_none)
Button noneButton;
@BindView(R.id.challenge_filter_owned)
CheckBox checkboxOwned;
@BindView(R.id.challenge_filter_not_owned)
CheckBox checkboxNotOwned;
private AlertDialog dialog;
private APIHelper apiHelper;
private HabitRPGUser user;
private List<Challenge> challengesViewed;
private ChallengeFilterOptions currentFilter;
private Action1<ChallengeFilterOptions> selectedGroupsCallback;
private Activity context;
private ChallengesFilterRecyclerViewAdapter adapter;
protected ChallegeFilterDialogHolder(View view, Activity context) {
this.context = context;
ButterKnife.bind(this, view);
}
public static void showDialog(Activity activity, APIHelper apiHelper, HabitRPGUser user, List<Challenge> challengesViewed,
ChallengeFilterOptions currentFilter,
Action1<ChallengeFilterOptions> selectedGroupsCallback) {
View dialogLayout = activity.getLayoutInflater().inflate(R.layout.dialog_challenge_filter, null);
ChallegeFilterDialogHolder challegeFilterDialogHolder = new ChallegeFilterDialogHolder(dialogLayout, activity);
AlertDialog.Builder builder = new AlertDialog.Builder(activity)
.setView(dialogLayout);
challegeFilterDialogHolder.bind(builder.show(), apiHelper, user, challengesViewed, currentFilter, selectedGroupsCallback);
}
public void bind(AlertDialog dialog, APIHelper apiHelper, HabitRPGUser user, List<Challenge> challengesViewed,
ChallengeFilterOptions currentFilter,
Action1<ChallengeFilterOptions> selectedGroupsCallback) {
this.dialog = dialog;
this.apiHelper = apiHelper;
this.user = user;
this.challengesViewed = challengesViewed;
this.currentFilter = currentFilter;
this.selectedGroupsCallback = selectedGroupsCallback;
fillChallengeGroups();
if(currentFilter != null ){
checkboxOwned.setChecked(currentFilter.ShowOwned);
checkboxNotOwned.setChecked(currentFilter.NotOwned);
}
}
private void fillChallengeGroups() {
this.groupRecyclerView.setLayoutManager(new LinearLayoutManager(context));
adapter = new ChallengesFilterRecyclerViewAdapter(getGroups(challengesViewed));
if(currentFilter != null && currentFilter.ShowByGroups != null){
adapter.selectAll(currentFilter.ShowByGroups);
}
this.groupRecyclerView.setAdapter(adapter);
}
private Collection<Group> getGroups(List<Challenge> challenges){
HashMap<String, Group> groupMap = new HashMap<>();
for (Challenge c : challenges) {
if(!groupMap.containsKey(c.groupName)){
Group g = new Group();
g.id = c.groupId;
g.name = c.groupName;
groupMap.put(c.groupName, g);
}
}
return groupMap.values();
}
@OnClick(R.id.challenge_filter_button_done)
public void doneClicked() {
ChallengeFilterOptions options = new ChallengeFilterOptions();
options.ShowByGroups = this.adapter.getCheckedEntries();
options.ShowOwned = checkboxOwned.isChecked();
options.NotOwned = checkboxNotOwned.isChecked();
selectedGroupsCallback.call(options);
this.dialog.hide();
}
@OnClick(R.id.challenge_filter_button_all)
public void allClicked() {
this.adapter.selectAll();
}
@OnClick(R.id.challenge_filter_button_none)
public void noneClicked() {
this.adapter.deSelectAll();
}
}

View file

@ -0,0 +1,11 @@
package com.habitrpg.android.habitica.ui.fragments.social.challenges;
import com.magicmicky.habitrpgwrapper.lib.models.Group;
import java.util.List;
public class ChallengeFilterOptions {
public List<Group> ShowByGroups;
public boolean ShowOwned;
public boolean NotOwned;
}

View file

@ -1,15 +1,20 @@
package com.habitrpg.android.habitica.ui.fragments.social.challenges;
import com.habitrpg.android.habitica.HabiticaApplication;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.ui.activities.ChallengeDetailActivity;
import com.habitrpg.android.habitica.ui.adapter.social.ChallengesListViewAdapter;
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
import com.magicmicky.habitrpgwrapper.lib.models.Challenge;
import com.raizlabs.android.dbflow.sql.builder.Condition;
import com.raizlabs.android.dbflow.sql.language.Select;
import com.raizlabs.android.dbflow.sql.language.Where;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -17,6 +22,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.HashSet;
@ -29,6 +35,12 @@ import rx.functions.Action0;
public class ChallengeListFragment extends BaseMainFragment implements SwipeRefreshLayout.OnRefreshListener {
@BindView(R.id.challenge_filter_layout)
LinearLayout challengeFilterLayout;
@BindView(R.id.action_filter_icon)
View actionFilterIcon;
@BindView(R.id.challenges_refresh_layout)
SwipeRefreshLayout swipeRefreshLayout;
@ -41,6 +53,11 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
private ChallengesListViewAdapter challengeAdapter;
private boolean viewUserChallengesOnly;
private Action0 refreshCallback;
private boolean withFilter;
public void setWithFilter(boolean withFilter){
this.withFilter = withFilter;
}
public void setViewUserChallengesOnly(boolean only) {
this.viewUserChallengesOnly = only;
@ -50,6 +67,10 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
this.refreshCallback = refreshCallback;
}
private List<Challenge> currentChallengesInView;
private ChallengeFilterOptions lastFilterOptions;
public void setObservable(Observable<ArrayList<Challenge>> listObservable) {
listObservable
.subscribe(challenges -> {
@ -100,11 +121,21 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
View v = inflater.inflate(R.layout.fragment_challengeslist, container, false);
unbinder = ButterKnife.bind(this, v);
challengeAdapter = new ChallengesListViewAdapter(viewUserChallengesOnly);
challengeAdapter = new ChallengesListViewAdapter(viewUserChallengesOnly, user);
swipeRefreshLayout.setOnRefreshListener(this);
swipeRefreshEmptyLayout.setOnRefreshListener(this);
challengeFilterLayout.setVisibility(withFilter?View.VISIBLE:View.GONE);
challengeFilterLayout.setClickable(true);
challengeFilterLayout.setOnClickListener(view -> {
ChallegeFilterDialogHolder.showDialog(HabiticaApplication.currentActivity, this.apiHelper,
HabiticaApplication.User, currentChallengesInView, lastFilterOptions, filterOptions -> {
challengeAdapter.setFilterByGroups(filterOptions);
this.lastFilterOptions = filterOptions;
});
});
recyclerView.setLayoutManager(new LinearLayoutManager(this.activity));
recyclerView.setAdapter(challengeAdapter);
if (!viewUserChallengesOnly) {
@ -159,6 +190,8 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
if (swipeRefreshEmptyLayout == null || swipeRefreshLayout == null) {
return;
}
currentChallengesInView = challenges;
if (viewUserChallengesOnly && challenges.size() == 0) {
swipeRefreshEmptyLayout.setVisibility(View.VISIBLE);
swipeRefreshLayout.setRefreshing(false);

View file

@ -58,6 +58,7 @@ public class ChallengesOverviewFragment extends BaseMainFragment {
userChallengesFragment.setRefreshingCallback(this::subscribeGetChallenges);
userChallengesFragment.setObservable(getUserChallengesObservable);
userChallengesFragment.setViewUserChallengesOnly(true);
userChallengesFragment.setWithFilter(true);
availableChallengesFragment = new ChallengeListFragment();
availableChallengesFragment.setUser(this.user);