根据文档修改新礼物UI
移除主界面预下载所有礼物svga入口 获取直播间状态后开始下载所有礼物svga GiftCacheUtil改为单例并支持顺序下载所有礼物及插队下载 预处理新人特惠红点显示/隐藏接口 获取svga播放时间统一由SVGAViewUtils处理
This commit is contained in:
@@ -291,6 +291,7 @@ public class IMLoginManager extends BaseCacheManager {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
if (code == 0 && info.length > 0) {
|
||||
SpUtil.setStringValue("userData",info[0]);
|
||||
userInfo = new Gson().fromJson(info[0], IMLoginModel.class);
|
||||
if (!TextUtils.isEmpty(uidAndToken[1])) {
|
||||
userInfo.setToken(uidAndToken[1]);
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.http.CommonHttpConsts;
|
||||
import com.yunbao.common.interfaces.CommonCallback;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/10/17.
|
||||
*/
|
||||
|
||||
public class GifCacheUtil {
|
||||
|
||||
public static void getFile(String fileName, String url,String forwhat, final CommonCallback<File> commonCallback) {
|
||||
if (commonCallback == null) {
|
||||
return;
|
||||
}
|
||||
File dir = new File(CommonAppConfig.GIF_PATH);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
File file1 = new File(dir, fileName+".svga");
|
||||
if (file1.exists()) {
|
||||
commonCallback.callback(file1);
|
||||
} else {
|
||||
DownloadUtil downloadUtil = new DownloadUtil();
|
||||
if(forwhat.equals("1")){
|
||||
ToastUtil.show("礼物正在获取中...");
|
||||
}
|
||||
downloadUtil.download(CommonHttpConsts.DOWNLOAD_GIF, dir, fileName, url, new DownloadUtil.Callback() {
|
||||
@Override
|
||||
public void onSuccess(File file) {
|
||||
commonCallback.callback(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(int progress) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
commonCallback.callback(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
285
common/src/main/java/com/yunbao/common/utils/GiftCacheUtil.java
Normal file
285
common/src/main/java/com/yunbao/common/utils/GiftCacheUtil.java
Normal file
@@ -0,0 +1,285 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.Constants;
|
||||
import com.yunbao.common.bean.LiveGiftBean;
|
||||
import com.yunbao.common.http.CommonHttpConsts;
|
||||
import com.yunbao.common.interfaces.CommonCallback;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* svga礼物缓存工具
|
||||
* Created by cxf on 2018/10/17.
|
||||
*/
|
||||
|
||||
public class GiftCacheUtil {
|
||||
private static GiftCacheUtil manager;
|
||||
private LinkedHashMap<Integer, LiveGiftBean> downloadCache = new LinkedHashMap<>();
|
||||
private CommonCallback<File> commonCallback;
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
private boolean pause = false;
|
||||
private boolean downloading = false;
|
||||
private int clickId = 0;
|
||||
|
||||
private GiftCacheUtil() {
|
||||
}
|
||||
|
||||
public static GiftCacheUtil getInstance() {
|
||||
if (manager == null) {
|
||||
manager = new GiftCacheUtil();
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单独下载
|
||||
*/
|
||||
public static void getFile(String fileName, String url, String forwhat, final CommonCallback<File> commonCallback) {
|
||||
if (commonCallback == null) {
|
||||
return;
|
||||
}
|
||||
File dir = new File(CommonAppConfig.GIF_PATH);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
File file1 = new File(dir, fileName + ".svga");
|
||||
if (file1.exists()) {
|
||||
commonCallback.callback(file1);
|
||||
} else {
|
||||
DownloadUtil downloadUtil = new DownloadUtil();
|
||||
if (forwhat.equals("1")) {
|
||||
ToastUtil.show("礼物正在获取中...");
|
||||
}
|
||||
downloadUtil.download(CommonHttpConsts.DOWNLOAD_GIF, dir, fileName, url, new DownloadUtil.Callback() {
|
||||
@Override
|
||||
public void onSuccess(File file) {
|
||||
commonCallback.callback(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(int progress) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
commonCallback.callback(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取保存的文件名
|
||||
*/
|
||||
public static String getDownloadSaveName(int id) {
|
||||
return Constants.GIF_GIFT_PREFIX + id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测礼物是否已经下载完毕
|
||||
*/
|
||||
public static boolean checkGiftIsDownload(int id) {
|
||||
return new File(CommonAppConfig.GIF_PATH, getDownloadSaveName(id) + ".svga").exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件名返回id
|
||||
*/
|
||||
public static int getIdForFileName(String name) {
|
||||
return Integer.parseInt(name
|
||||
.replace(Constants.GIF_GIFT_PREFIX, "")
|
||||
.replace(".svga", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下载列表
|
||||
*/
|
||||
public void setDownloadList(List<LiveGiftBean> list) {
|
||||
for (LiveGiftBean bean : list) {
|
||||
downloadCache.put(bean.getId(), bean);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置监听回调
|
||||
*/
|
||||
public void setCallback(CommonCallback<File> commonCallback) {
|
||||
this.commonCallback = commonCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插队优先下载指定id礼物
|
||||
*/
|
||||
public void downloadGiftForId(LiveGiftBean bean, CommonCallback<File> mDownloadGifCallback) {
|
||||
if(checkGiftIsDownload(bean.getId())){
|
||||
mDownloadGifCallback.callback(null);
|
||||
return;
|
||||
}
|
||||
this.clickId = bean.getId();
|
||||
getFile(getDownloadSaveName(bean.getId()), bean.getSwf(), "0", new CommonCallback<File>() {
|
||||
@Override
|
||||
public void callback(File bean) {
|
||||
GiftCacheUtil.this.clickId = -1;
|
||||
downloadCache.remove(getIdForFileName(bean.getName()));
|
||||
mDownloadGifCallback.callback(bean);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停下载
|
||||
*/
|
||||
public void pause() {
|
||||
pause = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复下载
|
||||
*/
|
||||
public void restart(){
|
||||
pause = false;
|
||||
startDownload();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置下载状态
|
||||
*/
|
||||
public void resetStatus() {
|
||||
downloading = false;
|
||||
pause=false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否下载中
|
||||
*/
|
||||
public boolean isDownloading() {
|
||||
return downloading;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载列表中所有文件
|
||||
*/
|
||||
public void downloadAllGift() {
|
||||
File dir = new File(CommonAppConfig.GIF_PATH);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
if (commonCallback == null) {
|
||||
return;
|
||||
}
|
||||
if (downloading) {
|
||||
commonCallback.callback(null);
|
||||
return;
|
||||
}
|
||||
downloading = true;
|
||||
startDownload();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始下载
|
||||
*/
|
||||
private void startDownload(){
|
||||
new Thread(() -> {
|
||||
File dir = new File(CommonAppConfig.GIF_PATH);
|
||||
DownloadUtil downloadUtil = new DownloadUtil();
|
||||
Object[] ids = downloadCache.keySet().toArray();
|
||||
for (Object _id :ids) {
|
||||
int id= (int) _id;
|
||||
if (pause) {
|
||||
return;
|
||||
}
|
||||
File file = new File(dir, Constants.GIF_GIFT_PREFIX + id + ".svga");
|
||||
if (file.exists()) {
|
||||
handler.post(() -> commonCallback.callback(file));
|
||||
downloadCache.remove(id);
|
||||
continue;
|
||||
}
|
||||
LiveGiftBean bean = downloadCache.get(id);
|
||||
if (bean == null) {
|
||||
continue;
|
||||
}
|
||||
if (clickId == id) {
|
||||
continue;
|
||||
}
|
||||
if (bean.getSwf().isEmpty()) {
|
||||
handler.post(() -> commonCallback.callback(null));
|
||||
continue;
|
||||
}
|
||||
downloadUtil.download(CommonHttpConsts.DOWNLOAD_GIF, dir, Constants.GIF_GIFT_PREFIX + bean.getId(), bean.getSwf(), new DownloadUtil.Callback() {
|
||||
@Override
|
||||
public void onSuccess(File file) {
|
||||
downloadCache.remove(getIdForFileName(file.getName()));
|
||||
if (downloadCache.isEmpty()) {
|
||||
downloading = false;
|
||||
}else{
|
||||
//单线程下载,以便插队下载和及时停止下载
|
||||
startDownload();
|
||||
}
|
||||
handler.post(() -> commonCallback.callback(file));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(int progress) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
handler.post(() -> commonCallback.callback(null));
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
if(downloadCache.isEmpty()){
|
||||
downloading = false;
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载状态
|
||||
*/
|
||||
public static class GiftDownloadStatus {
|
||||
private int download = 0;
|
||||
private int size = 0;
|
||||
private int id;
|
||||
|
||||
public GiftDownloadStatus(int download, int size, int id) {
|
||||
this.download = download;
|
||||
this.size = size;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getDownload() {
|
||||
return download;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GiftDownloadStatus{" +
|
||||
"download=" + download +
|
||||
", size=" + size +
|
||||
", id=" + id +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
25
common/src/main/java/com/yunbao/common/utils/NobleUtil.java
Normal file
25
common/src/main/java/com/yunbao/common/utils/NobleUtil.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import com.yunbao.common.R;
|
||||
|
||||
|
||||
public class NobleUtil {
|
||||
/**
|
||||
* 来自User.getBaseInfos接口
|
||||
* 根据noble_id返回对应的图片资源
|
||||
* id来自
|
||||
* @see com.yunbao.common.views.weight.NobleNoticeView.RoleType
|
||||
*/
|
||||
public static int nobleIdToImageResId(int id){
|
||||
switch (id){
|
||||
case 1:return R.mipmap.icon_open_nanjue;
|
||||
case 2:return R.mipmap.icon_open_zijue;
|
||||
case 3:return R.mipmap.icon_open_houjue;
|
||||
case 4:return R.mipmap.icon_open_gongjue;
|
||||
case 5:return R.mipmap.icon_open_guowang;
|
||||
case 6:return R.mipmap.icon_open_huangdi;
|
||||
case 7:return R.mipmap.icon_open_chaohuang;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
|
||||
import com.opensource.svgaplayer.SVGACallback;
|
||||
import com.opensource.svgaplayer.SVGAImageView;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -58,4 +61,21 @@ public class SVGAViewUtils {
|
||||
public static void playEndClear(SVGAImageView svga) {
|
||||
playEndClear(svga, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取svga动画播放时间
|
||||
*/
|
||||
public static long getPlayTimer(SVGAImageView svga){
|
||||
try {
|
||||
Field mAnimator = svga.getClass().getDeclaredField("mAnimator");
|
||||
mAnimator.setAccessible(true);
|
||||
ValueAnimator animator = (ValueAnimator) mAnimator.get(svga);
|
||||
if(animator!=null) {
|
||||
return animator.getDuration();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.opensource.svgaplayer.SVGAParser;
|
||||
import com.opensource.svgaplayer.SVGAVideoEntity;
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
import com.yunbao.common.utils.SVGAViewUtils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -127,15 +128,7 @@ public class FullServiceNotificationView extends FrameLayout {
|
||||
svagaBc.setVisibility(VISIBLE);
|
||||
SVGADrawable imageView = new SVGADrawable(svgaVideoEntity);
|
||||
svagaBc.setImageDrawable(imageView);
|
||||
try {
|
||||
Field mAnimator = svagaBc.getClass().getDeclaredField("mAnimator");
|
||||
mAnimator.setAccessible(true);
|
||||
ValueAnimator animator = (ValueAnimator) mAnimator.get(svagaBc);
|
||||
animationTime = animator.getDuration();
|
||||
System.out.println("播放时间 = " + animator.getDuration());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
animationTime= SVGAViewUtils.getPlayTimer(svagaBc);
|
||||
svagaBc.setLoops(1);
|
||||
svagaBc.startAnimation();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.opensource.svgaplayer.SVGAVideoEntity;
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
import com.yunbao.common.utils.BitmapUtil;
|
||||
import com.yunbao.common.utils.SVGAViewUtils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -204,15 +205,7 @@ public class NobleNoticeView extends FrameLayout {
|
||||
dynamicEntity.setDynamicImage(bitmap, "psd_31");
|
||||
SVGADrawable imageView = new SVGADrawable(svgaVideoEntity, dynamicEntity);
|
||||
svagaBc.setImageDrawable(imageView);
|
||||
try {
|
||||
Field mAnimator = svagaBc.getClass().getDeclaredField("mAnimator");
|
||||
mAnimator.setAccessible(true);
|
||||
ValueAnimator animator = (ValueAnimator) mAnimator.get(svagaBc);
|
||||
animationTime = animator.getDuration();
|
||||
System.out.println("播放时间 = " + animator.getDuration());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
animationTime= SVGAViewUtils.getPlayTimer(svagaBc);
|
||||
svagaBc.setLoops(1);
|
||||
svagaBc.startAnimation();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user