667 lines
29 KiB
Java
667 lines
29 KiB
Java
package com.gh.common.databind;
|
||
|
||
import android.content.Intent;
|
||
import android.graphics.Color;
|
||
import android.text.Spannable;
|
||
import android.text.SpannableString;
|
||
import android.text.TextUtils;
|
||
import android.text.style.ForegroundColorSpan;
|
||
import android.view.LayoutInflater;
|
||
import android.view.MotionEvent;
|
||
import android.view.View;
|
||
import android.widget.EditText;
|
||
import android.widget.LinearLayout;
|
||
import android.widget.TextView;
|
||
|
||
import com.facebook.drawee.view.SimpleDraweeView;
|
||
import com.gh.base.OnViewClickListener;
|
||
import com.gh.common.constant.Config;
|
||
import com.gh.common.dialog.ReserveDialogFragment;
|
||
import com.gh.common.exposure.ExposureEvent;
|
||
import com.gh.common.exposure.ExposureUtils;
|
||
import com.gh.common.repository.ReservationRepository;
|
||
import com.gh.common.util.CheckLoginUtils;
|
||
import com.gh.common.util.DataUtils;
|
||
import com.gh.common.util.DialogUtils;
|
||
import com.gh.common.util.DisplayUtils;
|
||
import com.gh.common.util.DownloadDialogHelper;
|
||
import com.gh.common.util.GameUtils;
|
||
import com.gh.common.util.GameViewUtils;
|
||
import com.gh.common.util.ImageUtils;
|
||
import com.gh.common.util.LogUtils;
|
||
import com.gh.common.util.MtaHelper;
|
||
import com.gh.common.util.NewsUtils;
|
||
import com.gh.common.util.NumberUtils;
|
||
import com.gh.common.util.PackageUtils;
|
||
import com.gh.common.util.PermissionHelper;
|
||
import com.gh.common.util.PlatformUtils;
|
||
import com.gh.common.util.ReservationHelper;
|
||
import com.gh.common.view.DownloadDialog;
|
||
import com.gh.common.view.DownloadProgressBar;
|
||
import com.gh.common.view.DrawableView;
|
||
import com.gh.download.DownloadManager;
|
||
import com.gh.gamecenter.DownloadManagerActivity;
|
||
import com.gh.gamecenter.R;
|
||
import com.gh.gamecenter.WebActivity;
|
||
import com.gh.gamecenter.baselist.LoadStatus;
|
||
import com.gh.gamecenter.databinding.KaifuAddItemBinding;
|
||
import com.gh.gamecenter.databinding.KaifuDetailItemRowBinding;
|
||
import com.gh.gamecenter.entity.ApkEntity;
|
||
import com.gh.gamecenter.entity.GameEntity;
|
||
import com.gh.gamecenter.entity.LinkEntity;
|
||
import com.gh.gamecenter.entity.PluginLocation;
|
||
import com.gh.gamecenter.entity.ServerCalendarEntity;
|
||
import com.gh.gamecenter.entity.TagStyleEntity;
|
||
import com.gh.gamecenter.eventbus.EBReuse;
|
||
import com.gh.gamecenter.manager.PackagesManager;
|
||
import com.gh.gamecenter.qa.entity.CommunityVideoEntity;
|
||
import com.lightgame.download.DownloadEntity;
|
||
import com.lightgame.download.FileUtils;
|
||
import com.lightgame.utils.Utils;
|
||
|
||
import org.greenrobot.eventbus.EventBus;
|
||
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.List;
|
||
import java.util.Locale;
|
||
|
||
import androidx.annotation.Nullable;
|
||
import androidx.appcompat.app.AppCompatActivity;
|
||
import androidx.core.content.ContextCompat;
|
||
import androidx.databinding.BindingAdapter;
|
||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||
|
||
/**
|
||
* Created by khy on 12/02/18.
|
||
*/
|
||
|
||
public class BindingAdapters {
|
||
|
||
@BindingAdapter("imageIcon")
|
||
public static void loadIcon(SimpleDraweeView view, String imageUrl) {
|
||
ImageUtils.displayIcon(view, imageUrl);
|
||
}
|
||
|
||
@BindingAdapter("imageUrl")
|
||
public static void loadImage(SimpleDraweeView view, String imageUrl) {
|
||
ImageUtils.display(view, imageUrl);
|
||
}
|
||
|
||
@BindingAdapter("setTextSize")
|
||
public static void setTextSize(TextView view, int number) {
|
||
view.setTextSize(number);
|
||
}
|
||
|
||
@BindingAdapter({"addDetailKaiFuView", "addDetailKaiFuViewListener", "isReadyPatch"})
|
||
public static void addDetailKaiFuView(LinearLayout view, List<ServerCalendarEntity> list
|
||
, OnViewClickListener listener, Boolean isReadyPatch) {
|
||
if (list == null) return;
|
||
view.removeAllViews();
|
||
for (int i = 0; i < list.size() + 1; i++) { // 1 is Title
|
||
View inflate = LayoutInflater.from(view.getContext()).inflate(R.layout.kaifu_detail_item_row, null);
|
||
KaifuDetailItemRowBinding binding = KaifuDetailItemRowBinding.bind(inflate);
|
||
binding.setIsCloseBottom(i == list.size());
|
||
binding.setIsReadyPatch(isReadyPatch);
|
||
if (i == 0) {
|
||
binding.setIsTitle(true);
|
||
} else {
|
||
ServerCalendarEntity serverEntity = list.get(i - 1);
|
||
binding.setEntity(serverEntity);
|
||
binding.getRoot().setOnClickListener(v -> {
|
||
listener.onClick(v, isReadyPatch != null && isReadyPatch ? serverEntity : null);
|
||
});
|
||
|
||
// 滑动冲突处理
|
||
binding.getRoot().setOnTouchListener((v, event) -> {
|
||
if (list.size() > 5) {
|
||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||
EventBus.getDefault().post(new EBReuse("CalenderDown"));
|
||
} else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
|
||
EventBus.getDefault().post(new EBReuse("CalenderCancel"));
|
||
}
|
||
}
|
||
return false;
|
||
});
|
||
}
|
||
view.addView(inflate);
|
||
}
|
||
}
|
||
|
||
// 如果超过10000,则转换为1.0W
|
||
@BindingAdapter("transSimpleCount")
|
||
public static void transSimpleCount(TextView view, int count) {
|
||
view.setText(NumberUtils.transSimpleCount(count));
|
||
}
|
||
|
||
@BindingAdapter({"addKaiFuView", "clickListener"})
|
||
public static void addKaiFuView(LinearLayout view, List<ServerCalendarEntity> list, OnViewClickListener listener) {
|
||
if (list == null) return;
|
||
view.removeAllViews();
|
||
view.addView(LayoutInflater.from(view.getContext()).inflate(R.layout.kaifu_add_item_title, null));
|
||
for (int i = 0; i < list.size(); i++) {
|
||
View inflate = LayoutInflater.from(view.getContext()).inflate(R.layout.kaifu_add_item, null);
|
||
KaifuAddItemBinding binding = KaifuAddItemBinding.bind(inflate);
|
||
binding.setClickListener(listener);
|
||
binding.setEntity(list.get(i));
|
||
binding.setPosition(i);
|
||
binding.setIsCloseBottom(list.size() - 1 == i);
|
||
view.addView(inflate);
|
||
|
||
binding.kaifuAddName.setOnFocusChangeListener((v, hasFocus) -> {
|
||
if (hasFocus) {
|
||
binding.kaifuAddName.setHint("");
|
||
} else {
|
||
binding.kaifuAddName.setHint("点击填写");
|
||
}
|
||
});
|
||
binding.kaifuAddRemark.setOnFocusChangeListener((v, hasFocus) -> {
|
||
if (hasFocus) {
|
||
binding.kaifuAddRemark.setHint("");
|
||
} else {
|
||
binding.kaifuAddRemark.setHint("点击填写");
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
@BindingAdapter({"addKaiFuTime", "addKaiFuPosition"})
|
||
public static void addKaiFuTime(EditText view, Long time, Integer position) {
|
||
if (time == 0) {
|
||
view.setHint("点击选择");
|
||
view.setText("");
|
||
} else {
|
||
String pattern;
|
||
if (position == 0) {
|
||
pattern = "yyy-MM-dd HH:mm +";
|
||
} else {
|
||
pattern = "yyy-MM-dd HH:mm";
|
||
}
|
||
SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.CHINA);
|
||
view.setText(format.format(time * 1000));
|
||
}
|
||
}
|
||
|
||
@BindingAdapter({"kaiFuTextColor", "kaiFuTextPosition"})
|
||
public static void kaiFuTextColor(EditText view, Integer dataMark, Integer position) {
|
||
if (dataMark == 1 && view.getId() == R.id.kaifu_add_time
|
||
|| dataMark == 2 && view.getId() == R.id.kaifu_add_name
|
||
|| dataMark == 3 && view.getId() == R.id.kaifu_add_remark
|
||
|| dataMark == 4 && (view.getId() == R.id.kaifu_add_time || view.getId() == R.id.kaifu_add_name)) {
|
||
view.setTextColor(ContextCompat.getColor(view.getContext(), R.color.red));
|
||
view.setHintTextColor(ContextCompat.getColor(view.getContext(), R.color.red));
|
||
} else if (position == 0) {
|
||
view.setTextColor(ContextCompat.getColor(view.getContext(), R.color.hint));
|
||
view.setHintTextColor(ContextCompat.getColor(view.getContext(), R.color.hint));
|
||
} else {
|
||
view.setTextColor(ContextCompat.getColor(view.getContext(), R.color.title));
|
||
view.setHintTextColor(ContextCompat.getColor(view.getContext(), R.color.hint));
|
||
}
|
||
}
|
||
|
||
@BindingAdapter("visibleGone")
|
||
public static void showHide(View view, Boolean show) {
|
||
if (show != null && show) {
|
||
view.setVisibility(View.VISIBLE);
|
||
} else {
|
||
view.setVisibility(View.GONE);
|
||
}
|
||
}
|
||
|
||
@BindingAdapter("messageUnread")
|
||
public static void setMessageUnread(TextView view, int unreadCount) {
|
||
if (unreadCount < 100) {
|
||
view.setText(String.valueOf(unreadCount));
|
||
} else {
|
||
view.setText("99+");
|
||
}
|
||
}
|
||
|
||
@BindingAdapter("serverTypePadding")
|
||
public static void setServerTypePadding(TextView view, String serverType) {
|
||
int paddRight = 0;
|
||
if (TextUtils.isEmpty(serverType)) {
|
||
} else {
|
||
if ("删档内测".equals(serverType) || "不删档内测".equals(serverType)) {
|
||
if ("删档内测".equals(serverType)) {
|
||
paddRight = DisplayUtils.dip2px(view.getContext(), 50);
|
||
} else {
|
||
paddRight = DisplayUtils.dip2px(view.getContext(), 60);
|
||
}
|
||
} else {
|
||
paddRight = DisplayUtils.dip2px(view.getContext(), 30);
|
||
}
|
||
}
|
||
view.setPadding(0, 0, paddRight, 0);
|
||
}
|
||
|
||
@BindingAdapter("serverType")
|
||
public static void setServerType(TextView view, String serverType) {
|
||
view.setText(serverType);
|
||
if ("删档内测".equals(serverType) || "不删档内测".equals(serverType)) {
|
||
view.setBackgroundResource(R.drawable.textview_server_tag);
|
||
} else {
|
||
view.setBackgroundResource(R.drawable.textview_orange_up);
|
||
}
|
||
}
|
||
|
||
@BindingAdapter("articleType")
|
||
public static void setArticleType(TextView view, String articleType) {
|
||
NewsUtils.setNewsType(view, articleType, 0, 0);
|
||
}
|
||
|
||
@BindingAdapter("detailDownloadText")
|
||
public static void setDetailDownloadText(TextView view, GameEntity gameEntity) {
|
||
if (gameEntity == null || gameEntity.getApk().isEmpty()) {
|
||
view.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||
view.setTextColor(0xFF999999);
|
||
view.setClickable(false);
|
||
}
|
||
}
|
||
|
||
@BindingAdapter("liBaoBtn")
|
||
public static void setLiBaoBtn(TextView view, String status) {
|
||
if (TextUtils.isEmpty(status)) return;
|
||
switch (status) {
|
||
case "coming":
|
||
view.setText(R.string.libao_coming);
|
||
view.setBackgroundResource(R.drawable.textview_blue_style);
|
||
break;
|
||
case "ling":
|
||
view.setText(R.string.libao_ling);
|
||
view.setBackgroundResource(R.drawable.textview_green_style);
|
||
break;
|
||
case "tao":
|
||
view.setText(R.string.libao_tao);
|
||
view.setBackgroundResource(R.drawable.textview_orange_style);
|
||
break;
|
||
case "used_up":
|
||
view.setText(R.string.libao_used_up);
|
||
view.setBackgroundResource(R.drawable.textview_cancel_up);
|
||
break;
|
||
case "finish":
|
||
view.setText(R.string.libao_finish);
|
||
view.setBackgroundResource(R.drawable.textview_cancel_up);
|
||
break;
|
||
case "linged":
|
||
view.setText(R.string.libao_linged);
|
||
view.setBackgroundResource(R.drawable.libao_linged_style);
|
||
view.setTextColor(ContextCompat.getColorStateList(view.getContext(), R.color.libao_linged_selector));
|
||
break;
|
||
case "taoed":
|
||
view.setText(R.string.libao_taoed);
|
||
view.setBackgroundResource(R.drawable.libao_taoed_style);
|
||
view.setTextColor(ContextCompat.getColorStateList(view.getContext(), R.color.libao_taoed_selector));
|
||
break;
|
||
case "copy":
|
||
view.setText(R.string.libao_copy);
|
||
view.setBackgroundResource(R.drawable.textview_blue_style);
|
||
break;
|
||
case "repeatLing":
|
||
view.setText(R.string.libao_repeat_ling);
|
||
view.setBackgroundResource(R.drawable.textview_cancel_up);
|
||
break;
|
||
case "repeatLinged":
|
||
view.setText(R.string.libao_repeat_ling);
|
||
view.setBackgroundResource(R.drawable.textview_green_style);
|
||
break;
|
||
case "repeatTao":
|
||
view.setText(R.string.libao_repeat_tao);
|
||
view.setBackgroundResource(R.drawable.textview_cancel_up);
|
||
break;
|
||
case "repeatTaoed":
|
||
view.setText(R.string.libao_repeat_tao);
|
||
view.setBackgroundResource(R.drawable.textview_orange_style);
|
||
break;
|
||
case "unshelve":
|
||
view.setBackgroundResource(R.drawable.textview_cancel_style);
|
||
view.setText(R.string.libao_unshelve);
|
||
break;
|
||
default:
|
||
view.setBackgroundResource(R.drawable.textview_cancel_style);
|
||
view.setText("异常");
|
||
}
|
||
}
|
||
|
||
// 大图下的进度条
|
||
@BindingAdapter({"downloadButton", "traceEvent", "clickCallBack", "entrance", "location"})
|
||
public static void setDownloadButton(DownloadProgressBar progressBar,
|
||
GameEntity gameEntity,
|
||
ExposureEvent traceEvent,
|
||
@Nullable View.OnClickListener clickCallBack,
|
||
@Nullable String entrance,
|
||
@Nullable String location) {
|
||
|
||
// 判断是否显示按钮
|
||
if (gameEntity != null
|
||
&& Config.isShowDownload(gameEntity.getId())
|
||
&& !"光环助手".equals(gameEntity.getName())) {
|
||
progressBar.setVisibility(View.VISIBLE);
|
||
} else {
|
||
progressBar.setVisibility(View.GONE);
|
||
return;
|
||
}
|
||
|
||
// 点击事件
|
||
progressBar.setOnClickListener(v -> {
|
||
if (clickCallBack != null) clickCallBack.onClick(v);
|
||
switch (progressBar.getDownloadType()) {
|
||
case DOWNLOADING_PLUGIN:
|
||
case DOWNLOADING_NORMAL:
|
||
Intent intent = DownloadManagerActivity.getDownloadMangerIntent(v.getContext(),
|
||
gameEntity.getApk().get(0).getUrl(), entrance);
|
||
v.getContext().startActivity(intent);
|
||
break;
|
||
case NONE:
|
||
Utils.toast(v.getContext(), "该游戏已关闭下载");
|
||
break;
|
||
case NORMAL:
|
||
case PLUGIN:
|
||
if (gameEntity.getApk().size() == 1) {
|
||
ApkEntity apk = gameEntity.getApk().get(0);
|
||
DownloadDialogHelper.findAvailableDialogAndShow(
|
||
v.getContext(),
|
||
gameEntity,
|
||
apk,
|
||
() -> {
|
||
DialogUtils.checkDownload(v.getContext(), apk.getSize(),
|
||
isSubscribe -> download(progressBar, gameEntity, traceEvent, isSubscribe, entrance, location));
|
||
});
|
||
} else {
|
||
DownloadDialog.getInstance(v.getContext()).showPopupWindow(v, gameEntity,
|
||
entrance, location + gameEntity.getName(), traceEvent);
|
||
}
|
||
break;
|
||
case LAUNCH_OR_OPEN:
|
||
if (gameEntity.getApk().size() == 1) {
|
||
DataUtils.onGameLaunchEvent(v.getContext(), gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), location);
|
||
PackageUtils.launchApplicationByPackageName(v.getContext(), gameEntity.getApk().get(0).getPackageName());
|
||
} else {
|
||
DownloadDialog.getInstance(v.getContext()).showPopupWindow(v, gameEntity,
|
||
entrance, location + gameEntity.getName(), traceEvent);
|
||
}
|
||
break;
|
||
case INSTALL_PLUGIN:
|
||
case INSTALL_NORMAL:
|
||
if (gameEntity.getApk().size() == 1) {
|
||
DownloadEntity downloadEntity = DownloadManager.getInstance(progressBar.getContext()).getDownloadEntityByUrl(gameEntity.getApk().get(0).getUrl());
|
||
if (downloadEntity != null) {
|
||
PackageUtils.launchSetup(v.getContext(), downloadEntity);
|
||
}
|
||
}
|
||
break;
|
||
case RESERVABLE:
|
||
CheckLoginUtils.checkLogin(progressBar.getContext(), "", () -> {
|
||
PermissionHelper.checkReadPhoneStatePermissionBeforeAction(progressBar.getContext(), () -> {
|
||
ReserveDialogFragment dialogFragment = ReserveDialogFragment.getInstance(gameEntity, () -> {
|
||
LogUtils.logReservation(gameEntity, traceEvent);
|
||
updateReservation(progressBar, gameEntity);
|
||
});
|
||
dialogFragment.show(((AppCompatActivity) progressBar.getContext()).getSupportFragmentManager(), "reserve");
|
||
});
|
||
});
|
||
break;
|
||
case RESERVED:
|
||
if ("download".equals(gameEntity.getReserveStatus())) {
|
||
ReservationHelper.showDeleteReservationDialog(progressBar.getContext(), () -> {
|
||
ReservationHelper.deleteReservation(gameEntity, () -> {
|
||
updateReservation(progressBar, gameEntity);
|
||
});
|
||
});
|
||
} else {
|
||
ReservationHelper.showCancelReservationDialog(progressBar.getContext(), () -> {
|
||
ReservationHelper.cancelReservation(gameEntity, () -> {
|
||
updateReservation(progressBar, gameEntity);
|
||
});
|
||
});
|
||
}
|
||
break;
|
||
case H5_GAME:
|
||
MtaHelper.onEvent("H5页面", "入口", "列表页_" + gameEntity.getName());
|
||
LinkEntity linkEntity = gameEntity.getH5Link();
|
||
Intent i = new Intent(WebActivity.getIntentForWebGame(progressBar.getContext(), linkEntity.getLink(), gameEntity.getName(), "play".equals(linkEntity.getType())));
|
||
progressBar.getContext().startActivity(i);
|
||
break;
|
||
}
|
||
});
|
||
|
||
// 显示预约
|
||
if (gameEntity.isReservable()) {
|
||
if (!ReservationRepository.thisGameHasBeenReserved(gameEntity.getId())) {
|
||
progressBar.setText("预约");
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.RESERVABLE);
|
||
} else {
|
||
progressBar.setText("已预约");
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.RESERVED);
|
||
}
|
||
return;
|
||
}
|
||
|
||
// 显示下载按钮状态
|
||
if (gameEntity.getApk().isEmpty() || gameEntity.getDownloadOffStatus() != null) {
|
||
LinkEntity h5LinkEntity = gameEntity.getH5Link();
|
||
String offStatus = gameEntity.getDownloadOffStatus();
|
||
if (h5LinkEntity != null) {
|
||
if ("play".equals(h5LinkEntity.getType())) {
|
||
progressBar.setText("开始玩");
|
||
} else {
|
||
progressBar.setText("查看");
|
||
}
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.H5_GAME);
|
||
} else {
|
||
if (offStatus != null && "dialog".equals(offStatus)) {
|
||
progressBar.setText("查看");
|
||
} else {
|
||
progressBar.setText("暂无");
|
||
}
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.NONE);
|
||
}
|
||
|
||
} else {
|
||
String status = GameUtils.getDownloadBtnText(progressBar.getContext(), gameEntity, PluginLocation.only_game);
|
||
switch (status) {
|
||
case "插件化":
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.PLUGIN);
|
||
break;
|
||
case "打开":
|
||
case "启动":
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.LAUNCH_OR_OPEN);
|
||
break;
|
||
default:
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.NORMAL);
|
||
break;
|
||
}
|
||
progressBar.setText(status);
|
||
}
|
||
|
||
// 显示下载过程状态
|
||
if (gameEntity.getApk().size() == 1) {
|
||
DownloadEntity downloadEntity = DownloadManager.getInstance(progressBar.getContext()).getDownloadEntityByUrl(gameEntity.getApk().get(0).getUrl());
|
||
if (downloadEntity != null) {
|
||
progressBar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||
switch (downloadEntity.getStatus()) {
|
||
case downloading:
|
||
case pause:
|
||
case timeout:
|
||
case neterror:
|
||
case waiting:
|
||
progressBar.setText(R.string.downloading);
|
||
if (downloadEntity.isPluggable() && PackagesManager.INSTANCE.isInstalled(downloadEntity.getPackageName())) {
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.DOWNLOADING_PLUGIN);
|
||
} else {
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.DOWNLOADING_NORMAL);
|
||
}
|
||
break;
|
||
case done:
|
||
progressBar.setText(R.string.install);
|
||
if (downloadEntity.isPluggable()
|
||
&& PackagesManager.INSTANCE.isInstalled(downloadEntity.getPackageName())) {
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.INSTALL_PLUGIN);
|
||
} else {
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.INSTALL_NORMAL);
|
||
}
|
||
break;
|
||
case cancel:
|
||
case hijack:
|
||
case notfound:
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
private static void updateReservation(DownloadProgressBar progressBar, GameEntity gameEntity) {
|
||
// 显示预约
|
||
if (gameEntity.isReservable()) {
|
||
if (!ReservationRepository.thisGameHasBeenReserved(gameEntity.getId())) {
|
||
progressBar.setText("预约");
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.RESERVABLE);
|
||
} else {
|
||
progressBar.setText("已预约");
|
||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.RESERVED);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
// 开始下载
|
||
private static void download(DownloadProgressBar progressBar,
|
||
GameEntity gameEntity,
|
||
ExposureEvent traceEvent,
|
||
boolean isSubscribe,
|
||
String entrance,
|
||
String location) {
|
||
String str = progressBar.getText();
|
||
String method;
|
||
if (str.contains("更新")) {
|
||
method = "更新";
|
||
} else if (str.contains("插件化")) {
|
||
method = "插件化";
|
||
} else {
|
||
method = progressBar.getContext().getString(R.string.download);
|
||
}
|
||
ApkEntity apkEntity = gameEntity.getApk().get(0);
|
||
String msg = FileUtils.isCanDownload(progressBar.getContext(), apkEntity.getSize());
|
||
if (TextUtils.isEmpty(msg)) {
|
||
DataUtils.onGameDownloadEvent(progressBar.getContext(), gameEntity.getName(), apkEntity.getPlatform(), entrance, "下载开始", method);
|
||
|
||
ExposureUtils.DownloadType downloadType = ExposureUtils.getDownloadType(apkEntity, method);
|
||
ExposureEvent downloadExposureEvent = ExposureUtils.logADownloadExposureEvent(gameEntity, apkEntity.getPlatform(), traceEvent, downloadType);
|
||
|
||
DownloadManager.createDownload(progressBar.getContext(),
|
||
apkEntity,
|
||
gameEntity,
|
||
method,
|
||
entrance,
|
||
location + gameEntity.getName(),
|
||
isSubscribe,
|
||
downloadExposureEvent);
|
||
|
||
progressBar.setProgress(0);
|
||
progressBar.setDownloadType("插件化".equals(method) ?
|
||
DownloadProgressBar.DownloadType.DOWNLOADING_PLUGIN : DownloadProgressBar.DownloadType.DOWNLOADING_NORMAL);
|
||
} else {
|
||
Utils.toast(progressBar.getContext(), msg);
|
||
}
|
||
}
|
||
|
||
@BindingAdapter({"gameLabelList", "subjectTag"})
|
||
public static void setGameLabelList(LinearLayout layout, GameEntity gameEntity, String subjectTag) {
|
||
if (gameEntity == null) return;
|
||
if (gameEntity.getTest() != null) {
|
||
layout.removeAllViews();
|
||
View testView = LayoutInflater.from(layout.getContext()).inflate(R.layout.game_test_label, null);
|
||
TextView testType = testView.findViewById(R.id.test_type);
|
||
TextView testTime = testView.findViewById(R.id.test_time);
|
||
testType.setText(gameEntity.getTest().getType());
|
||
testType.setBackgroundColor(ContextCompat.getColor(layout.getContext(), R.color.tag_yellow));
|
||
|
||
if (gameEntity.getTest().getStart() == 0) {
|
||
testTime.setVisibility(View.GONE);
|
||
} else {
|
||
testTime.setText(GameViewUtils.getGameTestDate(gameEntity.getTest().getStart()));
|
||
}
|
||
layout.addView(testView);
|
||
} else {
|
||
GameViewUtils.setLabelList(layout.getContext(), layout, gameEntity.getTag(), subjectTag, gameEntity.getTagStyle());
|
||
}
|
||
|
||
}
|
||
|
||
@BindingAdapter("isRefreshing")
|
||
public static void isRefreshing(SwipeRefreshLayout layout, LoadStatus status) {
|
||
if (status != LoadStatus.INIT_LOADING && status != LoadStatus.LIST_LOADING) {
|
||
layout.setRefreshing(false);
|
||
}
|
||
}
|
||
|
||
@BindingAdapter({"setGameName", "isShowPlatform"})
|
||
public static void setGameName(TextView view, GameEntity game, boolean isShowPlatform) {
|
||
if (isShowPlatform && game.getApk().size() > 0) {
|
||
view.setText(String.format("%s - %s", game.getName(),
|
||
PlatformUtils.getInstance(view.getContext()).getPlatformName(
|
||
game.getApk().get(0).getPlatform())));
|
||
} else {
|
||
view.setText(game.getName());
|
||
}
|
||
|
||
}
|
||
|
||
@BindingAdapter({"setCommunityImage", "setCommunityVideoImage"})
|
||
public static void setCommunityImage(SimpleDraweeView imageView, List<String> images, List<CommunityVideoEntity> videos) {
|
||
if (videos.size() > 0) {
|
||
CommunityVideoEntity videoEntity = videos.get(0);
|
||
ImageUtils.display(imageView, videoEntity.getPoster());
|
||
imageView.setVisibility(View.VISIBLE);
|
||
} else if (images.size() > 0) {
|
||
imageView.setVisibility(View.VISIBLE);
|
||
ImageUtils.display(imageView, images.get(0));
|
||
} else {
|
||
imageView.setVisibility(View.GONE);
|
||
}
|
||
}
|
||
|
||
@BindingAdapter({"setCommunityVideoDuration"})
|
||
public static void setCommunityVideoDuration(TextView mVideoDuration, List<CommunityVideoEntity> videos) {
|
||
if (videos != null && videos.size() > 0) {
|
||
CommunityVideoEntity videoEntity = videos.get(0);
|
||
mVideoDuration.setBackground(DrawableView.getOvalDrawable(R.color.black_alpha_80, 999F));
|
||
mVideoDuration.setText(videoEntity.getDuration());
|
||
mVideoDuration.setVisibility(View.VISIBLE);
|
||
} else {
|
||
mVideoDuration.setVisibility(View.GONE);
|
||
}
|
||
}
|
||
|
||
@BindingAdapter({"setGameTags", "setMaxGameTags"})
|
||
public static void setGameTags(TextView view, List<TagStyleEntity> tags, int maxTags) {
|
||
if (tags == null) {
|
||
view.setText("");
|
||
return;
|
||
}
|
||
|
||
int showCount = tags.size() > maxTags ? maxTags : tags.size(); // 最多显示3个
|
||
|
||
StringBuilder content = new StringBuilder();
|
||
for (int i = 0; i < showCount; i++) {
|
||
TagStyleEntity tag = tags.get(i);
|
||
content.append(tag.getName());
|
||
if (i != showCount - 1) content.append("/");
|
||
}
|
||
|
||
Spannable span = new SpannableString(content);
|
||
int index = 0;
|
||
for (int i = 0; i < showCount; i++) {
|
||
TagStyleEntity tag = tags.get(i);
|
||
int start = index;
|
||
int end = start + tag.getName().length() + ((i != showCount - 1) ? 1 : 0);
|
||
index = end;
|
||
span.setSpan(new ForegroundColorSpan(Color.parseColor("#" + tag.getColor())),
|
||
start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||
}
|
||
view.setText(span);
|
||
}
|
||
}
|