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