From 7e937330938eef9ced4c1e850b7f08ec72c94410 Mon Sep 17 00:00:00 2001 From: Jieyi Date: Wed, 8 Nov 2017 18:55:51 +0900 Subject: [PATCH] Added more api and upgrade. --- README.md | 10 +++++-- gradle.properties | 2 +- kotlinknifer/build.gradle | 4 +-- .../com/devrapid/kotlinknifer/ArrayList.kt | 14 ++++++++++ .../com/devrapid/kotlinknifer/Delegate.kt | 9 ++---- .../com/devrapid/kotlinknifer/Keyboard.kt | 28 +++++++++++++++++++ .../java/com/devrapid/kotlinknifer/Logs.kt | 1 - .../java/com/devrapid/kotlinknifer/String.kt | 11 ++++++++ .../java/com/devrapid/kotlinknifer/Thread.kt | 9 ++++++ .../java/com/devrapid/kotlinknifer/Time.kt | 4 ++- .../java/com/devrapid/kotlinknifer/View.kt | 1 - 11 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 kotlinknifer/src/main/java/com/devrapid/kotlinknifer/ArrayList.kt create mode 100644 kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Keyboard.kt create mode 100644 kotlinknifer/src/main/java/com/devrapid/kotlinknifer/String.kt create mode 100644 kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Thread.kt diff --git a/README.md b/README.md index a84887b..fb92176 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ The library has util tools as below: 7. Observer of RxJava 8. View 9. Time +10. ArrayList +11. Keyboard +12. String +13. Thread # Download @@ -35,7 +39,7 @@ allprojects { And add our dependency to your app `bundle.gradle`. ```gradle -compile 'com.devrapid.jieyi:kotlinknifer:1.0.13' +compile 'com.devrapid.jieyi:kotlinknifer:1.0.14' ``` Then you can use it!!! @@ -53,8 +57,8 @@ Then you can use it!!! # Also Included Library -1. Gson 2.8.1 -2. RxJava 2.1.3 +1. Gson 2.8.2 +2. RxJava 2.1.6 3. RxKotlin 2.1.0 # Feature diff --git a/gradle.properties b/gradle.properties index 7bde5a2..71017bc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,7 @@ proj_name=kotlinknifer proj_libname=KotlinKnifer proj_group=com.devrapid.jieyi proj_artifactid=kotlinknifer -proj_version=1.0.13 +proj_version=1.0.14 proj_description=For developing an Android conveniently and rapidly. proj_websiteurl=https://github.com/pokk/KotlinKnifer proj_issuetrackerurl=https://github.com/pokk/KotlinKnifer/issues diff --git a/kotlinknifer/build.gradle b/kotlinknifer/build.gradle index 5196ed3..04e5ecc 100644 --- a/kotlinknifer/build.gradle +++ b/kotlinknifer/build.gradle @@ -24,9 +24,9 @@ android { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - compile group: 'com.google.code.gson', name: 'gson', version: '2.8.1' + compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2' compile "io.reactivex.rxjava2:rxkotlin:2.1.0" - compile "io.reactivex.rxjava2:rxjava:2.1.3" + compile "io.reactivex.rxjava2:rxjava:2.1.6" compile "com.android.support:appcompat-v7:25.3.1" } diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/ArrayList.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/ArrayList.kt new file mode 100644 index 0000000..18bce81 --- /dev/null +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/ArrayList.kt @@ -0,0 +1,14 @@ +package com.devrapid.kotlinknifer + +/** + * @author jieyi + * @since 11/8/17 + */ +fun ArrayList.removeRange(from: Int, to: Int): Boolean = + if (!(from in 0..size - 1 && to in 0..size - 1 && from > to)) { + false + } + else { + subList(from, to).clear() + true + } \ No newline at end of file diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Delegate.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Delegate.kt index a05a8e9..0b967b2 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Delegate.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Delegate.kt @@ -13,10 +13,7 @@ import kotlin.reflect.KProperty * @author jieyi * @since 6/12/17 */ - -/** - * Delegate [WeakReference] for the variables. - */ +/** Delegate [WeakReference] for the variables. */ class WeakRef(default: T? = null): ReadWriteProperty { var variable: WeakReference? @@ -31,9 +28,7 @@ class WeakRef(default: T? = null): ReadWriteProperty { } } -/** - * Delegate the shared preferences variable. - */ +/** Delegate the shared preferences variable. */ class SharedPrefs(var defaultValue: T, val objectType: Class? = null, var onChange: (() -> Unit)? = null): ReadWriteProperty { companion object { diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Keyboard.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Keyboard.kt new file mode 100644 index 0000000..53e1790 --- /dev/null +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Keyboard.kt @@ -0,0 +1,28 @@ +@file:Suppress("NOTHING_TO_INLINE") + +package com.devrapid.kotlinknifer + +import android.content.Context +import android.view.View +import android.view.inputmethod.InputMethodManager + +/** + * @author jieyi + * @since 11/8/17 + */ +inline fun Context.hideSoftKeyboard() = + (getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager). + toggleSoftInput(InputMethodManager.SHOW_FORCED, 0) + +inline fun View.hideSoftKeyboard() = + (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager). + hideSoftInputFromWindow(windowToken, 0) + +inline fun View.showSoftKeyboard() = + apply { + isFocusable = true + isFocusableInTouchMode = true + requestFocus() + (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager). + showSoftInput(this, InputMethodManager.SHOW_FORCED) + } diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Logs.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Logs.kt index 3bc5a98..5c65dce 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Logs.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Logs.kt @@ -8,7 +8,6 @@ import android.util.Log * @author Jieyi * @since 8/1/15 */ - fun logv(vararg msg: Any?): Unit = Logs.v(*msg) fun logd(vararg msg: Any?): Unit = Logs.d(*msg) diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/String.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/String.kt new file mode 100644 index 0000000..f73efb8 --- /dev/null +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/String.kt @@ -0,0 +1,11 @@ +@file:Suppress("NOTHING_TO_INLINE") + +package com.devrapid.kotlinknifer + +import java.text.DecimalFormat + +/** + * @author jieyi + * @since 11/8/17 + */ +inline fun String.formatToMoneyKarma(): String = DecimalFormat("###,###").format(java.lang.Double.parseDouble(this)) \ No newline at end of file diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Thread.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Thread.kt new file mode 100644 index 0000000..3de028d --- /dev/null +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Thread.kt @@ -0,0 +1,9 @@ +@file:Suppress("NOTHING_TO_INLINE") + +package com.devrapid.kotlinknifer + +/** + * @author jieyi + * @since 11/8/17 + */ +inline fun threadName(): String = Thread.currentThread().name \ No newline at end of file diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Time.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Time.kt index f1bb4d0..f2cdbb7 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Time.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Time.kt @@ -1,3 +1,5 @@ +@file:Suppress("NOTHING_TO_INLINE") + package com.devrapid.kotlinknifer /** @@ -6,6 +8,6 @@ package com.devrapid.kotlinknifer * @author jieyi * @since 9/8/17 */ -fun Int.format(digits: Int) = String.format("%0${digits}d", this) +inline fun Int.format(digits: Int) = String.format("%0${digits}d", this) inline fun Int.toTimeString(): String = "${(this / 60).format(2)}:${(this % 60).format(2)}" diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt index 365b28b..20dcf1b 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt @@ -15,7 +15,6 @@ import com.example.kotlinknifer.R * @author jieyi * @since 4/12/17 */ - inline fun View.resizeView(width: Int? = null, height: Int? = null) = this.layoutParams?.apply { height?.let { this.height = it