srctree

Robin Linden parent 58a6c836 ff4e4005
Revert "Migrate from Picasso to Glide for image loading"

This reverts commit 5025392a51e4fc81e669589c08384860427e5dd3.

This is part 3/3 of reverts to get back to Picasso that handled imagesin the chat view without any flickering.

inlinesplit
WORKSPACE added: 49, removed: 25, total 24
@@ -192,6 +192,7 @@ maven_install(
"com.google.android.material:material:1.4.0",
"com.google.code.gson:gson:2.8.6",
"com.google.guava:guava:19.0",
"com.squareup.picasso:picasso:2.8",
"com.typesafe.scala-logging:scala-logging_2.11:3.7.2",
"javax.inject:javax.inject:1",
"junit:junit:4.13.1",
 
atox/build.gradle.kts added: 49, removed: 25, total 24
@@ -79,10 +79,10 @@ dependencies {
 
implementation(libs.androidx.multidex)
 
implementation(libs.bumptech.glide)
 
implementation(libs.nayuki.qrcodegen)
 
implementation(libs.square.picasso)
 
debugImplementation(libs.square.leakcanary)
 
androidTestImplementation(kotlin("test"))
 
atox/src/main/kotlin/ui/NotificationHelper.kt added: 49, removed: 25, total 24
@@ -8,6 +8,12 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.PorterDuff
import android.graphics.PorterDuffXfermode
import android.graphics.Rect
import android.media.AudioAttributes
import android.media.RingtoneManager
import android.os.Build
@@ -18,10 +24,10 @@ import androidx.core.app.Person
import androidx.core.app.RemoteInput
import androidx.core.content.getSystemService
import androidx.core.graphics.drawable.IconCompat
import androidx.core.graphics.drawable.toBitmap
import androidx.core.os.bundleOf
import androidx.navigation.NavDeepLinkBuilder
import com.bumptech.glide.Glide
import com.squareup.picasso.Picasso
import com.squareup.picasso.Transformation
import javax.inject.Inject
import javax.inject.Singleton
import ltd.evilcorp.atox.Action
@@ -86,6 +92,27 @@ class NotificationHelper @Inject constructor(
 
fun dismissNotifications(publicKey: PublicKey) = notifier.cancel(publicKey.string().hashCode())
 
private val circleTransform = object : Transformation {
override fun transform(bitmap: Bitmap): Bitmap {
val output = Bitmap.createBitmap(bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(output)
val paint = Paint()
val rect = Rect(0, 0, bitmap.width, bitmap.height)
 
paint.isAntiAlias = true
canvas.drawARGB(0, 0, 0, 0)
canvas.drawCircle(bitmap.width / 2.0f, bitmap.height / 2.0f, bitmap.width / 2.0f, paint)
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)
canvas.drawBitmap(bitmap, rect, rect, paint)
if (bitmap != output) {
bitmap.recycle()
}
return output
}
 
override fun key() = "circleTransform"
}
 
fun showMessageNotification(
contact: Contact,
message: String,
@@ -103,9 +130,7 @@ class NotificationHelper @Inject constructor(
 
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val icon = if (contact.avatarUri.isNotEmpty()) {
IconCompat.createWithBitmap(
Glide.with(context).load(contact.avatarUri).circleCrop().submit().get().toBitmap()
)
IconCompat.createWithBitmap(Picasso.get().load(contact.avatarUri).transform(circleTransform).get())
} else {
null
}
 
atox/src/main/kotlin/ui/chat/ChatAdapter.kt added: 49, removed: 25, total 24
@@ -19,9 +19,7 @@ import android.widget.ListView
import android.widget.ProgressBar
import android.widget.RelativeLayout
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy
import com.bumptech.glide.signature.ObjectKey
import com.squareup.picasso.Picasso
import java.net.URLConnection
import java.text.DateFormat
import java.util.Locale
@@ -37,7 +35,6 @@ import ltd.evilcorp.core.vo.isStarted
 
private const val TAG = "ChatAdapter"
private const val IMAGE_TO_SCREEN_RATIO = 0.75
private const val MAX_IMAGE_HEIGHT_PX = 1000
 
private fun FileTransfer.isImage() = try {
URLConnection.guessContentTypeFromName(fileName).startsWith("image/")
@@ -196,13 +193,11 @@ class ChatAdapter(
 
if (fileTransfer.isImage() && (fileTransfer.isComplete() || fileTransfer.outgoing)) {
vh.completedLayout.visibility = View.VISIBLE
Glide.with(vh.imagePreview)
val targetWidth = Resources.getSystem().displayMetrics.widthPixels * IMAGE_TO_SCREEN_RATIO
Picasso.get()
.load(fileTransfer.destination)
// Make sure fts with the same destination have unique caches.
.signature(ObjectKey(fileTransfer.id))
.downsample(DownsampleStrategy.AT_MOST)
.override((Resources.getSystem().displayMetrics.widthPixels * IMAGE_TO_SCREEN_RATIO).roundToInt(), MAX_IMAGE_HEIGHT_PX)
.into(vh.imagePreview)
.resize(targetWidth.roundToInt(), 0)
.onlyScaleDown().into(vh.imagePreview)
} else {
vh.completedLayout.visibility = View.GONE
}
 
atox/src/main/kotlin/ui/chat/ChatViewModel.kt added: 49, removed: 25, total 24
@@ -12,6 +12,7 @@ import android.widget.Toast
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import com.squareup.picasso.Picasso
import java.io.File
import java.io.FileInputStream
import javax.inject.Inject
@@ -128,6 +129,9 @@ class ChatViewModel @Inject constructor(
}
 
fun createFt(file: Uri) = scope.launch {
// Make sure there's no stale cached image in Picasso.
// This happens if the user sends 2 different files with the same path (e.g. by overwriting one with the other.)
Picasso.get().invalidate(file)
fileTransferManager.create(publicKey, file)
}
 
 
gradle/libs.versions.toml added: 49, removed: 25, total 24
@@ -62,8 +62,7 @@ kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-t
nayuki-qrcodegen = "io.nayuki:qrcodegen:1.8.0"
 
square-leakcanary = "com.squareup.leakcanary:leakcanary-android:2.12"
 
bumptech-glide = "com.github.bumptech.glide:glide:4.13.1"
square-picasso = "com.squareup.picasso:picasso:2.8"
 
tox4j-android-aarch64 = { module = "org.toktok:tox4j-c_aarch64-linux-android", version.ref = "tox4j-android" }
tox4j-android-arm = { module = "org.toktok:tox4j-c_armv7a-linux-androideabi", version.ref = "tox4j-android" }