mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-16 09:40:46 +00:00
Giphy integration
// FREEBIE
This commit is contained in:
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
|
||||
public class JsonUtils {
|
||||
|
||||
@@ -23,7 +24,11 @@ public class JsonUtils {
|
||||
return objectMapper.readValue(serialized, clazz);
|
||||
}
|
||||
|
||||
public static <T> T fromJson(InputStreamReader serialized, Class<T> clazz) throws IOException {
|
||||
public static <T> T fromJson(InputStream serialized, Class<T> clazz) throws IOException {
|
||||
return objectMapper.readValue(serialized, clazz);
|
||||
}
|
||||
|
||||
public static <T> T fromJson(Reader serialized, Class<T> clazz) throws IOException {
|
||||
return objectMapper.readValue(serialized, clazz);
|
||||
}
|
||||
|
||||
|
@@ -384,6 +384,14 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getRandomElement(T[] elements) {
|
||||
try {
|
||||
return elements[SecureRandom.getInstance("SHA1PRNG").nextInt(elements.length)];
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean equals(@Nullable Object a, @Nullable Object b) {
|
||||
return a == b || (a != null && a.equals(b));
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
package org.thoughtcrime.securesms.util.concurrent;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public interface ListenableFuture<T> {
|
||||
public interface ListenableFuture<T> extends Future<T> {
|
||||
void addListener(Listener<T> listener);
|
||||
|
||||
public interface Listener<T> {
|
||||
|
@@ -7,7 +7,7 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class SettableFuture<T> implements Future<T>, ListenableFuture<T> {
|
||||
public class SettableFuture<T> implements ListenableFuture<T> {
|
||||
|
||||
private final List<Listener<T>> listeners = new LinkedList<>();
|
||||
|
||||
@@ -42,6 +42,7 @@ public class SettableFuture<T> implements Future<T>, ListenableFuture<T> {
|
||||
|
||||
this.result = result;
|
||||
this.completed = true;
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
notifyAllListeners();
|
||||
@@ -54,6 +55,7 @@ public class SettableFuture<T> implements Future<T>, ListenableFuture<T> {
|
||||
|
||||
this.exception = throwable;
|
||||
this.completed = true;
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
notifyAllListeners();
|
||||
|
Reference in New Issue
Block a user