88 lines
3.2 KiB
Kotlin
88 lines
3.2 KiB
Kotlin
package com.gh.common.util
|
|
|
|
import android.annotation.SuppressLint
|
|
import android.content.Context
|
|
import com.gh.common.repository.ReservationRepository
|
|
import com.gh.gamecenter.entity.GameEntity
|
|
import com.gh.gamecenter.retrofit.BiResponse
|
|
import com.gh.gamecenter.retrofit.RetrofitManager
|
|
import com.halo.assistant.HaloApp
|
|
import com.lightgame.utils.Utils
|
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
import io.reactivex.schedulers.Schedulers
|
|
import okhttp3.ResponseBody
|
|
|
|
object ReservationHelper {
|
|
|
|
@JvmStatic
|
|
fun deleteReservation(game: GameEntity, refreshCallback: EmptyCallback) {
|
|
deleteOrCancelReservation(game, true, refreshCallback)
|
|
}
|
|
|
|
@JvmStatic
|
|
fun cancelReservation(game: GameEntity, refreshCallback: EmptyCallback) {
|
|
deleteOrCancelReservation(game, false, refreshCallback)
|
|
}
|
|
|
|
@SuppressLint("CheckResult")
|
|
private fun deleteOrCancelReservation(game: GameEntity, deleteReservation: Boolean, refreshCallback: EmptyCallback) {
|
|
val retrofit = RetrofitManager.getInstance(HaloApp.getInstance().application)
|
|
val requestMap = hashMapOf<String, String>()
|
|
requestMap["game_id"] = game.id
|
|
|
|
val single = if (deleteReservation) {
|
|
retrofit.api
|
|
.deleteGameReservation(requestMap.createRequestBody())
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
} else {
|
|
retrofit.api
|
|
.cancelGameReservation(requestMap.createRequestBody())
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
}
|
|
|
|
single.subscribe(object : BiResponse<ResponseBody>() {
|
|
override fun onSuccess(data: ResponseBody) {
|
|
ReservationRepository.removeReservationFromMemoryAndRefresh(game.id)
|
|
|
|
if (deleteReservation) {
|
|
// MtaHelper.onEvent("预约游戏", "取消预约", game.name)
|
|
} else {
|
|
// MtaHelper.onEvent("预约游戏", "删除预约", game.name)
|
|
}
|
|
|
|
refreshCallback.onCallback()
|
|
}
|
|
|
|
override fun onFailure(exception: Exception) {
|
|
Utils.toast(HaloApp.getInstance().application, exception.message)
|
|
exception.printStackTrace()
|
|
}
|
|
})
|
|
}
|
|
|
|
@JvmStatic
|
|
fun showDeleteReservationDialog(context: Context, emptyCallback: EmptyCallback) {
|
|
DialogUtils.showCancelOrDeleteReservationDialog(context,
|
|
"删除预约",
|
|
"游戏已上线,你可以删除此预约记录,确定删除吗?",
|
|
"确定删除",
|
|
"暂不删除", {
|
|
emptyCallback.onCallback()
|
|
}, null)
|
|
}
|
|
|
|
@JvmStatic
|
|
fun showCancelReservationDialog(context: Context, emptyCallback: EmptyCallback) {
|
|
DialogUtils.showCancelOrDeleteReservationDialog(context,
|
|
"取消预约",
|
|
"取消之后你将无法收到游戏上线的通知,确定取消预约吗?",
|
|
"确定取消",
|
|
"暂不取消", {
|
|
emptyCallback.onCallback()
|
|
}, null)
|
|
}
|
|
|
|
|
|
} |