mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Use streams and collectors supported below API 24 in StaticEmojiPageModel (#966)
* fix: use annimon stream instead of java util * refactor: convert remaining java.til stream and functions into annimon equivalent * refactor: remove a .stream() reference * fix: possible future NPE in ConversationReactionOverlay
This commit is contained in:
parent
c09e4e4907
commit
b6106d5506
@ -5,13 +5,14 @@ import android.net.Uri;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.annimon.stream.Collectors;
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.emoji.EmojiCategory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class StaticEmojiPageModel implements EmojiPageModel {
|
||||
private final @NonNull EmojiCategory category;
|
||||
@ -19,7 +20,7 @@ public class StaticEmojiPageModel implements EmojiPageModel {
|
||||
private final @Nullable Uri sprite;
|
||||
|
||||
public StaticEmojiPageModel(@NonNull EmojiCategory category, @NonNull String[] strings, @Nullable Uri sprite) {
|
||||
this(category, Arrays.stream(strings).map(s -> new Emoji(Collections.singletonList(s))).collect(Collectors.toList()), sprite);
|
||||
this(category, Stream.of(strings).map(s -> new Emoji(Collections.singletonList(s))).collect(Collectors.toList()), sprite);
|
||||
}
|
||||
|
||||
public StaticEmojiPageModel(@NonNull EmojiCategory category, @NonNull List<Emoji> emoji, @Nullable Uri sprite) {
|
||||
|
@ -46,6 +46,7 @@ import org.thoughtcrime.securesms.util.AnimationCompleteListener;
|
||||
import org.thoughtcrime.securesms.util.DateUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@ -655,6 +656,8 @@ public final class ConversationReactionOverlay extends FrameLayout {
|
||||
boolean hasText = !message.getBody().isEmpty();
|
||||
OpenGroup openGroup = DatabaseComponent.get(getContext()).lokiThreadDatabase().getOpenGroupChat(message.getThreadId());
|
||||
Recipient recipient = DatabaseComponent.get(getContext()).threadDatabase().getRecipientForThreadId(message.getThreadId());
|
||||
if (recipient == null) return Collections.emptyList();
|
||||
|
||||
String userPublicKey = TextSecurePreferences.getLocalNumber(getContext());
|
||||
// Select message
|
||||
items.add(new ActionItem(R.attr.menu_select_icon, getContext().getResources().getString(R.string.conversation_context__menu_select), () -> handleActionItemClicked(Action.SELECT)));
|
||||
|
@ -5,6 +5,8 @@ import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageModel;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageViewGridAdapter;
|
||||
@ -79,8 +81,7 @@ public final class ReactWithAnyEmojiViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
private static @NonNull MappingModelList toMappingModels(@NonNull EmojiPageModel model) {
|
||||
return model.getDisplayEmoji()
|
||||
.stream()
|
||||
return Stream.of(model.getDisplayEmoji())
|
||||
.map(e -> new EmojiPageViewGridAdapter.EmojiModel(model.getKey(), e))
|
||||
.collect(MappingModelList.collect());
|
||||
}
|
||||
|
@ -2,10 +2,11 @@ package org.thoughtcrime.securesms.util;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class ListUtil {
|
||||
private ListUtil() {}
|
||||
@ -23,7 +24,8 @@ public final class ListUtil {
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> List<T> concat(Collection<T>... items) {
|
||||
final List<T> concat = new ArrayList<>(Stream.of(items).map(Collection::size).reduce(0, Integer::sum));
|
||||
//noinspection Convert2MethodRef
|
||||
final List<T> concat = new ArrayList<>(Stream.of(items).map(Collection::size).reduce(0, (lhs, rhs) -> lhs+rhs));
|
||||
|
||||
for (Collection<T> list : items) {
|
||||
concat.addAll(list);
|
||||
|
@ -1,7 +1,8 @@
|
||||
package org.thoughtcrime.securesms.util
|
||||
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import java.util.stream.Collectors
|
||||
import com.annimon.stream.Collectors
|
||||
import com.annimon.stream.Stream
|
||||
|
||||
object SqlUtil {
|
||||
/** The maximum number of arguments (i.e. question marks) allowed in a SQL statement. */
|
||||
@ -73,8 +74,7 @@ object SqlUtil {
|
||||
@VisibleForTesting
|
||||
fun buildCustomCollectionQuery(query: String, argList: List<Array<String>>, maxQueryArgs: Int): List<Query> {
|
||||
val batchSize: Int = maxQueryArgs / argList[0].size
|
||||
return ListUtil.chunk(argList, batchSize)
|
||||
.stream()
|
||||
return Stream.of(ListUtil.chunk(argList, batchSize))
|
||||
.map { argBatch -> buildSingleCustomCollectionQuery(query, argBatch) }
|
||||
.collect(Collectors.toList())
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package org.thoughtcrime.securesms.util.adapter.mapping
|
||||
|
||||
import java.util.function.BiConsumer
|
||||
import java.util.function.BinaryOperator
|
||||
import java.util.function.Function
|
||||
import java.util.function.Supplier
|
||||
import java.util.stream.Collector
|
||||
import com.annimon.stream.Collector
|
||||
import com.annimon.stream.function.BiConsumer
|
||||
import com.annimon.stream.function.Function
|
||||
import com.annimon.stream.function.Supplier
|
||||
|
||||
class MappingModelList : ArrayList<MappingModel<*>?> {
|
||||
constructor() {}
|
||||
@ -22,26 +21,15 @@ class MappingModelList : ArrayList<MappingModel<*>?> {
|
||||
fun collect(): Collector<MappingModel<*>, MappingModelList, MappingModelList> {
|
||||
return object : Collector<MappingModel<*>, MappingModelList, MappingModelList> {
|
||||
override fun supplier(): Supplier<MappingModelList> {
|
||||
return java.util.function.Supplier { MappingModelList() }
|
||||
return Supplier { MappingModelList() }
|
||||
}
|
||||
|
||||
override fun accumulator(): BiConsumer<MappingModelList, MappingModel<*>> {
|
||||
return java.util.function.BiConsumer { obj: MappingModelList, e: MappingModel<*> -> obj.add(e) }
|
||||
}
|
||||
|
||||
override fun combiner(): BinaryOperator<MappingModelList> {
|
||||
return BinaryOperator { left: MappingModelList, right: MappingModelList ->
|
||||
left.addAll(right)
|
||||
left
|
||||
}
|
||||
return BiConsumer { obj: MappingModelList, e: MappingModel<*> -> obj.add(e) }
|
||||
}
|
||||
|
||||
override fun finisher(): Function<MappingModelList, MappingModelList> {
|
||||
return Function.identity()
|
||||
}
|
||||
|
||||
override fun characteristics(): Set<Collector.Characteristics> {
|
||||
return setOf(Collector.Characteristics.IDENTITY_FINISH)
|
||||
return Function { t -> t }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user