mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Clean
This commit is contained in:
parent
7c6c551b32
commit
fd389a637a
@ -37,8 +37,6 @@ import android.view.ViewTreeObserver;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.lelloman.identicon.drawable.ClassicIdenticonDrawable;
|
||||
|
||||
import org.thoughtcrime.securesms.components.RatingManager;
|
||||
import org.thoughtcrime.securesms.components.SearchToolbar;
|
||||
import org.thoughtcrime.securesms.conversation.ConversationActivity;
|
||||
@ -46,7 +44,7 @@ import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
||||
import org.thoughtcrime.securesms.lock.RegistrationLockDialog;
|
||||
import org.thoughtcrime.securesms.loki.identicon.JazzIdenticonDrawable;
|
||||
import org.thoughtcrime.securesms.loki.JazzIdenticonDrawable;
|
||||
import org.thoughtcrime.securesms.notifications.MarkReadReceiver;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
|
@ -16,13 +16,10 @@ import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewOutlineProvider;
|
||||
|
||||
import com.lelloman.identicon.drawable.ClassicIdenticonDrawable;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto;
|
||||
import org.thoughtcrime.securesms.loki.identicon.JazzIdenticonDrawable;
|
||||
import org.thoughtcrime.securesms.loki.JazzIdenticonDrawable;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientExporter;
|
||||
@ -30,6 +27,8 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
|
||||
public class AvatarImageView extends AppCompatImageView {
|
||||
|
||||
private static final String TAG = AvatarImageView.class.getSimpleName();
|
||||
|
@ -881,7 +881,9 @@ public class ConversationItem extends LinearLayout
|
||||
String serverId = GroupUtil.getDecodedStringId(conversationRecipient.getAddress().serialize());
|
||||
String senderDisplayName = DatabaseFactory.getLokiUserDatabase(context).getServerDisplayName(serverId, recipient.getAddress().serialize());
|
||||
if (senderDisplayName != null) { displayName = senderDisplayName; }
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
this.groupSender.setText(displayName);
|
||||
|
||||
|
@ -1,22 +1,13 @@
|
||||
package org.thoughtcrime.securesms.loki.identicon
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.ColorFilter
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Rect
|
||||
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() {
|
||||
|
||||
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)
|
@ -1,6 +1,8 @@
|
||||
package org.thoughtcrime.securesms.loki.identicon
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
import android.graphics.*
|
||||
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) {
|
@ -94,10 +94,8 @@ class LokiGroupChatPoller(private val context: Context, private val group: LokiG
|
||||
val x1 = SignalServiceGroup(SignalServiceGroup.Type.UPDATE, id, null, null, null)
|
||||
val x2 = SignalServiceDataMessage(message.timestamp, x1, null, message.body)
|
||||
val x3 = SignalServiceContent(x2, message.hexEncodedPublicKey, SignalServiceAddress.DEFAULT_DEVICE_ID, message.timestamp, false)
|
||||
|
||||
val senderDisplayName = "${message.displayName} (...${message.hexEncodedPublicKey.takeLast(8)})"
|
||||
DatabaseFactory.getLokiUserDatabase(context).setServerDisplayName(group.id, message.hexEncodedPublicKey, senderDisplayName)
|
||||
|
||||
PushDecryptJob(context).handleTextMessage(x3, x2, Optional.absent(), Optional.of(message.serverID))
|
||||
}
|
||||
fun processOutgoingMessage(message: LokiGroupMessage) {
|
||||
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.loki
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.util.Log
|
||||
import org.thoughtcrime.securesms.database.Address
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
@ -13,13 +14,16 @@ import org.whispersystems.signalservice.loki.messaging.LokiUserDatabaseProtocol
|
||||
class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiUserDatabaseProtocol {
|
||||
|
||||
companion object {
|
||||
private val displayNameTable = "loki_user_display_name_database"
|
||||
private val serverDisplayNameTable = "loki_user_server_display_name_database"
|
||||
private val hexEncodedPublicKey = "hex_encoded_public_key"
|
||||
// Shared
|
||||
private val displayName = "display_name"
|
||||
private val serverId = "server_id"
|
||||
// Display name cache
|
||||
private val displayNameTable = "loki_user_display_name_database"
|
||||
private val hexEncodedPublicKey = "hex_encoded_public_key"
|
||||
@JvmStatic val createDisplayNameTableCommand = "CREATE TABLE $displayNameTable ($hexEncodedPublicKey TEXT PRIMARY KEY, $displayName TEXT);"
|
||||
@JvmStatic val createServerDisplayNameTableCommand = "CREATE TABLE $serverDisplayNameTable ($hexEncodedPublicKey TEXT, $serverId TEXT, $displayName TEXT, PRIMARY KEY ($hexEncodedPublicKey, $serverId));"
|
||||
// Server display name cache
|
||||
private val serverDisplayNameTable = "loki_user_server_display_name_database"
|
||||
private val serverID = "server_id"
|
||||
@JvmStatic val createServerDisplayNameTableCommand = "CREATE TABLE $serverDisplayNameTable ($hexEncodedPublicKey TEXT, $serverID TEXT, $displayName TEXT, PRIMARY KEY ($hexEncodedPublicKey, $serverID));"
|
||||
}
|
||||
|
||||
override fun getDisplayName(hexEncodedPublicKey: String): String? {
|
||||
@ -42,24 +46,24 @@ class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database
|
||||
Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false).notifyListeners()
|
||||
}
|
||||
|
||||
fun getServerDisplayName(serverId: String, hexEncodedPublicKey: String): String? {
|
||||
fun getServerDisplayName(serverID: String, hexEncodedPublicKey: String): String? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(serverDisplayNameTable, "${Companion.hexEncodedPublicKey} = ? AND ${Companion.serverId} = ?", arrayOf(hexEncodedPublicKey, serverId)) { cursor ->
|
||||
return database.get(serverDisplayNameTable, "${Companion.hexEncodedPublicKey} = ? AND ${Companion.serverID} = ?", arrayOf(hexEncodedPublicKey, serverID)) { cursor ->
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(displayName))
|
||||
}
|
||||
}
|
||||
|
||||
fun setServerDisplayName(serverId: String, hexEncodedPublicKey: String, displayName: String) {
|
||||
fun setServerDisplayName(serverID: String, hexEncodedPublicKey: String, displayName: String) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val values = ContentValues(3)
|
||||
values.put(Companion.serverId, serverId)
|
||||
values.put(Companion.serverID, serverID)
|
||||
values.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey)
|
||||
values.put(Companion.displayName, displayName)
|
||||
try {
|
||||
database.insertWithOnConflict(serverDisplayNameTable, null, values, SQLiteDatabase.CONFLICT_REPLACE)
|
||||
Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false).notifyListeners()
|
||||
} catch (e: Exception) {
|
||||
print(e)
|
||||
Log.d("Loki", "Couldn't save server display name due to exception: $e.")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package org.thoughtcrime.securesms.loki.identicon
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
class RNG(hash: Long) {
|
||||
|
||||
private var seed: Long
|
||||
private val initial: Long
|
||||
|
||||
@ -13,17 +12,17 @@ class RNG(hash: Long) {
|
||||
initial = seed
|
||||
}
|
||||
|
||||
public fun next(): Long {
|
||||
fun next(): Long {
|
||||
val newSeed = (seed * 16807) % 2147483647
|
||||
seed = newSeed
|
||||
return seed
|
||||
}
|
||||
|
||||
public fun nextFloat(): Float {
|
||||
fun nextFloat(): Float {
|
||||
return (next() - 1).toFloat() / 2147483646
|
||||
}
|
||||
|
||||
public fun reset() {
|
||||
fun reset() {
|
||||
seed = initial
|
||||
}
|
||||
}
|
@ -18,10 +18,8 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.lelloman.identicon.drawable.ClassicIdenticonDrawable;
|
||||
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.loki.identicon.JazzIdenticonDrawable;
|
||||
import org.thoughtcrime.securesms.loki.JazzIdenticonDrawable;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
|
Loading…
x
Reference in New Issue
Block a user