Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/hss/onlyglide' into hss/onlyglide
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed May 14, 2024
2 parents c3afaef + c872c6a commit aa23b45
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public static File compressOriginalToJpg(String filePath, int quality) {
//todo renameTo - 垃圾api,只能同扩展名处理. 自动删除file2,变成file1.
/* boolean renameTo = file2.renameTo(file);
if(!renameTo){*/
LogUtils.w("不同jpg扩展名时,不能renameTo,使用fileCopy: " + file2);
LogUtils.i("不同jpg扩展名时,不能renameTo,使用fileCopy: " + file2);
try {
//todo 文件覆盖也会被miui警告,去tmd-->因为内部调用了file.delete()
/* boolean copy = FileUtils.copy(file2, file, new FileUtils.OnReplaceListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
Expand Down Expand Up @@ -34,11 +37,25 @@ public DownloadViewHolder(View view) {
try {
binding = ItemDownloadUiBinding.bind(itemView);
EventBus.getDefault().register(this);
LifecycleOwner lifecycleOwnerFromObj = LifecycleObjectUtil2.getLifecycleOwnerFromObj(view.getContext());
if(lifecycleOwnerFromObj !=null){
lifecycleOwnerFromObj.getLifecycle().addObserver(new DefaultLifecycleObserver() {
@Override
public void onDestroy(@NonNull LifecycleOwner owner) {
//DefaultLifecycleObserver.super.onDestroy(owner);
EventBus.getDefault().unregister(DownloadViewHolder.this);
LogUtils.w("EventBus.getDefault().unregister : "+DownloadViewHolder.this);
}
});
}else {
LogUtils.w("getLifecycleOwnerFromObj is null : "+view.getContext());
}
}catch (Throwable throwable){
throwable.printStackTrace();
}
}

//内存泄漏
public void onViewRecycled() {
try {
// EventBus.getDefault().unregister(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.hss.downloader.download;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;

import androidx.fragment.app.Fragment;
import androidx.lifecycle.LifecycleOwner;

/**
* @Despciption todo
* @Author hss
* @Date 11/08/2022 10:04
* @Version 1.0
*/
class LifecycleObjectUtil2 {

public static LifecycleOwner getLifecycleOwnerFromObj(Object contextOrFragment){
if(contextOrFragment instanceof LifecycleOwner){
LifecycleOwner owner = (LifecycleOwner) contextOrFragment;
return owner;
}
if(contextOrFragment instanceof Context){
Activity activity = getActivityFromContext((Context) contextOrFragment);
if(activity instanceof LifecycleOwner){
return (LifecycleOwner)activity;
}
return null;
}
return null;
}
public static Object getLifecycledObjectFromObj(Object contextOrFragment){
if(contextOrFragment instanceof LifecycleOwner){
LifecycleOwner owner = (LifecycleOwner) contextOrFragment;
return owner;
}
if(contextOrFragment instanceof Context){
Activity activity = getActivityFromContext((Context) contextOrFragment);
return activity;
}
if(contextOrFragment instanceof Fragment){
return contextOrFragment;
}
if(contextOrFragment instanceof android.app.Fragment){
return contextOrFragment;
}
return null;
}



public static Activity getActivityFromContext(Context context) {
if (context == null) {
return null;
}
if (context instanceof Activity) {
return (Activity) context;
}
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
return (Activity) context;
}
context = ((ContextWrapper) context).getBaseContext();
}
return null;
}
}
4 changes: 2 additions & 2 deletions webviewspider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ dependencies {
api 'org.jsoup:jsoup:1.11.2'
api 'com.blankj:utilcodex:1.30.6'
api project(':imagelist')
api 'com.github.hss01248.utilcodeEnhance:baseWebview:1.4.3'
api 'com.github.hss01248.utilcodeEnhance:iwidget:1.4.3'
api 'com.github.hss01248.utilcodeEnhance:baseWebview:1.4.5'
api 'com.github.hss01248.utilcodeEnhance:iwidget:1.4.5'
//api project(':baseWebview')


Expand Down

0 comments on commit aa23b45

Please sign in to comment.