Added formatToShortDate() and formatToMediumDate() to BankingPresenter to have a common place for formatting dates

This commit is contained in:
dankito 2020-09-27 02:56:11 +02:00
parent 77a4273179
commit 8df816c091
6 changed files with 20 additions and 31 deletions

View File

@ -10,16 +10,11 @@ import net.dankito.banking.ui.model.IAccountTransaction
import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.banking.ui.presenter.BankingPresenter
import net.dankito.utils.android.extensions.asActivity import net.dankito.utils.android.extensions.asActivity
import net.dankito.utils.android.ui.adapter.ListRecyclerAdapter import net.dankito.utils.android.ui.adapter.ListRecyclerAdapter
import java.text.DateFormat
open class AccountTransactionAdapter(protected val presenter: BankingPresenter) open class AccountTransactionAdapter(protected val presenter: BankingPresenter)
: ListRecyclerAdapter<IAccountTransaction, AccountTransactionViewHolder>() { : ListRecyclerAdapter<IAccountTransaction, AccountTransactionViewHolder>() {
companion object {
val ValueDateFormat = DateFormat.getDateInstance(DateFormat.SHORT)
}
var selectedTransaction: IAccountTransaction? = null var selectedTransaction: IAccountTransaction? = null
@ -35,7 +30,7 @@ open class AccountTransactionAdapter(protected val presenter: BankingPresenter)
} }
override fun bindItemToView(viewHolder: AccountTransactionViewHolder, item: IAccountTransaction) { override fun bindItemToView(viewHolder: AccountTransactionViewHolder, item: IAccountTransaction) {
viewHolder.txtvwDate.text = ValueDateFormat.format(item.valueDate) viewHolder.txtvwDate.text = presenter.formatToShortDate(item.valueDate)
val label = if (item.showOtherPartyName) item.otherPartyName else item.bookingText val label = if (item.showOtherPartyName) item.otherPartyName else item.bookingText
viewHolder.txtvwTransactionLabel.text = label ?: item.bookingText ?: "" viewHolder.txtvwTransactionLabel.text = label ?: item.bookingText ?: ""

View File

@ -26,7 +26,6 @@ import net.dankito.banking.ui.model.responses.GetTransactionsResponse
import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.banking.ui.presenter.BankingPresenter
import net.dankito.utils.android.extensions.asActivity import net.dankito.utils.android.extensions.asActivity
import net.dankito.utils.multiplatform.sum import net.dankito.utils.multiplatform.sum
import java.text.DateFormat
import javax.inject.Inject import javax.inject.Inject
@ -36,8 +35,6 @@ class HomeFragment : Fragment() {
val TransactionsCannotBeRetrievedStates = listOf(TransactionsRetrievalState.AccountTypeNotSupported, TransactionsRetrievalState.AccountDoesNotSupportFetchingTransactions) val TransactionsCannotBeRetrievedStates = listOf(TransactionsRetrievalState.AccountTypeNotSupported, TransactionsRetrievalState.AccountDoesNotSupportFetchingTransactions)
val RetrievedTransactionsPeriodDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM)
} }
@ -284,8 +281,8 @@ class HomeFragment : Fragment() {
TransactionsRetrievalState.AccountDoesNotSupportFetchingTransactions -> R.string.fragment_home_transactions_retrieval_state_account_does_not_support_retrieving_transactions TransactionsRetrievalState.AccountDoesNotSupportFetchingTransactions -> R.string.fragment_home_transactions_retrieval_state_account_does_not_support_retrieving_transactions
TransactionsRetrievalState.NoTransactionsInRetrievedPeriod -> { TransactionsRetrievalState.NoTransactionsInRetrievedPeriod -> {
val account = presenter.selectedAccounts.first() val account = presenter.selectedAccounts.first()
account.retrievedTransactionsFromOn?.let { messageArgs.add(RetrievedTransactionsPeriodDateFormat.format(it)) } account.retrievedTransactionsFromOn?.let { messageArgs.add(presenter.formatToMediumDate(it)) }
account.retrievedTransactionsUpTo?.let { messageArgs.add(RetrievedTransactionsPeriodDateFormat.format(it)) } account.retrievedTransactionsUpTo?.let { messageArgs.add(presenter.formatToMediumDate(it)) }
R.string.fragment_home_transactions_retrieval_state_no_transactions_in_retrieved_period R.string.fragment_home_transactions_retrieval_state_no_transactions_in_retrieved_period
} }
TransactionsRetrievalState.NeverRetrievedTransactions -> R.string.fragment_home_transactions_retrieval_state_never_retrieved_transactions TransactionsRetrievalState.NeverRetrievedTransactions -> R.string.fragment_home_transactions_retrieval_state_never_retrieved_transactions

View File

@ -16,7 +16,6 @@ import net.dankito.banking.ui.presenter.BankingPresenter
import net.dankito.utils.javafx.ui.extensions.ensureOnlyUsesSpaceIfVisible import net.dankito.utils.javafx.ui.extensions.ensureOnlyUsesSpaceIfVisible
import tornadofx.* import tornadofx.*
import tornadofx.FX.Companion.messages import tornadofx.FX.Companion.messages
import java.text.DateFormat
open class AccountTransactionsTable @JvmOverloads constructor( open class AccountTransactionsTable @JvmOverloads constructor(
@ -26,8 +25,6 @@ open class AccountTransactionsTable @JvmOverloads constructor(
companion object { companion object {
val ValueDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM)
private val LabelMargin = Insets(4.0, 0.0, 4.0, 4.0) private val LabelMargin = Insets(4.0, 0.0, 4.0, 4.0)
} }
@ -42,7 +39,7 @@ open class AccountTransactionsTable @JvmOverloads constructor(
prefWidth = 115.0 prefWidth = 115.0
cellFormat { cellFormat {
text = ValueDateFormat.format(it) text = presenter.formatToMediumDate(it)
alignment = Pos.CENTER_LEFT alignment = Pos.CENTER_LEFT
paddingLeft = 4.0 paddingLeft = 4.0
} }

View File

@ -59,6 +59,10 @@ open class BankingPresenter(
protected const val OneDayMillis = 24 * 60 * 60 * 1000L protected const val OneDayMillis = 24 * 60 * 60 * 1000L
protected val ShortDateStyleDateFormatter = DateFormatter(DateFormatStyle.Short)
protected val MediumDateStyleDateFormatter = DateFormatter(DateFormatStyle.Medium)
protected val MessageLogEntryDateFormatter = DateFormatter("yyyy.MM.dd HH:mm:ss.SSS") protected val MessageLogEntryDateFormatter = DateFormatter("yyyy.MM.dd HH:mm:ss.SSS")
private val log = LoggerFactory.getLogger(BankingPresenter::class) private val log = LoggerFactory.getLogger(BankingPresenter::class)
@ -430,6 +434,15 @@ open class BankingPresenter(
} }
open fun formatToShortDate(date: Date): String {
return ShortDateStyleDateFormatter.format(date)
}
open fun formatToMediumDate(date: Date): String {
return MediumDateStyleDateFormatter.format(date)
}
open fun allBanksUpdated() { open fun allBanksUpdated() {
allBanks.forEach { bank -> allBanks.forEach { bank ->
bankDisplayIndexUpdated(bank) bankDisplayIndexUpdated(bank)

View File

@ -6,8 +6,6 @@ struct AccountTransactionsDialog: View {
static private let HideTopFetchAllTransactionsViewButtonWidth: CGFloat = 34 static private let HideTopFetchAllTransactionsViewButtonWidth: CGFloat = 34
static private let RetrievedTransactionsPeriodDateFormat = DateFormatter()
private let title: String private let title: String
@ -75,8 +73,6 @@ struct AccountTransactionsDialog: View {
self.title = title self.title = title
self.showBankIcons = showBankIcons self.showBankIcons = showBankIcons
Self.RetrievedTransactionsPeriodDateFormat.dateStyle = .medium
} }
@ -271,8 +267,8 @@ struct AccountTransactionsDialog: View {
} }
private func mapDate(_ date: CommonDate?) -> String { private func mapDate(_ date: CommonDate?) -> String {
if let date = date?.date { if let date = date {
return Self.RetrievedTransactionsPeriodDateFormat.string(from: date) return presenter.formatToMediumDate(date: date)
} }
return "" return ""

View File

@ -4,15 +4,6 @@ import BankingUiSwift
struct AccountTransactionListItem: View { struct AccountTransactionListItem: View {
private static var ValueDateFormat: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .short
return formatter
}()
private let transaction: IAccountTransaction private let transaction: IAccountTransaction
private let areMoreThanOneBanksTransactionsDisplayed: Bool private let areMoreThanOneBanksTransactionsDisplayed: Bool
@ -56,7 +47,7 @@ struct AccountTransactionListItem: View {
Spacer() Spacer()
Text(Self.ValueDateFormat.string(from: transaction.valueDate.date)) Text(presenter.formatToShortDate(date: transaction.valueDate))
.styleAsDetail() .styleAsDetail()
} }
} }