From 36d69cc380883b772d052646a65a569e863311c7 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 10 Sep 2020 09:02:25 +1000 Subject: [PATCH] Remove unused files --- .../securesms/loki/todo/IdenticonDrawable.kt | 49 ------- .../loki/todo/JazzIdenticonContactPhoto.kt | 22 --- .../loki/todo/JazzIdenticonDrawable.kt | 132 ------------------ .../thoughtcrime/securesms/loki/todo/RNG.kt | 30 ---- .../AvatarPlaceholderGenerator.kt | 2 +- .../loki/views/ProfilePictureView.kt | 2 +- .../SingleRecipientNotificationBuilder.java | 2 +- .../securesms/recipients/Recipient.java | 11 +- 8 files changed, 6 insertions(+), 244 deletions(-) delete mode 100644 src/org/thoughtcrime/securesms/loki/todo/IdenticonDrawable.kt delete mode 100644 src/org/thoughtcrime/securesms/loki/todo/JazzIdenticonContactPhoto.kt delete mode 100644 src/org/thoughtcrime/securesms/loki/todo/JazzIdenticonDrawable.kt delete mode 100644 src/org/thoughtcrime/securesms/loki/todo/RNG.kt rename src/org/thoughtcrime/securesms/loki/{todo => utilities}/AvatarPlaceholderGenerator.kt (98%) diff --git a/src/org/thoughtcrime/securesms/loki/todo/IdenticonDrawable.kt b/src/org/thoughtcrime/securesms/loki/todo/IdenticonDrawable.kt deleted file mode 100644 index bbc6ee088e..0000000000 --- a/src/org/thoughtcrime/securesms/loki/todo/IdenticonDrawable.kt +++ /dev/null @@ -1,49 +0,0 @@ -package org.thoughtcrime.securesms.loki.todo - -import android.graphics.* -import android.graphics.drawable.Drawable - -/** - * Basically a [Bitmap] wrapper, the [Bitmap] size must be known when instantiating it - * but when drawing it will draw the [Bitmap] to fit the canvas. - */ -abstract class IdenticonDrawable(width: Int, height: Int, hash: Long) : Drawable() { - private val bitmapRect: Rect = Rect(0, 0, width, height) - private val destinationRect: Rect = Rect(0, 0, width, height) - private val bitmap: Bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) - private val canvas: Canvas = Canvas(bitmap) - private val bitmapPaint = Paint(Paint.ANTI_ALIAS_FLAG) - - var hash: Long = hash - set(value) { - field = value - onSetHash(value) - invalidateBitmap() - } - - protected fun invalidateBitmap() { - drawBitmap(canvas) - invalidateSelf() - } - - protected abstract fun drawBitmap(canvas: Canvas) - - protected open fun onSetHash(newHash: Long) = Unit - - override fun draw(canvas: Canvas) { - destinationRect.set(0, 0, canvas.width, canvas.height) - canvas.drawBitmap(bitmap, bitmapRect, destinationRect, bitmapPaint) - } - - override fun setAlpha(i: Int) { - bitmapPaint.alpha = i - } - - override fun setColorFilter(colorFilter: ColorFilter?) { - bitmapPaint.colorFilter = colorFilter - } - - override fun getOpacity(): Int { - return bitmapPaint.alpha - } -} \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/todo/JazzIdenticonContactPhoto.kt b/src/org/thoughtcrime/securesms/loki/todo/JazzIdenticonContactPhoto.kt deleted file mode 100644 index a26751ad48..0000000000 --- a/src/org/thoughtcrime/securesms/loki/todo/JazzIdenticonContactPhoto.kt +++ /dev/null @@ -1,22 +0,0 @@ -package org.thoughtcrime.securesms.loki.todo - -import android.content.Context -import android.graphics.drawable.Drawable -import androidx.appcompat.content.res.AppCompatResources -import network.loki.messenger.R -import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto - -class JazzIdenticonContactPhoto(val hexEncodedPublicKey: String) : FallbackContactPhoto { - override fun asDrawable(context: Context, color: Int): Drawable { - return asDrawable(context, color, false) - } - - override fun asDrawable(context: Context, color: Int, inverted: Boolean): Drawable { - val targetSize = context.resources.getDimensionPixelSize(R.dimen.contact_photo_target_size) - return JazzIdenticonDrawable(targetSize, targetSize, hexEncodedPublicKey) - } - - override fun asCallCard(context: Context): Drawable? { - return AppCompatResources.getDrawable(context, R.drawable.ic_person_large) - } -} \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/todo/JazzIdenticonDrawable.kt b/src/org/thoughtcrime/securesms/loki/todo/JazzIdenticonDrawable.kt deleted file mode 100644 index d3cb71ccb3..0000000000 --- a/src/org/thoughtcrime/securesms/loki/todo/JazzIdenticonDrawable.kt +++ /dev/null @@ -1,132 +0,0 @@ -package org.thoughtcrime.securesms.loki.todo - -import android.graphics.Canvas -import android.graphics.Color -import android.graphics.Paint -import kotlin.math.* - -class JazzIdenticonDrawable(width: Int, height: Int, hash: Long) : IdenticonDrawable(width, height, hash) { - - constructor(width: Int, height: Int, hashString: String): this(width, height, 0) { - val hexRegex = Regex("^[0-9A-Fa-f]+\$") - if (hashString.length >= 12 && hashString.matches(hexRegex)) { - hash = hashString.substring(0 until 12).toLong(16) - } - } - - companion object { - var colors = listOf( - "#01888c", // teal - "#fc7500", // bright orange - "#034f5d", // dark teal - "#E784BA", // light pink - "#81C8B6", // bright green - "#c7144c", // raspberry - "#f3c100", // goldenrod - "#1598f2", // lightning blue - "#2465e1", // sail blue - "#f19e02" // gold - ).map{ Color.parseColor(it) } - } - - private var generator: RNG = RNG(hash) - private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL } - - // Settings - private val wobble: Float = 30f - private val shapeCount = 4 - - init { - invalidateBitmap() - } - - override fun onSetHash(newHash: Long) { - super.onSetHash(newHash) - generator = RNG(newHash) - invalidateBitmap() - } - - override fun drawBitmap(canvas: Canvas) { - generator.reset() - - val newColors = hueShift(colors) - val shuffled = shuffleList(newColors) - - canvas.drawColor(shuffled[0]) - for (i in 0 until shapeCount) { - drawSquare(canvas, shuffled[i + 1], i, shapeCount - 1) - } - } - - private fun drawSquare(canvas: Canvas, color: Int, index: Int, total: Int) { - val size = min(canvas.width, canvas.height) - val center = (size / 2).toFloat() - val firstRotation = generator.nextFloat() - val angle = PI * 2 * firstRotation - - val a = size / total.toFloat() - val b = generator.nextFloat() - val c = index.toFloat() * a - val velocity = a * b + c - - val tx = cos(angle) * velocity - val ty = sin(angle) * velocity - - // Third random is a shape rotation on top of all that - val secondRotation = generator.nextFloat() - val rotation = (firstRotation * 360f) + (secondRotation * 180f) - - // Paint it! - canvas.save() - - paint.color = color - canvas.translate(tx.toFloat(), ty.toFloat()) - canvas.rotate(rotation.round(1), center, center) - canvas.drawRect(0f, 0f, canvas.width.toFloat(), canvas.height.toFloat(), paint) - - canvas.restore() - } - - private fun hueShift(colors: List): List { - val amount = generator.nextFloat() * 30 - wobble / 2 - - return colors.map { color -> - val red = Color.red(color) - val green = Color.green(color) - val blue = Color.blue(color) - - val hsv = FloatArray(3) - Color.RGBToHSV(red, green, blue, hsv) - - // Normalise between 0 and 360 - var newHue = hsv[0] + round(amount) - if (newHue < 0) { newHue += 360 } - if (newHue > 360) { newHue -= 360 } - - hsv[0] = newHue - Color.HSVToColor(hsv) - } - } - - private fun shuffleList(list: List): List { - var currentIndex = list.count() - val newList = list.toMutableList() - while (currentIndex > 0) { - val randomIndex = generator.next().toInt() % currentIndex - currentIndex -= 1 - - // Swap - val temp = newList[currentIndex] - newList[currentIndex] = newList[randomIndex] - newList[randomIndex] = temp - } - - return newList - } -} - -private fun Float.round(decimals: Int): Float { - var multiplier = 1f - repeat(decimals) { multiplier *= 10 } - return round(this * multiplier) / multiplier -} \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/todo/RNG.kt b/src/org/thoughtcrime/securesms/loki/todo/RNG.kt deleted file mode 100644 index e9e3dee898..0000000000 --- a/src/org/thoughtcrime/securesms/loki/todo/RNG.kt +++ /dev/null @@ -1,30 +0,0 @@ -package org.thoughtcrime.securesms.loki.todo - -class RNG(hash: Long) { - private var seed: Long - private val initial: Long - - private val maxInt32 = Int.MAX_VALUE.toLong() - - init { - seed = hash % maxInt32 - if (seed <= 0) { - seed = maxInt32 - 1 - } - initial = seed - } - - fun next(): Long { - val newSeed = (seed * 16807) % maxInt32 - seed = newSeed - return seed - } - - fun nextFloat(): Float { - return (next() - 1).toFloat() / (maxInt32 - 1) - } - - fun reset() { - seed = initial - } -} \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/todo/AvatarPlaceholderGenerator.kt b/src/org/thoughtcrime/securesms/loki/utilities/AvatarPlaceholderGenerator.kt similarity index 98% rename from src/org/thoughtcrime/securesms/loki/todo/AvatarPlaceholderGenerator.kt rename to src/org/thoughtcrime/securesms/loki/utilities/AvatarPlaceholderGenerator.kt index 70343f8434..c7bd12d2b3 100644 --- a/src/org/thoughtcrime/securesms/loki/todo/AvatarPlaceholderGenerator.kt +++ b/src/org/thoughtcrime/securesms/loki/utilities/AvatarPlaceholderGenerator.kt @@ -1,4 +1,4 @@ -package org.thoughtcrime.securesms.loki.todo +package org.thoughtcrime.securesms.loki.utilities import android.content.Context import android.graphics.* diff --git a/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt b/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt index 8186639c5f..3ca3317f4f 100644 --- a/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt +++ b/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt @@ -13,7 +13,7 @@ import network.loki.messenger.R import org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto import org.thoughtcrime.securesms.database.Address import org.thoughtcrime.securesms.database.DatabaseFactory -import org.thoughtcrime.securesms.loki.todo.AvatarPlaceholderGenerator +import org.thoughtcrime.securesms.loki.utilities.AvatarPlaceholderGenerator import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.recipients.Recipient import org.thoughtcrime.securesms.util.TextSecurePreferences diff --git a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java index 9abb67d1ba..40ade81932 100644 --- a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java @@ -29,7 +29,7 @@ import org.thoughtcrime.securesms.contacts.avatars.ContactColors; import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto; import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.loki.todo.AvatarPlaceholderGenerator; +import org.thoughtcrime.securesms.loki.utilities.AvatarPlaceholderGenerator; import org.thoughtcrime.securesms.loki.utilities.NotificationUtilities; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader; import org.thoughtcrime.securesms.mms.GlideApp; diff --git a/src/org/thoughtcrime/securesms/recipients/Recipient.java b/src/org/thoughtcrime/securesms/recipients/Recipient.java index 37fb87eaf0..530aa6ecb1 100644 --- a/src/org/thoughtcrime/securesms/recipients/Recipient.java +++ b/src/org/thoughtcrime/securesms/recipients/Recipient.java @@ -20,6 +20,7 @@ package org.thoughtcrime.securesms.recipients; import android.content.Context; import android.graphics.drawable.Drawable; import android.net.Uri; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -43,7 +44,6 @@ import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState; import org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode; import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.loki.todo.JazzIdenticonContactPhoto; import org.thoughtcrime.securesms.loki.utilities.ProfilePictureModifiedEvent; import org.thoughtcrime.securesms.notifications.NotificationChannels; import org.thoughtcrime.securesms.recipients.RecipientProvider.RecipientDetails; @@ -465,15 +465,10 @@ public class Recipient implements RecipientModifiedListener { } public synchronized @NonNull FallbackContactPhoto getFallbackContactPhoto() { + // TODO: I believe this is now completely unused if (isResolving()) return new TransparentContactPhoto(); else if (isGroupRecipient()) return new GeneratedContactPhoto(name, R.drawable.ic_profile_default); - else { - String userPublicKey = TextSecurePreferences.getLocalNumber(context); - String publicKey = address.serialize(); - String userMasterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context); - String publicKeyToUse = (publicKey.equalsIgnoreCase(userPublicKey) && userMasterPublicKey != null) ? userMasterPublicKey : publicKey; - return new JazzIdenticonContactPhoto(publicKeyToUse); - } + else { return new TransparentContactPhoto(); } } public synchronized @Nullable ContactPhoto getContactPhoto() {