Giphy integration

// FREEBIE
This commit is contained in:
Moxie Marlinspike
2016-10-16 19:05:07 -07:00
parent 8e9e3847b6
commit 69d0242574
58 changed files with 1644 additions and 15 deletions

View File

@@ -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);
}

View File

@@ -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));
}

View File

@@ -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> {

View File

@@ -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();