From 8c1b0cb6a07b87023238a488424ba40a27396811 Mon Sep 17 00:00:00 2001 From: norangebit Date: Sat, 30 Nov 2019 12:13:01 +0100 Subject: [PATCH] edit ServicesFactory --- .../ids/wedroid/app/util/ServicesFactory.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) 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 + } + } + } }