diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 74bf73508..b9e13dffd 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -3,18 +3,14 @@ package com.shayu.phonelive; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; -import android.net.Uri; import android.net.http.HttpResponseCache; -import android.os.Build; import android.os.Bundle; import android.os.Message; import android.text.TextUtils; import android.util.Log; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; import com.adjust.sdk.Adjust; import com.adjust.sdk.AdjustConfig; @@ -31,16 +27,12 @@ import com.tencent.imsdk.v2.V2TIMUserInfo; import com.yunbao.common.BuildConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; -import com.yunbao.common.glide.ImageLoadUtils; -import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.manager.imrongcloud.InstructorSendReward; import com.yunbao.common.manager.imrongcloud.InstructorSendRewardProvider; import com.yunbao.common.manager.imrongcloud.MessageIMManager; import com.yunbao.common.manager.imrongcloud.RecommendLiveRoom; -import com.yunbao.common.utils.FileUtil; -import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.views.RecommendLiveRoomProvider; import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import com.yunbao.common.utils.L; @@ -52,8 +44,6 @@ import com.yunbao.main.activity.MsgSettActivity; import java.io.File; import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; import java.util.ArrayList; import io.rong.imkit.config.RongConfigCenter; @@ -123,7 +113,7 @@ public class AppContext extends CommonAppContext { super.onCreate(); //注册全局异常捕获 //registerError(); - ImageLoadUtils.initImageLoader(this); + // ImageLoadUtils.initImageLoader(this); sInstance = this; L.setDeBug(BuildConfig.DEBUG); AppEventsLogger.activateApp(this); diff --git a/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java b/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java index f04f54a46..c85359a68 100644 --- a/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java +++ b/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java @@ -395,7 +395,7 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setBackgroundColor(0xffffffff); mImageViewList.add(imageView); - ImgLoader.display(mContext, mAdList.get(i).getUrl(), imageView); + ImgLoader.display(mContext, mAdList.get(i).getUrl(), imageView,480,960); } for (int i = imgSize - 1; i >= 0; i--) { mContainer.addView(mImageViewList.get(i)); @@ -553,7 +553,7 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL public void onDataUserInfoEvent(DataUserInfoEvent event) { if (event.isUpDataSuccess()) { //融云连接服务器 - RongcloudIMManager.connectIM(this); + RongcloudIMManager.connectIM(getApplication()); forwardMainActivity(); } else { releaseVideo(); diff --git a/common/build.gradle b/common/build.gradle index 6e39ec1eb..eb03a2177 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -128,8 +128,6 @@ dependencies { //鲁班 api rootProject.ext.dependencies["Luban"] - //图片加载器,可以压缩图 - api rootProject.ext.dependencies["imageloader"] //一个Picker控件,选择日期,城市用 api files('libs/AndroidPicker-1.5.6.jar') diff --git a/common/src/main/java/com/yunbao/common/glide/ImageLoadUtils.java b/common/src/main/java/com/yunbao/common/glide/ImageLoadUtils.java deleted file mode 100644 index 78a07eb6c..000000000 --- a/common/src/main/java/com/yunbao/common/glide/ImageLoadUtils.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.yunbao.common.glide; - -import android.content.Context; -import android.content.res.Configuration; -import android.graphics.Bitmap; -import android.view.View; -import android.widget.ImageView; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.RequestOptions; -import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache; -import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache; -import com.nostra13.universalimageloader.core.DisplayImageOptions; -import com.nostra13.universalimageloader.core.ImageLoader; -import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; -import com.nostra13.universalimageloader.core.assist.ImageSize; -import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; - -import jp.wasabeef.glide.transformations.BlurTransformation; - -public class ImageLoadUtils { - - public static void initImageLoader(Context context) { - ImageLoader imageLoader = ImageLoader.getInstance(); - ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(context) - .diskCache(new UnlimitedDiskCache(context.getCacheDir())) - .diskCacheSize(50 * 1024 * 1024) - .diskCacheFileCount(100) - .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) - .memoryCacheSize(2 * 1024 * 1024) - .build(); - imageLoader.init(configuration); - } - - private static ImageLoader getLoader() { - return ImageLoader.getInstance(); - } - - private static DisplayImageOptions getDisplayImageOptions() { - return new DisplayImageOptions.Builder() - .bitmapConfig(Bitmap.Config.RGB_565) - .build(); - } - - public static void loadUrl(String url, int width, int height, ImageView imageView) { - //ImageSize size = new ImageSize(width, height); - //getLoader().displayImage(url,imageView,size); - - } - public static void loadUrlToBlur(Context context,String url,int width,int height,ImageView imageView){ - getLoader().loadImage(url,new ImageSize(width,height),getDisplayImageOptions(),new SimpleImageLoadingListener(){ - @Override - public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { - super.onLoadingComplete(imageUri, view, loadedImage); - Glide.with(context).asBitmap().load(loadedImage) - .skipMemoryCache(false) - .apply(RequestOptions.bitmapTransform( new BlurTransformation(25))) - .into(imageView); - } - }); - - } - -} diff --git a/common/src/main/java/com/yunbao/common/glide/ImgLoader.java b/common/src/main/java/com/yunbao/common/glide/ImgLoader.java index b18655118..467cd7e0a 100644 --- a/common/src/main/java/com/yunbao/common/glide/ImgLoader.java +++ b/common/src/main/java/com/yunbao/common/glide/ImgLoader.java @@ -2,7 +2,9 @@ package com.yunbao.common.glide; import android.app.Activity; import android.content.Context; +import android.graphics.Bitmap; import android.graphics.drawable.Drawable; +import android.media.ThumbnailUtils; import android.net.Uri; import android.widget.ImageView; @@ -11,6 +13,7 @@ import androidx.annotation.Nullable; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.transition.Transition; import com.yunbao.common.R; @@ -32,36 +35,113 @@ public class ImgLoader { sBlurTransformation = new BlurTransformation(25); } - public static void display(Context context, String url, ImageView imageView) { + display(context, url, imageView, -1, -1); + } + + public static void display(Context context, String url, ImageView imageView, int width, int height) { if (!contextIsExist(context)) { return; } - Glide.with(context).asDrawable().load(url).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView); + Glide.with(context) + .asBitmap() + .load(url) + .skipMemoryCache(SKIP_MEMORY_CACHE) + .into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + if (width == -1 || height == -1) { + imageView.setImageBitmap(resource); + } else { + Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height); + imageView.setImageBitmap(bitmap); + } + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); } public static void display2(Context context, String url, ImageView imageView) { + display2(context, url, imageView, -1, -1); + } + + public static void display2(Context context, String url, ImageView imageView, int width, int height) { if (!contextIsExist(context)) { return; } - Glide.with(context).asDrawable().load(url).placeholder(imageView.getDrawable()).dontAnimate().skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView); + Glide.with(context) + .asBitmap() + .load(url) + .placeholder(imageView.getDrawable()) + .dontAnimate() + .skipMemoryCache(SKIP_MEMORY_CACHE) + .into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + if (width == -1 || height == -1) { + imageView.setImageBitmap(resource); + } else { + Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height); + imageView.setImageBitmap(bitmap); + } + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); } public static void display2(Context context, int url, ImageView imageView) { if (!contextIsExist(context)) { return; } - Glide.with(context).asDrawable().load(url).placeholder(imageView.getDrawable()).dontAnimate().skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView); + Glide.with(context) + .asDrawable() + .load(url) + .placeholder(imageView.getDrawable()) + .dontAnimate() + .skipMemoryCache(SKIP_MEMORY_CACHE) + .into(imageView); } public static void displayWithError(Context context, String url, ImageView imageView, int errorRes) { + displayWithError(context, url, imageView, errorRes, -1, -1); + } + + public static void displayWithError(Context context, String url, ImageView imageView, int errorRes, int width, int height) { if (!contextIsExist(context)) { return; } if (imageView == null) { return; } - Glide.with(context).asDrawable().load(url).error(errorRes).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView); + Glide.with(context) + .asBitmap() + .load(url) + .error(errorRes) + .skipMemoryCache(SKIP_MEMORY_CACHE) + .into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + if (width == -1 || height == -1) { + imageView.setImageBitmap(resource); + } else { + Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height); + imageView.setImageBitmap(bitmap); + } + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); } public static void displayWithError(Context context, int url, ImageView imageView, int errorRes) { @@ -78,8 +158,34 @@ public class ImgLoader { if (!contextIsExist(context)) { return; } - displayWithError(context, url, imageView, R.mipmap.icon_avatar_placeholder); + displayAvatar(context, url, imageView, -1, -1); + } + public static void displayAvatar(Context context, String url, ImageView imageView, int width, int height) { + if (!contextIsExist(context)) { + return; + } + Glide.with(context) + .asBitmap() + .load(url) + .error(R.mipmap.icon_avatar_placeholder) + .skipMemoryCache(SKIP_MEMORY_CACHE) + .into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + if (width == -1 || height == -1) { + imageView.setImageBitmap(resource); + } else { + Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height); + imageView.setImageBitmap(bitmap); + } + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); } public static void displayAvatar(Context context, int url, ImageView imageView) { @@ -94,14 +200,22 @@ public class ImgLoader { if (!contextIsExist(context)) { return; } - Glide.with(context).asDrawable().load(file).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView); + Glide.with(context) + .asDrawable() + .load(file) + .skipMemoryCache(SKIP_MEMORY_CACHE) + .into(imageView); } public static void display(Context context, int res, ImageView imageView) { if (!contextIsExist(context)) { return; } - Glide.with(context).asDrawable().load(res).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView); + Glide.with(context) + .asDrawable() + .load(res) + .skipMemoryCache(SKIP_MEMORY_CACHE) + .into(imageView); } /** @@ -111,7 +225,11 @@ public class ImgLoader { if (!contextIsExist(context)) { return; } - Glide.with(context).asDrawable().load(Uri.fromFile(new File(videoPath))).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView); + Glide.with(context) + .asDrawable() + .load(Uri.fromFile(new File(videoPath))) + .skipMemoryCache(SKIP_MEMORY_CACHE) + .into(imageView); } /** @@ -121,7 +239,11 @@ public class ImgLoader { if (!contextIsExist(context)) { return; } - Glide.with(context).asGif().load(videoPath).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView); + Glide.with(context) + .asGif() + .load(videoPath) + .skipMemoryCache(SKIP_MEMORY_CACHE) + .into(imageView); } public static void displayDrawable(Context context, String url, final DrawableCallback callback) { @@ -158,27 +280,67 @@ public class ImgLoader { * 显示模糊的毛玻璃图片 */ public static void displayBlur(Context context, String url, ImageView imageView) { + displayBlur(context, url, imageView, -1, -1); + } + + public static void displayBlur(Context context, String url, ImageView imageView, int width, int height) { if (!contextIsExist(context)) { return; } - Glide.with(context).asDrawable().load(url) + Glide.with(context) + .asBitmap() + .load(url) .skipMemoryCache(SKIP_MEMORY_CACHE) .apply(RequestOptions.bitmapTransform(sBlurTransformation)) - .into(imageView); + .into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + if (width == -1 || height == -1) { + imageView.setImageBitmap(resource); + } else { + Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height); + imageView.setImageBitmap(bitmap); + } + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); } /** * 显示模糊的毛玻璃图片 */ public static void displayBlurLive(Context context, String url, ImageView imageView) { + displayBlurLive(context, url, imageView, -1, -1); + } + + public static void displayBlurLive(Context context, String url, ImageView imageView, int width, int height) { if (!contextIsExist(context)) { return; } - Glide.with(context).asDrawable().load(url) + Glide.with(context).asBitmap().load(url) .skipMemoryCache(SKIP_MEMORY_CACHE) .apply(RequestOptions.bitmapTransform(new BlurTransformation(100))) .placeholder(R.mipmap.live_bg) - .into(imageView); + .into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + if (width == -1 || height == -1) { + imageView.setImageBitmap(resource); + } else { + Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height); + imageView.setImageBitmap(bitmap); + } + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); } private static boolean contextIsExist(Context context) { diff --git a/common/src/main/java/com/yunbao/common/views/CustomViewHolder.java b/common/src/main/java/com/yunbao/common/views/CustomViewHolder.java index 3e650f583..b52810567 100644 --- a/common/src/main/java/com/yunbao/common/views/CustomViewHolder.java +++ b/common/src/main/java/com/yunbao/common/views/CustomViewHolder.java @@ -8,6 +8,7 @@ import android.widget.ImageView; import com.bumptech.glide.Glide; import com.ms.banner.holder.BannerViewHolder; import com.yunbao.common.bean.BannerBean; +import com.yunbao.common.glide.ImgLoader; public class CustomViewHolder implements BannerViewHolder { @@ -20,7 +21,8 @@ public class CustomViewHolder implements BannerViewHolder { ); imageView.setLayoutParams(params); imageView.setScaleType(ImageView.ScaleType.FIT_XY); - Glide.with(context).load(data.getImageUrl()).into(imageView); + //Glide.with(context).load(data.getImageUrl()).into(imageView); + ImgLoader.display(context,data.getImageUrl(),imageView,600,170); return imageView; } diff --git a/dependencies.gradle b/dependencies.gradle index e1345a60d..2e349e7f2 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -31,7 +31,6 @@ ext { "arouter-compiler" : 'com.alibaba:arouter-compiler:1.2.2', "blank-utilcode" : 'com.blankj:utilcode:1.25.9', "leakcanary" : 'com.squareup.leakcanary:leakcanary-android:2.9.1', - "imageloader" : 'com.nostra13.universalimageloader:universal-image-loader:1.9.5', ] diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveUserAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveUserAdapter.java index 0520cebbb..bcb21a671 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveUserAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveUserAdapter.java @@ -3,30 +3,22 @@ package com.yunbao.live.adapter; import static android.text.TextUtils.isEmpty; import android.content.Context; -import android.graphics.Bitmap; import android.graphics.drawable.Drawable; -import android.media.ThumbnailUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.target.CustomTarget; -import com.bumptech.glide.request.transition.Transition; -import com.opensource.svgaplayer.SVGACallback; import com.opensource.svgaplayer.SVGADrawable; import com.opensource.svgaplayer.SVGAImageView; import com.opensource.svgaplayer.SVGAParser; import com.opensource.svgaplayer.SVGAVideoEntity; import com.yunbao.common.Constants; import com.yunbao.common.bean.UserBean; -import com.yunbao.common.glide.ImageLoadUtils; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.SVGAViewUtils; @@ -121,8 +113,8 @@ public class LiveUserAdapter extends RecyclerView.Adapter { itemView.setTag(position); if (payload == null) { - // ImgLoader.displayAvatar(mContext, userBean.getAvatar(), mAvatar); - ImageLoadUtils.loadUrl(userBean.getAvatar(),32,32,mAvatar); + ImgLoader.displayAvatar(mContext, userBean.getAvatar(), mAvatar,16,16); + // ImageLoadUtils.loadUrl(userBean.getAvatar(),32,32,mAvatar); } if (userBean.getDress() != null) { diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 89c848c3b..7ae7ff109 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -34,7 +34,6 @@ import com.yunbao.common.Constants; import com.yunbao.common.bean.UserBean; import com.yunbao.common.custom.MyViewPager; import com.yunbao.common.event.FollowEvent; -import com.yunbao.common.glide.ImageLoadUtils; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.CommonHttpConsts; import com.yunbao.common.http.CommonHttpUtil; @@ -240,8 +239,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); //直播间背景 - //ImgLoader.displayBlurLive(mContext, mLiveBean.getAvatar(), liveBack); - ImageLoadUtils.loadUrlToBlur(mContext,mLiveBean.getAvatar(),400,600,liveBack); + ImgLoader.displayBlurLive(mContext, mLiveBean.getAvatar(), liveBack,400,600); + //ImageLoadUtils.loadUrlToBlur(mContext,mLiveBean.getAvatar(),400,600,liveBack); mask.setVisibility(View.VISIBLE); mLivePlayViewHolder.setCover(data.getThumb()); mLivePlayViewHolder.play(data.getPull()); diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveItemViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveItemViewHolder.java index 0af5096e6..504061e82 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveItemViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveItemViewHolder.java @@ -72,7 +72,7 @@ public class MainHomeLiveItemViewHolder extends RecyclerView.ViewHolder { .load(bean.getContent_pic_size_three()) .into(liveType); } - ImgLoader.display(itemView.getContext(), bean.getThumb(), mCover); + ImgLoader.display(itemView.getContext(), bean.getThumb(), mCover,300,300); bgs.setVisibility(View.VISIBLE); pkico.setVisibility(View.GONE); pkAvatar.setVisibility(View.GONE);