mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-14 10:11:58 +00:00
fix challenge filtering
This commit is contained in:
parent
d4dfbbfbc5
commit
fead28b8a3
10 changed files with 84 additions and 49 deletions
|
|
@ -85,7 +85,8 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:checked="true"
|
android:checked="true"
|
||||||
android:text="@string/owned"
|
android:text="@string/owned"
|
||||||
android:textColor="@color/textColorLight"/>
|
android:textColor="@color/textColorLight"
|
||||||
|
android:paddingLeft="8dp" />
|
||||||
|
|
||||||
<CheckBox
|
<CheckBox
|
||||||
style="@style/Subheader2"
|
style="@style/Subheader2"
|
||||||
|
|
@ -94,6 +95,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:checked="true"
|
android:checked="true"
|
||||||
android:text="@string/not_owned"
|
android:text="@string/not_owned"
|
||||||
android:textColor="@color/textColorLight"/>
|
android:textColor="@color/textColorLight"
|
||||||
|
android:paddingLeft="8dp"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</com.habitrpg.android.habitica.ui.MaxHeightLinearLayout>
|
</com.habitrpg.android.habitica.ui.MaxHeightLinearLayout>
|
||||||
|
|
@ -1,22 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<CheckBox
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
android:id="@+id/challenge_filter_group_checkbox"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:checked="true"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
<CheckBox
|
android:paddingTop="8dp"
|
||||||
android:id="@+id/challenge_filter_group_checkbox"
|
android:paddingBottom="8dp"
|
||||||
android:layout_width="50dp"
|
android:paddingLeft="8dp"/>
|
||||||
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>
|
|
||||||
|
|
@ -282,7 +282,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
style="?android:buttonBarStyle"
|
style="?android:buttonBarStyle"
|
||||||
android:visibility="@{group.quest.active? View.VISIBLE : View.GONE}">
|
android:visibility="@{group.quest.active ? View.VISIBLE : View.GONE}">
|
||||||
|
|
||||||
<com.habitrpg.android.habitica.ui.views.ValueBar
|
<com.habitrpg.android.habitica.ui.views.ValueBar
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ public class Challenge extends RealmObject {
|
||||||
public boolean isParticipating;
|
public boolean isParticipating;
|
||||||
|
|
||||||
public HashMap<String, String[]> getTasksOrder() {
|
public HashMap<String, String[]> getTasksOrder() {
|
||||||
HashMap<String, String[]> map = new HashMap();
|
HashMap<String, String[]> map = new HashMap<>();
|
||||||
|
|
||||||
if (!dailyList.isEmpty()) {
|
if (!dailyList.isEmpty()) {
|
||||||
map.put(TASK_ORDER_DAILYS, dailyList.split(","));
|
map.put(TASK_ORDER_DAILYS, dailyList.split(","));
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import com.habitrpg.android.habitica.R;
|
||||||
import com.habitrpg.android.habitica.events.commands.ShowChallengeDetailActivityCommand;
|
import com.habitrpg.android.habitica.events.commands.ShowChallengeDetailActivityCommand;
|
||||||
import com.habitrpg.android.habitica.events.commands.ShowChallengeDetailDialogCommand;
|
import com.habitrpg.android.habitica.events.commands.ShowChallengeDetailDialogCommand;
|
||||||
import com.habitrpg.android.habitica.models.social.Challenge;
|
import com.habitrpg.android.habitica.models.social.Challenge;
|
||||||
|
import com.habitrpg.android.habitica.models.social.Group;
|
||||||
|
import com.habitrpg.android.habitica.ui.fragments.social.challenges.ChallengeFilterOptions;
|
||||||
|
|
||||||
import net.pherth.android.emoji_library.EmojiParser;
|
import net.pherth.android.emoji_library.EmojiParser;
|
||||||
import net.pherth.android.emoji_library.EmojiTextView;
|
import net.pherth.android.emoji_library.EmojiTextView;
|
||||||
|
|
@ -23,15 +25,19 @@ import org.greenrobot.eventbus.EventBus;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import io.realm.OrderedRealmCollection;
|
import io.realm.OrderedRealmCollection;
|
||||||
|
import io.realm.RealmQuery;
|
||||||
import io.realm.RealmRecyclerViewAdapter;
|
import io.realm.RealmRecyclerViewAdapter;
|
||||||
|
|
||||||
public class ChallengesListViewAdapter extends RealmRecyclerViewAdapter<Challenge, ChallengesListViewAdapter.ChallengeViewHolder> {
|
public class ChallengesListViewAdapter extends RealmRecyclerViewAdapter<Challenge, ChallengesListViewAdapter.ChallengeViewHolder> {
|
||||||
|
|
||||||
private boolean viewUserChallengesOnly;
|
private boolean viewUserChallengesOnly;
|
||||||
|
private OrderedRealmCollection<Challenge> unfilteredData;
|
||||||
|
private final String userId;
|
||||||
|
|
||||||
public ChallengesListViewAdapter(@Nullable OrderedRealmCollection<Challenge> data, boolean autoUpdate, boolean viewUserChallengesOnly) {
|
public ChallengesListViewAdapter(@Nullable OrderedRealmCollection<Challenge> data, boolean autoUpdate, boolean viewUserChallengesOnly, String userId) {
|
||||||
super(data, autoUpdate);
|
super(data, autoUpdate);
|
||||||
this.viewUserChallengesOnly = viewUserChallengesOnly;
|
this.viewUserChallengesOnly = viewUserChallengesOnly;
|
||||||
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -44,7 +50,42 @@ public class ChallengesListViewAdapter extends RealmRecyclerViewAdapter<Challeng
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ChallengeViewHolder holder, int position) {
|
public void onBindViewHolder(ChallengeViewHolder holder, int position) {
|
||||||
holder.bind(getData().get(position));
|
if (getData() != null) {
|
||||||
|
holder.bind(getData().get(position));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateUnfilteredData(@Nullable OrderedRealmCollection<Challenge> data) {
|
||||||
|
super.updateData(data);
|
||||||
|
unfilteredData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void filter(ChallengeFilterOptions filterOptions) {
|
||||||
|
if (unfilteredData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RealmQuery<Challenge> query = unfilteredData.where();
|
||||||
|
|
||||||
|
if (filterOptions.showByGroups != null && filterOptions.showByGroups.size() > 0) {
|
||||||
|
String[] groupIds = new String[filterOptions.showByGroups.size()];
|
||||||
|
int index = 0;
|
||||||
|
for (Group group : filterOptions.showByGroups) {
|
||||||
|
groupIds[index] = group.id;
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
query = query.in("groupId", groupIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filterOptions.showOwned != filterOptions.notOwned) {
|
||||||
|
if (filterOptions.showOwned) {
|
||||||
|
query = query.equalTo("leaderId", userId);
|
||||||
|
} else {
|
||||||
|
query = query.notEqualTo("leaderId", userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateData(query.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ChallengeViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
public static class ChallengeViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import com.habitrpg.android.habitica.models.social.Group;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
@ -65,7 +66,7 @@ public class ChallengesFilterRecyclerViewAdapter extends RecyclerView.Adapter<Ch
|
||||||
|
|
||||||
public void selectAll(List<Group> groupsToCheck){
|
public void selectAll(List<Group> groupsToCheck){
|
||||||
for (ChallengeViewHolder h : holderList) {
|
for (ChallengeViewHolder h : holderList) {
|
||||||
h.checkbox.setChecked($.find(groupsToCheck, g -> h.group.id == g.id).isPresent());
|
h.checkbox.setChecked($.find(groupsToCheck, g -> h.group.id.equals(g.id)).isPresent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public List<Group> getCheckedEntries(){
|
public List<Group> getCheckedEntries(){
|
||||||
|
|
@ -84,9 +85,6 @@ public class ChallengesFilterRecyclerViewAdapter extends RecyclerView.Adapter<Ch
|
||||||
@BindView(R.id.challenge_filter_group_checkbox)
|
@BindView(R.id.challenge_filter_group_checkbox)
|
||||||
CheckBox checkbox;
|
CheckBox checkbox;
|
||||||
|
|
||||||
@BindView(R.id.challenge_filter_group_label)
|
|
||||||
TextView label;
|
|
||||||
|
|
||||||
public Group group;
|
public Group group;
|
||||||
|
|
||||||
public ChallengeViewHolder(View itemView) {
|
public ChallengeViewHolder(View itemView) {
|
||||||
|
|
@ -98,8 +96,7 @@ public class ChallengesFilterRecyclerViewAdapter extends RecyclerView.Adapter<Ch
|
||||||
public void bind(Group group) {
|
public void bind(Group group) {
|
||||||
this.group = group;
|
this.group = group;
|
||||||
|
|
||||||
label.setText(group.name);
|
checkbox.setText(group.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.fragments.social.challenges;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
@ -63,20 +64,21 @@ class ChallengeFilterDialogHolder {
|
||||||
ChallengeFilterDialogHolder challengeFilterDialogHolder = new ChallengeFilterDialogHolder(dialogLayout, activity);
|
ChallengeFilterDialogHolder challengeFilterDialogHolder = new ChallengeFilterDialogHolder(dialogLayout, activity);
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
||||||
|
.setTitle(R.string.filter)
|
||||||
.setView(dialogLayout);
|
.setView(dialogLayout);
|
||||||
|
|
||||||
challengeFilterDialogHolder.bind(builder.show(), challengesViewed, currentFilter, selectedGroupsCallback);
|
challengeFilterDialogHolder.bind(builder, challengesViewed, currentFilter, selectedGroupsCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind(AlertDialog dialog, List<Challenge> challengesViewed,
|
public void bind(AlertDialog.Builder builder, List<Challenge> challengesViewed,
|
||||||
ChallengeFilterOptions currentFilter,
|
ChallengeFilterOptions currentFilter,
|
||||||
Action1<ChallengeFilterOptions> selectedGroupsCallback) {
|
Action1<ChallengeFilterOptions> selectedGroupsCallback) {
|
||||||
this.dialog = dialog;
|
builder = builder
|
||||||
this.dialog.setButton(Dialog.BUTTON_POSITIVE, context.getString(R.string.done), (dialog1, which) -> doneClicked());
|
.setPositiveButton(context.getString(R.string.done), (dialog1, which) -> doneClicked());
|
||||||
|
this.dialog = builder.show();
|
||||||
this.challengesViewed = challengesViewed;
|
this.challengesViewed = challengesViewed;
|
||||||
this.currentFilter = currentFilter;
|
this.currentFilter = currentFilter;
|
||||||
this.selectedGroupsCallback = selectedGroupsCallback;
|
this.selectedGroupsCallback = selectedGroupsCallback;
|
||||||
|
|
||||||
fillChallengeGroups();
|
fillChallengeGroups();
|
||||||
|
|
||||||
if(currentFilter != null ){
|
if(currentFilter != null ){
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,14 @@ import com.habitrpg.android.habitica.components.AppComponent;
|
||||||
import com.habitrpg.android.habitica.data.ChallengeRepository;
|
import com.habitrpg.android.habitica.data.ChallengeRepository;
|
||||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler;
|
import com.habitrpg.android.habitica.helpers.RxErrorHandler;
|
||||||
import com.habitrpg.android.habitica.models.social.Challenge;
|
import com.habitrpg.android.habitica.models.social.Challenge;
|
||||||
|
import com.habitrpg.android.habitica.modules.AppModule;
|
||||||
import com.habitrpg.android.habitica.ui.activities.CreateChallengeActivity;
|
import com.habitrpg.android.habitica.ui.activities.CreateChallengeActivity;
|
||||||
import com.habitrpg.android.habitica.ui.adapter.social.ChallengesListViewAdapter;
|
import com.habitrpg.android.habitica.ui.adapter.social.ChallengesListViewAdapter;
|
||||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||||
import com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport;
|
import com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
@ -35,6 +37,9 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ChallengeRepository challengeRepository;
|
ChallengeRepository challengeRepository;
|
||||||
|
@Inject
|
||||||
|
@Named(AppModule.NAMED_USER_ID)
|
||||||
|
String userId;
|
||||||
|
|
||||||
@BindView(R.id.refresh_layout)
|
@BindView(R.id.refresh_layout)
|
||||||
SwipeRefreshLayout swipeRefreshLayout;
|
SwipeRefreshLayout swipeRefreshLayout;
|
||||||
|
|
@ -45,11 +50,6 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
||||||
|
|
||||||
private ChallengesListViewAdapter challengeAdapter;
|
private ChallengesListViewAdapter challengeAdapter;
|
||||||
private boolean viewUserChallengesOnly;
|
private boolean viewUserChallengesOnly;
|
||||||
private boolean withFilter;
|
|
||||||
|
|
||||||
public void setWithFilter(boolean withFilter){
|
|
||||||
this.withFilter = withFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setViewUserChallengesOnly(boolean only) {
|
public void setViewUserChallengesOnly(boolean only) {
|
||||||
this.viewUserChallengesOnly = only;
|
this.viewUserChallengesOnly = only;
|
||||||
|
|
@ -58,7 +58,7 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
||||||
|
|
||||||
private RealmResults<Challenge> challenges;
|
private RealmResults<Challenge> challenges;
|
||||||
|
|
||||||
private ChallengeFilterOptions lastFilterOptions;
|
private ChallengeFilterOptions filterOptions;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
|
@ -73,7 +73,7 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
||||||
View v = inflater.inflate(R.layout.fragment_challengeslist, container, false);
|
View v = inflater.inflate(R.layout.fragment_challengeslist, container, false);
|
||||||
unbinder = ButterKnife.bind(this, v);
|
unbinder = ButterKnife.bind(this, v);
|
||||||
|
|
||||||
challengeAdapter = new ChallengesListViewAdapter(null, true, viewUserChallengesOnly);
|
challengeAdapter = new ChallengesListViewAdapter(null, true, viewUserChallengesOnly, userId);
|
||||||
|
|
||||||
swipeRefreshLayout.setOnRefreshListener(this);
|
swipeRefreshLayout.setOnRefreshListener(this);
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
||||||
fetchOnlineChallenges();
|
fetchOnlineChallenges();
|
||||||
}
|
}
|
||||||
this.challenges = challenges;
|
this.challenges = challenges;
|
||||||
challengeAdapter.updateData(challenges);
|
challengeAdapter.updateUnfilteredData(challenges);
|
||||||
}, RxErrorHandler.handleEmptyError());
|
}, RxErrorHandler.handleEmptyError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,8 +148,14 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
||||||
private void showFilterDialog() {
|
private void showFilterDialog() {
|
||||||
ChallengeFilterDialogHolder.showDialog(getActivity(),
|
ChallengeFilterDialogHolder.showDialog(getActivity(),
|
||||||
challenges,
|
challenges,
|
||||||
lastFilterOptions,
|
filterOptions, this::changeFilter);
|
||||||
filterOptions -> this.lastFilterOptions = filterOptions);
|
}
|
||||||
|
|
||||||
|
private void changeFilter(ChallengeFilterOptions challengeFilterOptions) {
|
||||||
|
filterOptions = challengeFilterOptions;
|
||||||
|
if (challengeAdapter != null) {
|
||||||
|
challengeAdapter.filter(filterOptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@ public class ChallengesOverviewFragment extends BaseMainFragment {
|
||||||
userChallengesFragment = new ChallengeListFragment();
|
userChallengesFragment = new ChallengeListFragment();
|
||||||
userChallengesFragment.setUser(this.user);
|
userChallengesFragment.setUser(this.user);
|
||||||
userChallengesFragment.setViewUserChallengesOnly(true);
|
userChallengesFragment.setViewUserChallengesOnly(true);
|
||||||
userChallengesFragment.setWithFilter(true);
|
|
||||||
|
|
||||||
availableChallengesFragment = new ChallengeListFragment();
|
availableChallengesFragment = new ChallengeListFragment();
|
||||||
availableChallengesFragment.setUser(this.user);
|
availableChallengesFragment.setUser(this.user);
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ public class PartyFragment extends BaseMainFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group != null && group.quest != null && group.quest.key != null && !group.quest.key.isEmpty()) {
|
if (group != null && group.quest != null && group.quest.key != null && !group.quest.key.isEmpty()) {
|
||||||
inventoryRepository.getQuestContent(group.quest.key).subscribe(content -> {
|
inventoryRepository.getQuestContent(group.quest.key).first().subscribe(content -> {
|
||||||
if (groupInformationFragment != null) {
|
if (groupInformationFragment != null) {
|
||||||
groupInformationFragment.setQuestContent(content);
|
groupInformationFragment.setQuestContent(content);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue