金币转现金
This commit is contained in:
parent
da56a8cb42
commit
0b0805d6bc
|
|
@ -2,6 +2,7 @@ package com.gamedog.vididin
|
||||||
|
|
||||||
object VidiConst {
|
object VidiConst {
|
||||||
|
|
||||||
|
|
||||||
const val URL_DISCORD: String = "https://www.baidu.com"
|
const val URL_DISCORD: String = "https://www.baidu.com"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -21,6 +22,8 @@ object VidiConst {
|
||||||
|
|
||||||
const val GOLD_IN_CONFIG: String = "金币"
|
const val GOLD_IN_CONFIG: String = "金币"
|
||||||
|
|
||||||
|
const val PER_CASH_COST_GOLD_NUM = 1000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ data class Account(
|
||||||
val deviceUUId: String,
|
val deviceUUId: String,
|
||||||
val token: String="",
|
val token: String="",
|
||||||
val createdAt: Long,
|
val createdAt: Long,
|
||||||
|
@Volatile
|
||||||
var goldCount: Long = 0L,
|
var goldCount: Long = 0L,
|
||||||
|
@Volatile
|
||||||
var cashCount: Float = 0F,
|
var cashCount: Float = 0F,
|
||||||
var bankInfo: BankInfo? = null,
|
var bankInfo: BankInfo? = null,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,23 @@
|
||||||
package com.gamedog.vididin.core.login.login
|
package com.gamedog.vididin.core.login.login
|
||||||
|
|
||||||
|
import com.ama.core.architecture.util.AndroidUtil
|
||||||
import com.ama.core.architecture.util.DateUtil
|
import com.ama.core.architecture.util.DateUtil
|
||||||
import com.ama.core.architecture.util.DeviceUtil
|
import com.ama.core.architecture.util.DeviceUtil
|
||||||
import com.ama.core.architecture.util.SpUtil
|
import com.ama.core.architecture.util.SpUtil
|
||||||
import com.ama.core.architecture.util.eventbus.NotifyMan
|
import com.ama.core.architecture.util.eventbus.NotifyMan
|
||||||
|
import com.gamedog.vididin.VidiConst
|
||||||
import com.gamedog.vididin.VididinEvents
|
import com.gamedog.vididin.VididinEvents
|
||||||
import com.gamedog.vididin.beans.Account
|
import com.gamedog.vididin.beans.Account
|
||||||
import com.gamedog.vididin.beans.BankInfo
|
import com.gamedog.vididin.beans.BankInfo
|
||||||
|
import com.gamedog.vididin.main.fragments.task.TaskBean
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
|
||||||
|
|
||||||
object AccountManager {
|
object AccountManager {
|
||||||
|
|
||||||
|
private val mutex = Mutex()
|
||||||
|
|
||||||
private val mAccount: Account? by lazy {
|
private val mAccount: Account? by lazy {
|
||||||
var account = SpUtil.instance().getObject<Account>(SpUtil.KEY_ACCOUNT)
|
var account = SpUtil.instance().getObject<Account>(SpUtil.KEY_ACCOUNT)
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
|
|
@ -71,5 +78,30 @@ object AccountManager {
|
||||||
VididinEvents.Event_Account_Bank_Info_Changed, NotifyMan.NotifyData(bankAccount))
|
VididinEvents.Event_Account_Bank_Info_Changed, NotifyMan.NotifyData(bankAccount))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun convertGold2Cash(): Boolean {
|
||||||
|
try {
|
||||||
|
val couldCovertCashTotal = mAccount?.goldCount?.div(VidiConst.PER_CASH_COST_GOLD_NUM) ?: 0L
|
||||||
|
if (couldCovertCashTotal > 0) {
|
||||||
|
val costGoldNum = couldCovertCashTotal * VidiConst.PER_CASH_COST_GOLD_NUM
|
||||||
|
mAccount?.goldCount?.let {
|
||||||
|
if (it > costGoldNum) {
|
||||||
|
addGold(-1 * costGoldNum.toInt())
|
||||||
|
addCash(couldCovertCashTotal.toFloat())
|
||||||
|
AndroidUtil.showToast("Has convert $costGoldNum gold to $couldCovertCashTotal cash.")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
AndroidUtil.showToast("You don't have enough gold.")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ class WatchVideoDialog(context: Activity, private val mTaskType: Int, private va
|
||||||
|
|
||||||
private fun gotoWatchVideo() {
|
private fun gotoWatchVideo() {
|
||||||
Router.WatchAd.startActivity(mActivity, mTaskType, mTaskDataJson)
|
Router.WatchAd.startActivity(mActivity, mTaskType, mTaskDataJson)
|
||||||
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
package com.gamedog.vididin.manager
|
package com.gamedog.vididin.manager
|
||||||
|
|
||||||
|
|
||||||
import com.ama.core.architecture.util.FileUtil
|
import com.ama.core.architecture.util.FileUtil
|
||||||
|
import com.ama.core.architecture.util.eventbus.NotifyMan
|
||||||
|
import com.gamedog.vididin.VididinEvents
|
||||||
|
import com.gamedog.vididin.core.login.login.AccountManager
|
||||||
import com.gamedog.vididin.main.fragments.task.Task
|
import com.gamedog.vididin.main.fragments.task.Task
|
||||||
import com.gamedog.vididin.main.fragments.task.TaskBean
|
import com.gamedog.vididin.main.fragments.task.TaskBean
|
||||||
import com.gamedog.vididin.manager.helpers.DailyBoxHelper
|
import com.gamedog.vididin.manager.helpers.DailyBoxHelper
|
||||||
|
|
@ -61,6 +65,7 @@ class TaskManager private constructor() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
loadTaskConfigAsync()
|
loadTaskConfigAsync()
|
||||||
|
registerEvents()
|
||||||
|
|
||||||
// TODO - remove test code
|
// TODO - remove test code
|
||||||
if (true) {
|
if (true) {
|
||||||
|
|
@ -68,6 +73,22 @@ class TaskManager private constructor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun registerEvents() {
|
||||||
|
NotifyMan.instance().register(object : NotifyMan.ICallback(true) {
|
||||||
|
override fun onEvent(data: NotifyMan.NotifyData<*>?) {
|
||||||
|
when (data?.mEventType) {
|
||||||
|
VididinEvents.Event_AD_TASK_TYPE_Convert_Gold_2_Cash -> {
|
||||||
|
AccountManager.convertGold2Cash()
|
||||||
|
}
|
||||||
|
|
||||||
|
VididinEvents.Event_AD_TASK_TYPE_Watch_Ad_For_Gold -> {
|
||||||
|
// TODO - add gold for user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, VididinEvents.Event_AD_TASK_TYPE_Convert_Gold_2_Cash, VididinEvents.Event_AD_TASK_TYPE_Watch_Ad_For_Gold)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
suspend fun getTaskConfig(): TaskBean? = mutex.withLock {
|
suspend fun getTaskConfig(): TaskBean? = mutex.withLock {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue