Skip to content

Commit

Permalink
Dialog update with token
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Nov 28, 2023
1 parent 35e87a4 commit 714e80e
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ object AppUpdateHelper {
activity: AppCompatActivity,
gitRepoUrl: String,
callback: ((String) -> Unit)? = null,
force: Boolean = false
force: Boolean = false,
token: String? = null
) = activity.lifecycle.coroutineScope.launch(Dispatchers.Main) {

val currentVersionName = activity.getVersionName()
Expand All @@ -61,7 +62,7 @@ object AppUpdateHelper {

if (force || prefs.getLong(key, 0) < System.currentTimeMillis() - 1000 * 3600 * 24 / 24 / 60 * 5) {
try {
val versionList = requestGithubVersions(gitRepoUrl)
val versionList = requestGithubVersions(gitRepoUrl, token)
prefs.edit().putLong(key, System.currentTimeMillis()).apply()

versionList.body()?.firstOrNull()?.let { release ->
Expand Down Expand Up @@ -107,13 +108,13 @@ object AppUpdateHelper {
}

private fun requestVersionsSync(gitRepoUrl: String, token: String? = null): Response<MutableList<GithubVersion>> {
val client = GithubClient(HttpLoggingInterceptor.Level.HEADERS, token)
val client = GithubClient(HttpLoggingInterceptor.Level.BODY, token)
return client.github.getGithubVersions(gitRepoUrl.user(), gitRepoUrl.repo()).execute()
}

private suspend fun requestGithubVersions(gitRepoUrl: String, token: String? = null): Response<MutableList<GithubVersion>> {
val versionList = withContext(Dispatchers.Default) {
val client = GithubClient(HttpLoggingInterceptor.Level.HEADERS, token)
val client = GithubClient(HttpLoggingInterceptor.Level.BODY, token)
client.github.getGithubVersions(gitRepoUrl.user(), gitRepoUrl.repo()).execute()
}
return versionList
Expand Down

0 comments on commit 714e80e

Please sign in to comment.