mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +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:checked="true"
|
||||
android:text="@string/owned"
|
||||
android:textColor="@color/textColorLight"/>
|
||||
android:textColor="@color/textColorLight"
|
||||
android:paddingLeft="8dp" />
|
||||
|
||||
<CheckBox
|
||||
style="@style/Subheader2"
|
||||
|
|
@ -94,6 +95,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:text="@string/not_owned"
|
||||
android:textColor="@color/textColorLight"/>
|
||||
android:textColor="@color/textColorLight"
|
||||
android:paddingLeft="8dp"/>
|
||||
</LinearLayout>
|
||||
</com.habitrpg.android.habitica.ui.MaxHeightLinearLayout>
|
||||
|
|
@ -1,22 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<CheckBox
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/challenge_filter_group_checkbox"
|
||||
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>
|
||||
android:checked="true"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingLeft="8dp"/>
|
||||
|
|
@ -282,7 +282,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
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
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class Challenge extends RealmObject {
|
|||
public boolean isParticipating;
|
||||
|
||||
public HashMap<String, String[]> getTasksOrder() {
|
||||
HashMap<String, String[]> map = new HashMap();
|
||||
HashMap<String, String[]> map = new HashMap<>();
|
||||
|
||||
if (!dailyList.isEmpty()) {
|
||||
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.ShowChallengeDetailDialogCommand;
|
||||
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.EmojiTextView;
|
||||
|
|
@ -23,15 +25,19 @@ import org.greenrobot.eventbus.EventBus;
|
|||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.realm.OrderedRealmCollection;
|
||||
import io.realm.RealmQuery;
|
||||
import io.realm.RealmRecyclerViewAdapter;
|
||||
|
||||
public class ChallengesListViewAdapter extends RealmRecyclerViewAdapter<Challenge, ChallengesListViewAdapter.ChallengeViewHolder> {
|
||||
|
||||
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);
|
||||
this.viewUserChallengesOnly = viewUserChallengesOnly;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -44,7 +50,42 @@ public class ChallengesListViewAdapter extends RealmRecyclerViewAdapter<Challeng
|
|||
|
||||
@Override
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import com.habitrpg.android.habitica.models.social.Group;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
|
@ -65,7 +66,7 @@ public class ChallengesFilterRecyclerViewAdapter extends RecyclerView.Adapter<Ch
|
|||
|
||||
public void selectAll(List<Group> groupsToCheck){
|
||||
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(){
|
||||
|
|
@ -84,9 +85,6 @@ public class ChallengesFilterRecyclerViewAdapter extends RecyclerView.Adapter<Ch
|
|||
@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) {
|
||||
|
|
@ -98,8 +96,7 @@ public class ChallengesFilterRecyclerViewAdapter extends RecyclerView.Adapter<Ch
|
|||
public void bind(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.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
|
@ -63,20 +64,21 @@ class ChallengeFilterDialogHolder {
|
|||
ChallengeFilterDialogHolder challengeFilterDialogHolder = new ChallengeFilterDialogHolder(dialogLayout, activity);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.filter)
|
||||
.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,
|
||||
Action1<ChallengeFilterOptions> selectedGroupsCallback) {
|
||||
this.dialog = dialog;
|
||||
this.dialog.setButton(Dialog.BUTTON_POSITIVE, context.getString(R.string.done), (dialog1, which) -> doneClicked());
|
||||
builder = builder
|
||||
.setPositiveButton(context.getString(R.string.done), (dialog1, which) -> doneClicked());
|
||||
this.dialog = builder.show();
|
||||
this.challengesViewed = challengesViewed;
|
||||
this.currentFilter = currentFilter;
|
||||
this.selectedGroupsCallback = selectedGroupsCallback;
|
||||
|
||||
fillChallengeGroups();
|
||||
|
||||
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.helpers.RxErrorHandler;
|
||||
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.adapter.social.ChallengesListViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
|
@ -35,6 +37,9 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
|
||||
@Inject
|
||||
ChallengeRepository challengeRepository;
|
||||
@Inject
|
||||
@Named(AppModule.NAMED_USER_ID)
|
||||
String userId;
|
||||
|
||||
@BindView(R.id.refresh_layout)
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
|
@ -45,11 +50,6 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
|
||||
private ChallengesListViewAdapter challengeAdapter;
|
||||
private boolean viewUserChallengesOnly;
|
||||
private boolean withFilter;
|
||||
|
||||
public void setWithFilter(boolean withFilter){
|
||||
this.withFilter = withFilter;
|
||||
}
|
||||
|
||||
public void setViewUserChallengesOnly(boolean only) {
|
||||
this.viewUserChallengesOnly = only;
|
||||
|
|
@ -58,7 +58,7 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
|
||||
private RealmResults<Challenge> challenges;
|
||||
|
||||
private ChallengeFilterOptions lastFilterOptions;
|
||||
private ChallengeFilterOptions filterOptions;
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
|
@ -73,7 +73,7 @@ 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(null, true, viewUserChallengesOnly);
|
||||
challengeAdapter = new ChallengesListViewAdapter(null, true, viewUserChallengesOnly, userId);
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
fetchOnlineChallenges();
|
||||
}
|
||||
this.challenges = challenges;
|
||||
challengeAdapter.updateData(challenges);
|
||||
challengeAdapter.updateUnfilteredData(challenges);
|
||||
}, RxErrorHandler.handleEmptyError());
|
||||
}
|
||||
|
||||
|
|
@ -148,8 +148,14 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
private void showFilterDialog() {
|
||||
ChallengeFilterDialogHolder.showDialog(getActivity(),
|
||||
challenges,
|
||||
lastFilterOptions,
|
||||
filterOptions -> this.lastFilterOptions = filterOptions);
|
||||
filterOptions, this::changeFilter);
|
||||
}
|
||||
|
||||
private void changeFilter(ChallengeFilterOptions challengeFilterOptions) {
|
||||
filterOptions = challengeFilterOptions;
|
||||
if (challengeAdapter != null) {
|
||||
challengeAdapter.filter(filterOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ public class ChallengesOverviewFragment extends BaseMainFragment {
|
|||
userChallengesFragment = new ChallengeListFragment();
|
||||
userChallengesFragment.setUser(this.user);
|
||||
userChallengesFragment.setViewUserChallengesOnly(true);
|
||||
userChallengesFragment.setWithFilter(true);
|
||||
|
||||
availableChallengesFragment = new ChallengeListFragment();
|
||||
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()) {
|
||||
inventoryRepository.getQuestContent(group.quest.key).subscribe(content -> {
|
||||
inventoryRepository.getQuestContent(group.quest.key).first().subscribe(content -> {
|
||||
if (groupInformationFragment != null) {
|
||||
groupInformationFragment.setQuestContent(content);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue