From d4c0f62b1d6cf9aba3434f5741b19ebff2cfe31c Mon Sep 17 00:00:00 2001 From: tzugen Date: Mon, 21 Jun 2021 19:11:30 +0200 Subject: [PATCH 1/4] Don't keep a reference to context here, it's a leak and not used anyway. --- .../src/main/java/org/moire/ultrasonic/view/UpdateView.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/view/UpdateView.java b/ultrasonic/src/main/java/org/moire/ultrasonic/view/UpdateView.java index d264994d..cbea03bb 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/view/UpdateView.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/view/UpdateView.java @@ -3,7 +3,6 @@ package org.moire.ultrasonic.view; import android.content.Context; import android.os.Handler; import android.os.Looper; -import timber.log.Timber; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.LinearLayout; @@ -14,6 +13,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.WeakHashMap; +import timber.log.Timber; + /** * A View that is periodically refreshed * @deprecated @@ -26,12 +27,10 @@ public class UpdateView extends LinearLayout private static Handler backgroundHandler; private static Handler uiHandler; private static Runnable updateRunnable; - private static Context context; public UpdateView(Context context) { super(context); - UpdateView.context = context; setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); INSTANCES.put(this, null); From d916e937f9a62560d42b4327c6034eb2c62a2d71 Mon Sep 17 00:00:00 2001 From: tzugen Date: Mon, 21 Jun 2021 19:12:11 +0200 Subject: [PATCH 2/4] Move a resource from a versioned folder (v14 is the default now) --- ultrasonic/lint-baseline.xml | 18 ------------------ .../appwidget_dark_bg_trans.9.png | Bin 2 files changed, 18 deletions(-) rename ultrasonic/src/main/res/{drawable-xhdpi-v14 => drawable-hdpi}/appwidget_dark_bg_trans.9.png (100%) diff --git a/ultrasonic/lint-baseline.xml b/ultrasonic/lint-baseline.xml index 037c3e49..e9795cea 100644 --- a/ultrasonic/lint-baseline.xml +++ b/ultrasonic/lint-baseline.xml @@ -451,13 +451,6 @@ column="9"/> - - - - - - - - Date: Wed, 23 Jun 2021 17:30:16 +0200 Subject: [PATCH 3/4] Increase memory cache size --- detekt-config.yml | 1 + .../moire/ultrasonic/imageloader/ImageLoader.kt | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/detekt-config.yml b/detekt-config.yml index 7fff31c3..eb76d7f7 100644 --- a/detekt-config.yml +++ b/detekt-config.yml @@ -45,6 +45,7 @@ complexity: thresholdInFiles: 20 thresholdInClasses: 20 thresholdInInterfaces: 20 + thresholdInObjects: 30 LabeledExpression: active: false diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/ImageLoader.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/ImageLoader.kt index 9d40ad28..73862c20 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/ImageLoader.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/ImageLoader.kt @@ -1,9 +1,13 @@ package org.moire.ultrasonic.imageloader +import android.app.ActivityManager import android.content.Context +import android.content.pm.ApplicationInfo import android.text.TextUtils import android.view.View import android.widget.ImageView +import androidx.core.content.ContextCompat +import com.squareup.picasso.LruCache import com.squareup.picasso.Picasso import com.squareup.picasso.RequestCreator import java.io.File @@ -35,6 +39,7 @@ class ImageLoader( private val picasso = Picasso.Builder(context) .addRequestHandler(CoverArtRequestHandler(apiClient)) .addRequestHandler(AvatarRequestHandler(apiClient)) + .memoryCache(LruCache(calculateMemoryCacheSize(context))) .build().apply { setIndicatorsEnabled(BuildConfig.DEBUG) } @@ -179,6 +184,18 @@ class ImageLoader( return requested } } + + private fun calculateMemoryCacheSize(context: Context): Int { + val am = ContextCompat.getSystemService( + context, + ActivityManager::class.java + ) + val largeHeap = context.applicationInfo.flags and ApplicationInfo.FLAG_LARGE_HEAP != 0 + val memoryClass = if (largeHeap) am!!.largeMemoryClass else am!!.memoryClass + // Target 25% of the available heap. + @Suppress("MagicNumber") + return (1024L * 1024L * memoryClass / 4).toInt() + } } /** From e3e8d36f5c099afec32ac950b67b838ccf959888 Mon Sep 17 00:00:00 2001 From: tzugen Date: Fri, 25 Jun 2021 17:47:11 +0200 Subject: [PATCH 4/4] Save the correct field to the server preferences --- .../kotlin/org/moire/ultrasonic/service/RESTMusicService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt index 6e0e44e1..0d6730d8 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt @@ -708,7 +708,7 @@ open class RESTMusicService( // By registering a callback we ensure this info is saved in the database as well subsonicAPIClient.onProtocolChange = { Timber.i("Server minimum API version set to %s", it) - activeServerProvider.setMinimumApiVersion(it.toString()) + activeServerProvider.setMinimumApiVersion(it.restApiVersion) } }