Activity内存泄漏处理
首页无法展示背景
This commit is contained in:
@@ -82,7 +82,7 @@ object FullVideoUtils {
|
||||
}
|
||||
try {
|
||||
if (windowManager != null) {
|
||||
windowManager!!.removeView(lastOverlayView)
|
||||
windowManager!!.removeViewImmediate(lastOverlayView)
|
||||
windowManager = null
|
||||
}
|
||||
if (lastOverlayView != null) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.bumptech.glide.request.RequestOptions;
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils;
|
||||
import com.mogo.och.taxi.passenger.R;
|
||||
import com.mogo.och.taxi.passenger.bean.TaxiPassengerVideoPlay;
|
||||
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -23,6 +24,7 @@ public class RecyclerVideoAdapter extends RecyclerView.Adapter<RecyclerItemVideo
|
||||
private List<TaxiPassengerVideoPlay> itemDataList = null;
|
||||
private Context context = null;
|
||||
private OnThumbImageClilckListener onThumbImageClilckListener;
|
||||
private RecyclerView recyclerView;
|
||||
|
||||
public OnThumbImageClilckListener getOnThumbImageClilckListener() {
|
||||
return onThumbImageClilckListener;
|
||||
@@ -32,9 +34,10 @@ public class RecyclerVideoAdapter extends RecyclerView.Adapter<RecyclerItemVideo
|
||||
this.onThumbImageClilckListener = onThumbImageClilckListener;
|
||||
}
|
||||
|
||||
public RecyclerVideoAdapter(Context context, List<TaxiPassengerVideoPlay> itemDataList) {
|
||||
public RecyclerVideoAdapter(Context context, List<TaxiPassengerVideoPlay> itemDataList,RecyclerView recyclerView) {
|
||||
this.itemDataList = itemDataList;
|
||||
this.context = context;
|
||||
this.recyclerView = recyclerView;
|
||||
}
|
||||
|
||||
public TaxiPassengerVideoPlay getItemByPosition(int position){
|
||||
@@ -53,6 +56,8 @@ public class RecyclerVideoAdapter extends RecyclerView.Adapter<RecyclerItemVideo
|
||||
return recyclerItemVideoHolder;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final RecyclerItemVideoHolder holder, int position) {
|
||||
final TaxiPassengerVideoPlay taxiPassengerVideoPlay = itemDataList.get(position);
|
||||
@@ -77,6 +82,33 @@ public class RecyclerVideoAdapter extends RecyclerView.Adapter<RecyclerItemVideo
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.gsyVideoPlayer.setVideoAllCallBack(new GSYSampleCallBack(){
|
||||
@Override
|
||||
public void onAutoComplete(String url, Object... objects) {
|
||||
holder.gsyVideoPlayer.onVideoReset();
|
||||
if(holder.getAbsoluteAdapterPosition()==getItemCount()-1){
|
||||
recyclerView.smoothScrollToPosition(0);
|
||||
}else {
|
||||
recyclerView.smoothScrollToPosition(holder.getAbsoluteAdapterPosition()+1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickBlank(String url, Object... objects) {
|
||||
super.onClickBlank(url, objects);
|
||||
recyclerView.smoothScrollToPosition(holder.getAbsoluteAdapterPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayError(String url, Object... objects) {
|
||||
ToastUtils.showLong("哎呀,出错了,看看其他视频吧");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickStartError(String url, Object... objects) {
|
||||
ToastUtils.showLong("哎呀,出错了,看看其他视频吧");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.mogo.och.taxi.passenger.ui.leftmenu.OverlayLeftViewUtils
|
||||
import com.mogo.och.taxi.passenger.ui.video.layoutmanage.CarouselLayoutManager
|
||||
import com.mogo.och.taxi.passenger.ui.video.layoutmanage.CarouselZoomPostLayoutListener
|
||||
import com.mogo.och.taxi.passenger.ui.video.layoutmanage.CenterScrollListener
|
||||
import com.mogo.och.taxi.passenger.utils.FixMemoryLeak
|
||||
import com.mogo.och.taxi.passenger.utils.blur.GlideBlurTransform
|
||||
import com.mogo.och.taxi.passenger.widget.ConsultVideoPlayer
|
||||
import com.mogo.och.taxi.passenger.widget.indicator.IndicatorView
|
||||
@@ -165,7 +166,6 @@ class VideoActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun initData() {
|
||||
val recyclerVideoAdapter = RecyclerVideoAdapter(this, arrayListOf)
|
||||
val carouselLayoutManager = CarouselLayoutManager(CarouselLayoutManager.HORIZONTAL, true)
|
||||
carouselLayoutManager.setPostLayoutListener(CarouselZoomPostLayoutListener())
|
||||
carouselLayoutManager.maxVisibleItems = 1
|
||||
@@ -197,7 +197,7 @@ class VideoActivity : AppCompatActivity() {
|
||||
playerHolder?.findViewById<ConsultVideoPlayer>(R.id.video_item_player)
|
||||
prePlayer?.onVideoReset()
|
||||
val taxiPassengerVideoPlay = arrayListOf[centerItemPosition]
|
||||
setBackageAndPlayNext(taxiPassengerVideoPlay, player, centerItemPosition)
|
||||
setBackageAndPlayNext(taxiPassengerVideoPlay)
|
||||
} else {
|
||||
player.onVideoResume(false)
|
||||
}
|
||||
@@ -225,6 +225,7 @@ class VideoActivity : AppCompatActivity() {
|
||||
}
|
||||
indicatorView.onPageScrolled(currentIndex, fl, 0)
|
||||
}
|
||||
val recyclerVideoAdapter = RecyclerVideoAdapter(this, arrayListOf,rvVideoPlaylist)
|
||||
recyclerVideoAdapter.setOnThumbImageClilckListener {
|
||||
val (_: Int, player) = getPlayer(carouselLayoutManager)
|
||||
if (player is ConsultVideoPlayer) {
|
||||
@@ -259,11 +260,7 @@ class VideoActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
|
||||
private fun setBackageAndPlayNext(
|
||||
taxiPassengerVideoPlay: TaxiPassengerVideoPlay,
|
||||
player: ConsultVideoPlayer,
|
||||
centerItemPosition: Int,
|
||||
) {
|
||||
private fun setBackageAndPlayNext(taxiPassengerVideoPlay: TaxiPassengerVideoPlay) {
|
||||
// 设置背景图片
|
||||
Glide.with(this).asBitmap()
|
||||
.load(taxiPassengerVideoPlay.imageUrl)
|
||||
@@ -280,36 +277,6 @@ class VideoActivity : AppCompatActivity() {
|
||||
clContain.background = BitmapDrawable(resources, resource)
|
||||
}
|
||||
})
|
||||
if (player.getVideoAllCallBack() == null) {
|
||||
player.setVideoAllCallBack(object : GSYSampleCallBack() {
|
||||
override fun onAutoComplete(url: String?, vararg objects: Any?) {
|
||||
player.onVideoReset()
|
||||
val itemCount = rvVideoPlaylist?.adapter?.itemCount
|
||||
itemCount?.let {
|
||||
if (centerItemPosition == itemCount - 1) {
|
||||
rvVideoPlaylist?.smoothScrollToPosition(0)
|
||||
} else {
|
||||
rvVideoPlaylist?.smoothScrollToPosition(centerItemPosition + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClickBlank(url: String?, vararg objects: Any?) {
|
||||
super.onClickBlank(url, *objects)
|
||||
rvVideoPlaylist?.smoothScrollToPosition(centerItemPosition)
|
||||
}
|
||||
|
||||
override fun onPlayError(url: String?, vararg objects: Any?) {
|
||||
super.onPlayError(url, *objects)
|
||||
ToastUtils.showLong("哎呀,出错了,看看其他视频吧")
|
||||
}
|
||||
|
||||
override fun onClickStartError(url: String?, vararg objects: Any?) {
|
||||
super.onClickStartError(url, *objects)
|
||||
ToastUtils.showLong("哎呀,出错了,看看其他视频吧")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
@@ -322,13 +289,15 @@ class VideoActivity : AppCompatActivity() {
|
||||
OverlayLeftViewUtils.showOverlayView(this,isOpen = false, checkIndex = OverlayLeftViewUtils.MOVIE)
|
||||
}
|
||||
}
|
||||
OverlayLeftViewUtils.addDragTarget(vOpenLeft)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val carouselLayoutManager = rvVideoPlaylist?.layoutManager as CarouselLayoutManager
|
||||
val (centerItemPosition: Int, player) = getPlayer(carouselLayoutManager)
|
||||
if(centerItemPosition<0){
|
||||
setBackageAndPlayNext(arrayListOf[0])
|
||||
}
|
||||
player?.let {
|
||||
if (player.isIfCurrentIsFullscreen) {// 全屏了
|
||||
|
||||
@@ -340,13 +309,7 @@ class VideoActivity : AppCompatActivity() {
|
||||
GSYVideoView.CURRENT_STATE_PLAYING -> {
|
||||
}
|
||||
else -> {
|
||||
val recyclerVideoAdapter =
|
||||
rvVideoPlaylist?.adapter as RecyclerVideoAdapter
|
||||
setBackageAndPlayNext(
|
||||
recyclerVideoAdapter.getItemByPosition(centerItemPosition),
|
||||
player, centerItemPosition
|
||||
)
|
||||
//player.startPlayLogic()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -375,6 +338,7 @@ class VideoActivity : AppCompatActivity() {
|
||||
super.onDestroy()
|
||||
releaseOnNewInstance()
|
||||
OverlayLeftViewUtils.dismissOverlayView()
|
||||
FixMemoryLeak.fixLeak(this)
|
||||
}
|
||||
|
||||
private fun releaseOnNewInstance() {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.mogo.och.taxi.passenger.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* memory leak fix:
|
||||
* <p>
|
||||
* InputMethodManager#mLastSrvView reference Last Page Activity.
|
||||
*/
|
||||
public class FixMemoryLeak {
|
||||
|
||||
private static Field field;
|
||||
private static boolean hasField = true;
|
||||
|
||||
public static void fixLeak(Context context) {
|
||||
if (!hasField) {
|
||||
return;
|
||||
}
|
||||
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (imm == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (field == null) {
|
||||
field = imm.getClass().getDeclaredField("mCurRootView");
|
||||
}
|
||||
if (field == null) {
|
||||
hasField = false;
|
||||
}
|
||||
if (field != null) {
|
||||
field.setAccessible(true);
|
||||
field.set(imm, null);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
hasField = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user