Merge branch 'tzugen-leaks' into develop

This commit is contained in:
Óscar García Amor 2021-06-29 11:27:31 +02:00
commit 2a6c9baa3d
No known key found for this signature in database
GPG Key ID: E18B2370D3D566EE
6 changed files with 21 additions and 22 deletions

View File

@ -45,6 +45,7 @@ complexity:
thresholdInFiles: 20 thresholdInFiles: 20
thresholdInClasses: 20 thresholdInClasses: 20
thresholdInInterfaces: 20 thresholdInInterfaces: 20
thresholdInObjects: 30
LabeledExpression: LabeledExpression:
active: false active: false

View File

@ -451,13 +451,6 @@
column="9"/> column="9"/>
</issue> </issue>
<issue
id="ObsoleteSdkInt"
message="This folder configuration (`v14`) is unnecessary; `minSdkVersion` is 14. Merge all the resources in this folder into `drawable-xhdpi`.">
<location
file="src/main/res/drawable-xhdpi-v14"/>
</issue>
<issue <issue
id="StaticFieldLeak" id="StaticFieldLeak"
message="This `AsyncTask` class should be static or leaks might occur (org.moire.ultrasonic.service.DownloadQueueSerializer.SerializeTask)" message="This `AsyncTask` class should be static or leaks might occur (org.moire.ultrasonic.service.DownloadQueueSerializer.SerializeTask)"
@ -480,17 +473,6 @@
column="19"/> column="19"/>
</issue> </issue>
<issue
id="StaticFieldLeak"
message="Do not place Android context classes in static fields; this is a memory leak"
errorLine1=" private static Context context;"
errorLine2=" ~~~~~~">
<location
file="src/main/java/org/moire/ultrasonic/view/UpdateView.java"
line="29"
column="10"/>
</issue>
<issue <issue
id="UseCompoundDrawables" id="UseCompoundDrawables"
message="This tag and its children can be replaced by one `&lt;TextView/>` and a compound drawable" message="This tag and its children can be replaced by one `&lt;TextView/>` and a compound drawable"

View File

@ -3,7 +3,6 @@ package org.moire.ultrasonic.view;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import timber.log.Timber;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AbsListView; import android.widget.AbsListView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -14,6 +13,8 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import timber.log.Timber;
/** /**
* A View that is periodically refreshed * A View that is periodically refreshed
* @deprecated * @deprecated
@ -26,12 +27,10 @@ public class UpdateView extends LinearLayout
private static Handler backgroundHandler; private static Handler backgroundHandler;
private static Handler uiHandler; private static Handler uiHandler;
private static Runnable updateRunnable; private static Runnable updateRunnable;
private static Context context;
public UpdateView(Context context) public UpdateView(Context context)
{ {
super(context); super(context);
UpdateView.context = context;
setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
INSTANCES.put(this, null); INSTANCES.put(this, null);

View File

@ -1,9 +1,13 @@
package org.moire.ultrasonic.imageloader package org.moire.ultrasonic.imageloader
import android.app.ActivityManager
import android.content.Context import android.content.Context
import android.content.pm.ApplicationInfo
import android.text.TextUtils import android.text.TextUtils
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import androidx.core.content.ContextCompat
import com.squareup.picasso.LruCache
import com.squareup.picasso.Picasso import com.squareup.picasso.Picasso
import com.squareup.picasso.RequestCreator import com.squareup.picasso.RequestCreator
import java.io.File import java.io.File
@ -35,6 +39,7 @@ class ImageLoader(
private val picasso = Picasso.Builder(context) private val picasso = Picasso.Builder(context)
.addRequestHandler(CoverArtRequestHandler(apiClient)) .addRequestHandler(CoverArtRequestHandler(apiClient))
.addRequestHandler(AvatarRequestHandler(apiClient)) .addRequestHandler(AvatarRequestHandler(apiClient))
.memoryCache(LruCache(calculateMemoryCacheSize(context)))
.build().apply { .build().apply {
setIndicatorsEnabled(BuildConfig.DEBUG) setIndicatorsEnabled(BuildConfig.DEBUG)
} }
@ -179,6 +184,18 @@ class ImageLoader(
return requested 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()
}
} }
/** /**

View File

@ -708,7 +708,7 @@ open class RESTMusicService(
// By registering a callback we ensure this info is saved in the database as well // By registering a callback we ensure this info is saved in the database as well
subsonicAPIClient.onProtocolChange = { subsonicAPIClient.onProtocolChange = {
Timber.i("Server minimum API version set to %s", it) Timber.i("Server minimum API version set to %s", it)
activeServerProvider.setMinimumApiVersion(it.toString()) activeServerProvider.setMinimumApiVersion(it.restApiVersion)
} }
} }