Skip to content

Commit

Permalink
Merge branch 'release/1.2.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mouredev committed Oct 7, 2021
2 parents ec8fd42 + b0f0f8b commit 8cb8609
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 37 deletions.
5 changes: 2 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.mouredev.twitimer"
minSdkVersion 23
targetSdkVersion 30
versionCode 13
versionName "1.2.1"
versionCode 14
versionName "1.2.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
25 changes: 14 additions & 11 deletions app/src/main/java/com/mouredev/twitimer/model/session/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,17 @@ class Session {
success()
}, true)
})
}, failure)
}, failure, failure)
}, failure)
}

fun revoke(context: Context, success: () -> Unit) {

token?.accessToken?.let { accessToken ->
TwitchService.revoke(accessToken, {
clear(context)
success()
clear(context, success)
}, {
clear(context)
success()
clear(context, success)
})
}
}
Expand Down Expand Up @@ -213,6 +211,11 @@ class Session {
reloadUser(context, completion, true)
}, {
reloadUser(context, completion)
}, {
clear(context) {
PreferencesProvider.set(context, PreferencesKey.ONBOARDING, true)
completion()
}
})
}
}
Expand Down Expand Up @@ -504,7 +507,7 @@ class Session {
}
}

private fun clear(context: Context) {
private fun clear(context: Context, completion: (() -> Unit)) {

user?.followedUsers?.forEach { user ->
setupNotification(false, user)
Expand All @@ -521,10 +524,10 @@ class Session {

// Firebase Auth
FirebaseAuth.getInstance().signOut()
firebaseAuth(context)
firebaseAuth(context, completion)
}

private fun firebaseAuth(context: Context, completion: (() -> Unit)? = null) {
private fun firebaseAuth(context: Context, completion: (() -> Unit)) {

// Firebase auth anónima y permanente para poder realizar operaciones autenticadas contra Firebase
// TODO: Intentar integrar Twitch como sistema OAuth personalizado en Firebase
Expand All @@ -533,12 +536,12 @@ class Session {
authResult.user?.uid?.let { uid ->
PreferencesProvider.set(context, PreferencesKey.FIREBASE_AUTH_UID, uid)
}
completion?.invoke()
completion()
}.addOnFailureListener {
completion?.invoke()
completion()
}
} else {
completion?.invoke()
completion()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ object TwitchService {
})
}

fun user(context: Context, success: (user: User) -> Unit, failure: () -> Unit, retry: Boolean = false) {
fun user(context: Context, success: (user: User) -> Unit, failure: () -> Unit, authFailure: () -> Unit, retry: Boolean = false) {

val retrofit = Retrofit.Builder().baseUrl(TwitchServiceAPI.USER.baseUrl()).addConverterFactory(GsonConverterFactory.create()).build()
val service = retrofit.create(TwitchAPIService::class.java)
Expand All @@ -141,13 +141,18 @@ object TwitchService {
success(user)
} ?: run {
val refreshToken = Session.instance.token?.refreshToken
if (response.code() == AUTH_ERROR_STATUS_CODE && refreshToken != null && !retry) {
refreshToken(context, refreshToken, success = {
// Retry
user(context, success, failure, true)
}, failure = {
failure()
})
if (response.code() == AUTH_ERROR_STATUS_CODE) {
if (refreshToken != null && !retry) {
refreshToken(context, refreshToken, success = {
// Retry
user(context, success, failure, authFailure, true)
}, failure = {
failure()
})
} else {
// Close session
authFailure()
}
} else {
failure()
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip

0 comments on commit 8cb8609

Please sign in to comment.