├── app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── styles.xml │ │ │ └── colors.xml │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── layout │ │ │ ├── item_type0.xml │ │ │ ├── activity_sigle1.xml │ │ │ ├── activity_sigle2.xml │ │ │ ├── activity_multi1.xml │ │ │ ├── activity_multi2.xml │ │ │ ├── item_sigle1.xml │ │ │ ├── item_sigle2.xml │ │ │ ├── item_type1.xml │ │ │ └── activity_main.xml │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ └── drawable │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ └── kt │ │ │ └── ktbindadapter │ │ │ ├── bean │ │ │ └── ItemInfo.kt │ │ │ ├── MainActivity.kt │ │ │ ├── Sigle1Activity.kt │ │ │ ├── Multi1Activity.kt │ │ │ ├── Sigle2Activity.kt │ │ │ └── Multi2Activity.kt │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── ktTool ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ └── attrs.xml │ │ ├── drawable-xxhdpi │ │ │ ├── toast_frame.9.png │ │ │ ├── ic_check_white_48dp.png │ │ │ ├── ic_clear_white_48dp.png │ │ │ ├── ic_info_outline_white_48dp.png │ │ │ ├── ic_error_outline_white_48dp.png │ │ │ └── shape_round_white.xml │ │ ├── hdpi-drawable │ │ │ ├── ic_check_white_48dp.png │ │ │ ├── ic_clear_white_48dp.png │ │ │ ├── ic_info_outline_white_48dp.png │ │ │ └── ic_error_outline_white_48dp.png │ │ └── layout │ │ │ ├── dia_base_bottom.xml │ │ │ ├── toast_layout.xml │ │ │ ├── view_error.xml │ │ │ ├── view_empty.xml │ │ │ ├── view_no_network.xml │ │ │ ├── view_loding.xml │ │ │ └── dia_t.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── tgs │ │ └── kttool │ │ ├── util │ │ ├── IntExt.kt │ │ ├── AnyExt.kt │ │ ├── BooleanExt.kt │ │ ├── AppUtil.kt │ │ ├── StringExt.kt │ │ ├── GlideCircleTransform.java │ │ ├── ViewExt.kt │ │ ├── SPUtil.kt │ │ ├── ViewBindingAdapter.kt │ │ ├── DateUtil.kt │ │ ├── FileUtil.kt │ │ └── ToastUtil.kt │ │ ├── ToolConfigs.kt │ │ ├── ToolApplication.kt │ │ └── view │ │ ├── BindEditText.kt │ │ ├── BaseBottomDia.kt │ │ ├── TDialog.kt │ │ ├── RotateLoading.java │ │ └── LoadView.kt ├── proguard-rules.pro └── build.gradle ├── ktAdapter ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ └── strings.xml │ │ └── layout │ │ │ └── item_test.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── tgs │ │ └── adapter │ │ ├── BindViewHolder.kt │ │ ├── MultiItem.kt │ │ ├── SimpleMultiAdapter.kt │ │ ├── SimpleAdapter.kt │ │ ├── BaseSigleAdapter.kt │ │ ├── BaseMultiAdapter.kt │ │ └── BaseAdapter.kt ├── build.gradle └── proguard-rules.pro ├── githubGreen-csharp.txt ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /ktTool/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /ktAdapter/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /githubGreen-csharp.txt: -------------------------------------------------------------------------------- 1 | 2019/7/12-4 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':ktAdapter', ':ktTool' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | KtBindAdapter 3 | 4 | -------------------------------------------------------------------------------- /ktTool/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | KtTool 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ktAdapter/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BindAdapter 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ktAdapter/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ktTool/src/main/res/drawable-xxhdpi/toast_frame.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/ktTool/src/main/res/drawable-xxhdpi/toast_frame.9.png -------------------------------------------------------------------------------- /ktTool/src/main/res/drawable-xxhdpi/ic_check_white_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/ktTool/src/main/res/drawable-xxhdpi/ic_check_white_48dp.png -------------------------------------------------------------------------------- /ktTool/src/main/res/drawable-xxhdpi/ic_clear_white_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/ktTool/src/main/res/drawable-xxhdpi/ic_clear_white_48dp.png -------------------------------------------------------------------------------- /ktTool/src/main/res/hdpi-drawable/ic_check_white_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/ktTool/src/main/res/hdpi-drawable/ic_check_white_48dp.png -------------------------------------------------------------------------------- /ktTool/src/main/res/hdpi-drawable/ic_clear_white_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/ktTool/src/main/res/hdpi-drawable/ic_clear_white_48dp.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | /.idea -------------------------------------------------------------------------------- /ktTool/src/main/res/hdpi-drawable/ic_info_outline_white_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/ktTool/src/main/res/hdpi-drawable/ic_info_outline_white_48dp.png -------------------------------------------------------------------------------- /ktTool/src/main/res/drawable-xxhdpi/ic_info_outline_white_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/ktTool/src/main/res/drawable-xxhdpi/ic_info_outline_white_48dp.png -------------------------------------------------------------------------------- /ktTool/src/main/res/hdpi-drawable/ic_error_outline_white_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/ktTool/src/main/res/hdpi-drawable/ic_error_outline_white_48dp.png -------------------------------------------------------------------------------- /ktTool/src/main/res/drawable-xxhdpi/ic_error_outline_white_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TianGuisen/KtBindAdapter/HEAD/ktTool/src/main/res/drawable-xxhdpi/ic_error_outline_white_48dp.png -------------------------------------------------------------------------------- /app/src/main/java/kt/ktbindadapter/bean/ItemInfo.kt: -------------------------------------------------------------------------------- 1 | package kt.ktbindadapter.bean 2 | 3 | class ItemInfo(var name: String?, var age: Int) { 4 | 5 | override fun toString(): String { 6 | return "ItemInfo(name=$name, age=$age)" 7 | } 8 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /ktAdapter/src/main/java/tgs/adapter/BindViewHolder.kt: -------------------------------------------------------------------------------- 1 | package kt.ktbindadapter.baseAdapter 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | 6 | class BindViewHolder(itemView: View, val binding: VB) : RecyclerView.ViewHolder(itemView) -------------------------------------------------------------------------------- /ktAdapter/src/main/java/tgs/adapter/MultiItem.kt: -------------------------------------------------------------------------------- 1 | package tgs.adapter 2 | 3 | /** 4 | * 多type的需要用这个包装实体类 5 | */ 6 | class MultiItem(var itemType: Int, var data: T) { 7 | override fun toString(): String { 8 | return "MultiItem(itemType=$itemType, data=$data)" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ktTool/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ktTool/src/main/java/tgs/kttool/util/IntExt.kt: -------------------------------------------------------------------------------- 1 | package tgs.kttool.util 2 | 3 | import tgs.kttool.ToolApplication.toolAppContext 4 | 5 | 6 | fun Int.dp2px() = (toolAppContext.getResources().getDisplayMetrics().density * this + 0.5).toInt() 7 | 8 | fun Int.px2dp() = (this / (toolAppContext.getResources().getDisplayMetrics().density) + 0.5).toInt() 9 | -------------------------------------------------------------------------------- /ktTool/src/main/res/drawable-xxhdpi/shape_round_white.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /ktTool/src/main/java/tgs/kttool/ToolConfigs.kt: -------------------------------------------------------------------------------- 1 | package tgs.kttool 2 | 3 | object ToolConfigs { 4 | //在Bugly上创建2个应用,一个用于测试一个用于线上,避免搞不清楚出的bug是测试测出的bug还是线上bug 5 | const val BUGLY_APPID_RELEASE = "9658217cfb" 6 | const val BUGLY_APPID_DEBUG = "abc" 7 | /** 8 | * Logger日志的tag 9 | */ 10 | const val LOGGER_TAG = "tian" 11 | /** 12 | * Logger网络请求日志的tag 13 | */ 14 | const val LOGGER_NET_TAG = "retrofit" 15 | 16 | 17 | } -------------------------------------------------------------------------------- /ktAdapter/src/main/res/layout/item_test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ktTool/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ktAdapter/src/main/java/tgs/adapter/SimpleMultiAdapter.kt: -------------------------------------------------------------------------------- 1 | package tgs.adapter 2 | 3 | import android.databinding.ViewDataBinding 4 | import kt.ktbindadapter.baseAdapter.BindViewHolder 5 | 6 | /** 7 | * Created by 田桂森 on 2017/8/18. 8 | * 多type如果不需要设置item中子类子类点击事件用这个 9 | */ 10 | class SimpleMultiAdapter(datas: MutableList>) : BaseMultiAdapter(datas) { 11 | override fun decorator(bean: MultiItem, holder: BindViewHolder, position: Int) { 12 | 13 | } 14 | } -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ktAdapter/src/main/java/tgs/adapter/SimpleAdapter.kt: -------------------------------------------------------------------------------- 1 | package tgs.adapter 2 | 3 | import android.databinding.ViewDataBinding 4 | import kt.ktbindadapter.baseAdapter.BindViewHolder 5 | 6 | /** 7 | * Created by 田桂森 on 2017/8/17. 8 | * 如果不需要设置item中子类点击事件用这个 9 | */ 10 | 11 | class SimpleAdapter(datas: MutableList, layoutId: Int) : BaseSigleAdapter(datas, layoutId) { 12 | override fun decorator(bean: E, holder: BindViewHolder, position: Int) { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ktAdapter/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'com.github.dcendents.android-maven' 4 | group='com.github.TianGuisen' 5 | kotlin { 6 | experimental { 7 | coroutines "enable" 8 | } 9 | } 10 | android { 11 | compileSdkVersion 27 12 | defaultConfig { 13 | minSdkVersion 15 14 | targetSdkVersion 27 15 | } 16 | dataBinding { 17 | enabled = true 18 | } 19 | 20 | } 21 | 22 | dependencies { 23 | implementation 'com.android.support:recyclerview-v7:27.1.1' 24 | } 25 | -------------------------------------------------------------------------------- /ktTool/src/main/java/tgs/kttool/util/AnyExt.kt: -------------------------------------------------------------------------------- 1 | package tgs.kttool.util 2 | 3 | import android.app.Activity 4 | import android.content.Intent 5 | import android.icu.lang.UCharacter.GraphemeClusterBreak.T 6 | import com.alibaba.fastjson.JSON 7 | 8 | fun Any.toJson(): String = JSON.toJSONString(this) 9 | 10 | /** 11 | * 获取泛型的.class 12 | * 以reified修饰类型后,就能够在函数内部使用相关类型。 13 | */ 14 | inline fun classOf() = T::class.java 15 | 16 | //以reified修饰类型后,就能够在函数内部使用相关类型。 17 | private inline fun Activity.startActivity() { 18 | startActivity(Intent(this, T::class.java)) 19 | } -------------------------------------------------------------------------------- /ktTool/src/main/res/layout/dia_base_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_type0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FB7299 4 | #FA7199 5 | #FA7199 6 | #FDC5D5 7 | #fff 8 | #555555 9 | #FFFFD11D 10 | #99AAAAAA 11 | #FFFFFF 12 | #66BABABA 13 | #FF797979 14 | #00f 15 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /ktTool/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /ktAdapter/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /ktTool/src/main/java/tgs/kttool/util/BooleanExt.kt: -------------------------------------------------------------------------------- 1 | package tgs.kttool.util; 2 | 3 | /** 4 | * 其实实用性不大,练习泛型和枚举类 5 | */ 6 | sealed class BooleanExt 7 | 8 | object Otherwise : BooleanExt() 9 | class WithData(val data:T) : BooleanExt() 10 | 11 | inline fun Boolean.yes(function: () -> T): BooleanExt = when { 12 | true -> { 13 | WithData(function()) 14 | } 15 | else -> { 16 | Otherwise 17 | } 18 | 19 | } 20 | 21 | 22 | inline fun Boolean.no(function: () -> T): BooleanExt = when { 23 | true -> { 24 | Otherwise 25 | } 26 | else -> { 27 | WithData(function()) 28 | } 29 | } 30 | 31 | @Suppress("UNCHECKED_CAST") 32 | inline fun BooleanExt.otherwise(function: () -> T): T = when (this) { 33 | is Otherwise -> function() 34 | is WithData -> this.data 35 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_sigle1.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_sigle2.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_multi1.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_multi2.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_sigle1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 18 | 19 | 26 | 27 | -------------------------------------------------------------------------------- /ktTool/src/main/res/layout/toast_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 20 | 21 | -------------------------------------------------------------------------------- /ktTool/src/main/java/tgs/kttool/ToolApplication.kt: -------------------------------------------------------------------------------- 1 | package tgs.kttool 2 | 3 | import android.app.Application 4 | import com.orhanobut.logger.AndroidLogAdapter 5 | import com.orhanobut.logger.Logger 6 | import com.orhanobut.logger.PrettyFormatStrategy 7 | import kt.ktbindadapter.BuildConfig 8 | 9 | 10 | object ToolApplication { 11 | lateinit var toolAppContext: Application 12 | fun init(appContext: Application) { 13 | toolAppContext = appContext 14 | val strategy = PrettyFormatStrategy.newBuilder() 15 | .showThreadInfo(false) // 是否显示线程信息,默认为ture 16 | .methodCount(1) // 显示的方法行数 17 | .methodOffset(0) // 隐藏内部方法调用到偏移量 18 | .tag(ToolConfigs.LOGGER_TAG) 19 | .build() 20 | Logger.addLogAdapter(object : AndroidLogAdapter(strategy) { 21 | override fun isLoggable(priority: Int, tag: String?): Boolean { 22 | return BuildConfig.DEBUG 23 | } 24 | }) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_sigle2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 18 | 19 | 25 | 26 | 32 | 33 | -------------------------------------------------------------------------------- /ktTool/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'kotlin-kapt' 5 | kotlin { 6 | experimental { 7 | coroutines "enable" 8 | } 9 | androidExtensions { 10 | experimental = true 11 | } 12 | } 13 | android { 14 | compileSdkVersion 27 15 | 16 | defaultConfig { 17 | minSdkVersion 15 18 | targetSdkVersion 27 19 | } 20 | dataBinding { 21 | enabled = true 22 | } 23 | } 24 | 25 | dependencies { 26 | //log日志 27 | api 'com.orhanobut:logger:2.2.0' 28 | //只能使用特定版本,最新版不支持kotlin 29 | api 'com.alibaba:fastjson:1.1.61.android' 30 | api 'com.android.support:support-v4:27.1.1' 31 | //下拉刷新https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_property.md 32 | api 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-7' 33 | api 'com.github.bumptech.glide:glide:4.7.1' 34 | api 'com.android.support:design:27.1.1' 35 | api 'com.android.support.constraint:constraint-layout:1.1.3' 36 | } 37 | -------------------------------------------------------------------------------- /ktTool/src/main/res/layout/view_error.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 24 | -------------------------------------------------------------------------------- /ktTool/src/main/res/layout/view_empty.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 24 | -------------------------------------------------------------------------------- /ktTool/src/main/java/tgs/kttool/util/AppUtil.kt: -------------------------------------------------------------------------------- 1 | package tgs.kttool.util 2 | 3 | import android.content.Context 4 | import android.net.ConnectivityManager 5 | import android.net.NetworkInfo 6 | import android.provider.Settings 7 | import android.support.v4.content.ContextCompat 8 | import tgs.kttool.ToolApplication.toolAppContext 9 | 10 | object AppUtil { 11 | 12 | /** 13 | * 网络是否链接 14 | */ 15 | fun isConnected(): Boolean { 16 | (toolAppContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).activeNetworkInfo.also { 17 | if (null != it && it.isConnected) { 18 | if (it.state == NetworkInfo.State.CONNECTED) { 19 | return true 20 | } 21 | } 22 | } 23 | return false 24 | } 25 | 26 | /** 27 | * 获得values里的colors 28 | */ 29 | fun getColor(colorId: Int) = ContextCompat.getColor(toolAppContext, colorId) 30 | 31 | /** 32 | * 设备id 33 | */ 34 | val deviceId: String 35 | get() = Settings.Secure.getString(toolAppContext.contentResolver, Settings.Secure.ANDROID_ID) 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/kt/ktbindadapter/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package kt.ktbindadapter 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.support.v7.app.AppCompatActivity 6 | import android.view.View 7 | 8 | class MainActivity : AppCompatActivity() { 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | setContentView(R.layout.activity_main) 13 | findViewById(R.id.tv1).setOnClickListener { 14 | MainActivity@ this.startActivity(Intent(MainActivity@ this, Sigle1Activity::class.java)) 15 | } 16 | findViewById(R.id.tv2).setOnClickListener { 17 | MainActivity@ this.startActivity(Intent(MainActivity@ this, Sigle2Activity::class.java)) 18 | } 19 | findViewById(R.id.tv3).setOnClickListener { 20 | MainActivity@ this.startActivity(Intent(MainActivity@ this, Multi1Activity::class.java)) 21 | } 22 | findViewById(R.id.tv4).setOnClickListener { 23 | MainActivity@ this.startActivity(Intent(MainActivity@ this, Multi2Activity::class.java)) 24 | } 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /ktTool/src/main/res/layout/view_no_network.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 25 | -------------------------------------------------------------------------------- /ktTool/src/main/res/layout/view_loding.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_type1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 17 | 18 | 26 | 27 | 35 | 36 | -------------------------------------------------------------------------------- /ktTool/src/main/java/tgs/kttool/view/BindEditText.kt: -------------------------------------------------------------------------------- 1 | package tgs.kttool.view 2 | 3 | import android.content.Context 4 | import android.graphics.Rect 5 | import android.util.AttributeSet 6 | 7 | /** 8 | * Created by 田桂森 on 2017/7/27. 9 | * 实现了使用ObservableBoolean监听和控制edittext的焦点。 10 | * 使用editText无法实现这个功能,这是自定义双向绑定. 11 | * bind:focus="@={vm.?}" 12 | */ 13 | 14 | class BindEditText : android.support.v7.widget.AppCompatEditText { 15 | 16 | private var onFocusChangedListener: OnFocusChangedListener? = null 17 | 18 | constructor(context: Context) : super(context) {} 19 | 20 | constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {} 21 | 22 | 23 | constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {} 24 | 25 | override fun onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?) { 26 | super.onFocusChanged(focused, direction, previouslyFocusedRect) 27 | onFocusChangedListener?.onChanged() 28 | } 29 | 30 | fun setListener(onFocusChangedListener: OnFocusChangedListener) { 31 | this.onFocusChangedListener = onFocusChangedListener 32 | } 33 | 34 | interface OnFocusChangedListener { 35 | fun onChanged() 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /app/src/main/java/kt/ktbindadapter/Sigle1Activity.kt: -------------------------------------------------------------------------------- 1 | package kt.ktbindadapter 2 | 3 | import android.databinding.ObservableArrayList 4 | import android.os.Bundle 5 | import android.support.v7.app.AppCompatActivity 6 | import android.support.v7.widget.DividerItemDecoration 7 | import kotlinx.android.synthetic.main.activity_sigle1.* 8 | import tgs.adapter.SimpleAdapter 9 | import kt.ktbindadapter.bean.ItemInfo 10 | import tgs.kttool.util.ToastUtil 11 | 12 | class Sigle1Activity : AppCompatActivity() { 13 | val listData = ObservableArrayList() 14 | 15 | init { 16 | for (i1 in 0..9) { 17 | listData.add(ItemInfo("name" + i1, i1)) 18 | } 19 | 20 | } 21 | 22 | override fun onCreate(savedInstanceState: Bundle?) { 23 | super.onCreate(savedInstanceState) 24 | setContentView(R.layout.activity_sigle1) 25 | //最普通的,直接创建SimpleAdapter即可,没有item子view的点击事件 26 | val testAdapter = SimpleAdapter(listData, R.layout.item_sigle1) 27 | rv.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL)) 28 | rv.setAdapter(testAdapter) 29 | 30 | testAdapter.setOnItemClickLisener { itemInfo, view, i -> 31 | ToastUtil.normal("点击的是item" + itemInfo) 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'kotlin-kapt' 5 | kotlin { 6 | experimental { 7 | coroutines "enable" 8 | } 9 | androidExtensions { 10 | experimental = true 11 | } 12 | } 13 | android { 14 | compileSdkVersion 27 15 | defaultConfig { 16 | applicationId "kt.ktbindadapter" 17 | minSdkVersion 15 18 | targetSdkVersion 27 19 | versionCode 1 20 | versionName "1.0" 21 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 22 | multiDexEnabled true 23 | } 24 | buildTypes { 25 | release { 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | } 29 | } 30 | dataBinding { 31 | enabled = true 32 | } 33 | compileOptions { 34 | targetCompatibility 1.8 35 | sourceCompatibility 1.8 36 | } 37 | } 38 | 39 | dependencies { 40 | implementation 'com.android.support:appcompat-v7:27.1.1' 41 | implementation 'com.android.support:recyclerview-v7:27.1.1' 42 | implementation project(path: ':ktAdapter') 43 | implementation project(path: ':ktTool') 44 | } 45 | -------------------------------------------------------------------------------- /ktTool/src/main/java/tgs/kttool/util/StringExt.kt: -------------------------------------------------------------------------------- 1 | package tgs.kttool.util 2 | 3 | import com.alibaba.fastjson.JSON 4 | 5 | /** 6 | * 获取最后位置的字符串 7 | */ 8 | fun String.lastStr(): String = this.get(this.length - 1).toString() 9 | 10 | fun String.fromJson(clazz: Class) = JSON.parseObject(this, clazz) 11 | 12 | inline fun String.fromJson() = JSON.parseObject(this, T::class.java) 13 | /** 14 | * 获取后面i个字符串 15 | */ 16 | fun String.subEnd(i: Int) = this.substring(this.length - i) 17 | 18 | /** 19 | * 获取前面i个字符串 20 | */ 21 | fun String.subStart(i: Int) = this.substring(0, i) 22 | 23 | /** 24 | * 对字符加星号处理:除前面几位和后面几位外,其他的字符以星号代替 25 | * 26 | * @param content 传入的字符串 27 | * @param frontNum 保留前面字符的位数 28 | * @param endNum 保留后面字符的位数 29 | */ 30 | fun String.getStarStr(content: String, frontNum: Int, endNum: Int): String { 31 | 32 | if (frontNum >= content.length || frontNum < 0) { 33 | return content 34 | } 35 | if (endNum >= content.length || endNum < 0) { 36 | return content 37 | } 38 | if (frontNum + endNum >= content.length) { 39 | return content 40 | } 41 | var starStr = "" 42 | for (i in 0 until content.length - frontNum - endNum) { 43 | starStr = "$starStr*" 44 | } 45 | return (content.substring(0, frontNum) + starStr + content.substring(content.length - endNum, content.length)) 46 | 47 | } -------------------------------------------------------------------------------- /ktAdapter/src/main/java/tgs/adapter/BaseSigleAdapter.kt: -------------------------------------------------------------------------------- 1 | package tgs.adapter 2 | 3 | import android.databinding.DataBindingUtil 4 | import android.databinding.ViewDataBinding 5 | import android.view.LayoutInflater 6 | import android.view.ViewGroup 7 | import kt.ktbindadapter.baseAdapter.BindViewHolder 8 | 9 | /** 10 | * 单type 11 | * 如果item内容填充较复杂,无法在item的xml中完成,需要在decorator完成填充,就使用这个 12 | * 或者需要子view的点击事件使用这个 13 | */ 14 | abstract class BaseSigleAdapter : BaseAdapter { 15 | 16 | private var layoutId: Int = 0 17 | 18 | constructor(datas: MutableList, layoutId: Int) : super(datas) { 19 | this.layoutId = layoutId 20 | } 21 | 22 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BindViewHolder { 23 | val binding = DataBindingUtil.inflate(LayoutInflater.from(parent.context), layoutId, parent, false) 24 | return BindViewHolder(binding.root, binding) 25 | } 26 | 27 | fun add(data: E) { 28 | mDatas.add(data) 29 | notifyDataSetChanged() 30 | } 31 | 32 | fun add(position: Int, data: E) { 33 | mDatas.add(position, data) 34 | notifyDataSetChanged() 35 | } 36 | 37 | fun set(data: List) { 38 | mDatas.clear() 39 | addAll(data) 40 | } 41 | 42 | fun addAll(data: List) { 43 | mDatas.addAll(data) 44 | notifyDataSetChanged() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ktAdapter/src/main/java/tgs/adapter/BaseMultiAdapter.kt: -------------------------------------------------------------------------------- 1 | package tgs.adapter 2 | 3 | import android.databinding.DataBindingUtil 4 | import android.databinding.ViewDataBinding 5 | import android.support.annotation.LayoutRes 6 | import android.util.SparseIntArray 7 | import android.view.LayoutInflater 8 | import android.view.ViewGroup 9 | import kt.ktbindadapter.baseAdapter.BindViewHolder 10 | 11 | /** 12 | * 多type 13 | * 如果item内容填充较复杂,无法在item的xml中完成,需要在decorator完成填充,就使用这个 14 | * 或者需要子view的点击事件使用这个 15 | */ 16 | abstract class BaseMultiAdapter : BaseAdapter, ViewDataBinding> { 17 | constructor(data: MutableList>) : super(data) 18 | 19 | private val layouts: SparseIntArray = SparseIntArray() 20 | 21 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BindViewHolder { 22 | val binding = DataBindingUtil.inflate(LayoutInflater.from(parent.context), layouts.get(viewType), parent, false) 23 | onCreateViewHolderDecorate(binding, viewType) 24 | return BindViewHolder(binding.root, binding) 25 | } 26 | 27 | open fun onCreateViewHolderDecorate(binding: ViewDataBinding, viewType: Int) { 28 | 29 | } 30 | 31 | override fun getItemViewType(position: Int): Int { 32 | return mDatas.get(position).itemType 33 | } 34 | 35 | fun addItemType(type: Int, @LayoutRes layoutResId: Int) { 36 | layouts.put(type, layoutResId) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 |