package com.gh.common.databind; import android.content.Intent; import android.graphics.Color; import android.graphics.Typeface; 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.CertificationDialog; import com.gh.common.dialog.ReserveDialogFragment; import com.gh.common.exposure.ExposureEvent; import com.gh.common.history.HistoryHelper; import com.gh.common.repository.ReservationRepository; import com.gh.common.simulator.SimulatorDownloadManager; import com.gh.common.simulator.SimulatorGameManager; 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.PackageInstaller; 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.DownloadProgressBar; import com.gh.common.view.DrawableView; import com.gh.common.view.GameIconView; import com.gh.download.DownloadManager; import com.gh.download.dialog.DownloadDialog; 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.entity.TestEntity; 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.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; 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("setTypeface") public static void setTypeface(TextView view, String type) { if (type == null) return; switch (type) { case "bold": view.setTypeface(null, Typeface.BOLD); break; case "italic": view.setTypeface(null, Typeface.ITALIC); break; case "bold_italic": view.setTypeface(null, Typeface.BOLD_ITALIC); break; default: view.setTypeface(null, Typeface.NORMAL); break; } } @BindingAdapter({"addDetailKaiFuView", "addDetailKaiFuViewListener", "isReadyPatch"}) public static void addDetailKaiFuView(LinearLayout view, List 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 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("textColorFromString") public static void textColorFromString(TextView tv, String hexString) { if (TextUtils.isEmpty(hexString)) return; try { tv.setTextColor(Color.parseColor(hexString)); } catch (Exception e) { e.printStackTrace(); } } @BindingAdapter("visibleGone") public static void showHide(View view, Boolean show) { if (show != null && show) { view.setVisibility(View.VISIBLE); } else { view.setVisibility(View.GONE); } } @BindingAdapter("goneIf") public static void goneIf(View view, Boolean gone) { if (gone != null && gone) { view.setVisibility(View.GONE); } else { view.setVisibility(View.VISIBLE); } } /** * lazy 的 paddingTop */ @BindingAdapter("lazyPaddingTop") public static void lazyPaddingTop(View view, int paddingTopInDp) { view.setPadding(view.getPaddingLeft(), DisplayUtils.dip2px(paddingTopInDp), view.getPaddingRight(), view.getPaddingBottom()); } /** * lazy 的 paddingBottom */ @BindingAdapter("lazyPaddingBottom") public static void lazyPaddingBottom(View view, int paddingBottomInDp) { view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), DisplayUtils.dip2px(paddingBottomInDp)); } @BindingAdapter("visibleInvisible") public static void visibleInvisible(View view, Boolean show) { if (show != null && show) { view.setVisibility(View.VISIBLE); } else { view.setVisibility(View.INVISIBLE); } } @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("game") public static void setGame(View view, GameEntity gameEntity) { if (gameEntity != null && view instanceof GameIconView) { ((GameIconView) view).displayGameIcon(gameEntity); } } @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); DownloadEntity downloadEntity = SimulatorGameManager.findDownloadEntityByUrl(apk.getUrl()); if (gameEntity.getSimulator() != null) { boolean isInstalled = PackageUtils.isInstalledFromAllPackage(v.getContext(), gameEntity.getSimulator().getApk().getPackageName()); if (downloadEntity != null && SimulatorGameManager.isSimulatorGame(gameEntity) && !isInstalled) { SimulatorDownloadManager.getInstance().showDownloadDialog(v.getContext(), gameEntity.getSimulator(), SimulatorDownloadManager.SimulatorLocation.LAUNCH, gameEntity.getId(), gameEntity.getName(), null); return; } } DownloadDialogHelper.findAvailableDialogAndShow(v.getContext(), gameEntity, apk, () -> { CertificationDialog.showCertificationDialog(v.getContext(), gameEntity, () -> { DialogUtils.showVersionNumberDialog(v.getContext(), gameEntity, () -> { DialogUtils.showOverseaDownloadDialog(v.getContext(), gameEntity, () -> { DialogUtils.checkDownload(v.getContext(), apk.getSize(), isSubscribe -> download(progressBar, gameEntity, traceEvent, isSubscribe, entrance, location)); }); }); }); }); } else { CertificationDialog.showCertificationDialog(v.getContext(), gameEntity, () -> { DialogUtils.showVersionNumberDialog(v.getContext(), gameEntity, () -> { DownloadDialog.showDownloadDialog( v.getContext(), gameEntity, traceEvent, entrance, location + ":" + gameEntity.getName()); }); }); } break; case LAUNCH_OR_OPEN: if (gameEntity.getApk().size() == 1) { //启动模拟器游戏 if (SimulatorGameManager.isSimulatorGame(gameEntity)) { DownloadEntity downloadEntity = SimulatorGameManager.findDownloadEntityByUrl(gameEntity.getApk().get(0).getUrl()); if (downloadEntity != null) { File file = new File(downloadEntity.getPath()); if (!file.exists()) { download(progressBar, gameEntity, traceEvent, false, entrance, location); return; } SimulatorGameManager.launchSimulatorGame(downloadEntity, gameEntity); } return; } DataUtils.onGameLaunchEvent(v.getContext(), gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), location); PackageUtils.launchApplicationByPackageName(v.getContext(), gameEntity.getApk().get(0).getPackageName()); } else { DownloadDialog.showDownloadDialog( v.getContext(), gameEntity, traceEvent, entrance, location + ":" + gameEntity.getName()); } 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) { PackageInstaller.install(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: LinkEntity linkEntity = gameEntity.getH5Link(); boolean isPlay = "play".equals(linkEntity.getType()); // 是否为开始玩 MtaHelper.onEvent("H5页面", "入口", "列表页_" + gameEntity.getName()); if (isPlay) { HistoryHelper.insertGameEntity(gameEntity); } Intent i = new Intent(WebActivity.getIntentForWebGame(progressBar.getContext(), linkEntity.getLink(), gameEntity.getName(), isPlay, linkEntity.getCloseButton())); progressBar.getContext().startActivity(i); break; case UPDATING: Utils.toast(progressBar.getContext(), "正在加急更新版本,敬请后续留意"); 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("查看"); progressBar.setDownloadType(DownloadProgressBar.DownloadType.NONE); } else if ("updating".equals(offStatus)) { progressBar.setText("更新中"); progressBar.setDownloadType(DownloadProgressBar.DownloadType.UPDATING); } 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 download(DownloadProgressBar progressBar, GameEntity gameEntity, ExposureEvent traceEvent, @Nullable String entrance, @Nullable String location, View v) { 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); } }*/ 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); DownloadManager.createDownload(progressBar.getContext(), apkEntity, gameEntity, method, entrance, location + gameEntity.getName(), isSubscribe, traceEvent); progressBar.setProgress(0); progressBar.setDownloadType("插件化".equals(method) ? DownloadProgressBar.DownloadType.DOWNLOADING_PLUGIN : DownloadProgressBar.DownloadType.DOWNLOADING_NORMAL); } else { Utils.toast(progressBar.getContext(), msg); } } @BindingAdapter("gameLabelList") public static void setGameLabelList(LinearLayout layout, List tagStyle) { GameViewUtils.setLabelList(layout.getContext(), layout, tagStyle); } // 包含测试开服标签 @BindingAdapter("setGameTags") public static void setGameTags(LinearLayout layout, GameEntity gameEntity) { try { ArrayList tagStyle = new ArrayList<>(); TestEntity test = gameEntity.getTest(); if (test != null) { TagStyleEntity typeTag = new TagStyleEntity(); typeTag.setName(test.getType() != null ? test.getType() : ""); typeTag.setBackground("FFF3E0"); typeTag.setColor("FA8500"); tagStyle.add(typeTag); TagStyleEntity timeTag = new TagStyleEntity(); timeTag.setName(GameViewUtils.getGameTestDate(test.getStart())); timeTag.setBackground("E0FFF9"); timeTag.setColor("00A887"); tagStyle.add(timeTag); } else { tagStyle = gameEntity.getTagStyle(); } GameViewUtils.setLabelList(layout.getContext(), layout, tagStyle); } catch (Exception e) { e.printStackTrace(); } } @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", "isShowSuffix"}) public static void setGameName(TextView view, GameEntity game, boolean isShowPlatform, @Nullable Boolean isShowSuffix) { if (isShowSuffix == null) isShowSuffix = true; // 默认显示 if (isShowPlatform && game.getApk().size() > 0) { view.setText(String.format("%s - %s", !isShowSuffix ? game.getNameWithoutSuffix() : game.getName(), PlatformUtils.getInstance(view.getContext()).getPlatformName( game.getApk().get(0).getPlatform()))); } else { view.setText(!isShowSuffix ? game.getNameWithoutSuffix() : game.getName()); } } @BindingAdapter({"setCommunityImage", "setCommunityVideoImage"}) public static void setCommunityImage(SimpleDraweeView imageView, List images, List 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 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 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); } @BindingAdapter({"setVideoData"}) public static void setVideoData(TextView view, int count) { if (count > 0) { view.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(view.getContext(), R.drawable.ic_video_data_up), null, null, null); view.setTextColor(ContextCompat.getColor(view.getContext(), R.color.text_EA3333)); view.setText(count + ""); } else { view.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); view.setTextColor(ContextCompat.getColor(view.getContext(), R.color.text_999999)); view.setText("-"); } } }