diff --git a/app/src/main/java/com/gh/common/databind/BindingAdapters.java b/app/src/main/java/com/gh/common/databind/BindingAdapters.java index d2704e2c18..4140b7dc4e 100644 --- a/app/src/main/java/com/gh/common/databind/BindingAdapters.java +++ b/app/src/main/java/com/gh/common/databind/BindingAdapters.java @@ -448,15 +448,12 @@ public class BindingAdapters { return; } } - - DialogUtils.showEmulatorGameDialog(v.getContext(), gameEntity, () -> { - 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)); - }); + 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)); }); }); }); diff --git a/app/src/main/java/com/gh/common/simulator/SimulatorGameManager.kt b/app/src/main/java/com/gh/common/simulator/SimulatorGameManager.kt index be9187b51c..e85660ad28 100644 --- a/app/src/main/java/com/gh/common/simulator/SimulatorGameManager.kt +++ b/app/src/main/java/com/gh/common/simulator/SimulatorGameManager.kt @@ -4,10 +4,14 @@ import android.annotation.SuppressLint import android.content.ActivityNotFoundException import android.content.Intent import android.net.Uri +import android.text.TextUtils +import com.g00fy2.versioncompare.Version import com.gh.common.util.* import com.gh.download.DownloadManager import com.gh.gamecenter.entity.GameEntity +import com.gh.gamecenter.manager.UserManager import com.gh.gamecenter.retrofit.BiResponse +import com.gh.gamecenter.retrofit.EmptyResponse import com.gh.gamecenter.retrofit.RetrofitManager import com.halo.assistant.HaloApp import com.lightgame.download.DownloadDao @@ -15,7 +19,11 @@ import com.lightgame.download.DownloadEntity import com.lightgame.download.FileUtils import com.lightgame.utils.AppManager import io.reactivex.schedulers.Schedulers +import okhttp3.MediaType +import okhttp3.RequestBody import okhttp3.ResponseBody +import org.json.JSONException +import org.json.JSONObject import java.io.File @@ -72,6 +80,15 @@ object SimulatorGameManager { @JvmStatic fun launchSimulatorGame(downloadEntity: DownloadEntity, gameEntity: GameEntity) { + val versionFromInstalledApp = PackageUtils.getVersionByPackage(gameEntity.simulator?.apk?.packageName) + val shouldShowUpdate = Version(gameEntity.simulator?.apk?.version).isHigherThan(versionFromInstalledApp) + if (shouldShowUpdate) { + SimulatorDownloadManager.getInstance().showDownloadDialog(AppManager.getInstance().recentActiveActivity, gameEntity.simulator, + SimulatorDownloadManager.SimulatorLocation.LAUNCH, gameEntity.id, gameEntity.name + ?: "") + return + } + val intent = Intent() intent.data = Uri.fromFile(File(downloadEntity.path)) if (gameEntity.simulatorType == "FBA") { @@ -113,11 +130,25 @@ object SimulatorGameManager { .downloadSimulatorGames(HaloApp.getInstance().gid, body) .subscribeOn(Schedulers.io()) .observeOn(Schedulers.io()) - .subscribe(object : BiResponse() { - override fun onSuccess(data: ResponseBody) { + .subscribe(EmptyResponse()) + } - } - }) + /** + * 标记已玩过 + */ + @SuppressLint("CheckResult") + fun postPlayedGame(gameId: String, packageName: String) { + if (!TextUtils.isEmpty(gameId) && UserManager.getInstance().isLoggedIn) { + val requestMap = hashMapOf() + requestMap["game_id"] = gameId + requestMap["package"] = packageName + val body = requestMap.toRequestBody() + RetrofitManager.getInstance(HaloApp.getInstance().application).api + .postPlayedGame(UserManager.getInstance().userId, body) + .subscribeOn(Schedulers.io()) + .observeOn(Schedulers.io()) + .subscribe(EmptyResponse()) + } } @@ -134,10 +165,6 @@ object SimulatorGameManager { .playedSimulatorGames(HaloApp.getInstance().gid, body) .subscribeOn(Schedulers.io()) .observeOn(Schedulers.io()) - .subscribe(object : BiResponse() { - override fun onSuccess(data: ResponseBody) { - - } - }) + .subscribe(EmptyResponse()) } } \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/util/DialogUtils.java b/app/src/main/java/com/gh/common/util/DialogUtils.java index 1e05950794..40cfd9630e 100644 --- a/app/src/main/java/com/gh/common/util/DialogUtils.java +++ b/app/src/main/java/com/gh/common/util/DialogUtils.java @@ -35,19 +35,11 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.core.content.ContextCompat; -import androidx.databinding.DataBindingUtil; -import androidx.recyclerview.widget.RecyclerView; - import com.facebook.drawee.generic.GenericDraweeHierarchy; import com.facebook.drawee.view.SimpleDraweeView; import com.gh.common.AppExecutor; import com.gh.common.constant.Config; import com.gh.common.dialog.TrackableDialog; -import com.gh.common.simulator.SimulatorGameManager; import com.gh.common.view.DrawableView; import com.gh.common.view.FixLinearLayoutManager; import com.gh.common.view.LimitHeightLinearLayout; @@ -83,6 +75,13 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.core.content.ContextCompat; +import androidx.databinding.DataBindingUtil; +import androidx.recyclerview.widget.RecyclerView; + public class DialogUtils { public static Dialog showWaitDialog(Context context, String msg) { @@ -1396,40 +1395,6 @@ public class DialogUtils { } } - //模拟器游戏下载提示弹窗 - public static void showEmulatorGameDialog(Context context, GameEntity gameEntity, @NonNull ConfirmListener listener) { - context = checkDialogContext(context); - - if (!SimulatorGameManager.isSimulatorGame(gameEntity)) { - listener.onConfirm(); - return; - } - - final Dialog dialog = new Dialog(context, R.style.GhAlertDialog); - - DialogOverseaConfirmationBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_oversea_confirmation, null, false); - - View contentView = binding.getRoot(); - - binding.setGame(gameEntity); - binding.urlTv.setText(gameEntity.getApk().get(0).getUrl()); - binding.closeIv.setOnClickListener(v -> dialog.dismiss()); - binding.downloadBtn.setText("下载(" + gameEntity.getApk().get(0).getSize() + ")"); - binding.downloadBtn.setOnClickListener(v -> { - listener.onConfirm(); - dialog.dismiss(); - }); - - Window window = dialog.getWindow(); - if (window != null) { - window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); - } - - dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - dialog.setContentView(contentView); - dialog.show(); - } - // 海外下载地址弹窗 public static void showOverseaDownloadDialog(Context context, GameEntity gameEntity, @NonNull ConfirmListener listener) { context = checkDialogContext(context); diff --git a/app/src/main/java/com/gh/common/util/DownloadItemUtils.java b/app/src/main/java/com/gh/common/util/DownloadItemUtils.java index e5f0094df1..8f78e5db8b 100644 --- a/app/src/main/java/com/gh/common/util/DownloadItemUtils.java +++ b/app/src/main/java/com/gh/common/util/DownloadItemUtils.java @@ -8,12 +8,6 @@ import android.text.TextUtils; import android.view.View; import android.widget.TextView; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.collection.ArrayMap; -import androidx.core.content.ContextCompat; -import androidx.recyclerview.widget.RecyclerView; - import com.gh.common.constant.Config; import com.gh.common.dialog.CertificationDialog; import com.gh.common.dialog.DeviceRemindDialog; @@ -45,6 +39,12 @@ import com.lightgame.utils.Utils; import java.io.File; import java.util.concurrent.LinkedBlockingQueue; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.collection.ArrayMap; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; + /** * todo 下载判断不能以按钮文案为判断条件,否则按钮文案修改时又要修改判断逻辑 */ @@ -548,17 +548,16 @@ public class DownloadItemUtils { if (str.equals(context.getString(R.string.download))) { // 先弹下载弹窗(如果需要的话) - DialogUtils.showEmulatorGameDialog(context, gameEntity, () -> { - DownloadDialogHelper.findAvailableDialogAndShow(context, gameEntity, apk, () -> { - CertificationDialog.showCertificationDialog(context, gameEntity, () -> { - DialogUtils.showOverseaDownloadDialog(context, gameEntity, () -> { - DialogUtils.checkDownload(context, apk.getSize(), - isSubscribe -> download(context, gameEntity, downloadBtn, entrance, location, isSubscribe, traceEvent)); - }); + DownloadDialogHelper.findAvailableDialogAndShow(context, gameEntity, apk, () -> { + CertificationDialog.showCertificationDialog(context, gameEntity, () -> { + DialogUtils.showOverseaDownloadDialog(context, gameEntity, () -> { + DialogUtils.checkDownload(context, apk.getSize(), + isSubscribe -> download(context, gameEntity, downloadBtn, entrance, location, isSubscribe, traceEvent)); }); }); }); + DataLogUtils.uploadGameLog(context, gameEntity.getId(), gameEntity.getName(), entrance); } else if (str.equals(context.getString(R.string.attempt))) { DownloadDialogHelper.findAvailableDialogAndShow(context, gameEntity, apk, () -> { diff --git a/app/src/main/java/com/gh/common/util/DownloadObserver.kt b/app/src/main/java/com/gh/common/util/DownloadObserver.kt index 587694b6b9..144c48c61c 100644 --- a/app/src/main/java/com/gh/common/util/DownloadObserver.kt +++ b/app/src/main/java/com/gh/common/util/DownloadObserver.kt @@ -145,6 +145,7 @@ object DownloadObserver { ?: "") } SimulatorGameManager.recordDownloadSimulatorGames(gameEntity.id) + SimulatorGameManager.postPlayedGame(gameEntity.id, downloadEntity.packageName) } } else { val downloadType = downloadEntity.getMetaExtra(Constants.EXTRA_DOWNLOAD_TYPE) diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/DetailViewHolder.java b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/DetailViewHolder.java index 67ac0f137c..54b791649e 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/DetailViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/DetailViewHolder.java @@ -5,10 +5,6 @@ import android.content.Intent; import android.text.TextUtils; import android.view.View; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.FragmentActivity; - import com.gh.common.dialog.CertificationDialog; import com.gh.common.dialog.DeviceRemindDialog; import com.gh.common.dialog.GameOffServiceDialogFragment; @@ -44,9 +40,15 @@ import com.gh.gamecenter.gamedetail.GameDetailFragment; 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 androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.FragmentActivity; + /** * Created by khy on 27/06/17. * 详情页面下载ViewHolder @@ -163,19 +165,16 @@ public class DetailViewHolder { PermissionHelper.checkStoragePermissionBeforeAction(mViewHolder.context, () -> { if (mGameEntity.getApk().size() == 1) { ApkEntity apk = mGameEntity.getApk().get(0); - - DialogUtils.showEmulatorGameDialog(mViewHolder.context, mGameEntity, () -> { - DownloadDialogHelper.findAvailableDialogAndShow(mViewHolder.context, mGameEntity, apk, - () -> { - CertificationDialog.showCertificationDialog(mViewHolder.context, mGameEntity, () -> { - DialogUtils.showVersionNumberDialog(mViewHolder.context, mGameEntity, () -> { - DialogUtils.showOverseaDownloadDialog(mViewHolder.context, mGameEntity, () -> { - DialogUtils.checkDownload(mViewHolder.context, apk.getSize(), this::download); - }); + DownloadDialogHelper.findAvailableDialogAndShow(mViewHolder.context, mGameEntity, apk, + () -> { + CertificationDialog.showCertificationDialog(mViewHolder.context, mGameEntity, () -> { + DialogUtils.showVersionNumberDialog(mViewHolder.context, mGameEntity, () -> { + DialogUtils.showOverseaDownloadDialog(mViewHolder.context, mGameEntity, () -> { + DialogUtils.checkDownload(mViewHolder.context, apk.getSize(), this::download); }); }); }); - }); + }); } else { CertificationDialog.showCertificationDialog(mViewHolder.context, mGameEntity, () -> { DialogUtils.showVersionNumberDialog(mViewHolder.context, mGameEntity, () -> { diff --git a/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragment.java b/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragment.java index c4a1c0214f..aed802de92 100644 --- a/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragment.java +++ b/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragment.java @@ -84,6 +84,14 @@ public class GameDownloadFragment extends BaseFragment implements View.OnClickLi return; } + if (downloadEntity.getStatus().equals(DownloadStatus.done) && ExtensionsKt.isSimulatorGame(downloadEntity)) { + adapter.initMap(); + adapter.notifyDataSetChanged(); + int listSize = adapter.getDownloadingList().size() + adapter.getDoneList().size(); + mNoDataSkip.setVisibility(listSize > 0 ? View.GONE : View.VISIBLE); + EventBus.getDefault().post(new EBDownloadChanged("download", View.GONE, listSize)); + } + if (downloadEntity.getStatus().equals(DownloadStatus.downloading) || downloadEntity.getStatus().equals(DownloadStatus.pause) || downloadEntity.getStatus().equals(DownloadStatus.waiting)) { diff --git a/app/src/main/java/com/gh/gamecenter/download/InstalledGameFragment.kt b/app/src/main/java/com/gh/gamecenter/download/InstalledGameFragment.kt index f406f3a420..b09c64c93b 100644 --- a/app/src/main/java/com/gh/gamecenter/download/InstalledGameFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/download/InstalledGameFragment.kt @@ -14,6 +14,7 @@ import com.ethanhua.skeleton.ViewSkeletonScreen import com.gh.base.OnRequestCallBackListener import com.gh.common.exposure.ExposureListener import com.gh.common.util.DownloadItemUtils +import com.gh.common.util.isSimulatorGame import com.gh.common.view.FixLinearLayoutManager import com.gh.common.view.VerticalItemDecoration import com.gh.download.DownloadManager @@ -29,6 +30,7 @@ import com.gh.gamecenter.normal.NormalFragment import com.gh.gamecenter.packagehelper.PackageViewModel import com.lightgame.download.DataWatcher import com.lightgame.download.DownloadEntity +import com.lightgame.download.DownloadStatus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode @@ -37,12 +39,16 @@ class InstalledGameFragment : NormalFragment(), OnRequestCallBackListener { @BindView(R.id.fm_install_rv_show) lateinit var mInstallRv: RecyclerView + @BindView(R.id.reuse_nodata_skip) lateinit var mNoDataSkip: LinearLayout + @BindView(R.id.reuse_nodata_skip_tv_hint) lateinit var mNoDataSkipHint: TextView + @BindView(R.id.reuse_nodata_skip_tv_btn) lateinit var mNoDataSkipBtn: TextView + @BindView(R.id.list_skeleton) lateinit var mListSkeleton: View @@ -56,6 +62,13 @@ class InstalledGameFragment : NormalFragment(), OnRequestCallBackListener { private val dataWatcher = object : DataWatcher() { override fun onDataChanged(downloadEntity: DownloadEntity) { + if (downloadEntity.status == DownloadStatus.done && downloadEntity.isSimulatorGame()) { + DownloadManager.getInstance(requireContext()).getEntryMap(downloadEntity.name)[downloadEntity.platform] = downloadEntity + mPackageViewModel?.getGameInstalledLiveData()?.value?.let { + mAdapter?.initData(PackagesManager.filterSameApk(PackagesManager.filterDownloadBlackPackage(it as MutableList?))) + } + return + } val locationList = mAdapter!!.locationMap[downloadEntity.packageName] if (locationList != null && locationList.size != 0) { var gameEntity: GameEntity?