Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanCaiCoding committed Nov 11, 2021
1 parent 127d611 commit 9c069e6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
16 changes: 16 additions & 0 deletions longan/src/main/java/com/dylanc/longan/Encrypt.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2021. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress("unused")

package com.dylanc.longan
Expand Down
14 changes: 7 additions & 7 deletions longan/src/main/java/com/dylanc/longan/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

@file:Suppress("unused")
@file:Suppress("unused", "NOTHING_TO_INLINE")

package com.dylanc.longan

Expand Down Expand Up @@ -84,22 +84,22 @@ fun Logger.logError(message: Any?, thr: Throwable? = null) =
fun Logger.logWtf(message: Any?, thr: Throwable? = null) =
Logger.printer.logWtf(loggerTag, message.toString(), thr)

fun logVerbose(message: Any?, thr: Throwable? = null) =
inline fun logVerbose(message: Any?, thr: Throwable? = null) =
log(LogLevel.VERBOSE, TAG, message, thr)

fun logDebug(message: Any?, thr: Throwable? = null) =
inline fun logDebug(message: Any?, thr: Throwable? = null) =
log(LogLevel.DEBUG, TAG, message, thr)

fun logInfo(message: Any?, thr: Throwable? = null) =
inline fun logInfo(message: Any?, thr: Throwable? = null) =
log(LogLevel.INFO, TAG, message, thr)

fun logWarn(message: Any?, thr: Throwable? = null) =
inline fun logWarn(message: Any?, thr: Throwable? = null) =
log(LogLevel.WARN, TAG, message, thr)

fun logError(message: Any?, thr: Throwable? = null) =
inline fun logError(message: Any?, thr: Throwable? = null) =
log(LogLevel.ERROR, TAG, message, thr)

fun logWtf(message: Any?, thr: Throwable? = null) =
inline fun logWtf(message: Any?, thr: Throwable? = null) =
Logger.printer.logWtf(TAG, message.toString(), thr)

fun log(level: LogLevel, tag: String, message: Any?, thr: Throwable? = null) {
Expand Down
10 changes: 5 additions & 5 deletions longan/src/main/java/com/dylanc/longan/Threads.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import android.os.Handler
import android.os.Looper


val mainHandler = lazy { Handler(Looper.getMainLooper()) }
val mainHandler by lazy { Handler(Looper.getMainLooper()) }

fun mainThread(block: () -> Unit) {
if (Looper.myLooper() == Looper.getMainLooper()) {
block()
if (Looper.myLooper() != Looper.getMainLooper()) {
mainHandler.post(block)
} else {
mainHandler.value.post(block)
block()
}
}

fun mainThread(delayMillis: Long, block: () -> Unit) =
mainHandler.value.postDelayed(block, delayMillis)
mainHandler.postDelayed(block, delayMillis)

0 comments on commit 9c069e6

Please sign in to comment.