From 72d95a190f2431cb71e1bff69d4ab3e9abc697c5 Mon Sep 17 00:00:00 2001 From: Jieyi Date: Wed, 18 Jul 2018 12:27:08 +0900 Subject: [PATCH 1/8] Upgraded: update to androidx. --- README.md | 9 ++ build.gradle | 4 +- gradle.properties | 7 +- gradle/wrapper/gradle-wrapper.properties | 4 +- kotlinknifer/build.gradle | 21 ++-- .../java/com/devrapid/kotlinknifer/Bitmap.kt | 4 +- .../java/com/devrapid/kotlinknifer/Color.kt | 6 +- .../com/devrapid/kotlinknifer/Drawable.kt | 4 +- .../com/devrapid/kotlinknifer/Fragment.kt | 22 ++-- .../java/com/devrapid/kotlinknifer/View.kt | 15 ++- .../WrapContentLinearLayoutManager.kt | 6 +- .../itemdecorator/GridSpacingItemDecorator.kt | 4 +- .../itemdecorator/HorizontalItemDecorator.kt | 4 +- .../itemdecorator/VerticalItemDecorator.kt | 4 +- .../kotlinknifer/support/v4/Fragment.kt | 109 ------------------ kotlinshaver/build.gradle | 6 +- sample/build.gradle | 18 +-- .../java/com/devrapid/utils/MainActivity.kt | 2 +- 18 files changed, 68 insertions(+), 181 deletions(-) delete mode 100644 kotlinknifer/src/main/java/com/devrapid/kotlinknifer/support/v4/Fragment.kt diff --git a/README.md b/README.md index b8b44fb..6e102a7 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,15 @@ implementation('com.devrapid.jieyi:kotlinknifer:1.5.7', { }) ``` +### For Androidx + +```gradle +implementation('com.devrapid.jieyi:kotlinknifer:2.0.0', { + exclude group: 'com.google.code.gson', module: 'gson' + exclude group: 'com.github.bumptech.glide', module: 'glide' +}) +``` + ```gradle implementation('com.devrapid.jieyi:kotlinshaverr:0.2.2', { exclude group: 'io.reactivex.rxjava2', module: 'rxjava' diff --git a/build.gradle b/build.gradle index 8bdcf69..6ec9710 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.31' + ext.kotlin_version = '1.2.51' repositories { jcenter() google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.0' + classpath 'com.android.tools.build:gradle:3.2.0-beta04' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle.properties b/gradle.properties index 3086c68..0c76ed0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,6 +11,9 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true +android.useAndroidX=true +android.enableJetifier=true + #### For JCenter #### ## Project information proj_repo=maven @@ -18,7 +21,7 @@ proj_name=kotlinknifer proj_libname=KotlinKnifer proj_group=com.devrapid.jieyi proj_artifactid=kotlinknifer -proj_version=1.5.7 +proj_version=2.0.0 proj_description=For developing an Android conveniently and rapidly. proj_websiteurl=https://github.com/pokk/KotlinKnifer proj_issuetrackerurl=https://github.com/pokk/KotlinKnifer/issues @@ -36,4 +39,4 @@ developer_email=pokkbaby@gmail.com proj_kotlin_name=kotlinshaver proj_kotlin_libname=KotlinShaver proj_kotlin_artifactid=kotlinshaver -proj_kotlin_version=0.2.2 +proj_kotlin_version=1.0.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f63486f..cf10787 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jan 24 11:07:46 JST 2018 +#Wed Jul 18 12:01:20 JST 2018 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-4.8-all.zip diff --git a/kotlinknifer/build.gradle b/kotlinknifer/build.gradle index ac94396..97b7dcc 100644 --- a/kotlinknifer/build.gradle +++ b/kotlinknifer/build.gradle @@ -2,12 +2,11 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { - compileSdkVersion 27 - buildToolsVersion '27.0.3' + compileSdkVersion 28 defaultConfig { minSdkVersion 21 - targetSdkVersion 27 + targetSdkVersion 28 } buildTypes { release { @@ -27,15 +26,15 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // 'compile' can also import to the new project with this. compile 'com.google.code.gson:gson:2.8.2' - compile 'com.github.bumptech.glide:glide:4.6.1' + compile 'com.github.bumptech.glide:glide:4.7.1' // 'implementation' can't import to the new project. - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.5' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.22.5' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.22.5' - implementation 'org.jetbrains.anko:anko-commons:0.10.4' - implementation 'com.android.support:appcompat-v7:27.1.0' - implementation 'com.android.support:recyclerview-v7:27.1.0' - implementation 'com.android.support:palette-v7:27.1.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.3' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.23.3' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.23.3' + implementation 'org.jetbrains.anko:anko-commons:0.10.5' + implementation 'androidx.appcompat:appcompat:1.0.0-beta01' + implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01' + implementation 'androidx.palette:palette:1.0.0-beta01' compile project(':kotlinshaver') } diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Bitmap.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Bitmap.kt index 09d79af..602dabd 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Bitmap.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Bitmap.kt @@ -8,7 +8,7 @@ import android.graphics.BitmapFactory import android.graphics.Canvas import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable -import android.support.annotation.DrawableRes +import androidx.annotation.DrawableRes /** * @author jieyi @@ -49,4 +49,4 @@ fun Bitmap.resizeImageAsRatio(aspectRatio: Double): Bitmap = also { it.width = (aspectRatio * it.height).toInt() else it.height = (it.width / aspectRatio).toInt() -} \ No newline at end of file +} diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Color.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Color.kt index 500e245..42c31fa 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Color.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Color.kt @@ -4,10 +4,10 @@ package com.devrapid.kotlinknifer import android.content.Context import android.graphics.Color -import android.support.annotation.ColorInt -import android.support.annotation.ColorRes -import android.support.v4.content.ContextCompat import android.view.View +import androidx.annotation.ColorInt +import androidx.annotation.ColorRes +import androidx.core.content.ContextCompat /** * diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Drawable.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Drawable.kt index 891d8fc..0847e9b 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Drawable.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Drawable.kt @@ -12,8 +12,8 @@ import android.renderscript.Allocation import android.renderscript.Element import android.renderscript.RenderScript import android.renderscript.ScriptIntrinsicBlur -import android.support.annotation.DrawableRes -import android.support.v7.graphics.Palette +import androidx.annotation.DrawableRes +import androidx.palette.graphics.Palette /** * @author jieyi diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Fragment.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Fragment.kt index 5672ea7..921d7a4 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Fragment.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Fragment.kt @@ -2,12 +2,10 @@ package com.devrapid.kotlinknifer -import android.annotation.TargetApi -import android.app.Fragment -import android.app.FragmentManager -import android.app.FragmentTransaction -import android.os.Build import android.view.View +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.fragment.app.FragmentTransaction import java.util.Stack /** @@ -70,21 +68,20 @@ inline fun FragmentManager.popAllFragment(fragmentStack: Stack? = null * Remove a specific [Fragment] from [FragmentManager]'s fragments. * NOTE: Don't mix this function with [popFragment] or [popAllFragment]. * - * @param manager [FragmentManager]. + * @param manager support v4 [FragmentManager]. */ inline fun Fragment.removeFrom(manager: FragmentManager) = manager.transaction { remove(this@removeFrom) } /** * Remove all fragments. */ -@TargetApi(Build.VERSION_CODES.O) inline fun FragmentManager.removeLastFragment() = fragments.lastOrNull()?.removeFrom(this) /** * Add a [Fragment] and hide the current presenting fragment. * NOTE: Don't mix this function with [popFragment] or [popAllFragment]. * - * @param manager [FragmentManager]. + * @param manager support v4 [FragmentManager]. */ inline fun Fragment.appendTo(manager: FragmentManager) = manager.transaction { hide(this@appendTo) @@ -94,7 +91,7 @@ inline fun Fragment.appendTo(manager: FragmentManager) = manager.transaction { /** * Hide a assigned [Fragment]. * - * @param manager [FragmentManager]. + * @param manager support v4 [FragmentManager]. */ inline fun Fragment.hideFrom(manager: FragmentManager) = manager.transaction { hide(this@hideFrom) } @@ -108,9 +105,4 @@ inline fun FragmentManager.transaction(block: FragmentTransaction.() -> Unit) = * Decorator between [beginTransaction] and [commitNow]. */ inline fun FragmentManager.transactionNow(block: FragmentTransaction.() -> Unit) = - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - beginTransaction().apply(block).commitNow() - } - else { - TODO("VERSION.SDK_INT < N") - } \ No newline at end of file + beginTransaction().apply(block).commitNow() diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt index 6aba646..66f710a 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt @@ -6,17 +6,16 @@ import android.app.Activity import android.content.Context import android.graphics.Rect import android.os.Build -import android.support.annotation.ColorInt -import android.support.annotation.ColorRes -import android.support.v7.app.AlertDialog import android.view.View import android.view.View.GONE import android.view.View.INVISIBLE import android.view.View.VISIBLE -import android.view.ViewGroup import android.view.ViewTreeObserver import android.view.Window import android.view.WindowManager +import androidx.annotation.ColorInt +import androidx.annotation.ColorRes +import androidx.appcompat.app.AlertDialog import com.example.kotlinknifer.R /** @@ -31,11 +30,11 @@ inline fun View.resizeView(width: Int? = null, height: Int? = null) { layoutParams = newLayoutParams } -inline fun View.visiable() { +inline fun View.visible() { visibility = VISIBLE } -inline fun View.invisiable() { +inline fun View.invisible() { visibility = INVISIBLE } @@ -43,7 +42,7 @@ inline fun View.gone() { visibility = GONE } -inline fun View.isVisiable() = VISIBLE == visibility +inline fun View.isVisible() = VISIBLE == visibility fun View.waitForMeasure(func: (v: View, w: Int, h: Int) -> Unit) { if (0 < width && 0 < height) { @@ -115,4 +114,4 @@ internal inline fun Activity.setStatusBarColorBy(block: Window.() -> Unit) { else { TODO("Don't support the sdk version is less than 21 yet.") } -} \ No newline at end of file +} diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/WrapContentLinearLayoutManager.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/WrapContentLinearLayoutManager.kt index 411c20f..b6462c5 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/WrapContentLinearLayoutManager.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/WrapContentLinearLayoutManager.kt @@ -1,9 +1,9 @@ package com.devrapid.kotlinknifer.recyclerview import android.content.Context -import android.support.v7.widget.LinearLayoutManager -import android.support.v7.widget.RecyclerView import android.util.AttributeSet +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import com.devrapid.kotlinknifer.loge import com.devrapid.kotlinknifer.logw @@ -29,4 +29,4 @@ class WrapContentLinearLayoutManager : LinearLayoutManager { loge(e) } } -} \ No newline at end of file +} diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/GridSpacingItemDecorator.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/GridSpacingItemDecorator.kt index 31320c8..fb6ca35 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/GridSpacingItemDecorator.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/GridSpacingItemDecorator.kt @@ -1,8 +1,8 @@ package com.devrapid.kotlinknifer.recyclerview.itemdecorator import android.graphics.Rect -import android.support.v7.widget.RecyclerView import android.view.View +import androidx.recyclerview.widget.RecyclerView /** * The item decorator for grid type recycler view. @@ -39,4 +39,4 @@ class GridSpacingItemDecorator(private val spanCount: Int, private val spacing: outRect.top = spacing } } -} \ No newline at end of file +} diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/HorizontalItemDecorator.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/HorizontalItemDecorator.kt index c057b52..ecbe7e4 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/HorizontalItemDecorator.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/HorizontalItemDecorator.kt @@ -1,8 +1,8 @@ package com.devrapid.kotlinknifer.recyclerview.itemdecorator import android.graphics.Rect -import android.support.v7.widget.RecyclerView import android.view.View +import androidx.recyclerview.widget.RecyclerView /** * The item decorator for horizontal recycler view. @@ -21,4 +21,4 @@ class HorizontalItemDecorator(private val space: Int) : RecyclerView.ItemDecorat else -> outRect.set(space / 2, space, space / 2, space) } } -} \ No newline at end of file +} diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/VerticalItemDecorator.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/VerticalItemDecorator.kt index 02c0d07..7c6ba78 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/VerticalItemDecorator.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/itemdecorator/VerticalItemDecorator.kt @@ -1,8 +1,8 @@ package com.devrapid.kotlinknifer.recyclerview.itemdecorator import android.graphics.Rect -import android.support.v7.widget.RecyclerView import android.view.View +import androidx.recyclerview.widget.RecyclerView /** * The item decorator for vertical type recycler view. @@ -24,4 +24,4 @@ class VerticalItemDecorator( else -> outRect.set(leftRight, topBottom / 2, leftRight, topBottom / 2) } } -} \ No newline at end of file +} diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/support/v4/Fragment.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/support/v4/Fragment.kt deleted file mode 100644 index 0277567..0000000 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/support/v4/Fragment.kt +++ /dev/null @@ -1,109 +0,0 @@ -@file:Suppress("NOTHING_TO_INLINE") - -package com.devrapid.kotlinknifer.support.v4 - -import android.support.v4.app.Fragment -import android.support.v4.app.FragmentManager -import android.support.v4.app.FragmentTransaction -import android.view.View -import com.devrapid.kotlinknifer.safePop -import java.util.Stack - -/** - * @author jieyi - * @since 2/15/17 - */ -/** - * Adds a [Fragment] to this manager's layout. - * Using the [replace] method, we couldn't obtain the fragments. There a way to get it is that - * obtaining fragment by [findFragmentByTag]. For convenient, I recommend that using a [Stack] - * for keeping fragments. - * - * @param containerViewId The container view to where add the fragment. - * @param fragment The fragment to be added. - * @param needBack Set that it can back to previous fragment. - * @param fragmentStack The stack for keeping the fragments. - * @param sharedElements Shared element objects and ids from layout xml [android:transitionName]. - * - * @return the identifier of this transaction's back stack entry. - */ -fun FragmentManager.addFragment( - containerViewId: Int, - fragment: Fragment, - needBack: Boolean = false, - fragmentStack: Stack? = null, - sharedElements: HashMap = hashMapOf(), - block: ((FragmentTransaction) -> Unit)? = null -) = transaction { - block?.invoke(this) - sharedElements.forEach { value -> addSharedElement(value.key, value.value) } - if (needBack) { - addToBackStack(fragment::class.java.simpleName) - fragmentStack?.push(fragment) - } - replace(containerViewId, fragment, fragment::class.java.simpleName) -} - -/** - * Pop a stack from the back stack. - * - * @param fragmentStack The stack for keeping the fragments. - * - * @return is success to pop a stack. - */ -inline fun FragmentManager.popFragment(fragmentStack: Stack? = null) = run { - fragmentStack?.safePop() - popBackStackImmediate() -} - -/** - * Clear all stacks from the back stack. - * - * @param fragmentStack The stack for keeping the fragments. - */ -inline fun FragmentManager.popAllFragment(fragmentStack: Stack? = null) { - while (true) if (!popFragment(fragmentStack)) break -} - -/** - * Remove a specific [Fragment] from [FragmentManager]'s fragments. - * NOTE: Don't mix this function with [popFragment] or [popAllFragment]. - * - * @param manager support v4 [FragmentManager]. - */ -inline fun Fragment.removeFrom(manager: FragmentManager) = manager.transaction { remove(this@removeFrom) } - -/** - * Remove all fragments. - */ -inline fun FragmentManager.removeLastFragment() = fragments.lastOrNull()?.removeFrom(this) - -/** - * Add a [Fragment] and hide the current presenting fragment. - * NOTE: Don't mix this function with [popFragment] or [popAllFragment]. - * - * @param manager support v4 [FragmentManager]. - */ -inline fun Fragment.appendTo(manager: FragmentManager) = manager.transaction { - hide(this@appendTo) - add(this@appendTo, this@appendTo::class.java.simpleName) -} - -/** - * Hide a assigned [Fragment]. - * - * @param manager support v4 [FragmentManager]. - */ -inline fun Fragment.hideFrom(manager: FragmentManager) = manager.transaction { hide(this@hideFrom) } - -/** - * Decorator between [beginTransaction] and [commit]. - */ -inline fun FragmentManager.transaction(block: FragmentTransaction.() -> Unit) = - beginTransaction().apply(block).commit() - -/** - * Decorator between [beginTransaction] and [commitNow]. - */ -inline fun FragmentManager.transactionNow(block: FragmentTransaction.() -> Unit) = - beginTransaction().apply(block).commitNow() \ No newline at end of file diff --git a/kotlinshaver/build.gradle b/kotlinshaver/build.gradle index 5347279..c655c8e 100644 --- a/kotlinshaver/build.gradle +++ b/kotlinshaver/build.gradle @@ -3,8 +3,8 @@ apply plugin: 'kotlin' dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.5' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.22.5' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.3' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.23.3' compile 'io.reactivex.rxjava2:rxkotlin:2.2.0' compile 'io.reactivex.rxjava2:rxjava:2.1.10' @@ -115,4 +115,4 @@ bintray { } } } -} \ No newline at end of file +} diff --git a/sample/build.gradle b/sample/build.gradle index 0950290..4665a06 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -2,15 +2,14 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" + compileSdkVersion 28 defaultConfig { applicationId "com.devrapid.utils" minSdkVersion 21 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -21,15 +20,10 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - implementation 'com.android.support:appcompat-v7:27.1.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta6' + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'androidx.appcompat:appcompat:1.0.0-beta01' + implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha1' implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation project(':kotlinknifer') // implementation "com.devrapid.jieyi:kotlinknifer:1.4.1" - - testImplementation 'junit:junit:4.12' } diff --git a/sample/src/main/java/com/devrapid/utils/MainActivity.kt b/sample/src/main/java/com/devrapid/utils/MainActivity.kt index 03e09ff..436a208 100644 --- a/sample/src/main/java/com/devrapid/utils/MainActivity.kt +++ b/sample/src/main/java/com/devrapid/utils/MainActivity.kt @@ -1,7 +1,7 @@ package com.devrapid.utils import android.os.Bundle -import android.support.v7.app.AppCompatActivity +import androidx.appcompat.app.AppCompatActivity class MainActivity: AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { From 2167439b7a1a59f963eb8c1c88174027bb0d2a3d Mon Sep 17 00:00:00 2001 From: Jieyi Date: Sat, 21 Jul 2018 16:47:16 +0900 Subject: [PATCH 2/8] Feature: added the casting feature. --- README.md | 23 +++++++------------ gradle.properties | 4 ++-- .../java/com/devrapid/kotlinshaver/Casting.kt | 13 +++++++++++ 3 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Casting.kt diff --git a/README.md b/README.md index 6e102a7..d637f63 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ The library has util tools as below: 6. String 7. Thread 8. Time +9. Casting # NOTE @@ -87,9 +88,9 @@ allprojects { And add our dependency to your app `bundle.gradle`. ```gradle -implementation 'com.devrapid.jieyi:kotlinknifer:1.5.7' +implementation 'com.devrapid.jieyi:kotlinknifer:2.0.1' -implementation 'com.devrapid.jieyi:kotlinshaver:0.2.2' +implementation 'com.devrapid.jieyi:kotlinshaver:1.0.1' ``` Then you can use it!!! @@ -100,14 +101,14 @@ Then you can use it!!! com.devrapid.jieyi kotlinknifer - 1.5.7 + 2.0.1 pom com.devrapid.jieyi kotlinshaver - 0.2.2 + 1.0.1 pom ``` @@ -120,6 +121,7 @@ Then you can use it!!! 2. Glide 4.6.1 ## kotlinshaver +### For Androidx 1. RxJava 2.1.10 2. RxKotlin 2.2.0 @@ -127,16 +129,7 @@ Then you can use it!!! If you'd not like to use them to your project, you can add the exclude as like below ```gradle -implementation('com.devrapid.jieyi:kotlinknifer:1.5.7', { - exclude group: 'com.google.code.gson', module: 'gson' - exclude group: 'com.github.bumptech.glide', module: 'glide' -}) -``` - -### For Androidx - -```gradle -implementation('com.devrapid.jieyi:kotlinknifer:2.0.0', { +implementation('com.devrapid.jieyi:kotlinknifer:2.0.1', { exclude group: 'com.google.code.gson', module: 'gson' exclude group: 'com.github.bumptech.glide', module: 'glide' }) @@ -159,7 +152,7 @@ Please let me know, thank you! # License ``` -Copyright (C) 2017 Jieyi Wu +Copyright (C) 2018 Jieyi Wu Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/gradle.properties b/gradle.properties index 0c76ed0..2185fc2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ proj_name=kotlinknifer proj_libname=KotlinKnifer proj_group=com.devrapid.jieyi proj_artifactid=kotlinknifer -proj_version=2.0.0 +proj_version=2.0.1 proj_description=For developing an Android conveniently and rapidly. proj_websiteurl=https://github.com/pokk/KotlinKnifer proj_issuetrackerurl=https://github.com/pokk/KotlinKnifer/issues @@ -39,4 +39,4 @@ developer_email=pokkbaby@gmail.com proj_kotlin_name=kotlinshaver proj_kotlin_libname=KotlinShaver proj_kotlin_artifactid=kotlinshaver -proj_kotlin_version=1.0.0 +proj_kotlin_version=1.0.1 diff --git a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Casting.kt b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Casting.kt new file mode 100644 index 0000000..9df1da3 --- /dev/null +++ b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Casting.kt @@ -0,0 +1,13 @@ +package com.devrapid.kotlinshaver + +inline fun castOrNull(from: Any?) = from as? T +inline fun cast(from: Any?): T { + if (null == from) throw NullPointerException("Null object can't cast.") + + try { + return T::class.java.cast(from) + } + catch (castExcept: ClassCastException) { + throw ClassCastException("Class casting failed.") + } +} From c507f436c33ea9c87b1fd239653a48e600b88baa Mon Sep 17 00:00:00 2001 From: Jieyi Date: Wed, 29 Aug 2018 15:18:46 +0900 Subject: [PATCH 3/8] Upgrade: upgraded the third-party libraries all version. --- README.md | 18 +++++++++--------- build.gradle | 4 ++-- gradle.properties | 4 ++-- kotlinknifer/build.gradle | 16 ++++++++-------- kotlinshaver/build.gradle | 8 ++++---- sample/build.gradle | 4 ++-- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index d637f63..8ed526f 100644 --- a/README.md +++ b/README.md @@ -88,9 +88,9 @@ allprojects { And add our dependency to your app `bundle.gradle`. ```gradle -implementation 'com.devrapid.jieyi:kotlinknifer:2.0.1' +implementation 'com.devrapid.jieyi:kotlinknifer:2.0.2' -implementation 'com.devrapid.jieyi:kotlinshaver:1.0.1' +implementation 'com.devrapid.jieyi:kotlinshaver:1.0.2' ``` Then you can use it!!! @@ -101,14 +101,14 @@ Then you can use it!!! com.devrapid.jieyi kotlinknifer - 2.0.1 + 2.0.2 pom com.devrapid.jieyi kotlinshaver - 1.0.1 + 1.0.2 pom ``` @@ -117,19 +117,19 @@ Then you can use it!!! ## kotlinknifer -1. Gson 2.8.2 -2. Glide 4.6.1 +1. Gson 2.8.5 +2. Glide 4.8.0 ## kotlinshaver ### For Androidx -1. RxJava 2.1.10 -2. RxKotlin 2.2.0 +1. RxJava 2.2.1 +2. RxKotlin 2.3.0 If you'd not like to use them to your project, you can add the exclude as like below ```gradle -implementation('com.devrapid.jieyi:kotlinknifer:2.0.1', { +implementation('com.devrapid.jieyi:kotlinknifer:2.0.2', { exclude group: 'com.google.code.gson', module: 'gson' exclude group: 'com.github.bumptech.glide', module: 'glide' }) diff --git a/build.gradle b/build.gradle index 6ec9710..eb6c779 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.51' + ext.kotlin_version = '1.2.61' repositories { jcenter() google() @@ -12,7 +12,7 @@ buildscript { // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files - classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3" + classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0" classpath "com.github.dcendents:android-maven-gradle-plugin:1.5" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } diff --git a/gradle.properties b/gradle.properties index 2185fc2..1dbcba4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ proj_name=kotlinknifer proj_libname=KotlinKnifer proj_group=com.devrapid.jieyi proj_artifactid=kotlinknifer -proj_version=2.0.1 +proj_version=2.0.2 proj_description=For developing an Android conveniently and rapidly. proj_websiteurl=https://github.com/pokk/KotlinKnifer proj_issuetrackerurl=https://github.com/pokk/KotlinKnifer/issues @@ -39,4 +39,4 @@ developer_email=pokkbaby@gmail.com proj_kotlin_name=kotlinshaver proj_kotlin_libname=KotlinShaver proj_kotlin_artifactid=kotlinshaver -proj_kotlin_version=1.0.1 +proj_kotlin_version=1.0.2 diff --git a/kotlinknifer/build.gradle b/kotlinknifer/build.gradle index 97b7dcc..42eef09 100644 --- a/kotlinknifer/build.gradle +++ b/kotlinknifer/build.gradle @@ -25,16 +25,16 @@ kotlin { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // 'compile' can also import to the new project with this. - compile 'com.google.code.gson:gson:2.8.2' - compile 'com.github.bumptech.glide:glide:4.7.1' + compile 'com.google.code.gson:gson:2.8.5' + compile 'com.github.bumptech.glide:glide:4.8.0' // 'implementation' can't import to the new project. - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.3' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.23.3' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.23.3' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.25.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.25.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.25.0' implementation 'org.jetbrains.anko:anko-commons:0.10.5' - implementation 'androidx.appcompat:appcompat:1.0.0-beta01' - implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01' - implementation 'androidx.palette:palette:1.0.0-beta01' + implementation 'androidx.appcompat:appcompat:1.0.0-rc02' + implementation 'androidx.recyclerview:recyclerview:1.0.0-rc02' + implementation 'androidx.palette:palette:1.0.0-rc02' compile project(':kotlinshaver') } diff --git a/kotlinshaver/build.gradle b/kotlinshaver/build.gradle index c655c8e..908595c 100644 --- a/kotlinshaver/build.gradle +++ b/kotlinshaver/build.gradle @@ -3,11 +3,11 @@ apply plugin: 'kotlin' dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.3' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.23.3' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.25.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.25.0' - compile 'io.reactivex.rxjava2:rxkotlin:2.2.0' - compile 'io.reactivex.rxjava2:rxjava:2.1.10' + compile 'io.reactivex.rxjava2:rxkotlin:2.3.0' + compile 'io.reactivex.rxjava2:rxjava:2.2.1' } sourceCompatibility = "1.8" diff --git a/sample/build.gradle b/sample/build.gradle index 4665a06..1632a66 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -21,8 +21,8 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'androidx.appcompat:appcompat:1.0.0-beta01' - implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha1' + implementation 'androidx.appcompat:appcompat:1.0.0-rc02' + implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2' implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation project(':kotlinknifer') // implementation "com.devrapid.jieyi:kotlinknifer:1.4.1" From e97cd5420a6b7b272545eaebda292822d854e653 Mon Sep 17 00:00:00 2001 From: Jieyi Date: Thu, 30 Aug 2018 11:06:08 +0900 Subject: [PATCH 4/8] Feature: added the field accessible and set cursor point color. --- README.md | 12 +++---- gradle.properties | 4 +-- .../com/devrapid/kotlinknifer/EditText.kt | 35 +++++++++++++++++++ .../java/com/devrapid/kotlinshaver/Field.kt | 7 ++++ 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt create mode 100644 kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Field.kt diff --git a/README.md b/README.md index 8ed526f..fdd46ed 100644 --- a/README.md +++ b/README.md @@ -88,9 +88,9 @@ allprojects { And add our dependency to your app `bundle.gradle`. ```gradle -implementation 'com.devrapid.jieyi:kotlinknifer:2.0.2' +implementation 'com.devrapid.jieyi:kotlinknifer:2.0.3' -implementation 'com.devrapid.jieyi:kotlinshaver:1.0.2' +implementation 'com.devrapid.jieyi:kotlinshaver:1.0.3' ``` Then you can use it!!! @@ -101,14 +101,14 @@ Then you can use it!!! com.devrapid.jieyi kotlinknifer - 2.0.2 + 2.0.3 pom com.devrapid.jieyi kotlinshaver - 1.0.2 + 1.0.3 pom ``` @@ -129,14 +129,14 @@ Then you can use it!!! If you'd not like to use them to your project, you can add the exclude as like below ```gradle -implementation('com.devrapid.jieyi:kotlinknifer:2.0.2', { +implementation('com.devrapid.jieyi:kotlinknifer:2.0.3', { exclude group: 'com.google.code.gson', module: 'gson' exclude group: 'com.github.bumptech.glide', module: 'glide' }) ``` ```gradle -implementation('com.devrapid.jieyi:kotlinshaverr:0.2.2', { +implementation('com.devrapid.jieyi:kotlinshaverr:1.0.3', { exclude group: 'io.reactivex.rxjava2', module: 'rxjava' exclude group: 'io.reactivex.rxjava2', module: 'rxkotlin' }) diff --git a/gradle.properties b/gradle.properties index 1dbcba4..58f2e00 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ proj_name=kotlinknifer proj_libname=KotlinKnifer proj_group=com.devrapid.jieyi proj_artifactid=kotlinknifer -proj_version=2.0.2 +proj_version=2.0.3 proj_description=For developing an Android conveniently and rapidly. proj_websiteurl=https://github.com/pokk/KotlinKnifer proj_issuetrackerurl=https://github.com/pokk/KotlinKnifer/issues @@ -39,4 +39,4 @@ developer_email=pokkbaby@gmail.com proj_kotlin_name=kotlinshaver proj_kotlin_libname=KotlinShaver proj_kotlin_artifactid=kotlinshaver -proj_kotlin_version=1.0.2 +proj_kotlin_version=1.0.3 diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt new file mode 100644 index 0000000..675b6cf --- /dev/null +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt @@ -0,0 +1,35 @@ +package com.devrapid.kotlinknifer + +import android.graphics.PorterDuff.Mode.SRC_IN +import android.widget.EditText +import android.widget.TextView +import androidx.annotation.ColorInt +import androidx.annotation.DrawableRes +import androidx.core.content.ContextCompat +import com.devrapid.kotlinshaver.accessible + +fun setCursorPointerColor(view: EditText, @ColorInt color: Int, @DrawableRes drawable: Int = -1) { + // Get the editor. + val editor = TextView::class.java.getDeclaredField("mEditor").accessible().get(view) + // Get all drawable's selection points. + val drawables = if (-1 == drawable) + listOf("mTextSelectHandleRes" // Selection cursor point. + , "mTextSelectHandleLeftRes" // Selection the highlight left cursor point. + , "mTextSelectHandleRightRes") // Selection the highlight right cursor point. + .asSequence() + .map { TextView::class.java.getDeclaredField(it).accessible() } // Get the drawables' field. + .map { it.getInt(view) } // Get the drawable resource id. + .map { requireNotNull(ContextCompat.getDrawable(view.context, it)) } // Get the drawable. + .map { it.setColorFilter(color, SRC_IN); it } // Change the color we set. + .toList() + else + (0..2).map { requireNotNull(ContextCompat.getDrawable(view.context, drawable)) } + // Get all handle fields. + val fields = listOf("mSelectHandleCenter" + , "mSelectHandleLeft" + , "mSelectHandleRight") + .map { editor.javaClass.getDeclaredField(it).accessible() } + fields.zip(drawables).forEach { (field, drawable) -> field.set(editor, drawable) } + + view.highlightColor = color +} diff --git a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Field.kt b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Field.kt new file mode 100644 index 0000000..32ca079 --- /dev/null +++ b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Field.kt @@ -0,0 +1,7 @@ +@file:Suppress("NOTHING_TO_INLINE") + +package com.devrapid.kotlinshaver + +import java.lang.reflect.Field + +inline fun Field.accessible() = apply { isAccessible = true } From 181d69063252f79c1ecbc662ff9d416826bc1be1 Mon Sep 17 00:00:00 2001 From: Jieyi Date: Thu, 30 Aug 2018 11:40:42 +0900 Subject: [PATCH 5/8] Fix: fixed the Bitmap to Drawable didn't become drawable. --- README.md | 12 ++++++------ gradle.properties | 4 ++-- kotlinknifer/build.gradle | 2 +- .../main/java/com/devrapid/kotlinknifer/Drawable.kt | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index fdd46ed..db74402 100644 --- a/README.md +++ b/README.md @@ -88,9 +88,9 @@ allprojects { And add our dependency to your app `bundle.gradle`. ```gradle -implementation 'com.devrapid.jieyi:kotlinknifer:2.0.3' +implementation 'com.devrapid.jieyi:kotlinknifer:2.0.4' -implementation 'com.devrapid.jieyi:kotlinshaver:1.0.3' +implementation 'com.devrapid.jieyi:kotlinshaver:1.0.4' ``` Then you can use it!!! @@ -101,14 +101,14 @@ Then you can use it!!! com.devrapid.jieyi kotlinknifer - 2.0.3 + 2.0.4 pom com.devrapid.jieyi kotlinshaver - 1.0.3 + 1.0.4 pom ``` @@ -129,14 +129,14 @@ Then you can use it!!! If you'd not like to use them to your project, you can add the exclude as like below ```gradle -implementation('com.devrapid.jieyi:kotlinknifer:2.0.3', { +implementation('com.devrapid.jieyi:kotlinknifer:2.0.4', { exclude group: 'com.google.code.gson', module: 'gson' exclude group: 'com.github.bumptech.glide', module: 'glide' }) ``` ```gradle -implementation('com.devrapid.jieyi:kotlinshaverr:1.0.3', { +implementation('com.devrapid.jieyi:kotlinshaverr:1.0.4', { exclude group: 'io.reactivex.rxjava2', module: 'rxjava' exclude group: 'io.reactivex.rxjava2', module: 'rxkotlin' }) diff --git a/gradle.properties b/gradle.properties index 58f2e00..33e52a5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ proj_name=kotlinknifer proj_libname=KotlinKnifer proj_group=com.devrapid.jieyi proj_artifactid=kotlinknifer -proj_version=2.0.3 +proj_version=2.0.4 proj_description=For developing an Android conveniently and rapidly. proj_websiteurl=https://github.com/pokk/KotlinKnifer proj_issuetrackerurl=https://github.com/pokk/KotlinKnifer/issues @@ -39,4 +39,4 @@ developer_email=pokkbaby@gmail.com proj_kotlin_name=kotlinshaver proj_kotlin_libname=KotlinShaver proj_kotlin_artifactid=kotlinshaver -proj_kotlin_version=1.0.3 +proj_kotlin_version=1.0.4 diff --git a/kotlinknifer/build.gradle b/kotlinknifer/build.gradle index 42eef09..8d21ca8 100644 --- a/kotlinknifer/build.gradle +++ b/kotlinknifer/build.gradle @@ -33,7 +33,7 @@ dependencies { implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.25.0' implementation 'org.jetbrains.anko:anko-commons:0.10.5' implementation 'androidx.appcompat:appcompat:1.0.0-rc02' - implementation 'androidx.recyclerview:recyclerview:1.0.0-rc02' + implementation 'androidx.recyclerview:recyclerview:1.0.0-rc01' implementation 'androidx.palette:palette:1.0.0-rc02' compile project(':kotlinshaver') } diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Drawable.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Drawable.kt index 0847e9b..e8ada5e 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Drawable.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Drawable.kt @@ -42,7 +42,7 @@ fun Context.scaledDrawable(@DrawableRes drawableId: Int, ratio: Float) = inline fun Int.toDrawable(context: Context) = context.getDrawable(this) -inline fun Bitmap.toDrawable(context: Context) = BitmapDrawable(context.resources, this).bitmap +inline fun Bitmap.toDrawable(context: Context) = BitmapDrawable(context.resources, this) inline fun Bitmap.palette() = Palette.from(this) From 712b66b6d588695d07dc06be987374583c3a97ab Mon Sep 17 00:00:00 2001 From: Jieyi Date: Tue, 11 Sep 2018 18:37:35 +0900 Subject: [PATCH 6/8] Feature: added the extension of the add drawable icon into textview. --- README.md | 12 ++--- gradle.properties | 4 +- .../com/devrapid/kotlinknifer/TextView.kt | 52 +++++++++++++++++++ .../java/com/devrapid/kotlinshaver/Int.kt | 7 +++ 4 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 kotlinknifer/src/main/java/com/devrapid/kotlinknifer/TextView.kt create mode 100644 kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Int.kt diff --git a/README.md b/README.md index db74402..cb30fee 100644 --- a/README.md +++ b/README.md @@ -88,9 +88,9 @@ allprojects { And add our dependency to your app `bundle.gradle`. ```gradle -implementation 'com.devrapid.jieyi:kotlinknifer:2.0.4' +implementation 'com.devrapid.jieyi:kotlinknifer:2.0.5' -implementation 'com.devrapid.jieyi:kotlinshaver:1.0.4' +implementation 'com.devrapid.jieyi:kotlinshaver:1.0.5' ``` Then you can use it!!! @@ -101,14 +101,14 @@ Then you can use it!!! com.devrapid.jieyi kotlinknifer - 2.0.4 + 2.0.5 pom com.devrapid.jieyi kotlinshaver - 1.0.4 + 1.0.5 pom ``` @@ -129,14 +129,14 @@ Then you can use it!!! If you'd not like to use them to your project, you can add the exclude as like below ```gradle -implementation('com.devrapid.jieyi:kotlinknifer:2.0.4', { +implementation('com.devrapid.jieyi:kotlinknifer:2.0.5', { exclude group: 'com.google.code.gson', module: 'gson' exclude group: 'com.github.bumptech.glide', module: 'glide' }) ``` ```gradle -implementation('com.devrapid.jieyi:kotlinshaverr:1.0.4', { +implementation('com.devrapid.jieyi:kotlinshaverr:1.0.5', { exclude group: 'io.reactivex.rxjava2', module: 'rxjava' exclude group: 'io.reactivex.rxjava2', module: 'rxkotlin' }) diff --git a/gradle.properties b/gradle.properties index 33e52a5..aaa86bb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ proj_name=kotlinknifer proj_libname=KotlinKnifer proj_group=com.devrapid.jieyi proj_artifactid=kotlinknifer -proj_version=2.0.4 +proj_version=2.0.5 proj_description=For developing an Android conveniently and rapidly. proj_websiteurl=https://github.com/pokk/KotlinKnifer proj_issuetrackerurl=https://github.com/pokk/KotlinKnifer/issues @@ -39,4 +39,4 @@ developer_email=pokkbaby@gmail.com proj_kotlin_name=kotlinshaver proj_kotlin_libname=KotlinShaver proj_kotlin_artifactid=kotlinshaver -proj_kotlin_version=1.0.4 +proj_kotlin_version=1.0.5 diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/TextView.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/TextView.kt new file mode 100644 index 0000000..da0a504 --- /dev/null +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/TextView.kt @@ -0,0 +1,52 @@ +package com.devrapid.kotlinknifer + +import android.widget.TextView +import androidx.annotation.DrawableRes +import androidx.annotation.IntDef +import com.devrapid.kotlinknifer.DrawableDriection.DRAWABLE_DIRECTION_BOTTOM +import com.devrapid.kotlinknifer.DrawableDriection.DRAWABLE_DIRECTION_END +import com.devrapid.kotlinknifer.DrawableDriection.DRAWABLE_DIRECTION_START +import com.devrapid.kotlinknifer.DrawableDriection.DRAWABLE_DIRECTION_TOP +import kotlin.annotation.AnnotationRetention.SOURCE +import kotlin.annotation.AnnotationTarget.FIELD +import kotlin.annotation.AnnotationTarget.TYPE +import kotlin.annotation.AnnotationTarget.VALUE_PARAMETER + +/** + * @author jieyi + * @since 09/11/18 + */ +object DrawableDriection { + const val DRAWABLE_DIRECTION_START = 0x1 + const val DRAWABLE_DIRECTION_TOP = 0x2 + const val DRAWABLE_DIRECTION_END = 0x4 + const val DRAWABLE_DIRECTION_BOTTOM = 0x8 +} + +@Retention(SOURCE) +@Target(TYPE, FIELD, VALUE_PARAMETER) +@IntDef(DRAWABLE_DIRECTION_START, + DRAWABLE_DIRECTION_TOP, + DRAWABLE_DIRECTION_END, + DRAWABLE_DIRECTION_BOTTOM) +annotation class DrawableDirection + +fun TextView.addDrawable( + @DrawableRes drawableId: Int, + @DrawableDirection direct: Int, + ratioWidth: Float = 1f, + ratioHeight: Float = 1f +) { + // Modify the icon size. + context.scaledDrawable(drawableId, ratioWidth, ratioHeight) + // Modify the icon bound. + .apply { setBounds(0, 0, (minimumWidth * ratioWidth).toInt(), (minimumHeight * ratioHeight).toInt()) } + .let { + when (direct) { + DRAWABLE_DIRECTION_START -> setCompoundDrawables(it, null, null, null) + DRAWABLE_DIRECTION_TOP -> setCompoundDrawables(null, it, null, null) + DRAWABLE_DIRECTION_END -> setCompoundDrawables(null, null, it, null) + DRAWABLE_DIRECTION_BOTTOM -> setCompoundDrawables(null, null, null, it) + } + } +} diff --git a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Int.kt b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Int.kt new file mode 100644 index 0000000..90e3b75 --- /dev/null +++ b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Int.kt @@ -0,0 +1,7 @@ +@file:Suppress("NOTHING_TO_INLINE") + +package com.devrapid.kotlinshaver + +inline fun Int.toBool() = 0 < this + +inline fun Boolean.toInt() = if (this) 1 else 0 From 58b0aad8f22b980d1b240b9650e80eb624d119a8 Mon Sep 17 00:00:00 2001 From: Jieyi Date: Tue, 30 Oct 2018 11:39:42 +0900 Subject: [PATCH 7/8] Upgrade: bump into kotlin 1.3.0 and coroutines 1.0.0. 1. Fixed the coroutines new API and android coroutines. --- README.md | 14 ++++++------- build.gradle | 6 ++++-- gradle.properties | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- kotlinknifer/build.gradle | 20 +++++++++--------- .../com/devrapid/kotlinknifer/Coroutine.kt | 21 ++++++++++++------- kotlinshaver/build.gradle | 8 +++---- .../com/devrapid/kotlinshaver/ArrayList.kt | 4 ++-- sample/build.gradle | 2 +- 9 files changed, 44 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index cb30fee..7f0cacb 100644 --- a/README.md +++ b/README.md @@ -88,9 +88,9 @@ allprojects { And add our dependency to your app `bundle.gradle`. ```gradle -implementation 'com.devrapid.jieyi:kotlinknifer:2.0.5' +implementation 'com.devrapid.jieyi:kotlinknifer:2.1.0' -implementation 'com.devrapid.jieyi:kotlinshaver:1.0.5' +implementation 'com.devrapid.jieyi:kotlinshaver:1.1.0' ``` Then you can use it!!! @@ -101,14 +101,14 @@ Then you can use it!!! com.devrapid.jieyi kotlinknifer - 2.0.5 + 2.1.0 pom com.devrapid.jieyi kotlinshaver - 1.0.5 + 1.1.0 pom ``` @@ -123,20 +123,20 @@ Then you can use it!!! ## kotlinshaver ### For Androidx -1. RxJava 2.2.1 +1. RxJava 2.2.3 2. RxKotlin 2.3.0 If you'd not like to use them to your project, you can add the exclude as like below ```gradle -implementation('com.devrapid.jieyi:kotlinknifer:2.0.5', { +implementation('com.devrapid.jieyi:kotlinknifer:2.1.0', { exclude group: 'com.google.code.gson', module: 'gson' exclude group: 'com.github.bumptech.glide', module: 'glide' }) ``` ```gradle -implementation('com.devrapid.jieyi:kotlinshaverr:1.0.5', { +implementation('com.devrapid.jieyi:kotlinshaverr:1.1.0', { exclude group: 'io.reactivex.rxjava2', module: 'rxjava' exclude group: 'io.reactivex.rxjava2', module: 'rxkotlin' }) diff --git a/build.gradle b/build.gradle index eb6c779..8f09f3c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,15 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.61' + ext.kotlin_version = '1.3.0' + ext.kotlin_coroutine_version = '1.0.0' repositories { jcenter() google() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.0-beta04' + classpath 'com.android.tools.build:gradle:3.2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle.properties b/gradle.properties index aaa86bb..55c1d3a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ proj_name=kotlinknifer proj_libname=KotlinKnifer proj_group=com.devrapid.jieyi proj_artifactid=kotlinknifer -proj_version=2.0.5 +proj_version=2.1.0 proj_description=For developing an Android conveniently and rapidly. proj_websiteurl=https://github.com/pokk/KotlinKnifer proj_issuetrackerurl=https://github.com/pokk/KotlinKnifer/issues @@ -39,4 +39,4 @@ developer_email=pokkbaby@gmail.com proj_kotlin_name=kotlinshaver proj_kotlin_libname=KotlinShaver proj_kotlin_artifactid=kotlinshaver -proj_kotlin_version=1.0.5 +proj_kotlin_version=1.1.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cf10787..47e406e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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.8-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip diff --git a/kotlinknifer/build.gradle b/kotlinknifer/build.gradle index 8d21ca8..88438e7 100644 --- a/kotlinknifer/build.gradle +++ b/kotlinknifer/build.gradle @@ -25,17 +25,17 @@ kotlin { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // 'compile' can also import to the new project with this. - compile 'com.google.code.gson:gson:2.8.5' - compile 'com.github.bumptech.glide:glide:4.8.0' + compile "com.google.code.gson:gson:2.8.5" + compile "com.github.bumptech.glide:glide:4.8.0" // 'implementation' can't import to the new project. - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.25.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.25.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.25.0' - implementation 'org.jetbrains.anko:anko-commons:0.10.5' - implementation 'androidx.appcompat:appcompat:1.0.0-rc02' - implementation 'androidx.recyclerview:recyclerview:1.0.0-rc01' - implementation 'androidx.palette:palette:1.0.0-rc02' - compile project(':kotlinshaver') + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutine_version" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutine_version" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutine_version" + implementation "org.jetbrains.anko:anko-commons:0.10.7-rc13" + implementation "androidx.appcompat:appcompat:1.0.0" + implementation "androidx.recyclerview:recyclerview:1.0.0-rc01" + implementation "androidx.palette:palette:1.0.0" + compile project(":kotlinshaver") } apply from: 'https://raw.githubusercontent.com/pokk/JCenterUploader/master/Uploader.gradle' diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Coroutine.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Coroutine.kt index 334105c..3961f90 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Coroutine.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Coroutine.kt @@ -1,11 +1,16 @@ +@file:Suppress("NOTHING_TO_INLINE") + package com.devrapid.kotlinknifer -import kotlinx.coroutines.experimental.CoroutineScope -import kotlinx.coroutines.experimental.android.UI -import kotlinx.coroutines.experimental.launch +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers.Default +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch + +inline fun ui(noinline block: suspend CoroutineScope.() -> Unit) = GlobalScope.launch(Main, block = block) + +inline fun bkg(noinline block: suspend CoroutineScope.() -> Unit) = GlobalScope.launch(Default, block = block) -/** - * @author Jieyi Wu - * @since 2018/04/04 - */ -fun ui(block: suspend CoroutineScope.() -> Unit) = launch(UI, block = block) \ No newline at end of file +inline fun io(noinline block: suspend CoroutineScope.() -> Unit) = GlobalScope.launch(IO, block = block) diff --git a/kotlinshaver/build.gradle b/kotlinshaver/build.gradle index 908595c..4bba54f 100644 --- a/kotlinshaver/build.gradle +++ b/kotlinshaver/build.gradle @@ -3,11 +3,11 @@ apply plugin: 'kotlin' dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.25.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.25.0' + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutine_version" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutine_version" - compile 'io.reactivex.rxjava2:rxkotlin:2.3.0' - compile 'io.reactivex.rxjava2:rxjava:2.2.1' + compile "io.reactivex.rxjava2:rxkotlin:2.3.0" + compile "io.reactivex.rxjava2:rxjava:2.2.3" } sourceCompatibility = "1.8" diff --git a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/ArrayList.kt b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/ArrayList.kt index 982c9a8..9d8fbf4 100644 --- a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/ArrayList.kt +++ b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/ArrayList.kt @@ -5,10 +5,10 @@ package com.devrapid.kotlinshaver * @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)) { + if (!(from in 0 until size && to in 0 until size && from > to)) { false } else { subList(from, to).clear() true - } \ No newline at end of file + } diff --git a/sample/build.gradle b/sample/build.gradle index 1632a66..73725d8 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -21,7 +21,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'androidx.appcompat:appcompat:1.0.0-rc02' + implementation 'androidx.appcompat:appcompat:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2' implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation project(':kotlinknifer') From 9cfcae15fe9048f633e1262083cc9f0f5cf39ca1 Mon Sep 17 00:00:00 2001 From: Jieyi Date: Tue, 30 Oct 2018 11:44:08 +0900 Subject: [PATCH 8/8] Update: updated readme and announce deprecate the Android AppCompat library support. --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 7f0cacb..2c9197b 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,12 @@ ![RxJava](https://img.shields.io/badge/RxJava-2.1.8-green.svg?style=flat-square) ![RxKotlin](https://img.shields.io/badge/RxKotlin-2.2.0-green.svg?style=flat-square) +# ⚠️ Deprecated AppCompat library + +We don't support AppCompat library, from Kotlin 1.3.0. All android libraries change to AndroidX. + + + The library has util tools as below: ### KotlinKnifer