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