From 6697790c85abaab9b43bbf9c80a946e87238491e Mon Sep 17 00:00:00 2001 From: Iiro Krankka Date: Mon, 6 Feb 2017 09:01:57 +0200 Subject: [PATCH] Reverting back to previous working method. Figure out the proper way to return something from realm after closing the instance. --- .../data/local/CoffeeEventRepository.kt | 47 +++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/codemate/koffeemate/data/local/CoffeeEventRepository.kt b/app/src/main/java/com/codemate/koffeemate/data/local/CoffeeEventRepository.kt index 1e1c5d7..9b2aa38 100644 --- a/app/src/main/java/com/codemate/koffeemate/data/local/CoffeeEventRepository.kt +++ b/app/src/main/java/com/codemate/koffeemate/data/local/CoffeeEventRepository.kt @@ -44,37 +44,26 @@ class RealmCoffeeEventRepository : CoffeeEventRepository { return@with event!! } - override fun getAccidentCountForUser(user: User) = with(Realm.getDefaultInstance()) { - val count = where(CoffeeBrewingEvent::class.java) - .equalTo("isSuccessful", false) - .equalTo("user.id", user.id) - .count() + override fun getAccidentCountForUser(user: User) = + Realm.getDefaultInstance() + .where(CoffeeBrewingEvent::class.java) + .equalTo("isSuccessful", false) + .equalTo("user.id", user.id) + .count() - close() - return@with count - } - - override fun getLastBrewingEvent() = with(Realm.getDefaultInstance()) { - val lastEvent = where(CoffeeBrewingEvent::class.java) - .equalTo("isSuccessful", true) - .findAllSorted("time", Sort.ASCENDING) - .lastOrNull() - val copy = copyFromRealm(lastEvent) + override fun getLastBrewingEvent() = + Realm.getDefaultInstance() + .where(CoffeeBrewingEvent::class.java) + .equalTo("isSuccessful", true) + .findAllSorted("time", Sort.ASCENDING) + .lastOrNull() - close() - return@with copy - } - - override fun getLastBrewingAccident() = with(Realm.getDefaultInstance()) { - val lastAccident = where(CoffeeBrewingEvent::class.java) - .equalTo("isSuccessful", false) - .findAllSorted("time", Sort.ASCENDING) - .lastOrNull() - val copy = copyFromRealm(lastAccident) - - close() - return@with copy - } + override fun getLastBrewingAccident() = + Realm.getDefaultInstance() + .where(CoffeeBrewingEvent::class.java) + .equalTo("isSuccessful", false) + .findAllSorted("time", Sort.ASCENDING) + .lastOrNull() private fun newEvent(realm: Realm) = realm.createObject(