mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
updates of dokka
This commit is contained in:
parent
c59e601e2e
commit
5b596c76e0
@ -11,13 +11,12 @@ kotlin {
|
|||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
api internalProject("micro_utils.repos.common")
|
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||||
api internalProject("micro_utils.coroutines")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
androidMain {
|
androidMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "androidx.core:core-ktx:$core_ktx_version"
|
api "androidx.recyclerview:recyclerview:$androidx_recycler_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
1
android/recyclerview/src/main/AndroidManifest.xml
Normal file
1
android/recyclerview/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1 @@
|
|||||||
|
<manifest package="dev.inmo.micro_utils.android.recyclerview"/>
|
@ -0,0 +1,22 @@
|
|||||||
|
package dev.inmo.micro_utils.android.recyclerview
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
|
||||||
|
abstract class AbstractStandardViewHolder<T>(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
viewId: Int,
|
||||||
|
onViewInflated: ((View) -> Unit)? = null
|
||||||
|
) : AbstractViewHolder<T>(
|
||||||
|
inflater.inflate(viewId, container, false).also {
|
||||||
|
onViewInflated ?.invoke(it)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
constructor(
|
||||||
|
container: ViewGroup,
|
||||||
|
viewId: Int,
|
||||||
|
onViewInflated: ((View) -> Unit)? = null
|
||||||
|
) : this(LayoutInflater.from(container.context), container, viewId, onViewInflated)
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package dev.inmo.micro_utils.android.recyclerview
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
|
abstract class AbstractViewHolder<in T>(
|
||||||
|
view: View
|
||||||
|
) : RecyclerView.ViewHolder(view) {
|
||||||
|
abstract fun onBind(item: T)
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package dev.inmo.micro_utils.android.recyclerview
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import androidx.recyclerview.widget.DividerItemDecoration
|
||||||
|
|
||||||
|
val Context.recyclerViewItemsDecoration
|
||||||
|
get() = DividerItemDecoration(this, LinearLayout.VERTICAL)
|
||||||
|
|
@ -0,0 +1,47 @@
|
|||||||
|
package dev.inmo.micro_utils.android.recyclerview
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.flow.*
|
||||||
|
|
||||||
|
fun RecyclerView.lastVisibleItemFlow(
|
||||||
|
completingScope: CoroutineScope
|
||||||
|
): Flow<Int> {
|
||||||
|
val lastVisibleElementFun: () -> Int = (layoutManager as? LinearLayoutManager) ?.let { it::findLastVisibleItemPosition } ?: error("Currently supported only linear layout manager")
|
||||||
|
val lastVisibleFlow = MutableStateFlow(lastVisibleElementFun())
|
||||||
|
addOnScrollListener(
|
||||||
|
object : RecyclerView.OnScrollListener() {
|
||||||
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
|
super.onScrolled(recyclerView, dx, dy)
|
||||||
|
lastVisibleFlow.value = lastVisibleElementFun()
|
||||||
|
}
|
||||||
|
}.also { scrollListener ->
|
||||||
|
lastVisibleFlow.onCompletion {
|
||||||
|
removeOnScrollListener(scrollListener)
|
||||||
|
}.launchIn(completingScope)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return lastVisibleFlow.asStateFlow()
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun Flow<Int>.mapLeftItems(
|
||||||
|
crossinline countGetter: () -> Int
|
||||||
|
): Flow<Int> = map { countGetter() - it }
|
||||||
|
|
||||||
|
inline fun Flow<Int>.mapRequireFilling(
|
||||||
|
minimalLeftItems: Int,
|
||||||
|
crossinline countGetter: () -> Int
|
||||||
|
): Flow<Int> = mapLeftItems(countGetter).mapNotNull {
|
||||||
|
if (it < minimalLeftItems) {
|
||||||
|
it
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun RecyclerView.mapRequireFilling(
|
||||||
|
minimalLeftItems: Int,
|
||||||
|
completingScope: CoroutineScope,
|
||||||
|
crossinline countGetter: () -> Int
|
||||||
|
): Flow<Int> = lastVisibleItemFlow(completingScope).mapRequireFilling(minimalLeftItems, countGetter)
|
@ -0,0 +1,68 @@
|
|||||||
|
package dev.inmo.micro_utils.android.recyclerview
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
|
|
||||||
|
abstract class RecyclerViewAdapter<T>(
|
||||||
|
val data: List<T>
|
||||||
|
): RecyclerView.Adapter<AbstractViewHolder<T>>() {
|
||||||
|
var emptyView: View? = null
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
checkEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
registerAdapterDataObserver(
|
||||||
|
object : RecyclerView.AdapterDataObserver() {
|
||||||
|
override fun onItemRangeChanged(positionStart: Int, itemCount: Int) {
|
||||||
|
super.onItemRangeChanged(positionStart, itemCount)
|
||||||
|
checkEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?) {
|
||||||
|
super.onItemRangeChanged(positionStart, itemCount, payload)
|
||||||
|
checkEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onChanged() {
|
||||||
|
super.onChanged()
|
||||||
|
checkEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||||
|
super.onItemRangeRemoved(positionStart, itemCount)
|
||||||
|
checkEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
|
||||||
|
super.onItemRangeMoved(fromPosition, toPosition, itemCount)
|
||||||
|
checkEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||||
|
super.onItemRangeInserted(positionStart, itemCount)
|
||||||
|
checkEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
checkEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = data.size
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: AbstractViewHolder<T>, position: Int) {
|
||||||
|
holder.onBind(data[position])
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkEmpty() {
|
||||||
|
emptyView ?. let {
|
||||||
|
if (data.isEmpty()) {
|
||||||
|
it.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
it.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ buildscript {
|
|||||||
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
|
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
|
||||||
classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:$dexcount_version"
|
classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:$dexcount_version"
|
||||||
classpath "com.github.breadmoirai:github-release:$github_release_plugin_version"
|
classpath "com.github.breadmoirai:github-release:$github_release_plugin_version"
|
||||||
|
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,5 +14,10 @@ kotlin {
|
|||||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
androidMain {
|
||||||
|
dependencies {
|
||||||
|
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package dev.inmo.micro_utils.coroutines
|
||||||
|
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
suspend inline fun <T> doInUI(noinline block: suspend CoroutineScope.() -> T) = withContext(
|
||||||
|
Dispatchers.Main,
|
||||||
|
block
|
||||||
|
)
|
@ -1,26 +1,15 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenLocal()
|
|
||||||
jcenter()
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
|
||||||
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
id "org.jetbrains.kotlin.plugin.serialization"
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
id "org.jetbrains.dokka" version "$dokka_version"
|
id "com.android.library"
|
||||||
|
id "kotlin-android-extensions"
|
||||||
|
id "org.jetbrains.dokka"
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
jcenter()
|
jcenter()
|
||||||
|
google()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +19,7 @@ kotlin {
|
|||||||
browser()
|
browser()
|
||||||
nodejs()
|
nodejs()
|
||||||
}
|
}
|
||||||
|
android {}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
@ -41,6 +31,57 @@ kotlin {
|
|||||||
it != project
|
it != project
|
||||||
&& it.hasProperty("kotlin")
|
&& it.hasProperty("kotlin")
|
||||||
&& it.kotlin.sourceSets.any { it.name.contains("commonMain") }
|
&& it.kotlin.sourceSets.any { it.name.contains("commonMain") }
|
||||||
|
&& it.kotlin.sourceSets.any { it.name.contains("jsMain") }
|
||||||
|
&& it.kotlin.sourceSets.any { it.name.contains("jvmMain") }
|
||||||
|
&& it.kotlin.sourceSets.any { it.name.contains("androidMain") }
|
||||||
|
) {
|
||||||
|
api it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jsMain {
|
||||||
|
dependencies {
|
||||||
|
implementation kotlin('stdlib')
|
||||||
|
|
||||||
|
project.parent.subprojects.forEach {
|
||||||
|
if (
|
||||||
|
it != project
|
||||||
|
&& it.hasProperty("kotlin")
|
||||||
|
&& it.kotlin.sourceSets.any { it.name.contains("commonMain") }
|
||||||
|
&& it.kotlin.sourceSets.any { it.name.contains("jsMain") }
|
||||||
|
) {
|
||||||
|
api it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jvmMain {
|
||||||
|
dependencies {
|
||||||
|
implementation kotlin('stdlib')
|
||||||
|
|
||||||
|
project.parent.subprojects.forEach {
|
||||||
|
if (
|
||||||
|
it != project
|
||||||
|
&& it.hasProperty("kotlin")
|
||||||
|
&& it.kotlin.sourceSets.any { it.name.contains("commonMain") }
|
||||||
|
&& it.kotlin.sourceSets.any { it.name.contains("jvmMain") }
|
||||||
|
) {
|
||||||
|
api it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
androidMain {
|
||||||
|
dependencies {
|
||||||
|
implementation kotlin('stdlib')
|
||||||
|
|
||||||
|
project.parent.subprojects.forEach {
|
||||||
|
if (
|
||||||
|
it != project
|
||||||
|
&& it.hasProperty("kotlin")
|
||||||
|
&& it.kotlin.sourceSets.any { it.name.contains("commonMain") }
|
||||||
|
&& it.kotlin.sourceSets.any { it.name.contains("androidMain") }
|
||||||
) {
|
) {
|
||||||
api it
|
api it
|
||||||
}
|
}
|
||||||
@ -84,5 +125,11 @@ tasks.dokkaHtml {
|
|||||||
named("jvmMain") {
|
named("jvmMain") {
|
||||||
sourceRoots.setFrom(findSourcesWithName("jvmMain", "commonMain"))
|
sourceRoots.setFrom(findSourcesWithName("jvmMain", "commonMain"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
named("androidMain") {
|
||||||
|
sourceRoots.setFrom(findSourcesWithName("androidMain", "commonMain"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$defaultAndroidSettingsPresetPath"
|
||||||
|
@ -1,3 +1 @@
|
|||||||
dokka_version=1.4.0
|
|
||||||
|
|
||||||
org.gradle.jvmargs=-Xmx1024m
|
org.gradle.jvmargs=-Xmx1024m
|
||||||
|
1
dokka/src/main/AndroidManifest.xml
Normal file
1
dokka/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1 @@
|
|||||||
|
<manifest package="dev.inmo.dokka"/>
|
@ -23,6 +23,7 @@ uuidVersion=0.2.2
|
|||||||
# ANDROID
|
# ANDROID
|
||||||
|
|
||||||
core_ktx_version=1.3.2
|
core_ktx_version=1.3.2
|
||||||
|
androidx_recycler_version=1.1.0
|
||||||
|
|
||||||
android_minSdkVersion=24
|
android_minSdkVersion=24
|
||||||
android_compileSdkVersion=30
|
android_compileSdkVersion=30
|
||||||
@ -32,6 +33,12 @@ junit_version=4.12
|
|||||||
test_ext_junit_version=1.1.2
|
test_ext_junit_version=1.1.2
|
||||||
espresso_core=3.3.0
|
espresso_core=3.3.0
|
||||||
|
|
||||||
|
# Dokka
|
||||||
|
|
||||||
|
dokka_version=1.4.0
|
||||||
|
|
||||||
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.3.1
|
version=0.3.1
|
||||||
android_code_version=1
|
android_code_version=1
|
||||||
|
@ -1 +0,0 @@
|
|||||||
<manifest package="${manifestPackage}"/>
|
|
@ -17,6 +17,7 @@ String[] includes = [
|
|||||||
":ktor:common",
|
":ktor:common",
|
||||||
":ktor:client",
|
":ktor:client",
|
||||||
":coroutines",
|
":coroutines",
|
||||||
|
":android:recyclerview",
|
||||||
|
|
||||||
":dokka"
|
":dokka"
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user