From 8df816c091549d3f89e9a2ce31c3e9e08f709f4e Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 27 Sep 2020 02:56:11 +0200 Subject: [PATCH] Added formatToShortDate() and formatToMediumDate() to BankingPresenter to have a common place for formatting dates --- .../ui/android/adapter/AccountTransactionAdapter.kt | 7 +------ .../dankito/banking/ui/android/home/HomeFragment.kt | 7 ++----- .../ui/javafx/controls/AccountTransactionsTable.kt | 5 +---- .../banking/ui/presenter/BankingPresenter.kt | 13 +++++++++++++ .../ui/dialogs/AccountTransactionsDialog.swift | 8 ++------ .../listitems/AccountTransactionListItem.swift | 11 +---------- 6 files changed, 20 insertions(+), 31 deletions(-) diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/AccountTransactionAdapter.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/AccountTransactionAdapter.kt index b47bc5db..58547283 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/AccountTransactionAdapter.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/AccountTransactionAdapter.kt @@ -10,16 +10,11 @@ import net.dankito.banking.ui.model.IAccountTransaction import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.utils.android.extensions.asActivity import net.dankito.utils.android.ui.adapter.ListRecyclerAdapter -import java.text.DateFormat open class AccountTransactionAdapter(protected val presenter: BankingPresenter) : ListRecyclerAdapter() { - companion object { - val ValueDateFormat = DateFormat.getDateInstance(DateFormat.SHORT) - } - var selectedTransaction: IAccountTransaction? = null @@ -35,7 +30,7 @@ open class AccountTransactionAdapter(protected val presenter: BankingPresenter) } 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 viewHolder.txtvwTransactionLabel.text = label ?: item.bookingText ?: "" diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt index f026c736..1458d1ef 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt @@ -26,7 +26,6 @@ import net.dankito.banking.ui.model.responses.GetTransactionsResponse import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.utils.android.extensions.asActivity import net.dankito.utils.multiplatform.sum -import java.text.DateFormat import javax.inject.Inject @@ -36,8 +35,6 @@ class HomeFragment : Fragment() { 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.NoTransactionsInRetrievedPeriod -> { val account = presenter.selectedAccounts.first() - account.retrievedTransactionsFromOn?.let { messageArgs.add(RetrievedTransactionsPeriodDateFormat.format(it)) } - account.retrievedTransactionsUpTo?.let { messageArgs.add(RetrievedTransactionsPeriodDateFormat.format(it)) } + account.retrievedTransactionsFromOn?.let { messageArgs.add(presenter.formatToMediumDate(it)) } + account.retrievedTransactionsUpTo?.let { messageArgs.add(presenter.formatToMediumDate(it)) } R.string.fragment_home_transactions_retrieval_state_no_transactions_in_retrieved_period } TransactionsRetrievalState.NeverRetrievedTransactions -> R.string.fragment_home_transactions_retrieval_state_never_retrieved_transactions diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsTable.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsTable.kt index 623a8cde..455a1352 100644 --- a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsTable.kt +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsTable.kt @@ -16,7 +16,6 @@ import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.utils.javafx.ui.extensions.ensureOnlyUsesSpaceIfVisible import tornadofx.* import tornadofx.FX.Companion.messages -import java.text.DateFormat open class AccountTransactionsTable @JvmOverloads constructor( @@ -26,8 +25,6 @@ open class AccountTransactionsTable @JvmOverloads constructor( companion object { - val ValueDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM) - private val LabelMargin = Insets(4.0, 0.0, 4.0, 4.0) } @@ -42,7 +39,7 @@ open class AccountTransactionsTable @JvmOverloads constructor( prefWidth = 115.0 cellFormat { - text = ValueDateFormat.format(it) + text = presenter.formatToMediumDate(it) alignment = Pos.CENTER_LEFT paddingLeft = 4.0 } diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index 5e6483dd..cecc334e 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -59,6 +59,10 @@ open class BankingPresenter( 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") 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() { allBanks.forEach { bank -> bankDisplayIndexUpdated(bank) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AccountTransactionsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AccountTransactionsDialog.swift index d7643f07..48e3b408 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AccountTransactionsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AccountTransactionsDialog.swift @@ -5,8 +5,6 @@ import BankingUiSwift struct AccountTransactionsDialog: View { static private let HideTopFetchAllTransactionsViewButtonWidth: CGFloat = 34 - - static private let RetrievedTransactionsPeriodDateFormat = DateFormatter() private let title: String @@ -75,8 +73,6 @@ struct AccountTransactionsDialog: View { self.title = title self.showBankIcons = showBankIcons - - Self.RetrievedTransactionsPeriodDateFormat.dateStyle = .medium } @@ -271,8 +267,8 @@ struct AccountTransactionsDialog: View { } private func mapDate(_ date: CommonDate?) -> String { - if let date = date?.date { - return Self.RetrievedTransactionsPeriodDateFormat.string(from: date) + if let date = date { + return presenter.formatToMediumDate(date: date) } return "" diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/listitems/AccountTransactionListItem.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/listitems/AccountTransactionListItem.swift index 216ff3fb..ae304fc9 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/listitems/AccountTransactionListItem.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/listitems/AccountTransactionListItem.swift @@ -4,15 +4,6 @@ import BankingUiSwift struct AccountTransactionListItem: View { - private static var ValueDateFormat: DateFormatter = { - let formatter = DateFormatter() - - formatter.dateStyle = .short - - return formatter - }() - - private let transaction: IAccountTransaction private let areMoreThanOneBanksTransactionsDisplayed: Bool @@ -56,7 +47,7 @@ struct AccountTransactionListItem: View { Spacer() - Text(Self.ValueDateFormat.string(from: transaction.valueDate.date)) + Text(presenter.formatToShortDate(date: transaction.valueDate)) .styleAsDetail() } }