Closed MuindiStephen closed 5 months ago
@PratyushSingh07 This issue is fixed. My code is working perfect!
This is what I was having previously
@Singleton
class DatabaseHelper @Inject constructor() {
fun syncCharges(charges: Page<Charge>?): Page<Charge>? {
if (charges != null) {
for (charge in charges.pageItems)
charge.save()
}
return charges
}
fun clientCharges(): Page<Charge?> {
val charges = SQLite.select()
.from(Charge::class.java)
.queryList()
val chargePage = Page<Charge?>()
chargePage.pageItems = charges
return chargePage
}
fun notifications(): List<MifosNotification> {
deleteOldNotifications()
val notifications = SQLite.select()
.from(MifosNotification::class.java)
.queryList()
Collections.sort(notifications, NotificationComparator())
return notifications
}
fun unreadNotificationsCount(): Int {
deleteOldNotifications()
return SQLite.select()
.from(MifosNotification::class.java)
.where(MifosNotification.isRead().eq(false))
.queryList().size
}
private fun deleteOldNotifications() {
Observable.defer<Void> {
val thirtyDaysInSeconds: Long = 2592000
val thirtyDaysFromCurrentTimeInSeconds = System.currentTimeMillis() / 1000 -
thirtyDaysInSeconds
SQLite.delete(MifosNotification::class.java)
.where(MifosNotification_Table.timeStamp.lessThan(thirtyDaysFromCurrentTimeInSeconds * 1000))
.execute()
null
}
}
}
instead of
@Singleton
class DatabaseHelper @Inject constructor() {
fun syncCharges(charges: Page<Charge>?): Page<Charge>? {
if (charges != null) {
for (charge in charges.pageItems)
charge.save()
}
return charges
}
fun clientCharges(): Page<Charge?> {
val charges = SQLite.select()
.from(Charge::class.java)
.queryList()
val chargePage = Page<Charge?>()
chargePage.pageItems = charges
return chargePage
}
fun notifications(): List<MifosNotification> {
deleteOldNotifications()
val notifications = SQLite.select()
.from(MifosNotification::class.java)
.queryList()
Collections.sort(notifications, NotificationComparator())
return notifications
}
fun unreadNotificationsCount(): Int {
deleteOldNotifications()
return SQLite.select()
.from(MifosNotification::class.java)
.where(MifosNotification_Table.read.eq(false))
.queryList().size
}
private fun deleteOldNotifications() {
Observable.defer<Void> {
val thirtyDaysInSeconds: Long = 2592000
val thirtyDaysFromCurrentTimeInSeconds = System.currentTimeMillis() / 1000 -
thirtyDaysInSeconds
SQLite.delete(MifosNotification::class.java)
.where(MifosNotification_Table.timeStamp.lessThan(thirtyDaysFromCurrentTimeInSeconds * 1000))
.execute()
null
}
}
}
Database helper class calls MifosNotification_Table class which is not available in package
import org.mifos.mobile.models.notification.MifosNotification_Table