From c454f329640bbf34f1a9fb5191235d2282261961 Mon Sep 17 00:00:00 2001 From: jieyi Date: Tue, 29 Sep 2020 16:46:43 +0900 Subject: [PATCH] style(*): change the coding style --- kotlinknifer/build.gradle | 1 - .../com/devrapid/kotlinknifer/Animation.kt | 10 +-- .../java/com/devrapid/kotlinknifer/Bitmap.kt | 18 +++-- .../com/devrapid/kotlinknifer/Delegate.kt | 6 +- .../com/devrapid/kotlinknifer/EditText.kt | 24 +++---- .../com/devrapid/kotlinknifer/Fragment.kt | 2 +- .../com/devrapid/kotlinknifer/Keyboard.kt | 10 --- .../java/com/devrapid/kotlinknifer/Logs.kt | 25 ++++--- .../java/com/devrapid/kotlinknifer/Network.kt | 3 +- .../com/devrapid/kotlinknifer/Resource.kt | 70 +++++++++++-------- .../com/devrapid/kotlinknifer/Spannable.kt | 2 +- .../com/devrapid/kotlinknifer/TextView.kt | 12 ++-- .../java/com/devrapid/kotlinknifer/Uri.kt | 15 ++-- .../java/com/devrapid/kotlinknifer/View.kt | 9 +-- .../com/devrapid/kotlinknifer/ViewStub.kt | 3 +- .../WrapContentLinearLayoutManager.kt | 2 +- .../itemdecorator/GridSpacingItemDecorator.kt | 6 +- .../itemdecorator/VerticalItemDecorator.kt | 2 +- kotlinshaver/build.gradle | 1 - .../com/devrapid/kotlinshaver/Coroutine.kt | 4 +- .../java/com/devrapid/kotlinshaver/Kits.kt | 4 +- 21 files changed, 126 insertions(+), 103 deletions(-) diff --git a/kotlinknifer/build.gradle b/kotlinknifer/build.gradle index 88b6c37..9ccf960 100644 --- a/kotlinknifer/build.gradle +++ b/kotlinknifer/build.gradle @@ -31,7 +31,6 @@ dependencies { implementation "com.google.code.gson:gson:2.8.6" // 'implementation' can't import to the new project. 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 "androidx.appcompat:appcompat:1.2.0" implementation "androidx.core:core-ktx:1.3.1" diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Animation.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Animation.kt index 2aff89b..2b2478e 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Animation.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Animation.kt @@ -15,7 +15,7 @@ import kotlin.math.pow fun View.registerCircularRevealAnimation( revealSettings: RevealAnimationSetting, startColor: Int, - endColor: Int + endColor: Int, ) { val duration = 1000L if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -29,7 +29,7 @@ fun View.registerCircularRevealAnimation( oldLeft: Int, oldTop: Int, oldRight: Int, - oldBottom: Int + oldBottom: Int, ) { v.removeOnLayoutChangeListener(this) val (cx, cy, width, height) = revealSettings @@ -50,7 +50,7 @@ fun View.startCircularExitAnimation( revealSettings: RevealAnimationSetting, startColor: Int, endColor: Int, - listener: () -> Unit + listener: () -> Unit, ) { val duration = 1000L if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -78,7 +78,7 @@ fun View.startCircularExitAnimation( fun View.startColorAnimation( startColor: Int, endColor: Int, - duration: Long + duration: Long, ) { ValueAnimator().apply { this.duration = duration @@ -92,7 +92,7 @@ data class RevealAnimationSetting( var centerX: Int, var centerY: Int, var width: Int, - var height: Int + var height: Int, ) : Parcelable { companion object CREATOR : Parcelable.Creator { override fun createFromParcel(parcel: Parcel) = RevealAnimationSetting(parcel) diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Bitmap.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Bitmap.kt index 70c49ed..b605417 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Bitmap.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Bitmap.kt @@ -25,8 +25,9 @@ import androidx.palette.graphics.Palette import java.io.ByteArrayOutputStream fun Resources.createBitmap( - drawableResId: Int, opts: BitmapFactory.Options? = null, - rect: Rect? = null + drawableResId: Int, + opts: BitmapFactory.Options? = null, + rect: Rect? = null, ): Bitmap? { var bitmap: Bitmap? = null openRawResource(drawableResId).use { @@ -67,7 +68,7 @@ fun Bitmap.scale(ratio: Float) = scale(ratio, ratio) fun Resources.createCompressedBitmap( @DrawableRes drawableResId: Int, simpleSize: Int = 1, - bitmapConf: Bitmap.Config? = null + bitmapConf: Bitmap.Config? = null, ): Bitmap { val opts = BitmapFactory.Options().apply { inJustDecodeBounds = false @@ -89,7 +90,7 @@ fun Resources.createScaledBitmap(@DrawableRes drawableResId: Int, ratio: Float) fun Resources.createRegionBitmap( drawableResId: Int, rect: Rect, - opts: BitmapFactory.Options = BitmapFactory.Options() + opts: BitmapFactory.Options = BitmapFactory.Options(), ) = openRawResource(drawableResId).use { // Create a region decoder. val decoder = BitmapRegionDecoder.newInstance(it, false) @@ -111,15 +112,18 @@ fun Bitmap.toBytes(format: Bitmap.CompressFormat = Bitmap.CompressFormat.PNG, qu fun Bitmap.resizeImageAsRatio(aspectRatio: Double): Bitmap = also { val ratio: Double = it.width.toDouble() / it.height.toDouble() - if (ratio > aspectRatio) + if (ratio > aspectRatio) { it.width = (aspectRatio * it.height).toInt() - else + } + else { it.height = (it.width / aspectRatio).toInt() + } } fun Bitmap?.safeRecycle() { - if (this != null && !isRecycled) + if (this != null && !isRecycled) { recycle() + } } fun Bitmap.decorateGradientMask(shaderDst: Shader): Bitmap { diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Delegate.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Delegate.kt index cb29022..a78b4c2 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Delegate.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Delegate.kt @@ -20,7 +20,7 @@ import kotlin.reflect.KProperty */ class SoftRef( default: T? = null, - private val queue: ReferenceQueue? = null + private val queue: ReferenceQueue? = null, ) : ReadWriteProperty { private var variable: SoftReference? @@ -50,7 +50,7 @@ class SoftRef( */ class WeakRef( default: T? = null, - private val queue: ReferenceQueue? = null + private val queue: ReferenceQueue? = null, ) : ReadWriteProperty { private var variable: WeakReference? @@ -80,7 +80,7 @@ class WeakRef( */ class PhantomRef( default: T? = null, - private val queue: ReferenceQueue + private val queue: ReferenceQueue, ) : ReadWriteProperty { private var variable: PhantomReference? diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt index 675b6cf..ff628d6 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt @@ -12,22 +12,22 @@ fun setCursorPointerColor(view: EditText, @ColorInt color: Int, @DrawableRes dra // 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. + 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. + .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 + } + else { (0..2).map { requireNotNull(ContextCompat.getDrawable(view.context, drawable)) } + } // Get all handle fields. - val fields = listOf("mSelectHandleCenter" - , "mSelectHandleLeft" - , "mSelectHandleRight") + val fields = listOf("mSelectHandleCenter", "mSelectHandleLeft", "mSelectHandleRight") .map { editor.javaClass.getDeclaredField(it).accessible() } fields.zip(drawables).forEach { (field, drawable) -> field.set(editor, drawable) } diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Fragment.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Fragment.kt index ff73ca5..38af067 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Fragment.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Fragment.kt @@ -28,7 +28,7 @@ fun FragmentManager.addFragment( needBack: Boolean = false, fragmentStack: Stack? = null, sharedElements: HashMap = hashMapOf(), - block: ((FragmentTransaction) -> Unit)? = null + block: ((FragmentTransaction) -> Unit)? = null, ) = transaction { block?.invoke(this) sharedElements.forEach { value -> addSharedElement(value.key, value.value) } diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Keyboard.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Keyboard.kt index 840b63d..342bd85 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Keyboard.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Keyboard.kt @@ -37,13 +37,3 @@ fun isShowingSoftKeyboard(rootView: View): Boolean { inline fun Context.toggleSoftKeyboard() = (getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager) .toggleSoftInput(InputMethodManager.SHOW_FORCED, 0) - -// FIXME(jieyi): 2018/01/23 Those functions don't work well. -//inline fun Context.hideSoftKeyboard() = if (isShowingSoftKeyboard()) toggleSoftKeyboard() else Unit -// -//inline fun Context.showSoftKeyboard() = if (isHidingSoftKeyboard()) toggleSoftKeyboard() else Unit -// -//inline fun Context.isHidingSoftKeyboard() = !isShowingSoftKeyboard() -// -//inline fun Context.isShowingSoftKeyboard() = -// (getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).isAcceptingText diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Logs.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Logs.kt index df38c71..91485a7 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Logs.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Logs.kt @@ -8,16 +8,22 @@ fun logi(vararg msg: Any?) = Logs.i(*msg) fun logw(vararg msg: Any?) = Logs.w(*msg) fun loge(vararg msg: Any?) = Logs.e(*msg) +fun logv(msg: Any?) = Logs.v(msg) +fun logd(msg: Any?) = Logs.d(msg) +fun logi(msg: Any?) = Logs.i(msg) +fun logw(msg: Any?) = Logs.w(msg) +fun loge(msg: Any?) = Logs.e(msg) + internal object Logs { - var _IS_DEBUG = true // Debug mode's switch, default is turn off. - var TAG = "MY_LOG" // TAG + var _IS_DEBUG = true // Debug mode's switch, default is turn off. + var TAG = "MY_LOG" // TAG private const val COLON = ":" private const val LEFT_PARENTHESIS = "(" private const val RIGHT_PARENTHESIS = ")" private const val SPACE_STRING = " " private const val METHOD_INDEX = 4 - private val lockLog = Any() // Avoid the threading's race condition. - private val strBuilder = StringBuilder() // String builder. + private val lockLog = Any() // Avoid the threading's race condition. + private val strBuilder = StringBuilder() // String builder. /** * VERBOSE log. @@ -53,10 +59,12 @@ internal object Logs { * @param msg output message */ internal fun e(vararg msg: Any?) { - if (1 == msg.size && msg[0] is Exception) + if (1 == msg.size && msg[0] is Exception) { LogWrapper().debugCheck(Log::class.java, getExceptionMsg(msg[0] as Exception)) - else + } + else { showLog(*msg) + } } /** @@ -73,11 +81,12 @@ internal object Logs { fun debugCheck(cls: Class<*>, msg: Any): Boolean { // Checking the debug mode. if (_IS_DEBUG) { - // Because the level of the function depth, the index is 4. + // Because the level of the function depth, the index is 4. var methodName = Thread.currentThread().stackTrace[METHOD_INDEX].methodName.substringBefore("$") // Only exception msg only is 3. - if (1 < methodName.length) + if (1 < methodName.length) { methodName = Thread.currentThread().stackTrace[METHOD_INDEX - 1].methodName.substringBefore("$") + } // Avoid the race condition. synchronized(lockLog) { return logMsg(cls, methodName, msg) diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Network.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Network.kt index 42142bc..b8f3fa0 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Network.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Network.kt @@ -20,7 +20,8 @@ fun hasNetwork(context: Context): Boolean { var isConnected = false // Initial Value val connectivityManager = cast(context.getSystemService(CONNECTIVITY_SERVICE)) val activeNetwork = connectivityManager.activeNetworkInfo - if (activeNetwork != null && activeNetwork.isConnected) + if (activeNetwork != null && activeNetwork.isConnected) { isConnected = true + } return isConnected } diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Resource.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Resource.kt index f2d133e..da72088 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Resource.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Resource.kt @@ -37,16 +37,18 @@ inline fun Context.getFont(@FontRes id: Int) = resources.getFont(id) inline fun Context.displayMetrics() = resources.displayMetrics inline fun Context.createBitmap( - @DrawableRes id: Int, opts: BitmapFactory.Options? = null, - rect: Rect? = null + @DrawableRes id: Int, + opts: BitmapFactory.Options? = null, + rect: Rect? = null, ) = resources.createBitmap(id, opts, rect) inline fun Context.obtainBitmapSize(@DrawableRes id: Int) = resources.obtainBitmapSize(id) inline fun Context.createCompressedBitmap( - @DrawableRes id: Int, simpleSize: Int = 1, - bitmapConf: Bitmap.Config? = null + @DrawableRes id: Int, + simpleSize: Int = 1, + bitmapConf: Bitmap.Config? = null, ) = resources.createCompressedBitmap(id, simpleSize, bitmapConf) inline fun Context.createScaledBitmap(@DrawableRes id: Int, width: Int, height: Int) = @@ -59,8 +61,9 @@ inline fun Context.createScaledBitmap(@DrawableRes id: Int, ratio: Float) = resources.createScaledBitmap(id, ratio) inline fun Context.createRegionBitmap( - @DrawableRes id: Int, rect: Rect, - opts: BitmapFactory.Options = BitmapFactory.Options() + @DrawableRes id: Int, + rect: Rect, + opts: BitmapFactory.Options = BitmapFactory.Options(), ) = resources.createRegionBitmap(id, rect, opts) //endregion @@ -84,24 +87,27 @@ inline fun Activity.getFont(@FontRes id: Int) = resources.getFont(id) inline fun Activity.displayMetrics() = resources.displayMetrics inline fun Activity.createBitmap( - @DrawableRes id: Int, opts: BitmapFactory.Options? = null, - rect: Rect? = null + @DrawableRes id: Int, + opts: BitmapFactory.Options? = null, + rect: Rect? = null, ) = resources.createBitmap(id, opts, rect) inline fun Activity.obtainBitmapSize(@DrawableRes id: Int) = resources.obtainBitmapSize(id) inline fun Activity.createCompressedBitmap( - @DrawableRes id: Int, simpleSize: Int = 1, - bitmapConf: Bitmap.Config? = null + @DrawableRes id: Int, + simpleSize: Int = 1, + bitmapConf: Bitmap.Config? = null, ) = resources.createCompressedBitmap(id, simpleSize, bitmapConf) inline fun Activity.createScaledBitmap(@DrawableRes id: Int, width: Int, height: Int) = resources.createScaledBitmap(id, width, height) inline fun Activity.createScaledBitmap( - @DrawableRes id: Int, widthRatio: Float, - heightRatio: Float + @DrawableRes id: Int, + widthRatio: Float, + heightRatio: Float, ) = resources.createScaledBitmap(id, widthRatio, heightRatio) @@ -109,8 +115,9 @@ inline fun Activity.createScaledBitmap(@DrawableRes id: Int, ratio: Float) = resources.createScaledBitmap(id, ratio) inline fun Activity.createRegionBitmap( - @DrawableRes id: Int, rect: Rect, - opts: BitmapFactory.Options = BitmapFactory.Options() + @DrawableRes id: Int, + rect: Rect, + opts: BitmapFactory.Options = BitmapFactory.Options(), ) = resources.createRegionBitmap(id, rect, opts) //endregion @@ -133,24 +140,27 @@ inline fun Fragment.getFont(@FontRes id: Int) = resources.getFont(id) inline fun Fragment.displayMetrics() = resources.displayMetrics inline fun Fragment.createBitmap( - @DrawableRes id: Int, opts: BitmapFactory.Options? = null, - rect: Rect? = null + @DrawableRes id: Int, + opts: BitmapFactory.Options? = null, + rect: Rect? = null, ) = resources.createBitmap(id, opts, rect) inline fun Fragment.obtainBitmapSize(@DrawableRes id: Int) = resources.obtainBitmapSize(id) inline fun Fragment.createCompressedBitmap( - @DrawableRes id: Int, simpleSize: Int = 1, - bitmapConf: Bitmap.Config? = null + @DrawableRes id: Int, + simpleSize: Int = 1, + bitmapConf: Bitmap.Config? = null, ) = resources.createCompressedBitmap(id, simpleSize, bitmapConf) inline fun Fragment.createScaledBitmap(@DrawableRes id: Int, width: Int, height: Int) = resources.createScaledBitmap(id, width, height) inline fun Fragment.createScaledBitmap( - @DrawableRes id: Int, widthRatio: Float, - heightRatio: Float + @DrawableRes id: Int, + widthRatio: Float, + heightRatio: Float, ) = resources.createScaledBitmap(id, widthRatio, heightRatio) @@ -158,8 +168,9 @@ inline fun Fragment.createScaledBitmap(@DrawableRes id: Int, ratio: Float) = resources.createScaledBitmap(id, ratio) inline fun Fragment.createRegionBitmap( - @DrawableRes id: Int, rect: Rect, - opts: BitmapFactory.Options = BitmapFactory.Options() + @DrawableRes id: Int, + rect: Rect, + opts: BitmapFactory.Options = BitmapFactory.Options(), ) = resources.createRegionBitmap(id, rect, opts) //endregion @@ -182,16 +193,18 @@ inline fun View.getFont(@FontRes id: Int) = resources.getFont(id) inline fun View.displayMetrics() = resources.displayMetrics inline fun View.createBitmap( - @DrawableRes id: Int, opts: BitmapFactory.Options? = null, - rect: Rect? = null + @DrawableRes id: Int, + opts: BitmapFactory.Options? = null, + rect: Rect? = null, ) = resources.createBitmap(id, opts, rect) inline fun View.obtainBitmapSize(@DrawableRes id: Int) = resources.obtainBitmapSize(id) inline fun View.createCompressedBitmap( - @DrawableRes id: Int, simpleSize: Int = 1, - bitmapConf: Bitmap.Config? = null + @DrawableRes id: Int, + simpleSize: Int = 1, + bitmapConf: Bitmap.Config? = null, ) = resources.createCompressedBitmap(id, simpleSize, bitmapConf) @@ -205,7 +218,8 @@ inline fun View.createScaledBitmap(@DrawableRes id: Int, ratio: Float) = resources.createScaledBitmap(id, ratio) inline fun View.createRegionBitmap( - @DrawableRes id: Int, rect: Rect, - opts: BitmapFactory.Options = BitmapFactory.Options() + @DrawableRes id: Int, + rect: Rect, + opts: BitmapFactory.Options = BitmapFactory.Options(), ) = resources.createRegionBitmap(id, rect, opts) //endregion diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Spannable.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Spannable.kt index a5d85e1..8038dfc 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Spannable.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Spannable.kt @@ -17,7 +17,7 @@ inline fun TextView.withMovement() = apply { inline fun TextView.parseAsHtml( flags: Int = HtmlCompat.FROM_HTML_MODE_LEGACY, imageGetter: Html.ImageGetter? = null, - tagHandler: Html.TagHandler? = null + tagHandler: Html.TagHandler? = null, ) = apply { text = text.toString().parseAsHtml(flags, imageGetter, tagHandler) } diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/TextView.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/TextView.kt index f4f2a67..768891e 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/TextView.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/TextView.kt @@ -13,8 +13,8 @@ import kotlin.annotation.AnnotationTarget.TYPE import kotlin.annotation.AnnotationTarget.VALUE_PARAMETER /** - * @author jieyi - * @since 09/11/18 + * @author jieyi + * @since 09/11/18 */ object DrawableDirectionConst { const val DRAWABLE_DIRECTION_START = 0x1 @@ -36,7 +36,7 @@ fun TextView.addDrawable( color: Int, @DrawableDirection direct: Int, ratioWidth: Float = 1f, - ratioHeight: Float = 1f + ratioHeight: Float = 1f, ) { // Modify the icon size. context.scaledDrawable(drawableId, ratioWidth, ratioHeight) @@ -59,7 +59,7 @@ fun TextView.addDrawable( @DrawableRes drawableId: Int, @DrawableDirection direct: Int, ratioWidth: Float = 1f, - ratioHeight: Float = 1f + ratioHeight: Float = 1f, ) = addDrawable(drawableId, 0, direct, ratioWidth, ratioHeight) fun TextView.addDrawableWithIntrinsicBounds( @@ -67,7 +67,7 @@ fun TextView.addDrawableWithIntrinsicBounds( color: Int, @DrawableDirection direct: Int, ratioWidth: Float = 1f, - ratioHeight: Float = 1f + ratioHeight: Float = 1f, ) { // Modify the icon size. context.scaledDrawable(drawableId, ratioWidth, ratioHeight) @@ -90,5 +90,5 @@ fun TextView.addDrawableWithIntrinsicBounds( @DrawableRes drawableId: Int, @DrawableDirection direct: Int, ratioWidth: Float = 1f, - ratioHeight: Float = 1f + ratioHeight: Float = 1f, ) = addDrawableWithIntrinsicBounds(drawableId, 0, direct, ratioWidth, ratioHeight) diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Uri.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Uri.kt index 7c1c7c4..38f5698 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Uri.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/Uri.kt @@ -17,8 +17,8 @@ import java.io.IOException import java.io.InputStreamReader /** - * @author Jieyi Wu - * @since 2018/03/23 + * @author Jieyi Wu + * @since 2018/03/23 */ /** * For above [Build.VERSION_CODES.KITKAT], convert the uri to the absolute path. @@ -96,8 +96,9 @@ fun Uri.getRealFileName(context: Context): String { if (it.moveToFirst()) { it.getString(it.getColumnIndex(OpenableColumns.DISPLAY_NAME)) } - else + else { null + } }.orEmpty() uriString.startsWith("file://") -> file.name.orEmpty() else -> "" @@ -142,7 +143,7 @@ internal fun getDataColumn( context: Context, uri: Uri, selection: String? = null, - selectionArgs: Array? = null + selectionArgs: Array? = null, ): String? { val column = "_data" val projection = arrayOf(column) @@ -153,8 +154,9 @@ internal fun getDataColumn( it.getString(columnIndex) } - else + else { null + } } } @@ -166,8 +168,9 @@ internal fun getFilePath(context: Context, uri: Uri): String? { val index = it.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME) return it.getString(index) } - else + else { null + } } } diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt index b224455..47445a1 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt @@ -79,9 +79,9 @@ fun Context.alert(message: Int, title: Int? = null, init: (AlertDialog.Builder.( init?.let { init() } } -inline fun Context.navigationBarHeiht() = getIdentifier("navigation_bar_height", "dimen", "android") - .takeIf { 0 < it } - ?.let { getDimenPixelSize(it) } ?: 0 +inline fun Context.navigationBarHeight() = getIdentifier("navigation_bar_height", "dimen", "android") + .takeIf { 0 < it } + ?.let { getDimenPixelSize(it) } ?: 0 inline fun Context.statusBarHeight() = getIdentifier("status_bar_height", "dimen", "android") .takeIf { 0 < it } @@ -98,7 +98,7 @@ fun Activity.changeStatusBarColor(@ColorInt color: Int, ratio: Float = 1f) = setStatusBarColorBy { statusBarColor = color.ofAlpha(ratio) } internal inline fun Activity.setStatusBarColorBy(block: Window.() -> Unit) { - if (Build.VERSION_CODES.LOLLIPOP <= Build.VERSION.SDK_INT) + if (Build.VERSION_CODES.LOLLIPOP <= Build.VERSION.SDK_INT) { window.apply { clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) @@ -106,6 +106,7 @@ internal inline fun Activity.setStatusBarColorBy(block: Window.() -> Unit) { // For not opaque(transparent) color. decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN } + } else { TODO("Don't support the sdk version is less than 21 yet.") } diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/ViewStub.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/ViewStub.kt index 0411c74..ba2001e 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/ViewStub.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/ViewStub.kt @@ -21,7 +21,8 @@ fun Activity.showViewStub(@IdRes stub: Int, @IdRes realView: Int, options: (View } fun Fragment.showViewStub(@IdRes stub: Int, @IdRes realView: Int, options: (View.() -> Unit)? = null) { - (requireNotNull(view).findViewById(stub)?.inflate() ?: requireNotNull(view).findViewById(realView)).apply { + (requireNotNull(view).findViewById(stub) + ?.inflate() ?: requireNotNull(view).findViewById(realView)).apply { visible() bringToFront() options?.let(this::apply) 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 cd0cac0..c507465 100644 --- a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/WrapContentLinearLayoutManager.kt +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/recyclerview/WrapContentLinearLayoutManager.kt @@ -11,7 +11,7 @@ class WrapContentLinearLayoutManager @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, - defStyleRes: Int = 0 + defStyleRes: Int = 0, ) : LinearLayoutManager(context, attrs, defStyleAttr, defStyleRes) { // FIXED(jieyi): 9/23/17 Workaround for fixing the android original recycler view problem. override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) { 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 7459bff..aedd89e 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 @@ -18,8 +18,9 @@ class GridSpacingItemDecorator(private val spanCount: Int, private val spacing: // (column + 1) * ((1f / spanCount) * spacing). outRect.right = (column + 1) * spacing / spanCount // top edge. - if (position < spanCount) + if (position < spanCount) { outRect.top = spacing + } // item bottom. outRect.bottom = spacing } @@ -29,8 +30,9 @@ class GridSpacingItemDecorator(private val spanCount: Int, private val spacing: // spacing - (column + 1) * ((1f / spanCount) * spacing). outRect.right = spacing - (column + 1) * spacing / spanCount // item top. - if (position >= spanCount) + if (position >= spanCount) { outRect.top = spacing + } } } } 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 e79a031..1429e8b 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 @@ -6,7 +6,7 @@ import androidx.recyclerview.widget.RecyclerView class VerticalItemDecorator( private val topBottom: Int, - private val leftRight: Int = topBottom + private val leftRight: Int = topBottom, ) : RecyclerView.ItemDecoration() { override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { val position: Int = parent.getChildAdapterPosition(view) diff --git a/kotlinshaver/build.gradle b/kotlinshaver/build.gradle index 30c6362..34c69a0 100644 --- a/kotlinshaver/build.gradle +++ b/kotlinshaver/build.gradle @@ -4,7 +4,6 @@ apply plugin: 'kotlin' dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutine_version" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutine_version" } sourceCompatibility = "1.8" diff --git a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Coroutine.kt b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Coroutine.kt index 11ca7c8..9ab158b 100644 --- a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Coroutine.kt +++ b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Coroutine.kt @@ -19,7 +19,7 @@ import kotlin.coroutines.EmptyCoroutineContext inline fun gLaunch( context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, - noinline block: suspend CoroutineScope.() -> Unit + noinline block: suspend CoroutineScope.() -> Unit, ) = GlobalScope.launch(context, start, block) inline fun ui(noinline block: suspend CoroutineScope.() -> Unit) = @@ -39,7 +39,7 @@ inline fun io(noinline block: suspend CoroutineScope.() -> Unit) = inline fun gAsync( context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, - noinline block: suspend CoroutineScope.() -> T + noinline block: suspend CoroutineScope.() -> T, ) = GlobalScope.async(context, start, block) inline fun uiAsync(noinline block: suspend CoroutineScope.() -> T) = diff --git a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Kits.kt b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Kits.kt index 89f2fbb..9172387 100644 --- a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Kits.kt +++ b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Kits.kt @@ -19,7 +19,7 @@ inline fun Any?.isNull() = null == this inline fun Any?.isNotNull() = null != this -@ExperimentalContracts +@OptIn(ExperimentalContracts::class) inline fun Any?.isNullExp(): Boolean { contract { returns(false) implies (this@isNullExp == null) @@ -27,7 +27,7 @@ inline fun Any?.isNullExp(): Boolean { return null == this } -@ExperimentalContracts +@OptIn(ExperimentalContracts::class) inline fun Any?.isNotNullExp(): Boolean { contract { returns(true) implies (this@isNotNullExp != null)