1
0
mirror of https://github.com/etesync/android synced 2025-02-02 02:41:31 +00:00

LocalEtebaseCache: make sure we always return the same item.

This commit is contained in:
Tom Hacohen 2020-08-25 18:21:30 +03:00
parent eeb93f523d
commit 79b650da38

View File

@ -4,6 +4,7 @@ import android.content.Context
import com.etebase.client.*
import com.etebase.client.Collection
import java.io.File
import java.util.HashMap
/*
File structure:
@ -83,8 +84,19 @@ class EtebaseLocalCache private constructor(context: Context, username: String)
}
companion object {
private val localCacheCache: HashMap<String, EtebaseLocalCache> = HashMap()
fun getInstance(context: Context, username: String): EtebaseLocalCache {
return EtebaseLocalCache(context, username)
synchronized(localCacheCache) {
val cached = localCacheCache.get(username)
if (cached != null) {
return cached
} else {
val ret = EtebaseLocalCache(context, username)
localCacheCache.set(username, ret)
return ret
}
}
}
fun getEtebase(context: Context, settings: AccountSettings): Account {