Commit ede7a417 authored by Dostonbek Ibragimov's avatar Dostonbek Ibragimov 💻

[REF] refactoring monitoring adapter

parent 5f3765fd
package uz.mobiuz.mobiservice.dev.ui.global
import android.annotation.SuppressLint
import java.text.SimpleDateFormat
object CONSTANTS {
const val IS_SAVED_CARD = 1
......@@ -86,7 +89,6 @@ object CONSTANTS {
const val CONFIRM_CHANGE_NEW_PIN = "CONFIRM_CHANGE_NEW_PIN"
//urls
const val API_LOGIN = "customer/login"
const val API_REGISTER = "customer/register"
......@@ -111,4 +113,8 @@ object CONSTANTS {
const val PAY_SAVE_CARD = "PAYMENT_SAVE_CARD"
const val PAY_CARD_NUMBER = "PAYMENT_CARD_NUMBER"
const val PAY_MONITORING = "PAY_MONITORING"
@SuppressLint("SimpleDateFormat")
val DATE_FORMAT = SimpleDateFormat("dd-MM-yyyy")
val HOUR_FORMAT = SimpleDateFormat("hh:mm")
}
......@@ -9,6 +9,7 @@ import kotlinx.android.synthetic.main.item_history_header.view.*
import uz.agr.mobiuz.model.Tuple2
import uz.agr.sdk.coreui.extension.inflate
import uz.mobiuz.mobiservice.dev.R
import uz.mobiuz.mobiservice.dev.utils.extensions.getDate
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*
......@@ -31,7 +32,7 @@ class HistoryHeaderDelegate : AdapterDelegate<MutableList<Any>>() {
@SuppressLint("SetTextI18n")
fun bind(header: Tuple2) {
try {
containerView.tvTitle.text = header.first
containerView.tvTitle.text = header.first.getDate(context = containerView.context)
if (header.second.isNotEmpty() && header.second.length > 4) {
if (header.second != "0") {
if (header.second[0] == '-') {
......
......@@ -10,6 +10,9 @@ import uz.agr.sdk.coreui.ui.history.DividerItem
import uz.agr.sdk.coreui.ui.list.ProgressAdapterDelegate
import uz.agr.sdk.coreui.ui.list.ProgressItem
import uz.mobiuz.mobiservice.dev.model.Monitoring
import uz.mobiuz.mobiservice.dev.ui.global.CONSTANTS
import java.util.*
import kotlin.collections.HashMap
class MonitoringAdapter : ListDelegationAdapter<MutableList<Any>>() {
......@@ -32,29 +35,31 @@ class MonitoringAdapter : ListDelegationAdapter<MutableList<Any>>() {
val hashMap = HashMap<String, String>()
for (item in historyList) {
val it = hashMap[item.date.toString()]
val todayDate = CONSTANTS.DATE_FORMAT.format((Date(item.date)))
val it = hashMap[todayDate]
summa -= item.amount
if (it != null) {
val i = (it.toLong() + summa).toString()
hashMap[item.date.toString()] = i
hashMap[todayDate] = i
} else {
hashMap[item.date.toString()] = "$summa"
hashMap[todayDate] = "$summa"
}
summa = 0
}
var tempDate = ""
for (item in historyList) {
if (tempDate != item.date.toString()) {
val todayDate = CONSTANTS.DATE_FORMAT.format((Date(item.date)))
if (tempDate != todayDate) {
items.add(DividerItem())
val value = hashMap[item.date.toString()]
val value = hashMap[todayDate]
items.add(
Tuple2(
item.date.toString(),
todayDate,
((value?.replaceRange(value.length - 2, value.length, "") ?: "0").toInt() * 100).formattedMoney(false) + " UZS"
)
)
tempDate = item.date.toString()
tempDate = todayDate
}
items.add(item)
}
......
......@@ -11,6 +11,7 @@ import uz.agr.sdk.coreui.extension.formattedMoney
import uz.agr.sdk.coreui.extension.inflate
import uz.mobiuz.mobiservice.dev.R
import uz.mobiuz.mobiservice.dev.model.Monitoring
import uz.mobiuz.mobiservice.dev.ui.global.CONSTANTS
import uz.mobiuz.mobiservice.dev.utils.extensions.formatPhone
import java.text.SimpleDateFormat
import java.util.*
......@@ -40,7 +41,7 @@ class MonitoringDelegate : AdapterDelegate<MutableList<Any>>() {
containerView.cardPan.text = history.pan.formatCard1()
containerView.tvAmount.text = "- " + (history.amount * 100).formattedMoney(false) + " " + itemView.context.getString(R.string.agr_mobi_uz_curr)
// val date = timeFormat.format(history.date)
val date = history.date.toString()
val date = CONSTANTS.HOUR_FORMAT.format((Date(history.date)))
containerView.tvTime.text = date
containerView.tvTransType.text = history.phone.formatPhone()
}
......
package uz.mobiuz.mobiservice.dev.utils.extensions
import android.content.Context
import uz.agr.mobiuz.R
import java.text.SimpleDateFormat
/**
* Created by DostonbekIbragimov on 07/01/2022.
*/
fun String.getDate(context: Context): String {
val day = SimpleDateFormat("dd").format(this)
val month = SimpleDateFormat("MM").format(this)
val year = SimpleDateFormat("yyyy").format(this)
return "${day.toInt()} ${getMonth(month.toInt(), context)} $year"
}
fun getMonth(month: Int, context: Context): String {
return when (month) {
1 -> context.getString(R.string.agr_mobi_uz_month_1)
2 -> context.getString(R.string.agr_mobi_uz_month_2)
3 -> context.getString(R.string.agr_mobi_uz_month_3)
4 -> context.getString(R.string.agr_mobi_uz_month_4)
5 -> context.getString(R.string.agr_mobi_uz_month_5)
6 -> context.getString(R.string.agr_mobi_uz_month_6)
7 -> context.getString(R.string.agr_mobi_uz_month_7)
8 -> context.getString(R.string.agr_mobi_uz_month_8)
9 -> context.getString(R.string.agr_mobi_uz_month_9)
10 -> context.getString(R.string.agr_mobi_uz_month_10)
11 -> context.getString(R.string.agr_mobi_uz_month_11)
else -> context.getString(R.string.agr_mobi_uz_month_12)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment