Deduplicate card history entries
This commit is contained in:
@ -39,6 +39,7 @@ public class MandiriEmoneyApi : UnifiedNfcApi {
|
||||
debugLog(response.getData().hexEncodedString())
|
||||
let balance = response.getData().hexEncodedString().subString(from: 0, to: 8)
|
||||
self.emoney.setBalance(self.getRealBalance(reverseHexa: balance))
|
||||
self.resetHistoryState()
|
||||
// self.updateScreen()
|
||||
if (self.cardType! == 131){
|
||||
self.getLogStep01(index: self.start)
|
||||
@ -64,7 +65,7 @@ public class MandiriEmoneyApi : UnifiedNfcApi {
|
||||
} else {
|
||||
self.parseNewLog()
|
||||
self.start = 0
|
||||
self.riwayatList = self.riwayatList.sorted(by: { $0.getTransationTime()?.compare($1.getTransationTime()!) == .orderedDescending })
|
||||
self.finalizeHistory()
|
||||
self.emoney.setRiwayatList(self.riwayatList)
|
||||
self.emoney.setTampilRiwayat(true)
|
||||
self.updateScreen()
|
||||
@ -74,7 +75,7 @@ public class MandiriEmoneyApi : UnifiedNfcApi {
|
||||
} else {
|
||||
self.parseNewLog()
|
||||
self.start = 0
|
||||
self.riwayatList = self.riwayatList.sorted(by: { $0.getTransationTime()?.compare($1.getTransationTime()!) == .orderedDescending })
|
||||
self.finalizeHistory()
|
||||
self.emoney.setRiwayatList(self.riwayatList)
|
||||
self.emoney.setTampilRiwayat(true)
|
||||
self.updateScreen()
|
||||
@ -125,7 +126,7 @@ public class MandiriEmoneyApi : UnifiedNfcApi {
|
||||
} else {
|
||||
self.parseOldLog()
|
||||
self.start = 0
|
||||
self.riwayatList = self.riwayatList.sorted(by: { $0.getTransationTime()?.compare($1.getTransationTime()!) == .orderedDescending })
|
||||
self.finalizeHistory()
|
||||
self.emoney.setRiwayatList(self.riwayatList)
|
||||
self.emoney.setTampilRiwayat(true)
|
||||
self.updateScreen()
|
||||
@ -135,7 +136,7 @@ public class MandiriEmoneyApi : UnifiedNfcApi {
|
||||
} else {
|
||||
self.parseOldLog()
|
||||
self.start = 0
|
||||
self.riwayatList = self.riwayatList.sorted(by: { $0.getTransationTime()?.compare($1.getTransationTime()!) == .orderedDescending })
|
||||
self.finalizeHistory()
|
||||
self.emoney.setRiwayatList(self.riwayatList)
|
||||
self.emoney.setTampilRiwayat(true)
|
||||
self.updateScreen()
|
||||
@ -198,6 +199,16 @@ public class MandiriEmoneyApi : UnifiedNfcApi {
|
||||
self.apduRunner.callback?.complete(emoney: self.emoney)
|
||||
}
|
||||
}
|
||||
|
||||
private func resetHistoryState() {
|
||||
riwayatList.removeAll()
|
||||
mapv1 = ""
|
||||
start = 0
|
||||
}
|
||||
|
||||
private func finalizeHistory() {
|
||||
riwayatList = riwayatList.sorted(by: { $0.getTransationTime()?.compare($1.getTransationTime()!) == .orderedDescending })
|
||||
}
|
||||
|
||||
func riwayatCard(_ bArr: [UInt8]) -> RiwayatCard? {
|
||||
var str: String
|
||||
|
||||
@ -668,7 +668,7 @@ extension HomeViewController: ApduCallback {
|
||||
self.updateCardNumberDisplay()
|
||||
|
||||
if (emoney.isTampilRiwayat()){
|
||||
let riwayat = emoney.getRiwayatList()
|
||||
let riwayat = self.deduplicateHistory(emoney.getRiwayatList())
|
||||
if let first = riwayat.first {
|
||||
let dateFmt = DateFormatter()
|
||||
dateFmt.dateFormat = "dd MMM yyyy, HH:mm"
|
||||
@ -707,6 +707,22 @@ private extension HomeViewController {
|
||||
formatter.minimumFractionDigits = 0
|
||||
return formatter
|
||||
}()
|
||||
|
||||
func deduplicateHistory(_ items: [RiwayatCard]) -> [RiwayatCard] {
|
||||
var seen = Set<String>()
|
||||
return items.filter { item in
|
||||
let key = historyKey(for: item)
|
||||
return seen.insert(key).inserted
|
||||
}
|
||||
}
|
||||
|
||||
func historyKey(for item: RiwayatCard) -> String {
|
||||
let timestamp = item.getTransationTime()?.timeIntervalSince1970 ?? 0
|
||||
let locationId = item.getLocationId() ?? ""
|
||||
let locationName = item.getLocationName() ?? ""
|
||||
let title = item.getTitle() ?? ""
|
||||
return "\(timestamp)|\(item.getAmount())|\(item.getProsesTipe())|\(locationId)|\(locationName)|\(title)"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UILabel letter spacing helper
|
||||
|
||||
Reference in New Issue
Block a user