Implemented IRemitteeSearcher in RoomBankingPersistence

This commit is contained in:
dankito 2020-09-16 03:14:45 +02:00
parent 12e84109f3
commit bf5514f37b
4 changed files with 29 additions and 3 deletions

View File

@ -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<Remittee> {
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) }
}
}

View File

@ -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<AccountTransaction> {
@Query("SELECT * FROM AccountTransaction")
fun getAll(): List<AccountTransaction>
@Query("SELECT otherPartyName, otherPartyBankCode, otherPartyAccountId FROM AccountTransaction WHERE otherPartyName LIKE '%' || :query || '%'")
fun findRemittees(query: String): List<Remittee>
}

View File

@ -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?
)

View File

@ -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