-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into enhancement/#93-intent-keys-and-dependencies
- Loading branch information
Showing
15 changed files
with
228 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 1 addition & 6 deletions
7
Project/app/src/main/java/org/ionproject/android/common/ionwebapi/IonService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
package org.ionproject.android.common.ionwebapi | ||
|
||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.Headers | ||
import retrofit2.http.Url | ||
import retrofit2.http.* | ||
|
||
interface IonService { | ||
|
||
@Headers("Authorization: Bearer $WEB_API_AUTHORIZATION_TOKEN") | ||
@GET | ||
suspend fun getFromUri( | ||
@Url uri: String, | ||
@Header("Accept") accept: String | ||
): String | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
Project/app/src/main/java/org/ionproject/android/loading/RemoteConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.ionproject.android.loading | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class RemoteConfig( | ||
@JsonProperty("api_link") | ||
var api_link: String | ||
) |
48 changes: 48 additions & 0 deletions
48
Project/app/src/main/java/org/ionproject/android/loading/RemoteConfigRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.ionproject.android.loading | ||
|
||
import android.util.Log | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.ionproject.android.common.ionwebapi.* | ||
import org.ionproject.android.settings.Preferences | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.scalars.ScalarsConverterFactory | ||
import java.net.URI | ||
|
||
const val REMOTE_CONFIG_LINK = | ||
"https://raw.githubusercontent.com/i-on-project/isel/main/Remote_Config.json" | ||
|
||
class RemoteConfigRepository(private val preferences: Preferences, mapper: JacksonIonMapper) { | ||
|
||
private val retrofit = Retrofit.Builder() | ||
.baseUrl("https://raw.githubusercontent.com/") | ||
.addConverterFactory(ScalarsConverterFactory.create()) | ||
.build() | ||
|
||
private val service: IonService = retrofit.create(IonService::class.java) | ||
|
||
private val ionWebAPI = IonWebAPI(service, mapper) | ||
|
||
suspend fun getRemoteConfig() = | ||
|
||
withContext(Dispatchers.IO) { | ||
|
||
var remoteConfig: RemoteConfig? | ||
|
||
remoteConfig = ionWebAPI.getFromURI( | ||
URI(REMOTE_CONFIG_LINK), | ||
RemoteConfig::class.java, | ||
"application/json" | ||
) | ||
|
||
val storedApiUrl = preferences.getWebApiHost() | ||
|
||
//update the stored API URL in case it changed | ||
if (remoteConfig.api_link != storedApiUrl) { | ||
preferences.saveWebApiHost(remoteConfig.api_link) | ||
} | ||
Log.d("API", "remoteConfig in repo: $remoteConfig") | ||
|
||
remoteConfig | ||
} | ||
} |
Oops, something went wrong.