Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanCaiCoding committed Jun 2, 2022
1 parent 5cb9c18 commit e9db54c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
7 changes: 1 addition & 6 deletions longan-design/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ android {
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -28,12 +26,9 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

compileOptions {
kotlinOptions.freeCompilerArgs += ['-module-name', "longan_design"]
}

kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs += ['-module-name', "longan_design"]
}
}

Expand Down
4 changes: 1 addition & 3 deletions longan/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ android {
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -27,11 +25,11 @@ android {
coreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
kotlinOptions.freeCompilerArgs += ['-module-name', "longan"]
}

kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs += ['-module-name', "longan"]
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
freeCompilerArgs += "-Xcontext-receivers"
}
Expand Down
7 changes: 4 additions & 3 deletions longan/src/main/java/com/dylanc/longan/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ inline val appVersionName: String get() = packageInfo.versionName

inline val appVersionCode: Long get() = PackageInfoCompat.getLongVersionCode(packageInfo)

inline val isAppDebug: Boolean
get() = application.packageManager.getApplicationInfo(packageName, 0).flags and
ApplicationInfo.FLAG_DEBUGGABLE != 0
inline val isAppDebug: Boolean get() = application.isAppDebug

inline val Application.isAppDebug: Boolean
get() = packageManager.getApplicationInfo(packageName, 0).flags and ApplicationInfo.FLAG_DEBUGGABLE != 0

inline val isAppDarkMode: Boolean
get() = (application.resources.configuration.uiMode and UI_MODE_NIGHT_MASK) == UI_MODE_NIGHT_YES
Expand Down
7 changes: 3 additions & 4 deletions longan/src/main/java/com/dylanc/longan/Network.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,11 @@ class WifiListLiveData @RequiresPermission(allOf = [ACCESS_WIFI_STATE, CHANGE_WI

private val wifiScanReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val success = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
intent.getBooleanExtra(WifiManager.EXTRA_RESULTS_UPDATED, false)
} else {
true
) {
value = wifiManager.scanResults
}
value = if (success) wifiManager.scanResults else null
}
}
}
16 changes: 8 additions & 8 deletions longan/src/main/java/com/dylanc/longan/TextView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun TextView.addUnderline() {
paint.flags = Paint.UNDERLINE_TEXT_FLAG
}

fun TextView.transparentHighlightColor(){
fun TextView.transparentHighlightColor() {
highlightColor = Color.TRANSPARENT
}

Expand All @@ -62,8 +62,8 @@ fun TextView.startCountDown(
secondInFuture: Int = 60,
onTick: TextView.(secondUntilFinished: Int) -> Unit,
onFinish: TextView.() -> Unit,
) {
val countDownTimer = object : CountDownTimer(secondInFuture * 1000L, 1000) {
): CountDownTimer =
object : CountDownTimer(secondInFuture * 1000L, 1000) {
override fun onTick(millisUntilFinished: Long) {
isEnabled = false
onTick((millisUntilFinished / 1000f).roundToInt())
Expand All @@ -73,12 +73,12 @@ fun TextView.startCountDown(
isEnabled = true
this@startCountDown.onFinish()
}
}.also { countDownTimer ->
countDownTimer.start()
lifecycleOwner.doOnLifecycle(onDestroy = {
countDownTimer.cancel()
})
}
countDownTimer.start()
lifecycleOwner.doOnLifecycle(onDestroy = {
countDownTimer.cancel()
})
}

fun TextView.enableWhenOtherTextNotEmpty(vararg textViews: TextView) =
enableWhenOtherTextChanged(*textViews) { textViews.all { it.isTextNotEmpty() } }
Expand Down

0 comments on commit e9db54c

Please sign in to comment.