Commit b818b158 by 王佳洋

悬浮窗内存泄漏尝试修复

parent 19f73ce3
......@@ -109,9 +109,9 @@ class PlayerFloatHelper {
}
fun removeView(context: Context) {
if (TextUtils.isEmpty(showingPageName) || showingPageName != context::class.qualifiedName) {
return
}
// if (TextUtils.isEmpty(showingPageName) || showingPageName != context::class.qualifiedName) {
// return
// }
mPlayerFloatView?.visibility = View.GONE
wm?.removeViewImmediate(mPlayerFloatView)
showingPageName = ""
......
package com.ydl.media.view
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.text.TextUtils
import android.view.MotionEvent
......@@ -20,22 +21,22 @@ import java.util.concurrent.CopyOnWriteArraySet
import kotlin.math.abs
class PlayerFloatView(private val ctx: Context) : FrameLayout(ctx) {
class PlayerFloatView(ctx: Context) : FrameLayout(ctx.applicationContext) {
private var mTouchDownX: Float = 0.toFloat()
private var mTouchDownY: Float = 0.toFloat()
private var mTouchX: Float = 0.toFloat()
private var mTouchY: Float = 0.toFloat()
private val mTouchSlop: Int = (ViewConfiguration.get(ctx).scaledTouchSlop + 8) * 3
private val mTouchSlop: Int = (ViewConfiguration.get(context).scaledTouchSlop + 8) * 3
private val mWindowManager: WindowManager = ctx.getSystemService(Context.WINDOW_SERVICE) as WindowManager
private val mWindowManager: WindowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
//全局变量,用以保存悬浮窗口的属性
var mFloatViewParams = WindowManager.LayoutParams()
private var mListeners: CopyOnWriteArraySet<FloatViewPlayListener> = CopyOnWriteArraySet()
private var mStateChangeListener: OnPlayerEventListener? = null
private val mStatusBarHeight: Int = StatusBarUtil.getStatusBarHeight(ctx)
private val mStatusBarHeight: Int = StatusBarUtil.getStatusBarHeight(context)
fun resetLayoutParams() {
......@@ -46,7 +47,7 @@ class PlayerFloatView(private val ctx: Context) : FrameLayout(ctx) {
View.inflate(context, R.layout.item_playing_float_btn, this)
resetFloatView()
if (!TextUtils.isEmpty(AudioPlayer.get().playMusic?.coverPath)) {
GlideApp.with(context.applicationContext)
GlideApp.with(context)
.load(AudioPlayer.get().playMusic?.coverPath)
.transform(GlideRoundTransform(context, 4))
.error(R.drawable.ico_play_float_pic)
......@@ -61,7 +62,7 @@ class PlayerFloatView(private val ctx: Context) : FrameLayout(ctx) {
mListeners.forEach {
it.onPauseClick()
}
PlayerFloatHelper.removeView(ctx)
PlayerFloatHelper.removeView(context)
PlayerFloatHelper.playTempData.clear()
AudioPlayer.get().resetPlayer()
}
......@@ -135,7 +136,7 @@ class PlayerFloatView(private val ctx: Context) : FrameLayout(ctx) {
@SuppressLint("SetTextI18n")
fun resetFloatView() {
if (!TextUtils.isEmpty(AudioPlayer.get().playMusic?.coverPath)) {
GlideApp.with(context.applicationContext)
GlideApp.with(context)
.load(AudioPlayer.get().playMusic?.coverPath)
.transform(GlideRoundTransform(context, 4))
.error(R.drawable.ico_play_float_pic)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment