From 9f089bd957f10df33118411ed41c95d3afac721a Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 19:11:27 +0200 Subject: [PATCH 01/22] check correct switch property --- .../unchained/newdownload/view/NewDownloadFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/newdownload/view/NewDownloadFragment.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/newdownload/view/NewDownloadFragment.kt index c7257d62e..8d3b0f18f 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/newdownload/view/NewDownloadFragment.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/newdownload/view/NewDownloadFragment.kt @@ -156,7 +156,7 @@ class NewDownloadFragment : UnchainedFragment(), NewDownloadListener { if (password.isNullOrBlank()) password = null val remote: Int? = - if (downloadBinding.switchRemote.isEnabled) REMOTE_TRAFFIC_ON else null + if (downloadBinding.switchRemote.isChecked) REMOTE_TRAFFIC_ON else null viewModel.fetchUnrestrictedLink( link, From 1351b46b6785e2aad5c89ac57176eab690257347 Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 19:13:36 +0200 Subject: [PATCH 02/22] removed extra space from rest call paramters --- .../livingwithhippos/unchained/data/remote/TorrentsApi.kt | 2 +- .../livingwithhippos/unchained/data/remote/UnrestrictApi.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/TorrentsApi.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/TorrentsApi.kt index b2941f272..1e79aff5c 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/TorrentsApi.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/TorrentsApi.kt @@ -65,7 +65,7 @@ interface TorrentsApi { @Query("offset") offset: Int? = 0, @Query("page") page: Int? = 1, @Query("limit") limit: Int? = 10, - @Query("filter ") filter: String? + @Query("filter") filter: String? ): Response> /** diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/UnrestrictApi.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/UnrestrictApi.kt index 0b30c8e36..fc1f679d2 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/UnrestrictApi.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/UnrestrictApi.kt @@ -37,7 +37,7 @@ interface UnrestrictApi { // Password to unlock the file access hoster side @Field("password") password: String? = null, // 0 or 1, use Remote traffic, dedicated servers and account sharing protections lifted - @Field("remote ") remote: Int? = null + @Field("remote") remote: Int? = null ): Response } \ No newline at end of file From 8f03d5d53ac4178f11a8b4f6a612487c3a7abe31 Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 19:14:22 +0200 Subject: [PATCH 03/22] added extra key to API error json --- .../github/livingwithhippos/unchained/data/model/APIError.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/APIError.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/APIError.kt index be10fef08..795d359ca 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/APIError.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/APIError.kt @@ -8,6 +8,8 @@ import com.squareup.moshi.JsonClass data class APIError( @Json(name = "error") val error: String, + @Json(name = "error_details") + val errorDetails: String?, @Json(name = "error_code") val errorCode: Int? ) From 01fcbc15811f5c25db6277bb2bfe4283d07cfdb1 Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 19:19:46 +0200 Subject: [PATCH 04/22] remove endpoint name space --- .../livingwithhippos/unchained/data/remote/DownloadApi.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/DownloadApi.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/DownloadApi.kt index 6fc220595..b24a0f662 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/DownloadApi.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/DownloadApi.kt @@ -22,7 +22,7 @@ interface DownloadsApi { * @param limit Entries returned per page / request (must be within 0 and 100, default: 50) * @return a Response> a list of download items */ - @GET(" downloads") + @GET("downloads") suspend fun getDownloads( @Header("Authorization") token: String, @Query("offset") offset: Int?, From 18eda5e13133c8dceec7e87780989fe1ceb9fe8d Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 20:33:28 +0200 Subject: [PATCH 05/22] added alternative network response model for caompatibility reasons --- .../unchained/data/model/NetworkResponse.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/NetworkResponse.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/NetworkResponse.kt index fb3ed48a3..252cf0e0a 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/NetworkResponse.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/NetworkResponse.kt @@ -13,4 +13,11 @@ sealed class NetworkResponse { data class Success(val data: T) : NetworkResponse() data class SuccessEmptyBody(val code: Int) : NetworkResponse() data class Error(val exception: Exception) : NetworkResponse() +} + +sealed class CompleteNetworkResponse { + data class Success(val data: T) : CompleteNetworkResponse() + data class SuccessEmptyBody(val code: Int) : CompleteNetworkResponse() + data class Error(val errorMessage: String) : CompleteNetworkResponse() + data class RDError(val error: U) : CompleteNetworkResponse() } \ No newline at end of file From 0154db8d97151d3d0bbbc3f622b29ea6e4bf0aa0 Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 20:34:30 +0200 Subject: [PATCH 06/22] added new function returning error json class --- .../data/repositoy/BaseRepository.kt | 79 ++++++++----------- .../data/repositoy/UnrestrictRepository.kt | 22 +++++- 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/BaseRepository.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/BaseRepository.kt index 381a448d9..5430637ce 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/BaseRepository.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/BaseRepository.kt @@ -2,7 +2,11 @@ package com.github.livingwithhippos.unchained.data.repositoy import android.util.Log import com.github.livingwithhippos.unchained.BuildConfig +import com.github.livingwithhippos.unchained.data.model.APIError +import com.github.livingwithhippos.unchained.data.model.CompleteNetworkResponse import com.github.livingwithhippos.unchained.data.model.NetworkResponse +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi import okhttp3.ResponseBody import retrofit2.Call import retrofit2.Callback @@ -15,25 +19,10 @@ import java.io.IOException */ open class BaseRepository { - suspend fun unsafeApiCall(call: suspend () -> Response, errorMessage: String): T? { - - val result: NetworkResponse = unsafeApiResult(call, errorMessage) - var data: T? = null - - when (result) { - is NetworkResponse.Success -> - data = result.data - is NetworkResponse.SuccessEmptyBody -> - if (BuildConfig.DEBUG) - Log.d("BaseRepository", "Successful call with empty body : ${result.code}") - is NetworkResponse.Error -> - if (BuildConfig.DEBUG) - Log.d("BaseRepository", errorMessage) - - } - - return data - } + //todo: inject this + private val jsonAdapter: JsonAdapter = Moshi.Builder() + .build() + .adapter(APIError::class.java) suspend fun safeApiCall(call: suspend () -> Response, errorMessage: String): T? { @@ -70,35 +59,6 @@ open class BaseRepository { return NetworkResponse.Error(IOException("Error Occurred while getting api result, error : $errorMessage")) } - private suspend fun unsafeApiResult( - call: suspend () -> Response, - errorMessage: String - ): NetworkResponse { - val response = call.invoke() - if (response.isSuccessful) { - val body = response.body() - if (body != null) - return NetworkResponse.Success(body) - else - return NetworkResponse.SuccessEmptyBody(response.code()) - } else { - //todo: implement error handling as JSON APIError class - /* - if (response.code() in 400..599) { - val moshi = Moshi.Builder().build() - val adapter: JsonAdapter = - moshi.adapter(APIError::class.java) - // todo: wrap with withContext(Dispatchers.IO)? - val apiError = adapter.fromJson(response.errorBody().toString()) - if (apiError!=null) - throw APIException(apiError) - }*/ - - } - - return NetworkResponse.Error(IOException("Error Occurred while getting api result, error : $errorMessage")) - } - suspend fun safeEmptyApiCall(call: suspend () -> Call, errorMessage: String): Int? { //fixme: this fun returns always -1 @@ -119,4 +79,27 @@ open class BaseRepository { return responseCode } + + public suspend fun errorApiResult( + call: suspend () -> Response, + errorMessage: String + ): CompleteNetworkResponse { + val response = call.invoke() + if (response.isSuccessful) { + val body = response.body() + if (body != null) + return CompleteNetworkResponse.Success(body) + else + return CompleteNetworkResponse.SuccessEmptyBody(response.code()) + } else { + try { + val error: APIError? = jsonAdapter.fromJson(response.errorBody()!!.string()) + return CompleteNetworkResponse.RDError(error) + } catch (e: IOException) { + e.printStackTrace() + } + } + + return CompleteNetworkResponse.Error(errorMessage) + } } \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/UnrestrictRepository.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/UnrestrictRepository.kt index 244cc404d..1370a5c8c 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/UnrestrictRepository.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/UnrestrictRepository.kt @@ -1,5 +1,6 @@ package com.github.livingwithhippos.unchained.data.repositoy +import com.github.livingwithhippos.unchained.data.model.CompleteNetworkResponse import com.github.livingwithhippos.unchained.data.model.DownloadItem import com.github.livingwithhippos.unchained.data.remote.UnrestrictApiHelper import kotlinx.coroutines.delay @@ -14,7 +15,7 @@ class UnrestrictRepository @Inject constructor(private val unrestrictApiHelper: remote: Int? = null ): DownloadItem? { - val linkResponse = unsafeApiCall( + val linkResponse = errorApiResult( call = { unrestrictApiHelper.getUnrestrictedLink( token = "Bearer $token", @@ -26,7 +27,24 @@ class UnrestrictRepository @Inject constructor(private val unrestrictApiHelper: errorMessage = "Error Fetching Unrestricted Link Info" ) - return linkResponse + when (linkResponse) { + is CompleteNetworkResponse.Success -> { + return linkResponse.data + } + is CompleteNetworkResponse.SuccessEmptyBody -> { + val code = linkResponse.code + return null + } + is CompleteNetworkResponse.RDError<*> -> { + val error = linkResponse.error + return null + } + is CompleteNetworkResponse.Error -> { + val message = linkResponse.errorMessage + return null + } + else -> return null + } } suspend fun getUnrestrictedLinkList( From a4092aa2bcab51f32889c58577a0d0fc5024fa0b Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 21:04:46 +0200 Subject: [PATCH 07/22] lowered auth call time --- .../authentication/viewmodel/AuthenticationViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt index 75c10827e..c5c305b50 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt @@ -48,7 +48,7 @@ class AuthenticationViewModel @ViewModelInject constructor( * @param expireIn: the time in seconds before the deviceCode is not valid anymore for the secrets endpoint */ fun fetchSecrets(deviceCode: String, expireIn: Int) { - val waitTime = 5000L + val waitTime = 2000L // this is just an estimate, keeping track of time would be more precise. As of now this value should be 120 var calls = (expireIn * 1000 / waitTime).toInt() - 10 // remove 10% of the calls to account for the api calls From bf43adbc7f60815aeac2913d0c346feebbcbc397 Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 21:14:03 +0200 Subject: [PATCH 08/22] corrected Token json value --- .../livingwithhippos/unchained/data/model/Authentiication.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/Authentiication.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/Authentiication.kt index 38d7dda10..4fc3a2a58 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/Authentiication.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/model/Authentiication.kt @@ -42,7 +42,7 @@ data class Token( @Json(name = "access_token") val accessToken: String, @Json(name = "expires_in") - val expiresIn: String, + val expiresIn: Int, @Json(name = "token_type") val tokenType: String, @Json(name = "refresh_token") From 8a094105ec026a432b2d6142705e145da43b9f16 Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 21:28:10 +0200 Subject: [PATCH 09/22] revert auth delay call --- .../authentication/viewmodel/AuthenticationViewModel.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt index c5c305b50..e7ce164ba 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt @@ -48,7 +48,8 @@ class AuthenticationViewModel @ViewModelInject constructor( * @param expireIn: the time in seconds before the deviceCode is not valid anymore for the secrets endpoint */ fun fetchSecrets(deviceCode: String, expireIn: Int) { - val waitTime = 2000L + // 5 seconds is the value suggested by real debrid + val waitTime = 5000L // this is just an estimate, keeping track of time would be more precise. As of now this value should be 120 var calls = (expireIn * 1000 / waitTime).toInt() - 10 // remove 10% of the calls to account for the api calls From 9c9df2db037180b442afeedeb0428dc0cd0d17dc Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 21:40:14 +0200 Subject: [PATCH 10/22] filter list to with needed value --- .../unchained/start/viewmodel/MainActivityViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt index 310f0978e..3d14406dd 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt @@ -58,7 +58,7 @@ class MainActivityViewModel @ViewModelInject constructor( } // if the private token is not working this also gets triggered if (user == null) - for (cred in completeCredentials) { + for (cred in completeCredentials.filter { it.deviceCode != PRIVATE_TOKEN }) { user = checkCredentials(cred) if (user != null) { break From cc0961cb6f8c6abff49c5a1671dab577a84c7ae3 Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 22:40:33 +0200 Subject: [PATCH 11/22] added programTokenRefresh function refresh the token after some time --- .../unchained/start/viewmodel/MainActivityViewModel.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt index 3d14406dd..5870cfcda 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt @@ -171,6 +171,15 @@ class MainActivityViewModel @ViewModelInject constructor( savedStateHandle.set(KEY_LAST_BACK_PRESS, time) } + fun programTokenRefresh(secondsDelay: Int) { + // todo: add job that is cancelled everytime this function is called + viewModelScope.launch { + // secondsDelay*950L -> expiration time - 5% + delay(secondsDelay * 950L) + refreshToken() + } + } + companion object { const val KEY_TORRENT_DOWNLOAD_ID = "torrent_download_id_key" const val KEY_TORRENT_PATH = "torrent_path_key" From 8a47fb5a51513e6f8a5fa58a661bcca5caa9c552 Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 22:42:05 +0200 Subject: [PATCH 12/22] program refresh token after getting a new one --- .../unchained/authentication/view/AuthenticationFragment.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/view/AuthenticationFragment.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/view/AuthenticationFragment.kt index edc3c21fc..540f96a5e 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/view/AuthenticationFragment.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/view/AuthenticationFragment.kt @@ -63,6 +63,8 @@ class AuthenticationFragment : UnchainedFragment(), ButtonListener { authBinding.token = token // pass the value to be checked and eventually saved viewModel.checkAndSaveToken(token = token) + // program the refresh of the token + activityViewModel.programTokenRefresh(token.expiresIn) } }) From e402553b10ade48a89dd0c161fc02f3ea58a4b8c Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 22:44:36 +0200 Subject: [PATCH 13/22] refresh token if expired --- .../start/viewmodel/MainActivityViewModel.kt | 58 +++++++++++++++---- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt index 5870cfcda..6e3021f58 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt @@ -17,6 +17,7 @@ import com.github.livingwithhippos.unchained.data.repositoy.UserRepository import com.github.livingwithhippos.unchained.lists.view.ListsTabFragment import com.github.livingwithhippos.unchained.utilities.Event import com.github.livingwithhippos.unchained.utilities.PRIVATE_TOKEN +import kotlinx.coroutines.delay import kotlinx.coroutines.launch /** @@ -45,28 +46,58 @@ class MainActivityViewModel @ViewModelInject constructor( @SuppressLint("NullSafeMutableLiveData") fun fetchFirstWorkingCredentials() { viewModelScope.launch { + + var user: User? = null + val completeCredentials = credentialRepository .getAllCredentials() .filter { it.accessToken != null && it.clientId != null && it.clientSecret != null && it.deviceCode.isNotBlank() && it.refreshToken != null } - var user: User? = null + + if (completeCredentials.isNotEmpty()) { - val privateCredentials = - completeCredentials.firstOrNull { it.deviceCode == PRIVATE_TOKEN } - if (privateCredentials != null) { - user = checkCredentials(privateCredentials) + // step #1: test for private API token + completeCredentials.firstOrNull { it.deviceCode == PRIVATE_TOKEN }?.let{ + user = checkCredentials(it) + } + // step #2: test for open source credentials + if (user == null) { + completeCredentials.firstOrNull { it.deviceCode != PRIVATE_TOKEN }?.let{ + user = checkCredentials(it) + } } - // if the private token is not working this also gets triggered - if (user == null) - for (cred in completeCredentials.filter { it.deviceCode != PRIVATE_TOKEN }) { - user = checkCredentials(cred) - if (user != null) { - break + // step #3: try to refresh open source credentials + if (user == null) { + // to check values refreshToken was ported here + completeCredentials.firstOrNull { it.deviceCode != PRIVATE_TOKEN }?.let{ + // refresh the token + authRepository.refreshToken(it)?.let {token-> + val newCredentials = Credentials( + it.deviceCode, + it.clientId, + it.clientSecret, + token.accessToken, + token.refreshToken + ) + + user = userRepository.getUserInfo(token.accessToken) + + if (user != null) { + // update the credentials + credentialRepository.updateCredentials(newCredentials) + // program the refresh of the token + programTokenRefresh(token.expiresIn) + } + } } + } + } - // passes null if no working credentials, otherwise pass the first working one + + // pass whatever user was retrieved, or null if none was found userLiveData.postValue(user) + } } @@ -135,6 +166,9 @@ class MainActivityViewModel @ViewModelInject constructor( ) // update the credentials credentialRepository.updateCredentials(newCredentials) + + // program the refresh of the token + programTokenRefresh(it.expiresIn) } } } From a3b48f1ba00201347fc14a07aabc39da5ca0ca52 Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 23:00:40 +0200 Subject: [PATCH 14/22] remove temporary code --- .../com/github/livingwithhippos/unchained/base/MainActivity.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/base/MainActivity.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/base/MainActivity.kt index a5dca26bc..89d83b28f 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/base/MainActivity.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/base/MainActivity.kt @@ -245,8 +245,6 @@ class MainActivity : UnchainedActivity() { if (bottomNavManager?.onBackPressed()==false) { // check if we're in the home bottom bar, otherwise press back val bottomNav = findViewById(R.id.bottom_nav_view) - val asd = bottomNav.selectedItemId - val home = R.id.navigation_home if (bottomNav.selectedItemId != R.id.navigation_home) super.onBackPressed() else { From 4fbb17866e84b284107e1a9611cb82a4aadffabb Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 23:02:41 +0200 Subject: [PATCH 15/22] moved disable token api to own class in authentication api it had the wrong base url --- .../unchained/di/ApiFactory.kt | 15 ++++++++++++ .../unchained/data/remote/AuthApiHelper.kt | 4 ---- .../data/remote/AuthApiHelperImpl.kt | 3 --- .../data/remote/AuthenticationApi.kt | 8 ------- .../unchained/data/remote/VariousApi.kt | 18 +++++++++++++++ .../unchained/data/remote/VariousApiHelper.kt | 7 ++++++ .../data/remote/VariousApiHelperImpl.kt | 9 ++++++++ .../repositoy/AuthenticationRepository.kt | 12 ---------- .../data/repositoy/VariousApiRepository.kt | 23 +++++++++++++++++++ .../start/viewmodel/MainActivityViewModel.kt | 6 +++-- 10 files changed, 76 insertions(+), 29 deletions(-) create mode 100644 app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApi.kt create mode 100644 app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApiHelper.kt create mode 100644 app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApiHelperImpl.kt create mode 100644 app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/VariousApiRepository.kt diff --git a/app/app/src/debug/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt b/app/app/src/debug/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt index 5ed3b543a..7369a09a3 100644 --- a/app/app/src/debug/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt +++ b/app/app/src/debug/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt @@ -21,6 +21,9 @@ import com.github.livingwithhippos.unchained.data.remote.UnrestrictApiHelperImpl import com.github.livingwithhippos.unchained.data.remote.UserApi import com.github.livingwithhippos.unchained.data.remote.UserApiHelper import com.github.livingwithhippos.unchained.data.remote.UserApiHelperImpl +import com.github.livingwithhippos.unchained.data.remote.VariousApi +import com.github.livingwithhippos.unchained.data.remote.VariousApiHelper +import com.github.livingwithhippos.unchained.data.remote.VariousApiHelperImpl import com.github.livingwithhippos.unchained.utilities.BASE_AUTH_URL import com.github.livingwithhippos.unchained.utilities.BASE_URL import com.squareup.moshi.Moshi @@ -159,4 +162,16 @@ object ApiFactory { @Singleton fun provideHostsApiHelper(apiHelper: HostsApiHelperImpl): HostsApiHelper = apiHelper + + // various api injection + @Provides + @Singleton + fun provideVariousApi(@ApiRetrofit retrofit: Retrofit): VariousApi { + return retrofit.create(VariousApi::class.java) + } + + @Provides + @Singleton + fun provideVariousApiHelper(apiHelper: VariousApiHelperImpl): VariousApiHelper = + apiHelper } \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelper.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelper.kt index 7bf326d9b..bc1808b65 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelper.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelper.kt @@ -18,8 +18,4 @@ interface AuthApiHelper { clientSecret: String, deviceCode: String ): Response - - suspend fun disableToken( - token: String - ): Response } \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelperImpl.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelperImpl.kt index c0b11e657..0804b5778 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelperImpl.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelperImpl.kt @@ -20,7 +20,4 @@ class AuthApiHelperImpl @Inject constructor(private val authenticationApi: Authe clientSecret: String, deviceCode: String ): Response = authenticationApi.getToken(clientId, clientSecret, deviceCode) - - override suspend fun disableToken(token: String): Response = - authenticationApi.disableToken(token) } \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthenticationApi.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthenticationApi.kt index e934928a4..030efecc7 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthenticationApi.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthenticationApi.kt @@ -41,12 +41,4 @@ interface AuthenticationApi { @Field("code") deviceCode: String, @Field("grant_type") grantType: String = OPEN_SOURCE_GRANT_TYPE ): Response - - /** - * Disable the current access token - */ - @GET("disable_access_token") - suspend fun disableToken( - @Header("Authorization") token: String - ): Response } \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApi.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApi.kt new file mode 100644 index 000000000..f1f67ebc1 --- /dev/null +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApi.kt @@ -0,0 +1,18 @@ +package com.github.livingwithhippos.unchained.data.remote + +import retrofit2.Response +import retrofit2.http.GET +import retrofit2.http.Header + +/** + * This interface is used by Retrofit to manage various api calls not fitting elsewhere + */ +interface VariousApi { + /** + * Disable the current access token + */ + @GET("disable_access_token") + suspend fun disableToken( + @Header("Authorization") token: String + ): Response +} \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApiHelper.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApiHelper.kt new file mode 100644 index 000000000..2b4f3842c --- /dev/null +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApiHelper.kt @@ -0,0 +1,7 @@ +package com.github.livingwithhippos.unchained.data.remote + +import retrofit2.Response + +interface VariousApiHelper { + suspend fun disableToken(token: String): Response +} \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApiHelperImpl.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApiHelperImpl.kt new file mode 100644 index 000000000..a34c2a034 --- /dev/null +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/VariousApiHelperImpl.kt @@ -0,0 +1,9 @@ +package com.github.livingwithhippos.unchained.data.remote + +import retrofit2.Response +import javax.inject.Inject + +class VariousApiHelperImpl @Inject constructor(private val variousApi: VariousApi) : +VariousApiHelper { + override suspend fun disableToken(token: String): Response = variousApi.disableToken(token) +} \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt index 0109be725..f190c709d 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt @@ -49,18 +49,6 @@ class AuthenticationRepository @Inject constructor(private val apiHelper: AuthAp } - suspend fun disableToken(token: String): Any? { - - val authResponse = safeApiCall( - call = { apiHelper.disableToken("Bearer $token") }, - errorMessage = "Error disabling token" - ) - - return authResponse; - - } - - /** * Get a new open source Token that usually lasts one hour. * You can not use both offset and page at the same time, page is prioritized in case it happens. diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/VariousApiRepository.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/VariousApiRepository.kt new file mode 100644 index 000000000..abf994a4e --- /dev/null +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/VariousApiRepository.kt @@ -0,0 +1,23 @@ +package com.github.livingwithhippos.unchained.data.repositoy + +import com.github.livingwithhippos.unchained.data.remote.VariousApiHelper +import javax.inject.Inject + +class VariousApiRepository @Inject constructor(private val variousApiHelper: VariousApiHelper) : + BaseRepository() { + + suspend fun disableToken(token: String): Unit? { + + val response = safeApiCall( + call = { + variousApiHelper.disableToken( + token = "Bearer $token" + ) + }, + errorMessage = "Error disabling token" + ) + + return response + } + +} \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt index 6e3021f58..add46be90 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt @@ -14,6 +14,7 @@ import com.github.livingwithhippos.unchained.data.model.User import com.github.livingwithhippos.unchained.data.repositoy.AuthenticationRepository import com.github.livingwithhippos.unchained.data.repositoy.CredentialsRepository import com.github.livingwithhippos.unchained.data.repositoy.UserRepository +import com.github.livingwithhippos.unchained.data.repositoy.VariousApiRepository import com.github.livingwithhippos.unchained.lists.view.ListsTabFragment import com.github.livingwithhippos.unchained.utilities.Event import com.github.livingwithhippos.unchained.utilities.PRIVATE_TOKEN @@ -28,7 +29,8 @@ class MainActivityViewModel @ViewModelInject constructor( @Assisted private val savedStateHandle: SavedStateHandle, private val authRepository: AuthenticationRepository, private val credentialRepository: CredentialsRepository, - private val userRepository: UserRepository + private val userRepository: UserRepository, + private val variousApiRepository: VariousApiRepository ) : ViewModel() { val authenticationState = MutableLiveData>() @@ -133,7 +135,7 @@ class MainActivityViewModel @ViewModelInject constructor( credentialRepository.getFirstCredentials()?.let { if (it.refreshToken != null && it.refreshToken != PRIVATE_TOKEN) { //setUnauthenticated() - authRepository.disableToken(it.accessToken!!) + variousApiRepository.disableToken(it.accessToken!!) } } From 53d4ca773f091d451ab5308899de2689a85ef5b4 Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 23:29:44 +0200 Subject: [PATCH 16/22] remove repeated code --- .../authentication/viewmodel/AuthenticationViewModel.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt index e7ce164ba..2e79d84de 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/viewmodel/AuthenticationViewModel.kt @@ -56,7 +56,6 @@ class AuthenticationViewModel @ViewModelInject constructor( calls -= calls / 10 viewModelScope.launch { var secretData = authRepository.getSecrets(deviceCode) - secretLiveData.postValue(Event(secretData)) while (secretData?.clientId == null && calls-- > 0 && (getAuthState() != AuthenticationState.AUTHENTICATED || getAuthState() != AuthenticationState.AUTHENTICATED_NO_PREMIUM)) { delay(waitTime) secretData = authRepository.getSecrets(deviceCode) From 1762cdaabf60a98b78f5b7fc477ce4c1b8ab13e1 Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 23:30:16 +0200 Subject: [PATCH 17/22] moved to single credentials model --- .../start/viewmodel/MainActivityViewModel.kt | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt index add46be90..a30c238bf 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/start/viewmodel/MainActivityViewModel.kt @@ -65,15 +65,7 @@ class MainActivityViewModel @ViewModelInject constructor( // step #2: test for open source credentials if (user == null) { completeCredentials.firstOrNull { it.deviceCode != PRIVATE_TOKEN }?.let{ - user = checkCredentials(it) - } - } - // step #3: try to refresh open source credentials - if (user == null) { - // to check values refreshToken was ported here - completeCredentials.firstOrNull { it.deviceCode != PRIVATE_TOKEN }?.let{ - // refresh the token - authRepository.refreshToken(it)?.let {token-> + authRepository.refreshToken(it)?.let { token -> val newCredentials = Credentials( it.deviceCode, it.clientId, @@ -82,15 +74,13 @@ class MainActivityViewModel @ViewModelInject constructor( token.refreshToken ) - user = userRepository.getUserInfo(token.accessToken) - + user = userRepository.getUserInfo(newCredentials.accessToken!!) if (user != null) { // update the credentials credentialRepository.updateCredentials(newCredentials) // program the refresh of the token programTokenRefresh(token.expiresIn) } - } } } From 2c91a3181f28c834c0ebc8ad2ee7e50bfad924cf Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 23:43:54 +0200 Subject: [PATCH 18/22] renamed variables --- .../unchained/data/repositoy/AuthenticationRepository.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt index f190c709d..85bdb7ed1 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt @@ -23,18 +23,18 @@ class AuthenticationRepository @Inject constructor(private val apiHelper: AuthAp suspend fun getSecrets(code: String): Secrets? { - val authResponse = safeApiCall( + val secretResponse = safeApiCall( call = { apiHelper.getSecrets(deviceCode = code) }, errorMessage = "Error Fetching Secrets" ) - return authResponse; + return secretResponse; } suspend fun getToken(clientId: String, clientSecret: String, deviceCode: String): Token? { - val authResponse = safeApiCall( + val tokenResponse = safeApiCall( call = { apiHelper.getToken( clientId = clientId, @@ -45,7 +45,7 @@ class AuthenticationRepository @Inject constructor(private val apiHelper: AuthAp errorMessage = "Error Fetching Token" ) - return authResponse; + return tokenResponse; } From a32d0f17b0a026a3fb658477687161419874850e Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 23:44:17 +0200 Subject: [PATCH 19/22] Fix refresh token variables --- .../unchained/data/repositoy/AuthenticationRepository.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt index 85bdb7ed1..e35f565f0 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt @@ -53,13 +53,13 @@ class AuthenticationRepository @Inject constructor(private val apiHelper: AuthAp * Get a new open source Token that usually lasts one hour. * You can not use both offset and page at the same time, page is prioritized in case it happens. * @param clientId the client id obtained from the /device/credentials endpoint - * @param refreshCode the code obtained from the /token endpoint + * @param clientSecret the code obtained from the /token endpoint * @param deviceCode the device code obtained from the /device/code endpoint * @return the new Token */ - suspend fun refreshToken(clientId: String, refreshCode: String, deviceCode: String): Token? = - getToken(clientId, refreshCode, deviceCode) + suspend fun refreshToken(clientId: String, clientSecret: String, refreshToken: String): Token? = + getToken(clientId, clientSecret, refreshToken) suspend fun refreshToken(credentials: Credentials): Token? = - refreshToken(credentials.clientId!!, credentials.refreshToken!!, credentials.deviceCode) + refreshToken(credentials.clientId!!, credentials.clientSecret!!, credentials.refreshToken!!) } \ No newline at end of file From 4fc1bb7f563288b9a944f5b525a15ad6647ef93b Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Thu, 1 Oct 2020 23:46:05 +0200 Subject: [PATCH 20/22] renamed deviceCode to code since we can also use refreshCode --- .../livingwithhippos/unchained/data/remote/AuthApiHelper.kt | 2 +- .../unchained/data/remote/AuthApiHelperImpl.kt | 4 ++-- .../unchained/data/remote/AuthenticationApi.kt | 2 +- .../unchained/data/repositoy/AuthenticationRepository.kt | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelper.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelper.kt index bc1808b65..ccb50fc82 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelper.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelper.kt @@ -16,6 +16,6 @@ interface AuthApiHelper { suspend fun getToken( clientId: String, clientSecret: String, - deviceCode: String + code: String ): Response } \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelperImpl.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelperImpl.kt index 0804b5778..9affde805 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelperImpl.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthApiHelperImpl.kt @@ -18,6 +18,6 @@ class AuthApiHelperImpl @Inject constructor(private val authenticationApi: Authe override suspend fun getToken( clientId: String, clientSecret: String, - deviceCode: String - ): Response = authenticationApi.getToken(clientId, clientSecret, deviceCode) + code: String + ): Response = authenticationApi.getToken(clientId, clientSecret, code) } \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthenticationApi.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthenticationApi.kt index 030efecc7..257bb6f31 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthenticationApi.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/remote/AuthenticationApi.kt @@ -38,7 +38,7 @@ interface AuthenticationApi { suspend fun getToken( @Field("client_id") clientId: String, @Field("client_secret") clientSecret: String, - @Field("code") deviceCode: String, + @Field("code") code: String, @Field("grant_type") grantType: String = OPEN_SOURCE_GRANT_TYPE ): Response } \ No newline at end of file diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt index e35f565f0..66d65397b 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/data/repositoy/AuthenticationRepository.kt @@ -32,14 +32,14 @@ class AuthenticationRepository @Inject constructor(private val apiHelper: AuthAp } - suspend fun getToken(clientId: String, clientSecret: String, deviceCode: String): Token? { + suspend fun getToken(clientId: String, clientSecret: String, code: String): Token? { val tokenResponse = safeApiCall( call = { apiHelper.getToken( clientId = clientId, clientSecret = clientSecret, - deviceCode = deviceCode + code = code ) }, errorMessage = "Error Fetching Token" From eef4ae99bc368fc931d1874124f7c1183d29d46f Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Fri, 2 Oct 2020 11:04:13 +0200 Subject: [PATCH 21/22] removed extra token refreshing scheduling --- .../unchained/authentication/view/AuthenticationFragment.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/view/AuthenticationFragment.kt b/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/view/AuthenticationFragment.kt index 540f96a5e..edc3c21fc 100644 --- a/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/view/AuthenticationFragment.kt +++ b/app/app/src/main/java/com/github/livingwithhippos/unchained/authentication/view/AuthenticationFragment.kt @@ -63,8 +63,6 @@ class AuthenticationFragment : UnchainedFragment(), ButtonListener { authBinding.token = token // pass the value to be checked and eventually saved viewModel.checkAndSaveToken(token = token) - // program the refresh of the token - activityViewModel.programTokenRefresh(token.expiresIn) } }) From 5cb4a3efe946fa0c0e9e56412c16e1d87d8685ac Mon Sep 17 00:00:00 2001 From: LivingWithHippos Date: Fri, 2 Oct 2020 11:11:36 +0200 Subject: [PATCH 22/22] added missing injections to release flavor --- .../unchained/di/ApiFactory.kt | 6 ++++++ .../unchained/di/ApiFactory.kt | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/app/src/debug/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt b/app/app/src/debug/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt index 7369a09a3..8322d6b54 100644 --- a/app/app/src/debug/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt +++ b/app/app/src/debug/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt @@ -45,6 +45,12 @@ import javax.inject.Singleton @Module object ApiFactory { + /*********************************/ + // N.B. all updates to this code // + // also need to be ported to the // + // release build flavor version. // + /*********************************/ + @Provides @Singleton fun provideOkHttpClient(): OkHttpClient { diff --git a/app/app/src/release/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt b/app/app/src/release/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt index 412c7024e..a42025117 100644 --- a/app/app/src/release/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt +++ b/app/app/src/release/java/com/github/livingwithhippos/unchained/di/ApiFactory.kt @@ -21,6 +21,9 @@ import com.github.livingwithhippos.unchained.data.remote.UnrestrictApiHelperImpl import com.github.livingwithhippos.unchained.data.remote.UserApi import com.github.livingwithhippos.unchained.data.remote.UserApiHelper import com.github.livingwithhippos.unchained.data.remote.UserApiHelperImpl +import com.github.livingwithhippos.unchained.data.remote.VariousApi +import com.github.livingwithhippos.unchained.data.remote.VariousApiHelper +import com.github.livingwithhippos.unchained.data.remote.VariousApiHelperImpl import com.github.livingwithhippos.unchained.utilities.BASE_AUTH_URL import com.github.livingwithhippos.unchained.utilities.BASE_URL import com.squareup.moshi.Moshi @@ -42,6 +45,12 @@ import javax.inject.Singleton @Module object ApiFactory { + /*********************************/ + // N.B. all updates to this code // + // also need to be ported to the // + // debug build flavor version. // + /*********************************/ + @Provides @Singleton fun provideOkHttpClient(): OkHttpClient = OkHttpClient() @@ -153,4 +162,16 @@ object ApiFactory { @Singleton fun provideHostsApiHelper(apiHelper: HostsApiHelperImpl): HostsApiHelper = apiHelper + + // various api injection + @Provides + @Singleton + fun provideVariousApi(@ApiRetrofit retrofit: Retrofit): VariousApi { + return retrofit.create(VariousApi::class.java) + } + + @Provides + @Singleton + fun provideVariousApiHelper(apiHelper: VariousApiHelperImpl): VariousApiHelper = + apiHelper } \ No newline at end of file