diff --git a/README.md b/README.md
index faf7841..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
@@ -55,6 +61,7 @@ The library has util tools as below:
6. String
7. Thread
8. Time
+9. Casting
# NOTE
@@ -87,9 +94,9 @@ allprojects {
And add our dependency to your app `bundle.gradle`.
```gradle
-implementation 'com.devrapid.jieyi:kotlinknifer:1.5.9'
+implementation 'com.devrapid.jieyi:kotlinknifer:2.1.0'
-implementation 'com.devrapid.jieyi:kotlinshaver:0.2.4'
+implementation 'com.devrapid.jieyi:kotlinshaver:1.1.0'
```
Then you can use it!!!
@@ -100,14 +107,14 @@ Then you can use it!!!
com.devrapid.jieyi
kotlinknifer
- 1.5.9
+ 2.1.0
pom
com.devrapid.jieyi
kotlinshaver
- 0.2.4
+ 1.1.0
pom
```
@@ -120,21 +127,22 @@ Then you can use it!!!
2. Glide 4.8.0
## 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:1.5.9', {
+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:0.2.4', {
+implementation('com.devrapid.jieyi:kotlinshaverr:1.1.0', {
exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
exclude group: 'io.reactivex.rxjava2', module: 'rxkotlin'
})
@@ -150,7 +158,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/build.gradle b/build.gradle
index bde582c..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.1.0'
+ 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 b9fbae3..55c1d3a 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.9
+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
@@ -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.4
+proj_kotlin_version=1.1.0
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index f63486f..47e406e 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.10.2-all.zip
diff --git a/kotlinknifer/build.gradle b/kotlinknifer/build.gradle
index 646b84f..88438e7 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 {
@@ -26,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 'com.android.support:appcompat-v7:27.1.1'
- implementation 'com.android.support:recyclerview-v7:27.1.1'
- implementation 'com.android.support:palette-v7:27.1.1'
- 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/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/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/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Drawable.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Drawable.kt
index 7b6a81d..e8ada5e 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/EditText.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt
index d8d1b3c..675b6cf 100644
--- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt
+++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt
@@ -1,11 +1,11 @@
package com.devrapid.kotlinknifer
import android.graphics.PorterDuff.Mode.SRC_IN
-import android.support.annotation.ColorInt
-import android.support.annotation.DrawableRes
-import android.support.v4.content.ContextCompat
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) {
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/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/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 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/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
diff --git a/sample/build.gradle b/sample/build.gradle
index c731217..73725d8 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.1'
- implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha2'
+ implementation fileTree(include: ['*.jar'], dir: 'libs')
+ 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')
// 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?) {