Skip to content

Commit

Permalink
Merge branch 'androidx'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	build.gradle
#	gradle.properties
#	kotlinknifer/build.gradle
#	kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt
#	kotlinshaver/build.gradle
#	sample/build.gradle
  • Loading branch information
pokk committed Oct 30, 2018
2 parents d0247af + 9cfcae1 commit a2f7c7e
Show file tree
Hide file tree
Showing 23 changed files with 157 additions and 205 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,6 +61,7 @@ The library has util tools as below:
6. String
7. Thread
8. Time
9. Casting

# NOTE

Expand Down Expand Up @@ -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!!!
Expand All @@ -100,14 +107,14 @@ Then you can use it!!!
<dependency>
<groupId>com.devrapid.jieyi</groupId>
<artifactId>kotlinknifer</artifactId>
<version>1.5.9</version>
<version>2.1.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.devrapid.jieyi</groupId>
<artifactId>kotlinshaver</artifactId>
<version>0.2.4</version>
<version>1.1.0</version>
<type>pom</type>
</dependency>
```
Expand All @@ -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'
})
Expand All @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ 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
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
Expand All @@ -36,4 +39,4 @@ [email protected]
proj_kotlin_name=kotlinshaver
proj_kotlin_libname=KotlinShaver
proj_kotlin_artifactid=kotlinshaver
proj_kotlin_version=0.2.4
proj_kotlin_version=1.1.0
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
25 changes: 12 additions & 13 deletions kotlinknifer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,4 +49,4 @@ fun Bitmap.resizeImageAsRatio(aspectRatio: Double): Bitmap = also {
it.width = (aspectRatio * it.height).toInt()
else
it.height = (it.width / aspectRatio).toInt()
}
}
6 changes: 3 additions & 3 deletions kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
*
Expand Down
21 changes: 13 additions & 8 deletions kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Coroutine.kt
Original file line number Diff line number Diff line change
@@ -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)
inline fun io(noinline block: suspend CoroutineScope.() -> Unit) = GlobalScope.launch(IO, block = block)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
22 changes: 7 additions & 15 deletions kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Fragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -70,21 +68,20 @@ inline fun FragmentManager.popAllFragment(fragmentStack: Stack<Fragment>? = 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)
Expand All @@ -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) }

Expand All @@ -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")
}
beginTransaction().apply(block).commitNow()
52 changes: 52 additions & 0 deletions kotlinknifer/src/main/java/com/devrapid/kotlinknifer/TextView.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Loading

0 comments on commit a2f7c7e

Please sign in to comment.