三种记录manager 定义及存取方法
This commit is contained in:
parent
3b4e8522ec
commit
3a3a7c10bd
|
|
@ -2,14 +2,14 @@ package com.gamedog.vididin.beans
|
||||||
|
|
||||||
data class RecordCash(
|
data class RecordCash(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val dateTime: String,
|
val dateTime: Long,
|
||||||
val status: TransactionStatus,
|
val status: TransactionStatus,
|
||||||
val statusText: String,
|
val statusText: String,
|
||||||
val description: String,
|
val description: String,
|
||||||
val amount: String,
|
val amount: String,
|
||||||
val amountColor: Int
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
enum class TransactionStatus {
|
enum class TransactionStatus {
|
||||||
SUCCESS, FAILED, PROCESSING, REDEEM
|
SUCCESS, FAILED, PROCESSING, REDEEM
|
||||||
}
|
}
|
||||||
|
|
@ -2,11 +2,10 @@ package com.gamedog.vididin.beans
|
||||||
|
|
||||||
data class RecordGold(
|
data class RecordGold(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val dateTime: String,
|
val dateTime: Long,
|
||||||
val status: TransactionStatus,
|
val status: TransactionStatus,
|
||||||
val statusText: String,
|
val statusText: String,
|
||||||
val description: String,
|
val description: String,
|
||||||
val amount: String,
|
val amount: String,
|
||||||
val amountColor: Int
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.gamedog.vididin.beans
|
||||||
|
|
||||||
|
data class RecordZero(
|
||||||
|
val id: Long,
|
||||||
|
val dateTime: Long,
|
||||||
|
val status: TransactionStatus,
|
||||||
|
val statusText: String,
|
||||||
|
val description: String,
|
||||||
|
val amount: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
@ -7,6 +7,7 @@ import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.ListAdapter
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.gamedog.vididin.beans.RecordCash
|
import com.gamedog.vididin.beans.RecordCash
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
import com.vididin.real.money.game.databinding.FragmentWithdrawRecordCashItemBinding as ViewBinding
|
import com.vididin.real.money.game.databinding.FragmentWithdrawRecordCashItemBinding as ViewBinding
|
||||||
|
|
||||||
class RecordCashRvAdapter : ListAdapter<RecordCash, RecordCashRvAdapter.ViewHolder>(DiffCallback()) {
|
class RecordCashRvAdapter : ListAdapter<RecordCash, RecordCashRvAdapter.ViewHolder>(DiffCallback()) {
|
||||||
|
|
@ -22,12 +23,11 @@ class RecordCashRvAdapter : ListAdapter<RecordCash, RecordCashRvAdapter.ViewHold
|
||||||
|
|
||||||
inner class ViewHolder(private val binding: ViewBinding) : RecyclerView.ViewHolder(binding.root) {
|
inner class ViewHolder(private val binding: ViewBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||||
fun bind(transaction: RecordCash) {
|
fun bind(transaction: RecordCash) {
|
||||||
binding.tvDate.text = transaction.dateTime
|
binding.tvDate.text = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(transaction.dateTime)
|
||||||
binding.tvTitle.text = transaction.statusText
|
binding.tvTitle.text = transaction.statusText
|
||||||
binding.tvDescription.text = transaction.description
|
binding.tvDescription.text = transaction.description
|
||||||
binding.tvAmount.text = transaction.amount
|
binding.tvAmount.text = transaction.amount
|
||||||
binding.tvAmount.setTextColor(ContextCompat.getColor(binding.root.context, transaction.amountColor))
|
binding.tvAmount.setTextColor(ContextCompat.getColor(binding.root.context, transaction.amountColor))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.ListAdapter
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.gamedog.vididin.beans.RecordGold
|
import com.gamedog.vididin.beans.RecordGold
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
import com.vididin.real.money.game.databinding.FragmentWithdrawRecordGoldItemBinding as ViewBinding
|
import com.vididin.real.money.game.databinding.FragmentWithdrawRecordGoldItemBinding as ViewBinding
|
||||||
|
|
||||||
class RecordGoldRvAdapter : ListAdapter<RecordGold, RecordGoldRvAdapter.ViewHolder>(DiffCallback()) {
|
class RecordGoldRvAdapter : ListAdapter<RecordGold, RecordGoldRvAdapter.ViewHolder>(DiffCallback()) {
|
||||||
|
|
@ -22,7 +23,7 @@ class RecordGoldRvAdapter : ListAdapter<RecordGold, RecordGoldRvAdapter.ViewHold
|
||||||
|
|
||||||
inner class ViewHolder(private val binding: ViewBinding) : RecyclerView.ViewHolder(binding.root) {
|
inner class ViewHolder(private val binding: ViewBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||||
fun bind(transaction: RecordGold) {
|
fun bind(transaction: RecordGold) {
|
||||||
binding.tvDate.text = transaction.dateTime
|
binding.tvDate.text = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(transaction.dateTime)
|
||||||
binding.tvTitle.text = transaction.statusText
|
binding.tvTitle.text = transaction.statusText
|
||||||
binding.tvDescription.text = transaction.description
|
binding.tvDescription.text = transaction.description
|
||||||
binding.tvAmount.text = transaction.amount
|
binding.tvAmount.text = transaction.amount
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,150 @@
|
||||||
|
package com.gamedog.vididin.manager
|
||||||
|
|
||||||
|
import com.ama.core.architecture.util.SpUtil
|
||||||
|
import com.gamedog.vididin.beans.RecordCash
|
||||||
|
import com.gamedog.vididin.beans.RecordGold
|
||||||
|
import com.gamedog.vididin.beans.RecordZero
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import java.util.concurrent.locks.ReentrantLock
|
||||||
|
|
||||||
|
|
||||||
|
class RecordsManager private constructor() {
|
||||||
|
private val mCashHelper by lazy { CashRecordHelper() }
|
||||||
|
private val mGoldHelper by lazy { GoldRecordHelper() }
|
||||||
|
private val mZeroHelper by lazy { ZeroRecordHelper() }
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@Volatile
|
||||||
|
private var instance: RecordsManager? = null
|
||||||
|
|
||||||
|
fun instance(): RecordsManager {
|
||||||
|
return instance ?: synchronized(this) {
|
||||||
|
instance ?: RecordsManager().also {
|
||||||
|
instance = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun appendCashRecord(newRecord: RecordCash) {
|
||||||
|
mCashHelper.addRecord(newRecord)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun appendGoldRecord(newRecord: RecordGold) {
|
||||||
|
mGoldHelper.addRecord(newRecord)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun appendZeroRecord(newRecord: RecordZero) {
|
||||||
|
mZeroHelper.addRecord(newRecord)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getCashRecords() : List<RecordCash> {
|
||||||
|
return mCashHelper.getRecordList()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getGoldRecords() : List<RecordGold> {
|
||||||
|
return mGoldHelper.getRecordList()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getZeroRecords() : List<RecordZero> {
|
||||||
|
return mZeroHelper.getRecordList()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class CashRecordHelper() : BaseRecordHelper<RecordCash>() {
|
||||||
|
override val mSpKey = SpUtil.KEY_RECORD_CASH
|
||||||
|
override suspend fun loadRecordsFromSp(): List<RecordCash> {
|
||||||
|
return SpUtil.instance().getList<RecordCash>(mSpKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
// Record 类型
|
||||||
|
const val RECORD_CASH_PLUS_GOLD_CONVERT: Int = 1
|
||||||
|
const val RECORD_CASH_PLUS_NEWBIE_GIFT: Int = 2
|
||||||
|
const val RECORD_CASH_PLUS_BOX_TASK: Int = 3
|
||||||
|
const val RECORD_CASH_MINUS_WITHDRAW_SMALL: Int = 4
|
||||||
|
const val RECORD_CASH_MINUS_WITHDRAW_BIG: Int = 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GoldRecordHelper() : BaseRecordHelper<RecordGold>() {
|
||||||
|
override val mSpKey = SpUtil.KEY_RECORD_GOLD
|
||||||
|
override suspend fun loadRecordsFromSp(): List<RecordGold> {
|
||||||
|
return SpUtil.instance().getList<RecordGold>(mSpKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
// Record 类型
|
||||||
|
const val RECORD_GOLD_PLUS_WATCH_VIDEO: Int = 1
|
||||||
|
const val RECORD_GOLD_PLUS_WATCH_REWARD_AD: Int = 2
|
||||||
|
const val RECORD_GOLD_PLUS_TASK_NEWBIE: Int = 3
|
||||||
|
const val RECORD_GOLD_PLUS_TASK_DAILY: Int = 3
|
||||||
|
const val RECORD_GOLD_PLUS_TASK_BOX: Int = 3
|
||||||
|
const val RECORD_GOLD_MINUS_CONVERT_2_CASH: Int = 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ZeroRecordHelper() : BaseRecordHelper<RecordZero>() {
|
||||||
|
override val mSpKey = SpUtil.KEY_RECORD_ZERO
|
||||||
|
override suspend fun loadRecordsFromSp(): List<RecordZero> {
|
||||||
|
return SpUtil.instance().getList<RecordZero>(mSpKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
abstract class BaseRecordHelper<T> {
|
||||||
|
abstract val mSpKey: String
|
||||||
|
private val mbgScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||||
|
private val mRecordLocker = ReentrantLock()
|
||||||
|
private lateinit var mRecordList: MutableList<T>
|
||||||
|
|
||||||
|
|
||||||
|
init {
|
||||||
|
mbgScope.launch {
|
||||||
|
mRecordList = loadRecordsFromSp().toMutableList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract suspend fun loadRecordsFromSp() : List<T>
|
||||||
|
|
||||||
|
|
||||||
|
fun getRecordList(): List<T> {
|
||||||
|
return mRecordList.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveRecordList() {
|
||||||
|
mbgScope.launch {
|
||||||
|
try {
|
||||||
|
mRecordLocker.lock()
|
||||||
|
SpUtil.instance().putList(mSpKey, mRecordList)
|
||||||
|
} finally {
|
||||||
|
mRecordLocker.unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addRecord(dataBean: T) {
|
||||||
|
mbgScope.launch {
|
||||||
|
try {
|
||||||
|
mRecordLocker.lock()
|
||||||
|
mRecordList.add(dataBean)
|
||||||
|
saveRecordList()
|
||||||
|
} finally {
|
||||||
|
mRecordLocker.unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,27 +1,27 @@
|
||||||
package com.ama.core.architecture.util
|
package com.ama.core.architecture.util
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Rect
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.Base64
|
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
|
import android.view.PixelCopy
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.Window
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.GravityInt
|
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import com.ama.core.architecture.BaseApp
|
|
||||||
import kotlin.random.Random
|
|
||||||
import androidx.core.graphics.createBitmap
|
import androidx.core.graphics.createBitmap
|
||||||
|
import com.ama.core.architecture.BaseApp
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import java.nio.charset.Charset
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
|
||||||
class AndroidUtil private constructor() {
|
class AndroidUtil private constructor() {
|
||||||
|
|
@ -126,6 +126,24 @@ class AndroidUtil private constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun captureView(window: Window, targetView: View, callback: (Bitmap?) -> Unit) {
|
||||||
|
val location = IntArray(2)
|
||||||
|
targetView.getLocationInWindow(location)
|
||||||
|
val (x, y) = location
|
||||||
|
val rect = Rect(x, y, x + targetView.width, y + targetView.height)
|
||||||
|
|
||||||
|
val destBitmap = Bitmap.createBitmap(targetView.width, targetView.height, Bitmap.Config.ARGB_8888)
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
PixelCopy.request(window, rect, destBitmap, { copyResult ->
|
||||||
|
if (copyResult == PixelCopy.SUCCESS) {
|
||||||
|
callback(destBitmap)
|
||||||
|
} else {
|
||||||
|
callback(null)
|
||||||
|
}
|
||||||
|
}, Handler(Looper.getMainLooper()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getThumbOfView2(targetView: View): Bitmap {
|
fun getThumbOfView2(targetView: View): Bitmap {
|
||||||
if (targetView.width <= 0 || targetView.height <= 0) {
|
if (targetView.width <= 0 || targetView.height <= 0) {
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,10 @@ class SpUtil private constructor(spFileName: String) {
|
||||||
const val KEY_HAS_REQUEST_NOTIFICATION_PERMISSION = "KEY_HAS_REQUEST_NOTIFICATION_PERMISSION"
|
const val KEY_HAS_REQUEST_NOTIFICATION_PERMISSION = "KEY_HAS_REQUEST_NOTIFICATION_PERMISSION"
|
||||||
|
|
||||||
|
|
||||||
|
const val KEY_RECORD_CASH = "KEY_RECORD_CASH"
|
||||||
|
const val KEY_RECORD_GOLD = "KEY_RECORD_GOLD"
|
||||||
|
const val KEY_RECORD_ZERO = "KEY_RECORD_ZERO"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue