diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..61a9130c --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 1e920cb0..08f79fea 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -15,6 +15,7 @@ diff --git a/.idea/misc.xml b/.idea/misc.xml index 703e5d4b..33782299 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,7 @@ - + diff --git a/build.gradle b/build.gradle index ad5456cb..0344cc20 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/sampleapp/build.gradle b/sampleapp/build.gradle index dd2a90b6..ebc9cb66 100644 --- a/sampleapp/build.gradle +++ b/sampleapp/build.gradle @@ -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") @@ -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' @@ -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" } diff --git a/sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/WikiPageActivity.kt b/sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/WikiPageActivity.kt index fd5d63b9..6f730515 100644 --- a/sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/WikiPageActivity.kt +++ b/sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/WikiPageActivity.kt @@ -95,7 +95,7 @@ class WikiPageActivity : BaseActivity() { doAsync( doWork = { - wikiPage = client?.wikisClient?.wikiPage(subreddit, page) + wikiPage = client?.wikisClient?.wikiPage(subreddit!!, page!!) }, onPost = { diff --git a/sampleapp/src/main/java/com/kirkbushman/sampleapp/util/doAsync.kt b/sampleapp/src/main/java/com/kirkbushman/sampleapp/util/doAsync.kt index c62119fd..09537bd3 100644 --- a/sampleapp/src/main/java/com/kirkbushman/sampleapp/util/doAsync.kt +++ b/sampleapp/src/main/java/com/kirkbushman/sampleapp/util/doAsync.kt @@ -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() { 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() + } }