mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-08-01 03:30:34 +00:00
fix task filtering
This commit is contained in:
parent
d2eaebcc14
commit
8a2c80ea03
4 changed files with 20 additions and 4 deletions
|
|
@ -12,7 +12,7 @@ import io.realm.OrderedRealmCollectionChangeListener
|
|||
import io.realm.RealmList
|
||||
import io.realm.RealmResults
|
||||
|
||||
abstract class RealmBaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(private val unfilteredData: OrderedRealmCollection<Task>?, private val hasAutoUpdates: Boolean, private val layoutResource: Int, private val taskFilterHelper: TaskFilterHelper?) : RecyclerView.Adapter<VH>(), TaskRecyclerViewAdapter {
|
||||
abstract class RealmBaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(private var unfilteredData: OrderedRealmCollection<Task>?, private val hasAutoUpdates: Boolean, private val layoutResource: Int, private val taskFilterHelper: TaskFilterHelper?) : RecyclerView.Adapter<VH>(), TaskRecyclerViewAdapter {
|
||||
private var updateOnModification: Boolean = false
|
||||
private var ignoreUpdates: Boolean = false
|
||||
private val listener: OrderedRealmCollectionChangeListener<OrderedRealmCollection<Task>> by lazy {
|
||||
|
|
@ -49,8 +49,9 @@ abstract class RealmBaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(privat
|
|||
get() = data?.isValid ?: false
|
||||
|
||||
init {
|
||||
if (unfilteredData != null && !unfilteredData.isManaged)
|
||||
if (unfilteredData != null && unfilteredData?.isManaged == false) {
|
||||
throw IllegalStateException("Only use this adapter with managed RealmCollection, " + "for un-managed lists you can just use the BaseRecyclerViewAdapter")
|
||||
}
|
||||
this.data = unfilteredData
|
||||
this.updateOnModification = true
|
||||
}
|
||||
|
|
@ -76,6 +77,8 @@ abstract class RealmBaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(privat
|
|||
|
||||
fun getItem(index: Int): Task? = if (isDataValid) data!![index] else null
|
||||
|
||||
|
||||
|
||||
override fun updateData(data: OrderedRealmCollection<Task>?) {
|
||||
if (hasAutoUpdates) {
|
||||
if (isDataValid) {
|
||||
|
|
@ -91,6 +94,11 @@ abstract class RealmBaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(privat
|
|||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun updateUnfilteredData(data: OrderedRealmCollection<Task>?) {
|
||||
unfilteredData = data
|
||||
updateData(data)
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun addListener(data: OrderedRealmCollection<Task>?) = when (data) {
|
||||
is RealmResults<*> -> {
|
||||
|
|
@ -126,7 +134,6 @@ abstract class RealmBaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(privat
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
internal fun getContentView(parent: ViewGroup): View = getContentView(parent, layoutResource)
|
||||
|
||||
private fun getContentView(parent: ViewGroup, layoutResource: Int): View =
|
||||
|
|
|
|||
|
|
@ -86,6 +86,11 @@ public class RewardsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUnfilteredData(@org.jetbrains.annotations.Nullable OrderedRealmCollection<Task> data) {
|
||||
updateData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int rewardCount = getCustomRewardCount();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ package com.habitrpg.android.habitica.ui.adapter.tasks;
|
|||
|
||||
import com.habitrpg.android.habitica.models.tasks.Task;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import io.realm.OrderedRealmCollection;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
public interface TaskRecyclerViewAdapter {
|
||||
|
||||
|
|
@ -17,4 +20,5 @@ public interface TaskRecyclerViewAdapter {
|
|||
void setIgnoreUpdates(boolean ignoreUpdates);
|
||||
boolean getIgnoreUpdates();
|
||||
|
||||
void updateUnfilteredData(@Nullable OrderedRealmCollection<Task> data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ open class TaskRecyclerViewFragment : BaseFragment(), View.OnClickListener, Swip
|
|||
recyclerView.adapter = adapter
|
||||
|
||||
if (this.classType != null) {
|
||||
taskRepository.getTasks(this.classType ?: "", userID).first().subscribe(Action1 { this.recyclerAdapter?.updateData(it) }, RxErrorHandler.handleEmptyError())
|
||||
taskRepository.getTasks(this.classType ?: "", userID).first().subscribe(Action1 { this.recyclerAdapter?.updateUnfilteredData(it) }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue