pull/420/head
Ryan ZHAO 3 years ago
parent 543019f93c
commit 88ae3a9d93

@ -18,8 +18,6 @@ object AvatarPlaceholderGenerator {
fun generate(context: Context, pixelSize: Int, hashString: String, displayName: String?): BitmapDrawable {
val hash: Long
if (hashString.length >= 12 && hashString.matches(Regex("^[0-9A-Fa-f]+\$"))) {
val sha = getSha512(hashString)
val test = sha.substring(0 until 12)
hash = getSha512(hashString).substring(0 until 12).toLong(16)
} else {
hash = 0

@ -21,6 +21,8 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import android.text.TextUtils;
@ -42,6 +44,8 @@ import network.loki.messenger.BuildConfig;
public class Util {
private static volatile Handler handler;
public static String join(String[] list, String delimiter) {
return join(Arrays.asList(list), delimiter);
}
@ -144,4 +148,24 @@ public class Util {
public static boolean isMmsCapable(Context context) {
return (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) || OutgoingLegacyMmsConnection.isConnectionPossible(context);
}
public static boolean isMainThread() {
return Looper.myLooper() == Looper.getMainLooper();
}
public static void runOnMain(final @NonNull Runnable runnable) {
if (isMainThread()) runnable.run();
else getHandler().post(runnable);
}
private static Handler getHandler() {
if (handler == null) {
synchronized (Util.class) {
if (handler == null) {
handler = new Handler(Looper.getMainLooper());
}
}
}
return handler;
}
}

Loading…
Cancel
Save