mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 16:49:40 +01:00
Add React With Any Search and update UX.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package org.thoughtcrime.securesms.util
|
||||
|
||||
import android.graphics.Rect
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
private typealias Predicate = (view: View, parent: RecyclerView) -> Boolean
|
||||
private val ALWAYS_TRUE: Predicate = { _, _ -> true }
|
||||
|
||||
/**
|
||||
* Externally configurable inset "setter" for recycler views.
|
||||
*
|
||||
* Primary constructor provides full external control of view insets.
|
||||
* Secondary constructors provide basic predicate based insets on the horizontal and vertical.
|
||||
*/
|
||||
open class InsetItemDecoration(
|
||||
private val setInset: SetInset
|
||||
) : RecyclerView.ItemDecoration() {
|
||||
|
||||
constructor(horizontalInset: Int = 0, verticalInset: Int = 0) : this(horizontalInset, verticalInset, ALWAYS_TRUE)
|
||||
constructor(horizontalInset: Int = 0, verticalInset: Int = 0, predicate: Predicate) : this(horizontalInset, horizontalInset, verticalInset, verticalInset, predicate)
|
||||
constructor(leftInset: Int = 0, rightInset: Int = 0, topInset: Int = 0, bottomInset: Int = 0, predicate: Predicate = ALWAYS_TRUE) : this(
|
||||
setInset = object : SetInset() {
|
||||
override fun setInset(outRect: Rect, view: View, parent: RecyclerView) {
|
||||
if (predicate == ALWAYS_TRUE || predicate.invoke(view, parent)) {
|
||||
outRect.left = leftInset
|
||||
outRect.right = rightInset
|
||||
outRect.top = topInset
|
||||
outRect.bottom = bottomInset
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
|
||||
super.getItemOffsets(outRect, view, parent, state)
|
||||
setInset.setInset(outRect, view, parent)
|
||||
}
|
||||
|
||||
abstract class SetInset {
|
||||
abstract fun setInset(outRect: Rect, view: View, parent: RecyclerView)
|
||||
|
||||
fun getPosition(view: View, parent: RecyclerView): Int {
|
||||
return parent.getChildAdapterPosition(view)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,13 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import org.whispersystems.libsignal.util.guava.Function;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
|
||||
/**
|
||||
* A reusable and composable {@link androidx.recyclerview.widget.RecyclerView.Adapter} built on-top of {@link ListAdapter} to
|
||||
@@ -103,6 +108,21 @@ public class MappingAdapter extends ListAdapter<MappingModel<?>, MappingViewHold
|
||||
holder.bind(getItem(position));
|
||||
}
|
||||
|
||||
public <T extends MappingModel<T>> int indexOfFirst(@NonNull Class<T> clazz, @NonNull Function1<T, Boolean> predicate) {
|
||||
return CollectionsKt.indexOfFirst(getCurrentList(), m -> {
|
||||
//noinspection unchecked
|
||||
return clazz.isAssignableFrom(m.getClass()) && predicate.invoke((T) m);
|
||||
});
|
||||
}
|
||||
|
||||
public @NonNull Optional<MappingModel<?>> getModel(int index) {
|
||||
List<MappingModel<?>> currentList = getCurrentList();
|
||||
if (index >= 0 && index < currentList.size()) {
|
||||
return Optional.ofNullable(currentList.get(index));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static class MappingDiffCallback extends DiffUtil.ItemCallback<MappingModel<?>> {
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull MappingModel oldItem, @NonNull MappingModel newItem) {
|
||||
|
||||
@@ -6,11 +6,59 @@ import com.annimon.stream.Collector;
|
||||
import com.annimon.stream.function.BiConsumer;
|
||||
import com.annimon.stream.function.Function;
|
||||
import com.annimon.stream.function.Supplier;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.BinaryOperator;
|
||||
|
||||
public class MappingModelList extends ArrayList<MappingModel<?>> {
|
||||
|
||||
public MappingModelList() { }
|
||||
|
||||
public MappingModelList(@NonNull Collection<? extends MappingModel<?>> c) {
|
||||
super(c);
|
||||
}
|
||||
|
||||
public static @NonNull MappingModelList singleton(@NonNull MappingModel<?> model) {
|
||||
MappingModelList list = new MappingModelList();
|
||||
list.add(model);
|
||||
return list;
|
||||
}
|
||||
|
||||
public static @NonNull java.util.stream.Collector<MappingModel<?>, MappingModelList, MappingModelList> collect() {
|
||||
return new java.util.stream.Collector<MappingModel<?>, MappingModelList, MappingModelList>() {
|
||||
@Override
|
||||
public java.util.function.Supplier<MappingModelList> supplier() {
|
||||
return MappingModelList::new;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.function.BiConsumer<MappingModelList, MappingModel<?>> accumulator() {
|
||||
return MappingModelList::add;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryOperator<MappingModelList> combiner() {
|
||||
return (left, right) -> {
|
||||
left.addAll(right);
|
||||
return left;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.function.Function<MappingModelList, MappingModelList> finisher() {
|
||||
return java.util.function.Function.identity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Characteristics> characteristics() {
|
||||
return Sets.immutableEnumSet(Characteristics.IDENTITY_FINISH);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static @NonNull Collector<MappingModel<?>, MappingModelList, MappingModelList> toMappingModelList() {
|
||||
return new Collector<MappingModel<?>, MappingModelList, MappingModelList>() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user