Skip to content

Commit

Permalink
updated to sdk 30, moved sample from asyncTask to coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
KirkBushman committed Aug 14, 2020
1 parent bccb493 commit 1d3530f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

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

1 change: 1 addition & 0 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.

9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ buildscript {
ext {
android_gradle_ver = '4.0.1'

compile_sdk_ver = 29
build_tools_ver = '29.0.3'
compile_sdk_ver = 30
build_tools_ver = '30.0.2'

min_sdk_ver = 19
compile_sdk_ver = 29
compile_sdk_ver = 30

kotlin_ver = '1.3.72'
coroutines_ver = '1.3.8'
ktx_core_ver = '1.3.1'
ktlint_ver = '0.37.2'
constr_ver = '2.0.0-rc1'
annot_ver = '1.1.0'
retrofit_ver = '2.9.0'
moshi_ver = '1.9.3' // '1.10.0-SNAPSHOT'
okhttp_ver = '4.8.0'
okhttp_ver = '4.8.1'
oauth2_ver = '1.2.1'
mdc_ver = '1.2.0'
epoxy_ver = '3.11.0'
Expand Down
5 changes: 3 additions & 2 deletions sampleapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_ver"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_ver"
implementation "androidx.constraintlayout:constraintlayout:$constr_ver"

implementation project(":lib")
Expand All @@ -60,7 +61,7 @@ dependencies {
implementation "com.google.android.material:material:$mdc_ver"

implementation "androidx.core:core-ktx:$ktx_core_ver"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
implementation 'androidx.browser:browser:1.2.0'

Expand All @@ -74,7 +75,7 @@ dependencies {
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"

androidTestImplementation "androidx.core:core:$ktx_core_ver"
androidTestImplementation "androidx.appcompat:appcompat:1.1.0"
androidTestImplementation "androidx.appcompat:appcompat:1.2.0"

androidTestImplementation "com.github.KirkBushman:Android-Reddit-OAuth2:$oauth2_ver"
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class WikiPageActivity : BaseActivity() {
doAsync(
doWork = {

wikiPage = client?.wikisClient?.wikiPage(subreddit, page)
wikiPage = client?.wikisClient?.wikiPage(subreddit!!, page!!)
},
onPost = {

Expand Down
34 changes: 28 additions & 6 deletions sampleapp/src/main/java/com/kirkbushman/sampleapp/util/doAsync.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
package com.kirkbushman.sampleapp.util

import android.os.AsyncTask
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.coroutines.CoroutineContext

class doAsync(

private val doWork: () -> Unit,
private val onPre: (() -> Unit)? = null,
private val onPost: (() -> Unit)? = null
) : CoroutineScope {

private val job = Job()
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + job

class doAsync(private val doWork: () -> Unit, private val onPost: (() -> Unit)? = null) : AsyncTask<Void, Void, Void>() {
init {
execute()
}

override fun doInBackground(vararg params: Void?): Void? {
doWork()
return null
fun cancel() {
job.cancel()
}

override fun onPostExecute(result: Void?) {
private fun execute() = launch {

onPre?.invoke()
doInBackground()
onPost?.invoke()
}

private suspend fun doInBackground() = withContext(Dispatchers.IO) {

doWork.invoke()
}
}

0 comments on commit 1d3530f

Please sign in to comment.