Merge branch 'feature_util' into feature_boards_list
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Raffaele Mignone 2019-11-30 12:22:25 +01:00
commit c06bd99fd0
Signed by: norangebit
GPG Key ID: F5255658CB220573
2 changed files with 23 additions and 4 deletions

View File

@ -5,9 +5,10 @@ import okhttp3.OkHttpClient
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
object ServicesFactory { class ServicesFactory private constructor(
reader: PreferenceReader
) {
private val retrofit: Retrofit private val retrofit: Retrofit
private lateinit var reader: PreferenceReader //TODO
init { init {
val httpClient = OkHttpClient.Builder() val httpClient = OkHttpClient.Builder()
@ -55,5 +56,23 @@ object ServicesFactory {
val userService by lazy { val userService by lazy {
retrofit.create(UserService::class.java) retrofit.create(UserService::class.java)
} }
companion object {
@Volatile
private var INSTANCE: ServicesFactory? = null
fun getInstance(reader: PreferenceReader): ServicesFactory {
val tempInstance = INSTANCE
if (tempInstance != null)
return tempInstance
synchronized(this) {
val instance = ServicesFactory(reader)
INSTANCE = instance
return instance
}
}
}
} }

View File

@ -13,8 +13,8 @@ class BoardListViewModel(application: Application) : AndroidViewModel(applicatio
private val repository: BoardRepository = BoardRepository( private val repository: BoardRepository = BoardRepository(
BoardDatabase.getDatabase(application).boardDao(), BoardDatabase.getDatabase(application).boardDao(),
ServicesFactory.boardService, ServicesFactory.getInstance(TODO()).boardService,
DumReader() TODO()
) )
val allBoards: LiveData<List<Board>> = repository.allBoards val allBoards: LiveData<List<Board>> = repository.allBoards