Skip to content
Snippets Groups Projects
Unverified Commit 0834a6f1 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

wip: progress

parent c049be70
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,26 @@
package de.chaosdorf.meteroid
import android.app.Application
import coil.ImageLoader
import coil.ImageLoaderFactory
import coil.disk.DiskCache
import coil.memory.MemoryCache
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class MeteroidApplication : Application()
class MeteroidApplication : Application(), ImageLoaderFactory {
override fun newImageLoader() = ImageLoader.Builder(applicationContext)
.memoryCache {
MemoryCache.Builder(applicationContext)
.maxSizePercent(0.25)
.build()
}
.diskCache {
DiskCache.Builder()
.directory(applicationContext.cacheDir.resolve("image_cache"))
.maxSizePercent(0.02)
.build()
}
.respectCacheHeaders(false)
.build()
}
......@@ -24,6 +24,7 @@
package de.chaosdorf.meteroid.sync
import android.util.Log
import de.chaosdorf.mete.model.MeteApiFactory
import de.chaosdorf.meteroid.model.AccountInfo
import de.chaosdorf.meteroid.model.Drink
......@@ -39,34 +40,66 @@ class SyncManager @Inject constructor(
private val transactionSyncHandler: TransactionSyncHandler
) {
suspend fun sync(server: Server, user: User?) {
userSyncHandler.sync(server)
drinkSyncHandler.sync(server)
if (user != null) {
transactionSyncHandler.sync(Pair(server, user.userId))
try {
userSyncHandler.sync(server)
drinkSyncHandler.sync(server)
if (user != null) {
transactionSyncHandler.sync(Pair(server, user.userId))
}
} catch (e: Exception) {
Log.e(
"Sync",
"Could not finish transaction for ${user.name} (${user.userId}) on ${account.server.url}",
e
)
}
}
suspend fun purchase(account: AccountInfo, drink: Drink) {
account.user?.let { user ->
val api = factory.newInstance(account.server.url)
api.purchase(user.userId, drink.drinkId)
sync(account.server, user)
try {
api.purchase(user.userId, drink.drinkId)
sync(account.server, user)
} catch (e: Exception) {
Log.e(
"Sync",
"Could not finish transaction for ${user.name} (${user.userId}) on ${account.server.url}",
e
)
}
}
}
suspend fun deposit(account: AccountInfo, amount: BigDecimal) {
account.user?.let { user ->
val api = factory.newInstance(account.server.url)
api.deposit(user.userId, amount)
sync(account.server, user)
try {
val api = factory.newInstance(account.server.url)
api.deposit(user.userId, amount)
sync(account.server, user)
} catch (e: Exception) {
Log.e(
"Sync",
"Could not finish transaction for ${user.name} (${user.userId}) on ${account.server.url}",
e
)
}
}
}
suspend fun withdraw(account: AccountInfo, amount: BigDecimal) {
account.user?.let { user ->
val api = factory.newInstance(account.server.url)
api.withdraw(user.userId, amount)
sync(account.server, user)
try {
api.withdraw(user.userId, amount)
sync(account.server, user)
} catch (e: Exception) {
Log.e(
"Sync",
"Could not finish transaction for ${user.name} (${user.userId}) on ${account.server.url}",
e
)
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment