完成简单的预约游戏弹窗样式
This commit is contained in:
118
app/src/main/java/com/gh/common/dialog/ReserveDialogFragment.kt
Normal file
118
app/src/main/java/com/gh/common/dialog/ReserveDialogFragment.kt
Normal file
@ -0,0 +1,118 @@
|
||||
package com.gh.common.dialog
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import butterknife.BindView
|
||||
import butterknife.ButterKnife
|
||||
import butterknife.OnClick
|
||||
import com.gh.common.util.observeNonNull
|
||||
import com.gh.common.util.viewModelProvider
|
||||
import com.gh.gamecenter.R
|
||||
import com.lightgame.dialog.BaseDialogFragment
|
||||
import com.lightgame.utils.Utils
|
||||
|
||||
class ReserveDialogFragment : BaseDialogFragment() {
|
||||
|
||||
@BindView(R.id.reserve_hint_tv)
|
||||
lateinit var reserveHintTv: TextView
|
||||
@BindView(R.id.reserve_content_tv)
|
||||
lateinit var reserveContentTv: TextView
|
||||
@BindView(R.id.reserve_completed_content_tv)
|
||||
lateinit var reserveCompletedContentTv: TextView
|
||||
@BindView(R.id.mobile_et)
|
||||
lateinit var mobileEt: EditText
|
||||
@BindView(R.id.reserve_container)
|
||||
lateinit var reserveContainer: View
|
||||
@BindView(R.id.reserve_completed_container)
|
||||
lateinit var reserveCompletedContainer: View
|
||||
|
||||
lateinit var mViewModel: ReserveViewModel
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
mViewModel = viewModelProvider()
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.dialog_reserve_game, null)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
ButterKnife.bind(this, view)
|
||||
|
||||
val reserveContent = "游戏上线,您将<font color='#ff4147'>免费</font>收到短信提醒"
|
||||
|
||||
reserveContentTv.text = Html.fromHtml(reserveContent)
|
||||
|
||||
mViewModel.reservation.observeNonNull(this) {
|
||||
if (it) {
|
||||
showSuccessDialog()
|
||||
}
|
||||
}
|
||||
dialog.setCanceledOnTouchOutside(true)
|
||||
}
|
||||
|
||||
private fun showSuccessDialog() {
|
||||
reserveHintTv.text = "游戏预约成功"
|
||||
reserveCompletedContentTv.text = Html.fromHtml("游戏上线,将通过<font color='#ff4147'>免费短信</font>提醒您建议你设置微信提醒,多渠道提醒,不会错过任何预约的游戏。" +
|
||||
"一个帐号仅需设置一次,即可永久有效。")
|
||||
|
||||
reserveContainer.visibility = View.GONE
|
||||
reserveCompletedContainer.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
@OnClick(R.id.reserve_with_mobile_btn,
|
||||
R.id.reserve_without_mobile_btn,
|
||||
R.id.close_btn,
|
||||
R.id.customizable_btn)
|
||||
fun onClick(view: View) {
|
||||
when (view.id) {
|
||||
R.id.reserve_without_mobile_btn -> {
|
||||
mViewModel.reserve()
|
||||
}
|
||||
|
||||
R.id.reserve_with_mobile_btn -> {
|
||||
val mobile = mobileEt.text.toString()
|
||||
if (mobile.length < 11 || !mobile.startsWith("1")) {
|
||||
Utils.toast(context, "手机号格式错误,请检查并重新输入")
|
||||
return
|
||||
}
|
||||
|
||||
mViewModel.reserve(mobile = mobile)
|
||||
}
|
||||
|
||||
R.id.close_btn -> {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
R.id.customizable_btn -> {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ReserveViewModel : ViewModel() {
|
||||
val reservation = MutableLiveData<Boolean>()
|
||||
|
||||
fun reserve(mobile: String = "") {
|
||||
if (mobile.isNotEmpty()) {
|
||||
reservation.postValue(true)
|
||||
} else {
|
||||
reservation.postValue(true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,15 +3,18 @@ package com.gh.common.util;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Message;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.collection.ArrayMap;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
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.ReserveDialogFragment;
|
||||
import com.gh.common.exposure.ExposureEvent;
|
||||
import com.gh.common.exposure.ExposureUtils;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
@ -124,6 +127,17 @@ public class DownloadItemUtils {
|
||||
holder.gameLibaoIcon.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// 显示预约
|
||||
if (gameEntity.getCanReserve()) {
|
||||
holder.gameDes.setVisibility(View.VISIBLE);
|
||||
holder.gameProgressbar.setVisibility(View.GONE);
|
||||
holder.gameInfo.setVisibility(View.GONE);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.button_reserve);
|
||||
holder.gameDownloadBtn.setText("预约");
|
||||
holder.gameDownloadBtn.setTextColor(Color.WHITE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
holder.gameDes.setVisibility(View.VISIBLE);
|
||||
holder.gameProgressbar.setVisibility(View.GONE);
|
||||
@ -297,6 +311,16 @@ public class DownloadItemUtils {
|
||||
final String location,
|
||||
final ExposureEvent traceEvent) {
|
||||
|
||||
if (gameEntity.getCanReserve()) {
|
||||
downloadBtn.setOnClickListener(v -> {
|
||||
CheckLoginUtils.checkLogin(context, entrance, () -> {
|
||||
ReserveDialogFragment dialogFragment = new ReserveDialogFragment();
|
||||
dialogFragment.show(((AppCompatActivity) context).getSupportFragmentManager(), "reserve");
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameEntity.getApk().size() == 1) {
|
||||
downloadBtn.setOnClickListener(v -> onNormalClick(context, downloadBtn, gameEntity, position, adapter, entrance, location, traceEvent));
|
||||
} else {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package com.gh.gamecenter.entity
|
||||
|
||||
import android.os.Parcelable
|
||||
import androidx.collection.ArrayMap
|
||||
import com.gh.common.constant.Config
|
||||
import com.gh.gamecenter.game.data.GameSubjectData
|
||||
import com.google.gson.annotations.SerializedName
|
||||
@ -20,6 +19,8 @@ data class GameEntity(
|
||||
var nameSuffix: String = "",
|
||||
var brief: String? = null,
|
||||
|
||||
var canReserve: Boolean = false,
|
||||
|
||||
private var tag: ArrayList<String>? = null,
|
||||
private var apk: ArrayList<ApkEntity>? = null,
|
||||
@SerializedName("apk_normal")
|
||||
|
||||
Reference in New Issue
Block a user