Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions KEx/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.novoda.bintray-release'
apply plugin: 'com.github.dcendents.android-maven'

group='com.robertlevonyan.components'

android {
compileSdkVersion 27
Expand Down Expand Up @@ -36,14 +38,4 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

publish {
groupId = 'com.robertlevonyan.components'
artifactId = 'AndroidKEx'
publishVersion = '1.1.0'
userOrg = ''
desc = 'Extensions for Kotlin'
licences = ['Apache-2.0']
website = 'https://github.com/robertlevonyan/AndroidKEx'
}
34 changes: 22 additions & 12 deletions KEx/app/src/main/java/com/robertlevonyan/components/kex/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter

internal class ListAdapter<out T> : BaseAdapter {
class ListAdapter<out T> : BaseAdapter {
@LayoutRes
private val itemLayout: Int
private var items: Array<T>? = null
Expand Down Expand Up @@ -73,7 +73,7 @@ internal class ListAdapter<out T> : BaseAdapter {
}
}

internal class RecyclerAdapter<T> : RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
class RecyclerAdapter<T> : RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
@LayoutRes
private val itemLayout: Int
private var items: Array<T>? = null
Expand Down Expand Up @@ -124,13 +124,22 @@ internal class RecyclerAdapter<T> : RecyclerView.Adapter<RecyclerAdapter.ViewHol
creator(holder.itemView!!, item, position)
}

fun addItem(item: T) {
fun getItem(position: Int): T {
items?.let {
return it[position]
} ?: itemsList?.let {
return it[position]
}
?: throw NullPointerException("Your list is empty")
}

fun addItem(item: T, position: Int = 0) {
if (itemsList == null) {
throw NullPointerException("Your data is Array, change to List to add items dynamically")
}

itemsList?.add(item)
notifyItemInserted(itemsList?.size!!)
itemsList?.add(position, item)
notifyItemInserted(position)
}

fun updateItem(item: T, position: Int) = if (itemsList == null) {
Expand Down Expand Up @@ -160,10 +169,10 @@ internal class RecyclerAdapter<T> : RecyclerView.Adapter<RecyclerAdapter.ViewHol
return item!!
}

internal class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView)
class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView)
}

internal class TypedRecyclerAdapter<T> : RecyclerView.Adapter<TypedRecyclerAdapter.TypedViewHolder> {
class TypedRecyclerAdapter<T> : RecyclerView.Adapter<TypedRecyclerAdapter.TypedViewHolder> {
private val layoutForType: Map<Int, Int>
private var items: Array<T>? = null
private var itemsList: MutableList<T>? = null
Expand Down Expand Up @@ -202,11 +211,12 @@ internal class TypedRecyclerAdapter<T> : RecyclerView.Adapter<TypedRecyclerAdapt

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TypedRecyclerAdapter.TypedViewHolder {
var v: View? = null
layoutForType.forEach { type, layout ->
for (type in layoutForType.keys) {
val layout = layoutForType[type]
if (type == viewType) {
currentType = type
v = parent inflate layout
return@forEach
v = parent inflate layout!!
break
}
}
return TypedViewHolder(v)
Expand Down Expand Up @@ -273,10 +283,10 @@ internal class TypedRecyclerAdapter<T> : RecyclerView.Adapter<TypedRecyclerAdapt
return item!!
}

internal class TypedViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView)
class TypedViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView)
}

internal class PagerAdapter(fm: FragmentManager?) : FragmentPagerAdapter(fm) {
class PagerAdapter(fm: FragmentManager?) : FragmentPagerAdapter(fm) {

var fragmentsList = ArrayList<Fragment>()
var fragmentsArray: Array<Fragment>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager

val externalMap = mutableMapOf<View, Any>()

var View.isSwipable: Boolean
get() = externalMap[this] as Boolean
set(value) {
externalMap[this] = value
}

fun View.dismissKeyboard() {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(windowToken, 0)
Expand Down
5 changes: 4 additions & 1 deletion KEx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.novoda:bintray-release:0.8.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

}
}

allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }

}
}

Expand Down
2 changes: 1 addition & 1 deletion KEx/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
1 change: 1 addition & 0 deletions KEx/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ':app'
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,19 @@ Add following line of code to your module(app) level gradle file
viewPager.onPageScrolled { position, positionOffset, positionOffsetPixels -> ... }
viewPager.onPageSelected { position -> ... }
```


License
Copyright

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.