diff --git a/SampleApplications/AndroidApp/build.gradle b/SampleApplications/AndroidApp/build.gradle index f7eeabac..39a19852 100644 --- a/SampleApplications/AndroidApp/build.gradle +++ b/SampleApplications/AndroidApp/build.gradle @@ -35,10 +35,17 @@ android { } dependencies { + implementation project(":fints4k") + + implementation "net.dankito.utils:android-utils:1.1.2" + + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" implementation 'androidx.appcompat:appcompat:1.0.0' implementation 'com.google.android.material:material:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0-rc02' implementation 'androidx.navigation:navigation-ui-ktx:2.0.0-rc02' + + implementation "org.slf4j:slf4j-android:1.7.32" } \ No newline at end of file diff --git a/SampleApplications/AndroidApp/src/main/AndroidManifest.xml b/SampleApplications/AndroidApp/src/main/AndroidManifest.xml index 893fcd62..cc2d942a 100644 --- a/SampleApplications/AndroidApp/src/main/AndroidManifest.xml +++ b/SampleApplications/AndroidApp/src/main/AndroidManifest.xml @@ -2,6 +2,9 @@ + + + + if (response.successful) { + accountTransactionsAdapter.items = response.retrievedData.flatMap { it.bookedTransactions } + } } } diff --git a/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/Presenter.kt b/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/Presenter.kt new file mode 100644 index 00000000..ecb32797 --- /dev/null +++ b/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/Presenter.kt @@ -0,0 +1,54 @@ +package net.codinux.banking.fints4k.android + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.datetime.LocalDate +import net.dankito.banking.fints.FinTsClientDeprecated +import net.dankito.banking.fints.callback.SimpleFinTsClientCallback +import net.dankito.banking.fints.model.AddAccountParameter +import net.dankito.banking.fints.response.client.AddAccountResponse +import net.dankito.utils.multiplatform.extensions.millisSinceEpochAtSystemDefaultTimeZone +import org.slf4j.LoggerFactory +import java.math.BigDecimal +import java.text.DateFormat +import java.util.* + +class Presenter { + + companion object { + val ValueDateFormat = DateFormat.getDateInstance(DateFormat.SHORT) + + private val log = LoggerFactory.getLogger(Presenter::class.java) + } + + private val fintsClient = FinTsClientDeprecated(SimpleFinTsClientCallback()) + + + + fun retrieveAccountData(bankCode: String, customerId: String, pin: String, finTs3ServerAddress: String, retrievedResult: (AddAccountResponse) -> Unit) { + fintsClient.addAccountAsync(AddAccountParameter(bankCode, customerId, pin, finTs3ServerAddress)) { response -> + log.info("Retrieved response from ${response.bank.bankName} for ${response.bank.customerName}") + + GlobalScope.launch(Dispatchers.Main) { + retrievedResult(response) + } + } + } + + + fun formatDate(date: LocalDate): String { + try { + return ValueDateFormat.format(Date(date.millisSinceEpochAtSystemDefaultTimeZone)) + } catch (e: Exception) { + log.error("Could not format date $date", e) + } + + return date.toString() + } + + fun formatAmount(amount: BigDecimal): String { + return String.format("%.02f", amount) + } + +} \ No newline at end of file diff --git a/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/adapter/AccountTransactionsListRecyclerAdapter.kt b/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/adapter/AccountTransactionsListRecyclerAdapter.kt new file mode 100644 index 00000000..70145290 --- /dev/null +++ b/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/adapter/AccountTransactionsListRecyclerAdapter.kt @@ -0,0 +1,46 @@ +package net.codinux.banking.fints4k.android.adapter + +import android.view.View +import net.codinux.banking.fints4k.android.Presenter +import net.codinux.banking.fints4k.android.R +import net.codinux.banking.fints4k.android.adapter.viewholder.AccountTransactionsViewHolder +import net.dankito.banking.fints.model.AccountTransaction +import net.dankito.banking.fints.util.toBigDecimal +import net.dankito.utils.android.extensions.setTextColorToColorResource +import net.dankito.utils.android.ui.adapter.ListRecyclerAdapter +import org.slf4j.LoggerFactory +import java.math.BigDecimal + +class AccountTransactionsListRecyclerAdapter : ListRecyclerAdapter() { + + private val presenter = Presenter() // TOOD: inject + + private val log = LoggerFactory.getLogger(AccountTransactionsListRecyclerAdapter::class.java) + + + override fun getListItemLayoutId() = R.layout.list_item_account_transaction + + override fun createViewHolder(itemView: View): AccountTransactionsViewHolder { + return AccountTransactionsViewHolder(itemView) + } + + override fun bindItemToView(viewHolder: AccountTransactionsViewHolder, item: AccountTransaction) { + try { + viewHolder.txtvwBookingText.text = item.bookingText ?: "" + + viewHolder.txtvwOtherPartyName.visibility = if (item.showOtherPartyName) View.VISIBLE else View.GONE + viewHolder.txtvwOtherPartyName.text = item.otherPartyName ?: "" + + viewHolder.txtvwReference.text = item.reference + + viewHolder.txtvwDate.text = presenter.formatDate(item.valueDate) + + val amount = item.amount.toBigDecimal() + viewHolder.txtvwAmount.text = presenter.formatAmount(amount) + viewHolder.txtvwAmount.setTextColorToColorResource(if (amount >= BigDecimal.ZERO) R.color.positiveAmount else R.color.negativeAmount) + } catch (e: Exception) { + log.error("Could not display account transaction $item", e) + } + } + +} \ No newline at end of file diff --git a/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/adapter/viewholder/AccountTransactionsViewHolder.kt b/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/adapter/viewholder/AccountTransactionsViewHolder.kt new file mode 100644 index 00000000..5cfd49a6 --- /dev/null +++ b/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/adapter/viewholder/AccountTransactionsViewHolder.kt @@ -0,0 +1,20 @@ +package net.codinux.banking.fints4k.android.adapter.viewholder + +import android.view.View +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import net.codinux.banking.fints4k.android.R + +class AccountTransactionsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + + val txtvwBookingText: TextView = itemView.findViewById(R.id.txtvwBookingText) + + val txtvwOtherPartyName: TextView = itemView.findViewById(R.id.txtvwOtherPartyName) + + val txtvwReference: TextView = itemView.findViewById(R.id.txtvwReference) + + val txtvwAmount: TextView = itemView.findViewById(R.id.txtvwAmount) + + val txtvwDate: TextView = itemView.findViewById(R.id.txtvwDate) + +} \ No newline at end of file diff --git a/SampleApplications/AndroidApp/src/main/res/layout/content_main.xml b/SampleApplications/AndroidApp/src/main/res/layout/content_main.xml index f2418499..3fbbc317 100644 --- a/SampleApplications/AndroidApp/src/main/res/layout/content_main.xml +++ b/SampleApplications/AndroidApp/src/main/res/layout/content_main.xml @@ -4,6 +4,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" + android:padding="@dimen/activity_content_padding" app:layout_behavior="@string/appbar_scrolling_view_behavior"> - - -