统一 金币 钻石 现金 存取方法
This commit is contained in:
parent
95da77184d
commit
59c80a6e58
|
|
@ -15,7 +15,9 @@ data class Account(
|
|||
var diamondCount: Int = 0,
|
||||
var bankInfo: BankInfo? = null,
|
||||
val zeroBuyServerSecret: String = "",
|
||||
)
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
data class BankInfo(
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ open class RecordGold {
|
|||
var uuid: String = ""
|
||||
var dateMs: Long = 0L
|
||||
var isSuccess: Boolean = false
|
||||
var amountNum: Int = 0
|
||||
var amountNum: Long = 0
|
||||
var recordType: Int = 0
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,13 +39,11 @@ class WithdrawInfoConfirmDialog(context: Activity, private val onConfirmed: (cas
|
|||
}
|
||||
|
||||
tvActionApply -> {
|
||||
AccountManager.getAccount()?.cashCount?.let {
|
||||
if (it < mWithdrawCashNum) {
|
||||
AndroidUtil.showToast(R.string.not_enough_cash)
|
||||
} else {
|
||||
//WithdrawWatchAdDialog(mActivity, mWithdrawCashNum).show()
|
||||
onConfirmed.invoke(mWithdrawCashNum)
|
||||
}
|
||||
if (AccountManager.getCash() < mWithdrawCashNum) {
|
||||
AndroidUtil.showToast(R.string.not_enough_cash)
|
||||
} else {
|
||||
//WithdrawWatchAdDialog(mActivity, mWithdrawCashNum).show()
|
||||
onConfirmed.invoke(mWithdrawCashNum)
|
||||
}
|
||||
|
||||
dismiss()
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ class ZeroBuyActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
}
|
||||
|
||||
private fun updateUIDiamondNum() {
|
||||
binding.tvZeroGoldNum.text = AccountManager.getAccount()?.diamondCount.toString()
|
||||
binding.tvZeroGoldNum.text = AccountManager.getDiamond().toString()
|
||||
}
|
||||
|
||||
override fun ViewBinding.initObservers() {
|
||||
|
|
|
|||
|
|
@ -9,19 +9,15 @@ import com.gamedog.vididin.VidiConst
|
|||
import com.gamedog.vididin.VididinEvents
|
||||
import com.gamedog.vididin.beans.Account
|
||||
import com.gamedog.vididin.beans.BankInfo
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
|
||||
|
||||
object AccountManager {
|
||||
|
||||
private val mutex = Mutex()
|
||||
|
||||
init {
|
||||
NotifyMan.instance().register(object: NotifyMan.ICallback(true) {
|
||||
override fun onEvent(data: NotifyMan.NotifyData<*>?) {
|
||||
when (data?.mEventType) {
|
||||
VididinEvents.EVENT_AD_WATCHED_FOR_ZEROBUY_EARN_DIAMOND -> {
|
||||
addDiamond(VidiConst.DIAMOND_NUM_FOR_ONE_AD)
|
||||
adjustDiamond(VidiConst.DIAMOND_NUM_FOR_ONE_AD)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +25,7 @@ object AccountManager {
|
|||
}, VididinEvents.EVENT_AD_WATCHED_FOR_ZEROBUY_EARN_DIAMOND)
|
||||
}
|
||||
|
||||
private val mAccount: Account? by lazy {
|
||||
private val mAccount: Account by lazy {
|
||||
var account = SpUtil.instance().getObject<Account>(SpUtil.KEY_ACCOUNT)
|
||||
if (account == null) {
|
||||
val deviceUUId = DeviceUtil.generateDeviceId()
|
||||
|
|
@ -45,46 +41,60 @@ object AccountManager {
|
|||
SpUtil.instance().putObject(SpUtil.KEY_ACCOUNT, mAccount)
|
||||
}
|
||||
|
||||
fun getAccount() : Account? {
|
||||
|
||||
//------------------------- 3个数值相关属性 增减 start --------------------------//
|
||||
fun getAccount() : Account {
|
||||
return mAccount
|
||||
}
|
||||
|
||||
fun getGold(): Long {
|
||||
return mAccount?.goldCount ?: 0L
|
||||
return mAccount.goldCount
|
||||
}
|
||||
|
||||
fun getCash(): Float {
|
||||
return mAccount?.cashCount ?: 0F
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun addGold(newGold: Int) {
|
||||
mAccount?.goldCount += newGold
|
||||
fun adjustGold(adjustNum: Long): Boolean {
|
||||
if (adjustNum < 0L && Math.abs(adjustNum) > getGold()) {
|
||||
return false
|
||||
}
|
||||
mAccount.goldCount += adjustNum
|
||||
saveAccountInfo()
|
||||
NotifyMan.instance().sendEvent(VididinEvents.Event_Account_Gold_Changed, null)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
fun getCash(): Float {
|
||||
return mAccount.cashCount
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun addDiamond(diamondNum: Int) {
|
||||
mAccount?.diamondCount += diamondNum
|
||||
fun adjustCash(adjustNum: Float): Boolean {
|
||||
if (adjustNum < 0L && Math.abs(adjustNum) > getGold()) {
|
||||
return false
|
||||
}
|
||||
mAccount.cashCount += adjustNum
|
||||
saveAccountInfo()
|
||||
NotifyMan.instance().sendEvent(VididinEvents.Event_Account_Cash_Changed, null)
|
||||
return true
|
||||
}
|
||||
|
||||
fun getDiamond(): Int {
|
||||
return mAccount.diamondCount
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun adjustDiamond(adjustNum: Int): Boolean {
|
||||
if (adjustNum < 0L && Math.abs(adjustNum) > getGold()) {
|
||||
return false
|
||||
}
|
||||
mAccount.diamondCount += adjustNum
|
||||
saveAccountInfo()
|
||||
NotifyMan.instance().sendEvent(VididinEvents.Event_Account_Diamond_Changed, null)
|
||||
return true
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun adjustAccountCash(newCash: Float): Boolean {
|
||||
val result = false
|
||||
mAccount?.let {
|
||||
val newCashTotal = it.cashCount + newCash
|
||||
if (newCashTotal >= 0F) {
|
||||
it.cashCount = newCashTotal
|
||||
saveAccountInfo()
|
||||
NotifyMan.instance().sendEvent(VididinEvents.Event_Account_Cash_Changed, null)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
//------------------------- 3个数值相关属性 增减 End --------------------------//
|
||||
|
||||
|
||||
|
||||
fun getBankInfo(): BankInfo? {
|
||||
return mAccount?.bankInfo
|
||||
|
|
@ -111,16 +121,14 @@ object AccountManager {
|
|||
@Synchronized
|
||||
fun convertGold2Cash(): Boolean {
|
||||
try {
|
||||
val couldCovertCashTotal = mAccount?.goldCount?.div(VidiConst.PER_01CASH_COST_GOLD_NUM) ?: 0
|
||||
val couldCovertCashTotal = getGold().div(VidiConst.PER_01CASH_COST_GOLD_NUM) ?: 0
|
||||
if (couldCovertCashTotal > 0) {
|
||||
val costGoldNum = couldCovertCashTotal * VidiConst.PER_01CASH_COST_GOLD_NUM
|
||||
mAccount?.goldCount?.let {
|
||||
if (it >= costGoldNum) {
|
||||
addGold(-1 * costGoldNum.toInt())
|
||||
adjustAccountCash(couldCovertCashTotal * 0.1F)
|
||||
AndroidUtil.showToast("Has convert $costGoldNum gold to $couldCovertCashTotal cash.")
|
||||
return true
|
||||
}
|
||||
if (getGold() >= costGoldNum) {
|
||||
adjustGold(-1L * costGoldNum.toInt())
|
||||
adjustCash(couldCovertCashTotal * 0.1F)
|
||||
AndroidUtil.showToast("Has convert $costGoldNum gold to $couldCovertCashTotal cash.")
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
AndroidUtil.showToast("You don't have enough gold.")
|
||||
|
|
@ -142,17 +150,6 @@ object AccountManager {
|
|||
return !mAccount?.bankInfo?.bankAccount.isNullOrEmpty()
|
||||
}
|
||||
|
||||
fun adjustDiamond(diamondCost: Int): Boolean {
|
||||
mAccount?.let {
|
||||
if (it.diamondCount >= diamondCost) {
|
||||
it.diamondCount -= diamondCost
|
||||
saveAccountInfo()
|
||||
NotifyMan.instance().sendEvent(VididinEvents.Event_Account_Diamond_Changed, null)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import com.ama.core.architecture.highlightpro.HighlightPro
|
|||
import com.ama.core.architecture.highlightpro.parameter.Constraints
|
||||
import com.ama.core.architecture.highlightpro.parameter.HighlightParameter
|
||||
import com.ama.core.architecture.highlightpro.parameter.MarginOffset
|
||||
import com.ama.core.architecture.highlightpro.shape.OvalShape
|
||||
import com.ama.core.architecture.highlightpro.shape.RectShape
|
||||
import com.ama.core.architecture.util.ResUtil.dp
|
||||
import com.ama.core.architecture.util.SpUtil
|
||||
|
|
@ -49,7 +48,7 @@ class BeginnerGiftDialog(activity: Activity) : BindingDialog<DialogBeginnerGiftB
|
|||
(mActivity as MainActivity).switchTab(1)
|
||||
}
|
||||
if (!SpUtil.instance().getBoolean(SpUtil.KEY_GUIDE_HAS_GOT_NEWBIE_GOLD)) {
|
||||
AccountManager.addGold(100)
|
||||
AccountManager.adjustGold(100)
|
||||
SpUtil.instance().putBoolean(SpUtil.KEY_GUIDE_HAS_GOT_NEWBIE_GOLD, true)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ class HomeFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnSwit
|
|||
} else {
|
||||
mTotalMs = 0L
|
||||
binding?.dragIconView?.setProgress(mTotalMs * 100/ RewardConst.HOME_WATCH_DURATION)
|
||||
AccountManager.addGold(RewardConst.HOME_WATCH_REWARD_NUM)
|
||||
AccountManager.adjustGold(RewardConst.HOME_WATCH_REWARD_NUM.toLong())
|
||||
binding?.dragIconView?.showRewardGoldAnim()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class TaskManager private constructor() {
|
|||
}
|
||||
|
||||
VididinEvents.EVENT_AD_WATCHED_FOR_EARN_GOLD -> {
|
||||
AccountManager.addGold(VidiConst.WATCH_AD_REWARD_GOLD)
|
||||
AccountManager.adjustGold(VidiConst.WATCH_AD_REWARD_GOLD.toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ class WithdrawManager private constructor() {
|
|||
}
|
||||
|
||||
private fun adjustAccountCash(cashNum: Float) {
|
||||
AccountManager.adjustAccountCash(cashNum)
|
||||
AccountManager.adjustCash(cashNum)
|
||||
}
|
||||
|
||||
private fun saveRecords2Sp() {
|
||||
|
|
@ -481,40 +481,19 @@ class WithdrawManager private constructor() {
|
|||
return allStartedItemRestCashNum
|
||||
}
|
||||
|
||||
fun getItemState(itemIndex: Int): Int {
|
||||
var returnState = ITEM_STATE_CANNOT_START
|
||||
|
||||
AccountManager.getAccount()?.let {
|
||||
if (itemIndex in 0..mItemList.size-1) {
|
||||
val curItem = mItemList[itemIndex]
|
||||
val userCashTotal = it.cashCount
|
||||
val allStartedItemRestCashNum = getStartedItemRestCashCount()
|
||||
|
||||
if (curItem.hasStarted) {
|
||||
returnState = ITEM_STATE_STARTED
|
||||
} else if ((userCashTotal - allStartedItemRestCashNum) >= curItem.totalCashNum) {
|
||||
returnState = ITEM_STATE_CAN_START
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnState
|
||||
}
|
||||
|
||||
fun getItemProgress(itemIndex: Int): Float {
|
||||
var itemProgress = 0F
|
||||
|
||||
AccountManager.getAccount()?.let {
|
||||
if (itemIndex in 0..mItemList.size-1) {
|
||||
val curItem = mItemList[itemIndex]
|
||||
val userCashTotal = it.cashCount
|
||||
val restAvailableCashNum = userCashTotal - getStartedItemRestCashCount()
|
||||
if (itemIndex in 0..mItemList.size-1) {
|
||||
val curItem = mItemList[itemIndex]
|
||||
val userCashTotal = AccountManager.getCash()
|
||||
val restAvailableCashNum = userCashTotal - getStartedItemRestCashCount()
|
||||
|
||||
if (curItem.hasStarted || restAvailableCashNum >= curItem.totalCashNum) {
|
||||
itemProgress = 1F
|
||||
} else {
|
||||
itemProgress = restAvailableCashNum / curItem.totalCashNum
|
||||
}
|
||||
if (curItem.hasStarted || restAvailableCashNum >= curItem.totalCashNum) {
|
||||
itemProgress = 1F
|
||||
} else {
|
||||
itemProgress = restAvailableCashNum / curItem.totalCashNum
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ abstract class BaseDailyTaskHelper<T : BaseDailyTaskState> : BaseTaskHelper<T, T
|
|||
try {
|
||||
val subTask = mStateBean.getSubTaskRewardState()[subTaskIndex]
|
||||
if (subTask.state == STATE_FINISH) {
|
||||
AccountManager.addGold(subTask.mRewardNum)
|
||||
AccountManager.adjustGold(subTask.mRewardNum.toLong())
|
||||
subTask.state = STATE_CLAIMED
|
||||
saveState2Sp()
|
||||
notifyEvents()
|
||||
|
|
|
|||
|
|
@ -323,7 +323,7 @@ class BoxTaskHelper: BaseTaskHelper<TaskStateBoxRoot, BoxTaskRoot>() {
|
|||
try {
|
||||
val couldClaimCashNum = getCouldClaimCashNum()
|
||||
if (couldClaimCashNum > 0F) {
|
||||
AccountManager.adjustAccountCash(couldClaimCashNum)
|
||||
AccountManager.adjustCash(couldClaimCashNum)
|
||||
mStateBean.boxList.forEachIndexed { index, box ->
|
||||
if (getBoxStateEnum(index) == STATE_FINISH) {
|
||||
box.hasClaimedReward = true
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class DailySignTaskHelper : BaseTaskHelper<TaskDailySignBean, Task>() {
|
|||
daySignState.hasSigned = true
|
||||
daySignState.hasWatchedAd = isByAd
|
||||
saveState2Sp()
|
||||
AccountManager.addGold(finalReward)
|
||||
AccountManager.adjustGold(finalReward.toLong())
|
||||
notifySignStateChanged(Pair(dayIndex, daySignState))
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class NewbieEnableNotifyHelper: BaseTaskHelper<TaskStateNewBieEnableNotify, Task
|
|||
|
||||
fun claimReward() : Boolean {
|
||||
if (!mStateBean.hasClaimReward) {
|
||||
AccountManager.addGold(mStateBean.rewardGoldNum)
|
||||
AccountManager.adjustGold(mStateBean.rewardGoldNum.toLong())
|
||||
mStateBean.hasClaimReward = true
|
||||
saveState2Sp()
|
||||
notifyStateChangeEvent()
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class NewbieFirstWithdrawHelper: BaseTaskHelper<TaskStateNewBieFirstWithDraw, Ta
|
|||
|
||||
fun claimReward(): Boolean {
|
||||
if (!mStateBean.hasClaimReward) {
|
||||
AccountManager.addGold(mStateBean.rewardGoldNum)
|
||||
AccountManager.adjustGold(mStateBean.rewardGoldNum.toLong())
|
||||
mStateBean.hasClaimReward = true
|
||||
saveState2Sp()
|
||||
notifyStateChangeEvent()
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class NewbieJoinDiscordHelper: BaseTaskHelper<TaskStateNewBieJoinDiscord, Task>(
|
|||
|
||||
fun claimReward() : Boolean {
|
||||
if (!mStateBean.hasClaimReward) {
|
||||
AccountManager.addGold(mStateBean.rewardGoldNum)
|
||||
AccountManager.adjustGold(mStateBean.rewardGoldNum.toLong())
|
||||
mStateBean.hasClaimReward = true
|
||||
saveState2Sp()
|
||||
notifyStateChangeEvent()
|
||||
|
|
|
|||
Loading…
Reference in New Issue