From e5de70af66d1f76b573a4cae7f71c4e82116f660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=8E=89=E4=B9=85?= Date: Thu, 30 Jun 2022 11:06:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=80=90=E5=85=89=E7=8E=AF=E5=8A=A9?= =?UTF-8?q?=E6=89=8BV=5F5.11.0=E3=80=91=E5=9B=BD=E9=99=85=E6=9C=8D?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E4=B8=8B=E8=BD=BD=E5=BC=B9=E7=AA=97=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20https://git.shanqu.cc/pm/halo/halo-app-issues/-/iss?= =?UTF-8?q?ues/1933?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gh/common/util/DialogUtils.java | 50 ++++++++++++++----- .../retrofit/service/ApiService.java | 7 ++- 2 files changed, 44 insertions(+), 13 deletions(-) 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 17f92ea226..1f53aa1a23 100644 --- a/app/src/main/java/com/gh/common/util/DialogUtils.java +++ b/app/src/main/java/com/gh/common/util/DialogUtils.java @@ -41,6 +41,7 @@ import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.content.ContextCompat; @@ -59,6 +60,7 @@ import com.gh.gamecenter.common.callback.CancelListener; import com.gh.gamecenter.common.callback.ConfirmListener; import com.gh.gamecenter.common.callback.SimpleCallback; import com.gh.gamecenter.common.databinding.DialogAlertDefaultBinding; +import com.gh.gamecenter.common.retrofit.Response; import com.gh.gamecenter.common.utils.ExtensionsKt; import com.gh.gamecenter.common.utils.ImageUtils; import com.gh.gamecenter.common.utils.NetworkUtils; @@ -94,8 +96,10 @@ import com.gh.gamecenter.entity.PrivacyPolicyEntity; import com.gh.gamecenter.entity.SettingsEntity; import com.gh.gamecenter.entity.SimpleGameEntity; import com.gh.gamecenter.entity.TrackableEntity; +import com.gh.gamecenter.retrofit.RetrofitManager; import com.gh.gamecenter.setting.GameDownloadSettingFragment; import com.gh.gamecenter.suggest.SuggestType; +import com.google.gson.JsonObject; import com.halo.assistant.HaloApp; import com.lightgame.adapter.BaseRecyclerAdapter; import com.lightgame.download.DownloadEntity; @@ -112,6 +116,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import kotlin.Unit; import kotlin.jvm.functions.Function0; +import retrofit2.HttpException; public class DialogUtils { @@ -210,8 +215,6 @@ public class DialogUtils { } - - public static void checkDownload(Context context, String size, CheckDownloadCallBack callBack) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(HaloApp.getInstance().getApplication()); if (!NetworkUtils.isNetworkConnected(context)) { @@ -412,7 +415,6 @@ public class DialogUtils { } - public static Dialog showDialogWithHtmlContent(Context context, String title, String content , String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) { context = checkDialogContext(context); @@ -1310,17 +1312,41 @@ public class DialogUtils { binding.gameIcon.displayGameIcon(gameEntity); binding.gameNameTv.setText(context.getString(R.string.dialog_oversea_hint, gameEntity.getName())); - binding.urlTv.setText(gameEntity.getOverseasAddressDialog().getLink()); binding.closeIv.setOnClickListener(v -> dialog.dismiss()); - binding.downloadBtn.setText("下载(" + gameEntity.getApk().get(0).getSize() + ")"); - binding.downloadBtn.setOnClickListener(v -> { - listener.onConfirm(); - dialog.dismiss(); - }); - if ("show&download".equals(gameEntity.getOverseasAddressDialog().getStatus())) { - gameEntity.getApk().get(0).setUrl(gameEntity.getOverseasAddressDialog().getLink()); - } + Context finalContext = context; + RetrofitManager.getInstance().getApi().getThirdPartyAddress(gameEntity.getId()) + .compose(ExtensionsKt.observableToMain()) + .subscribe(new Response() { + @Override + public void onResponse(@Nullable JsonObject response) { + super.onResponse(response); + if (response == null) return; + String h5Link = response.get("h5_link").getAsString(); + String downloadLink = response.get("download_link").getAsString(); + String buttonText = response.get("button_text").getAsString(); + binding.urlTv.setText(downloadLink); + binding.downloadBtn.setText(buttonText); + binding.downloadBtn.setOnClickListener(v -> { + DirectUtils.directToExternalBrowser(finalContext, h5Link); + dialog.dismiss(); + }); + } + + @Override + public void onFailure(@Nullable HttpException e) { + super.onFailure(e); + if ("show&download".equals(gameEntity.getOverseasAddressDialog().getStatus())) { + gameEntity.getApk().get(0).setUrl(gameEntity.getOverseasAddressDialog().getLink()); + } + binding.urlTv.setText(gameEntity.getOverseasAddressDialog().getLink()); + binding.downloadBtn.setText("下载(" + gameEntity.getApk().get(0).getSize() + ")"); + binding.downloadBtn.setOnClickListener(v -> { + listener.onConfirm(); + dialog.dismiss(); + }); + } + }); Window window = dialog.getWindow(); if (window != null) { diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java index 3700febd0d..0710515fe1 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java @@ -2008,7 +2008,6 @@ public interface ApiService { * 获取活动的视频流(可滑动) * * @param type hot最热,new最新,award获奖(只返回获奖视频) - * @param act 活动名称 */ @GET("videos/{video_id}/scroll") Single> getActivitiesVideoStreamScroll(@Path("video_id") String videoId, @Query("type") String type, @Query("act_id") String actId, @Query("filter") String filter); @@ -3549,4 +3548,10 @@ public interface ApiService { */ @POST("games/platform_requests/{platform_requests_id}/apk") Observable postPlatformRequestApk(@Path("platform_requests_id") String platformRequestsId, @Body RequestBody body); + + /** + * 获取第三方下载链接 + */ + @GET("games/{game_id}/third_party_address") + Observable getThirdPartyAddress(@Path("game_id") String gameId); } \ No newline at end of file