-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from InsanusMokrassar/0.3.1
0.3.1
- Loading branch information
Showing
56 changed files
with
1,196 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ build/ | |
out/ | ||
|
||
secret.gradle | ||
local.properties | ||
|
||
publishing.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
plugins { | ||
id "org.jetbrains.kotlin.multiplatform" | ||
id "org.jetbrains.kotlin.plugin.serialization" | ||
id "com.android.library" | ||
id "kotlin-android-extensions" | ||
} | ||
|
||
apply from: "$mppAndroidProjectPresetPath" | ||
|
||
kotlin { | ||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version" | ||
} | ||
} | ||
androidMain { | ||
dependencies { | ||
api "androidx.recyclerview:recyclerview:$androidx_recycler_version" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<manifest package="dev.inmo.micro_utils.android.recyclerview"/> |
22 changes: 22 additions & 0 deletions
22
...w/src/main/kotlin/dev/inmo/micro_utils/android/recyclerview/AbstractStandardViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
10 changes: 10 additions & 0 deletions
10
...yclerview/src/main/kotlin/dev/inmo/micro_utils/android/recyclerview/AbstractViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
9 changes: 9 additions & 0 deletions
9
android/recyclerview/src/main/kotlin/dev/inmo/micro_utils/android/recyclerview/Divider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
47 changes: 47 additions & 0 deletions
47
android/recyclerview/src/main/kotlin/dev/inmo/micro_utils/android/recyclerview/LeftItems.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
68 changes: 68 additions & 0 deletions
68
...clerview/src/main/kotlin/dev/inmo/micro_utils/android/recyclerview/RecyclerViewAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
plugins { | ||
id "org.jetbrains.kotlin.multiplatform" | ||
id "org.jetbrains.kotlin.plugin.serialization" | ||
id "com.android.library" | ||
id "kotlin-android-extensions" | ||
} | ||
|
||
apply from: "$mppProjectWithSerializationPresetPath" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<manifest package="dev.inmo.micro_utils.common"/> |
7 changes: 7 additions & 0 deletions
7
common/src/main/kotlin/dev/inmo/micro_utils/common/Mapping.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.inmo.micro_utils.common | ||
|
||
@Suppress("UNCHECKED_CAST", "SimplifiableCall") | ||
inline fun <T, R> Iterable<T>.mapNotNullA(transform: (T) -> R?): List<R> = map(transform).filter { it != null } as List<R> | ||
|
||
@Suppress("UNCHECKED_CAST", "SimplifiableCall") | ||
inline fun <T, R> Array<T>.mapNotNullA(mapper: (T) -> R?): List<R> = map(mapper).filter { it != null } as List<R> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<manifest package="dev.inmo.micro_utils.coroutines"/> |
10 changes: 10 additions & 0 deletions
10
coroutines/src/main/kotlin/dev/inmo/micro_utils/coroutines/DoInUI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
android { | ||
compileSdkVersion "$android_compileSdkVersion".toInteger() | ||
buildToolsVersion "$android_buildToolsVersion" | ||
|
||
defaultConfig { | ||
minSdkVersion "$android_minSdkVersion".toInteger() | ||
targetSdkVersion "$android_compileSdkVersion".toInteger() | ||
versionCode "${android_code_version}".toInteger() | ||
versionName "$version" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
} | ||
} | ||
|
||
packagingOptions { | ||
exclude 'META-INF/kotlinx-serialization-runtime.kotlin_module' | ||
exclude 'META-INF/kotlinx-serialization-cbor.kotlin_module' | ||
exclude 'META-INF/kotlinx-serialization-properties.kotlin_module' | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_1_8.toString() | ||
} | ||
} |
Oops, something went wrong.