Skip to content

Commit 754ac99

Browse files
author
luca
committed
updated deps, updated ktlint, tested again
1 parent b5d0b4b commit 754ac99

File tree

11 files changed

+146
-98
lines changed

11 files changed

+146
-98
lines changed

.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth/src/main/java/com/kirkbushman/auth/managers/SharedPrefsStorageManager.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,20 @@ class SharedPrefsStorageManager(context: Context) : StorageManager {
3838

3939
override fun hasToken(): Boolean {
4040
return prefs.contains(LAST_ACCESS_TOKEN) &&
41-
prefs.contains(LAST_TOKEN_TYPE) &&
42-
prefs.contains(LAST_EXPIRES_IN) &&
43-
prefs.contains(LAST_CREATED_TIME) &&
44-
prefs.contains(LAST_SCOPES)
41+
prefs.contains(LAST_TOKEN_TYPE) &&
42+
prefs.contains(LAST_EXPIRES_IN) &&
43+
prefs.contains(LAST_CREATED_TIME) &&
44+
prefs.contains(LAST_SCOPES)
4545
}
4646

4747
override fun getToken(): Token {
48-
if (!prefs.contains(LAST_ACCESS_TOKEN) ||
48+
if (
49+
!prefs.contains(LAST_ACCESS_TOKEN) ||
4950
!prefs.contains(LAST_TOKEN_TYPE) ||
5051
!prefs.contains(LAST_EXPIRES_IN) ||
5152
!prefs.contains(LAST_CREATED_TIME) ||
52-
!prefs.contains(LAST_SCOPES)) {
53-
53+
!prefs.contains(LAST_SCOPES)
54+
) {
5455
throw IllegalStateException("Token not found in store! did you ever saved one?")
5556
}
5657

build.gradle

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@
33
buildscript {
44

55
ext {
6-
android_gradle_ver = '4.0.0'
6+
android_gradle_ver = '4.0.1'
77

8-
compileSdkVer = 29
9-
buildToolsVer = '29.0.3'
8+
compileSdkVer = 30
9+
buildToolsVer = '30.0.2'
1010

1111
minSdkVer = 19
12-
compileSdkVer = 29
12+
compileSdkVer = 30
1313

14-
kotlin_ver = '1.3.72'
15-
ktx_ver = '1.3.0'
16-
ktlint_ver = '0.36.0'
17-
mdc_ver = '1.1.0'
14+
kotlin_ver = '1.4.0'
15+
coroutines_ver = '1.3.9'
16+
ktx_ver = '1.3.1'
17+
ktlint_ver = '0.37.2'
18+
mdc_ver = '1.2.0'
1819
retrofit_ver = '2.9.0'
1920
moshi_ver = '1.9.3'
20-
okhttp_ver = '4.7.2'
21+
okhttp_ver = '4.8.1'
22+
23+
leakcanary_ver = '2.4'
2124
}
2225

2326
repositories {

sampleapp/build.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,19 @@ android {
4040
dependencies {
4141
implementation fileTree(dir: 'libs', include: ['*.jar'])
4242

43-
testImplementation 'junit:junit:4.13'
44-
4543
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_ver"
44+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_ver"
4645

4746
implementation project(':auth')
4847

4948
implementation "com.squareup.retrofit2:retrofit:$retrofit_ver"
5049

5150
implementation "com.google.android.material:material:$mdc_ver"
5251
implementation "androidx.core:core-ktx:$ktx_ver"
53-
implementation 'androidx.appcompat:appcompat:1.2.0-beta01'
52+
implementation 'androidx.appcompat:appcompat:1.2.0'
5453
implementation 'androidx.browser:browser:1.2.0'
54+
55+
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_ver"
56+
57+
testImplementation 'junit:junit:4.13'
5558
}

sampleapp/src/main/java/com/kirkbushman/sampleapp/DoAsync.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

sampleapp/src/main/java/com/kirkbushman/sampleapp/InstalledActivity.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,20 @@ class InstalledActivity : AppCompatActivity() {
3939
if (authClient!!.isRedirectedUrl(url)) {
4040
browser.stopLoading()
4141

42-
DoAsync(doWork = {
42+
doAsync(
43+
doWork = {
4344

44-
Log.i("Response URL", url)
45+
Log.i("Response URL", url)
4546

46-
val bearer = authClient.getTokenBearer(url)
47-
Log.i("SUCCESS", bearer?.toString() ?: "The bearer is null")
47+
val bearer = authClient.getTokenBearer(url)
48+
Log.i("SUCCESS", bearer?.toString() ?: "The bearer is null")
4849

49-
app.setBearer(bearer!!)
50+
app.setBearer(bearer!!)
5051

51-
val intent = Intent(this@InstalledActivity, TokenInfoActivity::class.java)
52-
startActivity(intent)
53-
})
52+
val intent = Intent(this@InstalledActivity, TokenInfoActivity::class.java)
53+
startActivity(intent)
54+
}
55+
)
5456
}
5557
}
5658
}

sampleapp/src/main/java/com/kirkbushman/sampleapp/MainActivity.kt

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,20 @@ class MainActivity : AppCompatActivity() {
4242

4343
var bearer: TokenBearer? = null
4444

45-
DoAsync(doWork = {
46-
47-
bearer = authClient?.getTokenBearer()
48-
}, onPost = {
49-
50-
if (bearer != null) {
51-
app.setBearer(bearer!!)
45+
doAsync(
46+
doWork = {
47+
bearer = authClient?.getTokenBearer()
48+
},
49+
onPost = {
50+
51+
if (bearer != null) {
52+
app.setBearer(bearer!!)
53+
}
54+
55+
val intent = Intent(this, TokenInfoActivity::class.java)
56+
startActivity(intent)
5257
}
53-
54-
val intent = Intent(this, TokenInfoActivity::class.java)
55-
startActivity(intent)
56-
})
58+
)
5759
}
5860
}
5961

@@ -71,18 +73,20 @@ class MainActivity : AppCompatActivity() {
7173

7274
var bearer: TokenBearer? = null
7375

74-
DoAsync(doWork = {
76+
doAsync(
77+
doWork = {
78+
bearer = authClient?.getTokenBearer()
79+
},
80+
onPost = {
7581

76-
bearer = authClient?.getTokenBearer()
77-
}, onPost = {
82+
if (bearer != null) {
83+
app.setBearer(bearer!!)
84+
}
7885

79-
if (bearer != null) {
80-
app.setBearer(bearer!!)
86+
val intent = Intent(this, TokenInfoActivity::class.java)
87+
startActivity(intent)
8188
}
82-
83-
val intent = Intent(this, TokenInfoActivity::class.java)
84-
startActivity(intent)
85-
})
89+
)
8690
}
8791
}
8892

sampleapp/src/main/java/com/kirkbushman/sampleapp/TokenInfoActivity.kt

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,31 @@ class TokenInfoActivity : AppCompatActivity() {
6464

6565
var exception: Exception? = null
6666

67-
DoAsync(doWork = {
67+
doAsync(
68+
doWork = {
6869

69-
try {
70-
bearer!!.renewToken()
71-
} catch (ex: Exception) {
72-
exception = ex
73-
}
74-
}, onPost = {
70+
try {
71+
bearer!!.renewToken()
72+
} catch (ex: Exception) {
73+
exception = ex
74+
}
75+
},
76+
onPost = {
7577

76-
val message = if (exception != null) {
78+
val message = if (exception != null) {
7779

78-
"A problem occured while refreshing the token, with exception: ${exception!!.message}"
79-
} else {
80-
val now = SimpleDateFormat("dd-MM-yyyy HH:mm", Locale.getDefault()).format(Date())
80+
"A problem occured while refreshing the token, with exception: ${exception!!.message}"
81+
} else {
82+
val now = SimpleDateFormat("dd-MM-yyyy HH:mm", Locale.getDefault()).format(Date())
8183

82-
"${bearer!!.getAccessToken()}, Refreshed $now"
83-
}
84+
"${bearer!!.getAccessToken()}, Refreshed $now"
85+
}
8486

85-
bindToken(bearer, message)
87+
bindToken(bearer, message)
8688

87-
Toast.makeText(this, "Token refreshed successfully", Toast.LENGTH_LONG).show()
88-
})
89+
Toast.makeText(this, "Token refreshed successfully", Toast.LENGTH_LONG).show()
90+
}
91+
)
8992
}
9093

9194
return true
@@ -98,28 +101,31 @@ class TokenInfoActivity : AppCompatActivity() {
98101
revokedErrorDialog.show()
99102
} else {
100103

101-
DoAsync(doWork = {
104+
doAsync(
105+
doWork = {
102106

103-
try {
104-
bearer!!.revokeToken()
105-
} catch (ex: Exception) {
106-
exception = ex
107-
}
108-
}, onPost = {
107+
try {
108+
bearer!!.revokeToken()
109+
} catch (ex: Exception) {
110+
exception = ex
111+
}
112+
},
113+
onPost = {
109114

110-
val message = if (exception != null) {
115+
val message = if (exception != null) {
111116

112-
"A problem has occurred while revoking the token, with message: ${exception!!.message}"
113-
} else {
114-
val now = SimpleDateFormat("dd-MM-yyyy HH:mm", Locale.getDefault()).format(Date())
117+
"A problem has occurred while revoking the token, with message: ${exception!!.message}"
118+
} else {
119+
val now = SimpleDateFormat("dd-MM-yyyy HH:mm", Locale.getDefault()).format(Date())
115120

116-
"Token was revoked $now"
117-
}
121+
"Token was revoked $now"
122+
}
118123

119-
bindToken(bearer, message)
124+
bindToken(bearer, message)
120125

121-
Toast.makeText(this, "Token revoked successfully", Toast.LENGTH_LONG).show()
122-
})
126+
Toast.makeText(this, "Token revoked successfully", Toast.LENGTH_LONG).show()
127+
}
128+
)
123129
}
124130

125131
return true
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.kirkbushman.sampleapp
2+
3+
import kotlinx.coroutines.CoroutineScope
4+
import kotlinx.coroutines.Dispatchers
5+
import kotlinx.coroutines.Job
6+
import kotlinx.coroutines.launch
7+
import kotlinx.coroutines.withContext
8+
import kotlin.coroutines.CoroutineContext
9+
10+
class doAsync(
11+
12+
private val doWork: () -> Unit,
13+
private val onPre: (() -> Unit)? = null,
14+
private val onPost: (() -> Unit)? = null
15+
) : CoroutineScope {
16+
17+
private val job = Job()
18+
override val coroutineContext: CoroutineContext
19+
get() = Dispatchers.Main + job
20+
21+
init {
22+
execute()
23+
}
24+
25+
fun cancel() {
26+
job.cancel()
27+
}
28+
29+
private fun execute() = launch {
30+
31+
onPre?.invoke()
32+
doInBackground()
33+
onPost?.invoke()
34+
}
35+
36+
private suspend fun doInBackground() = withContext(Dispatchers.IO) {
37+
38+
doWork.invoke()
39+
}
40+
}

0 commit comments

Comments
 (0)