diff --git a/app/src/main/java/it/unisannio/ding/ids/wedroid/app/util/ServicesFactory.kt b/app/src/main/java/it/unisannio/ding/ids/wedroid/app/util/ServicesFactory.kt index aa0c3d2..b64032e 100644 --- a/app/src/main/java/it/unisannio/ding/ids/wedroid/app/util/ServicesFactory.kt +++ b/app/src/main/java/it/unisannio/ding/ids/wedroid/app/util/ServicesFactory.kt @@ -5,9 +5,10 @@ import okhttp3.OkHttpClient import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory -object ServicesFactory { +class ServicesFactory private constructor( + reader: PreferenceReader +) { private val retrofit: Retrofit - private lateinit var reader: PreferenceReader //TODO init { val httpClient = OkHttpClient.Builder() @@ -55,5 +56,23 @@ object ServicesFactory { val userService by lazy { 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 + } + } + } } diff --git a/app/src/main/java/it/unisannio/ding/ids/wedroid/app/viewmodel/BoardListViewModel.kt b/app/src/main/java/it/unisannio/ding/ids/wedroid/app/viewmodel/BoardListViewModel.kt index 582051d..50f7161 100644 --- a/app/src/main/java/it/unisannio/ding/ids/wedroid/app/viewmodel/BoardListViewModel.kt +++ b/app/src/main/java/it/unisannio/ding/ids/wedroid/app/viewmodel/BoardListViewModel.kt @@ -13,8 +13,8 @@ class BoardListViewModel(application: Application) : AndroidViewModel(applicatio private val repository: BoardRepository = BoardRepository( BoardDatabase.getDatabase(application).boardDao(), - ServicesFactory.boardService, - DumReader() + ServicesFactory.getInstance(TODO()).boardService, + TODO() ) val allBoards: LiveData> = repository.allBoards