From bf5514f37bdefd01727025027ed2331a253df049 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 16 Sep 2020 03:14:45 +0200 Subject: [PATCH] Implemented IRemitteeSearcher in RoomBankingPersistence --- .../banking/persistence/RoomBankingPersistence.kt | 12 +++++++++++- .../banking/persistence/dao/AccountTransactionDao.kt | 4 ++++ .../dankito/banking/persistence/model/Remittee.kt | 12 ++++++++++++ .../dankito/banking/ui/android/di/BankingModule.kt | 4 ++-- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/Remittee.kt diff --git a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt index 78cd1523..0bbfa2ae 100644 --- a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt +++ b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt @@ -4,6 +4,8 @@ import android.content.Context import androidx.room.Room import net.dankito.banking.persistence.dao.saveOrUpdate import net.dankito.banking.persistence.model.* +import net.dankito.banking.search.IRemitteeSearcher +import net.dankito.banking.search.Remittee import net.dankito.banking.ui.model.IAccountTransaction import net.dankito.banking.ui.model.TypedBankAccount import net.dankito.banking.ui.model.TypedCustomer @@ -13,7 +15,7 @@ import net.dankito.banking.util.persistence.doSaveUrlToFile import net.dankito.utils.multiplatform.File -open class RoomBankingPersistence(applicationContext: Context) : IBankingPersistence { +open class RoomBankingPersistence(applicationContext: Context) : IBankingPersistence, IRemitteeSearcher { protected val db = Room.databaseBuilder( applicationContext, @@ -131,4 +133,12 @@ open class RoomBankingPersistence(applicationContext: Context) : IBankingPersist doSaveUrlToFile(url, file) } + + override fun findRemittees(query: String): List { + return db.accountTransactionDao().findRemittees(query) + .toSet() // don't display same Remittee multiple times + .filterNot { it.bankCode.isNullOrBlank() || it.accountId.isNullOrBlank() } + .map { Remittee(it.name, it.accountId, it.bankCode) } + } + } \ No newline at end of file diff --git a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/dao/AccountTransactionDao.kt b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/dao/AccountTransactionDao.kt index 3aeab1b8..bce96118 100644 --- a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/dao/AccountTransactionDao.kt +++ b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/dao/AccountTransactionDao.kt @@ -3,6 +3,7 @@ package net.dankito.banking.persistence.dao import androidx.room.Dao import androidx.room.Query import net.dankito.banking.persistence.model.AccountTransaction +import net.dankito.banking.persistence.model.Remittee @Dao @@ -11,4 +12,7 @@ interface AccountTransactionDao : BaseDao { @Query("SELECT * FROM AccountTransaction") fun getAll(): List + @Query("SELECT otherPartyName, otherPartyBankCode, otherPartyAccountId FROM AccountTransaction WHERE otherPartyName LIKE '%' || :query || '%'") + fun findRemittees(query: String): List + } \ No newline at end of file diff --git a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/Remittee.kt b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/Remittee.kt new file mode 100644 index 00000000..f3944942 --- /dev/null +++ b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/Remittee.kt @@ -0,0 +1,12 @@ +package net.dankito.banking.persistence.model + +import androidx.room.ColumnInfo + + +data class Remittee( + @ColumnInfo(name = "otherPartyName") val name: String, + + @ColumnInfo(name = "otherPartyBankCode") val bankCode: String?, + + @ColumnInfo(name = "otherPartyAccountId") val accountId: String? +) \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingModule.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingModule.kt index 68bf6a36..439e26e0 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingModule.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingModule.kt @@ -121,8 +121,8 @@ class BankingModule(private val applicationContext: Context) { @Provides @Singleton - fun provideRemitteeSearcher(@Named(IndexFolderKey) indexFolder: File) : IRemitteeSearcher { - return LuceneRemitteeSearcher(indexFolder) + fun provideRemitteeSearcher(bankingPersistence: IBankingPersistence) : IRemitteeSearcher { + return bankingPersistence as RoomBankingPersistence } @Provides