2025-11-25 10:23:37 +00:00
|
|
|
package com.gamedog.vididin.core.login.login
|
|
|
|
|
|
2025-12-31 05:57:33 +00:00
|
|
|
import com.ama.core.architecture.BaseApp
|
2025-12-01 11:26:14 +00:00
|
|
|
import com.ama.core.architecture.util.AndroidUtil
|
2025-11-25 10:23:37 +00:00
|
|
|
import com.ama.core.architecture.util.DateUtil
|
|
|
|
|
import com.ama.core.architecture.util.DeviceUtil
|
2026-01-12 05:37:53 +00:00
|
|
|
import com.ama.core.architecture.util.ResUtil
|
2025-11-25 10:23:37 +00:00
|
|
|
import com.ama.core.architecture.util.SpUtil
|
2025-11-27 06:43:33 +00:00
|
|
|
import com.ama.core.architecture.util.eventbus.NotifyMan
|
2025-12-01 11:26:14 +00:00
|
|
|
import com.gamedog.vididin.VidiConst
|
2025-11-27 06:43:33 +00:00
|
|
|
import com.gamedog.vididin.VididinEvents
|
2025-11-25 10:23:37 +00:00
|
|
|
import com.gamedog.vididin.beans.Account
|
2025-11-27 08:30:33 +00:00
|
|
|
import com.gamedog.vididin.beans.BankInfo
|
2025-12-24 08:31:38 +00:00
|
|
|
import com.gamedog.vididin.beans.RECORD_CASH_PLUS_GOLD_CONVERT
|
2025-12-24 09:12:21 +00:00
|
|
|
import com.gamedog.vididin.beans.RECORD_GOLD_MINUS_CONVERT_2_CASH
|
2025-12-24 08:31:38 +00:00
|
|
|
import com.gamedog.vididin.beans.RecordCash
|
2025-12-24 09:12:21 +00:00
|
|
|
import com.gamedog.vididin.beans.RecordGold
|
2025-12-24 08:31:38 +00:00
|
|
|
import com.gamedog.vididin.manager.RecordsManager
|
2025-12-31 05:57:33 +00:00
|
|
|
import com.remax.notification.service.NotificationKeepAliveService
|
2026-01-12 05:37:53 +00:00
|
|
|
import com.viddin.videos.free.R
|
2025-11-25 10:23:37 +00:00
|
|
|
|
|
|
|
|
object AccountManager {
|
|
|
|
|
|
2025-12-10 03:22:07 +00:00
|
|
|
init {
|
|
|
|
|
NotifyMan.instance().register(object: NotifyMan.ICallback(true) {
|
|
|
|
|
override fun onEvent(data: NotifyMan.NotifyData<*>?) {
|
|
|
|
|
when (data?.mEventType) {
|
2025-12-10 09:35:49 +00:00
|
|
|
VididinEvents.EVENT_AD_WATCHED_FOR_ZEROBUY_EARN_DIAMOND -> {
|
2025-12-24 08:04:05 +00:00
|
|
|
adjustDiamond(VidiConst.DIAMOND_NUM_FOR_ONE_AD)
|
2025-12-10 03:22:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-10 09:35:49 +00:00
|
|
|
}, VididinEvents.EVENT_AD_WATCHED_FOR_ZEROBUY_EARN_DIAMOND)
|
2025-12-10 03:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-24 08:04:05 +00:00
|
|
|
private val mAccount: Account by lazy {
|
2025-11-25 10:23:37 +00:00
|
|
|
var account = SpUtil.instance().getObject<Account>(SpUtil.KEY_ACCOUNT)
|
|
|
|
|
if (account == null) {
|
|
|
|
|
val deviceUUId = DeviceUtil.generateDeviceId()
|
|
|
|
|
account = Account(accountId = "user_$deviceUUId", deviceUUId=deviceUUId, createdAt = DateUtil.getCurTimeMs())
|
|
|
|
|
account.let {
|
|
|
|
|
SpUtil.instance().putObject(SpUtil.KEY_ACCOUNT, account)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
account
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 06:49:15 +00:00
|
|
|
private fun saveAccountInfo() {
|
|
|
|
|
SpUtil.instance().putObject(SpUtil.KEY_ACCOUNT, mAccount)
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 08:04:05 +00:00
|
|
|
|
2026-01-12 09:43:15 +00:00
|
|
|
fun updateUserName(userName: String) {
|
|
|
|
|
mAccount.userName = userName
|
|
|
|
|
saveAccountInfo()
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 08:04:05 +00:00
|
|
|
//------------------------- 3个数值相关属性 增减 start --------------------------//
|
|
|
|
|
fun getAccount() : Account {
|
2025-11-25 10:23:37 +00:00
|
|
|
return mAccount
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 06:43:33 +00:00
|
|
|
fun getGold(): Long {
|
2025-12-24 08:04:05 +00:00
|
|
|
return mAccount.goldCount
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 09:12:21 +00:00
|
|
|
fun adjustGold(adjustNum: Long, recordBean: RecordGold): Boolean {
|
2025-12-24 08:04:05 +00:00
|
|
|
if (adjustNum < 0L && Math.abs(adjustNum) > getGold()) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
mAccount.goldCount += adjustNum
|
|
|
|
|
saveAccountInfo()
|
|
|
|
|
NotifyMan.instance().sendEvent(VididinEvents.Event_Account_Gold_Changed, null)
|
2025-12-24 09:12:21 +00:00
|
|
|
RecordsManager.instance().appendGoldRecord(recordBean)
|
2025-12-31 05:57:33 +00:00
|
|
|
updateResidentNotification()
|
2025-12-24 08:04:05 +00:00
|
|
|
return true
|
2025-11-27 06:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-31 05:57:33 +00:00
|
|
|
private fun updateResidentNotification() {
|
|
|
|
|
NotificationKeepAliveService.updateNotification(BaseApp.appContext())
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 08:04:05 +00:00
|
|
|
|
2025-12-29 05:48:09 +00:00
|
|
|
fun getCash(): Double {
|
2025-12-24 08:04:05 +00:00
|
|
|
return mAccount.cashCount
|
2025-11-27 06:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-04 03:27:27 +00:00
|
|
|
@Synchronized
|
2026-01-06 09:56:38 +00:00
|
|
|
fun adjustCash(adjustNum: Double, recordBean: RecordCash? = null): Boolean {
|
2025-12-24 10:34:10 +00:00
|
|
|
if (adjustNum < 0L && Math.abs(adjustNum) > getCash()) {
|
2025-12-24 08:04:05 +00:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
mAccount.cashCount += adjustNum
|
2025-11-27 06:49:15 +00:00
|
|
|
saveAccountInfo()
|
2025-12-24 08:04:05 +00:00
|
|
|
NotifyMan.instance().sendEvent(VididinEvents.Event_Account_Cash_Changed, null)
|
2025-12-24 08:31:38 +00:00
|
|
|
recordBean?.let {
|
|
|
|
|
RecordsManager.instance().appendCashRecord(recordBean)
|
|
|
|
|
}
|
2025-12-31 05:57:33 +00:00
|
|
|
updateResidentNotification()
|
2025-12-24 08:04:05 +00:00
|
|
|
return true
|
2025-11-27 06:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-24 08:04:05 +00:00
|
|
|
fun getDiamond(): Int {
|
|
|
|
|
return mAccount.diamondCount
|
2025-12-10 03:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-04 03:27:27 +00:00
|
|
|
@Synchronized
|
2025-12-24 08:04:05 +00:00
|
|
|
fun adjustDiamond(adjustNum: Int): Boolean {
|
2025-12-24 10:34:10 +00:00
|
|
|
if (adjustNum < 0L && Math.abs(adjustNum) > getDiamond()) {
|
2025-12-24 08:04:05 +00:00
|
|
|
return false
|
2025-12-15 09:30:16 +00:00
|
|
|
}
|
2025-12-24 08:04:05 +00:00
|
|
|
mAccount.diamondCount += adjustNum
|
|
|
|
|
saveAccountInfo()
|
|
|
|
|
NotifyMan.instance().sendEvent(VididinEvents.Event_Account_Diamond_Changed, null)
|
|
|
|
|
return true
|
2025-11-27 06:43:33 +00:00
|
|
|
}
|
2025-11-25 10:23:37 +00:00
|
|
|
|
2025-12-24 08:04:05 +00:00
|
|
|
//------------------------- 3个数值相关属性 增减 End --------------------------//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-27 08:30:33 +00:00
|
|
|
fun getBankInfo(): BankInfo? {
|
|
|
|
|
return mAccount?.bankInfo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun hasValidBankInfo(): Boolean {
|
|
|
|
|
val backInfo = getBankInfo()
|
|
|
|
|
return !backInfo?.bankName.isNullOrEmpty() && !backInfo.bankAccount.isNullOrEmpty()
|
|
|
|
|
}
|
2025-11-25 10:23:37 +00:00
|
|
|
|
2025-11-27 09:11:56 +00:00
|
|
|
fun saveBankAccount(bankAccount: String?) {
|
|
|
|
|
if (bankAccount.isNullOrEmpty()) {
|
2025-12-26 09:49:39 +00:00
|
|
|
mAccount.bankInfo = null
|
2025-11-27 09:11:56 +00:00
|
|
|
} else {
|
2025-12-26 09:49:39 +00:00
|
|
|
mAccount.bankInfo = BankInfo(bankAccount=bankAccount)
|
2025-11-27 09:11:56 +00:00
|
|
|
}
|
2025-11-27 09:07:30 +00:00
|
|
|
saveAccountInfo()
|
|
|
|
|
NotifyMan.instance().sendEvent(
|
2025-12-26 09:49:39 +00:00
|
|
|
VididinEvents.EVENT_BANK_INFO_CHANGED, NotifyMan.NotifyData(bankAccount))
|
2025-11-27 09:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-01 11:26:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@Synchronized
|
|
|
|
|
fun convertGold2Cash(): Boolean {
|
|
|
|
|
try {
|
2025-12-24 08:04:05 +00:00
|
|
|
val couldCovertCashTotal = getGold().div(VidiConst.PER_01CASH_COST_GOLD_NUM) ?: 0
|
2025-12-01 11:26:14 +00:00
|
|
|
if (couldCovertCashTotal > 0) {
|
2025-12-16 10:08:11 +00:00
|
|
|
val costGoldNum = couldCovertCashTotal * VidiConst.PER_01CASH_COST_GOLD_NUM
|
2025-12-24 08:04:05 +00:00
|
|
|
if (getGold() >= costGoldNum) {
|
2025-12-24 09:12:21 +00:00
|
|
|
adjustGold(-1L * costGoldNum.toInt(), RecordGold(RECORD_GOLD_MINUS_CONVERT_2_CASH, -1L * costGoldNum.toInt()))
|
2025-12-29 05:48:09 +00:00
|
|
|
val adjustCashNum = couldCovertCashTotal * 0.1
|
2026-01-07 04:01:38 +00:00
|
|
|
adjustCash(adjustCashNum, RecordCash(RECORD_CASH_PLUS_GOLD_CONVERT, adjustCashNum.toDouble()))
|
2026-01-12 05:37:53 +00:00
|
|
|
AndroidUtil.showCustomToast(String.format(ResUtil.getString(R.string.has_claim_box_cash_hint), adjustCashNum))
|
2025-12-24 08:04:05 +00:00
|
|
|
return true
|
2025-12-01 11:26:14 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2026-01-12 05:44:38 +00:00
|
|
|
AndroidUtil.showToast(ResUtil.getString(R.string.not_enough_gold))
|
2025-12-01 11:26:14 +00:00
|
|
|
}
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-08 07:12:53 +00:00
|
|
|
fun saveUserIdInfo(userId: Int) {
|
|
|
|
|
mAccount?.let {
|
|
|
|
|
it.userId = userId
|
|
|
|
|
saveAccountInfo()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-15 05:44:00 +00:00
|
|
|
fun isBankAccountExist(): Boolean {
|
|
|
|
|
return !mAccount?.bankInfo?.bankAccount.isNullOrEmpty()
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-23 09:08:13 +00:00
|
|
|
|
2025-12-09 03:53:33 +00:00
|
|
|
|
2025-11-25 10:23:37 +00:00
|
|
|
}
|
|
|
|
|
|