feat: 优化代码

pull/103/head
kunfei 5 years ago
parent e17de8669e
commit 0b1c4b6de0
  1. 16
      app/src/main/java/io/legado/app/utils/BatteryUtils.kt
  2. 11
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  3. 1
      app/src/main/java/io/legado/app/utils/DocumentUtils.kt
  4. 1
      app/src/main/java/io/legado/app/utils/EncoderUtils.kt
  5. 2
      app/src/main/java/io/legado/app/utils/FileUtils.kt
  6. 2
      app/src/main/java/io/legado/app/utils/LogUtils.kt
  7. 2
      app/src/main/java/io/legado/app/utils/MD5Utils.kt
  8. 1
      app/src/main/java/io/legado/app/utils/NetworkUtils.kt
  9. 1
      app/src/main/java/io/legado/app/utils/StringUtils.kt
  10. 2
      app/src/main/java/io/legado/app/utils/SystemUtils.kt
  11. 1
      app/src/main/java/io/legado/app/utils/UTF8BOMFighter.kt
  12. 9
      app/src/main/java/io/legado/app/utils/ZipUtils.kt

@ -1,16 +0,0 @@
package io.legado.app.utils
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.BatteryManager
object BatteryUtils {
fun getLevel(context: Context): Int {
val iFilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)
val batteryStatus = context.registerReceiver(null, iFilter)
return batteryStatus?.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) ?: -1
}
}

@ -3,10 +3,12 @@ package io.legado.app.utils
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.os.BatteryManager
import android.provider.Settings
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
@ -134,3 +136,12 @@ fun Context.sysIsDarkMode(): Boolean {
val mode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
return mode == Configuration.UI_MODE_NIGHT_YES
}
/**
* 获取电量
*/
fun Context.getBettery(): Int {
val iFilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)
val batteryStatus = registerReceiver(null, iFilter)
return batteryStatus?.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) ?: -1
}

@ -7,6 +7,7 @@ import android.provider.DocumentsContract
import androidx.documentfile.provider.DocumentFile
import java.util.*
@Suppress("unused")
object DocumentUtils {
fun exists(root: DocumentFile, fileName: String, vararg subDirs: String): Boolean {

@ -3,6 +3,7 @@ package io.legado.app.utils
import android.util.Base64
import java.nio.charset.StandardCharsets
@Suppress("unused")
object EncoderUtils {
fun escape(src: String): String {

@ -10,7 +10,7 @@ import io.legado.app.App
import java.io.File
import java.io.IOException
@Suppress("unused")
object FileUtils {
fun exists(root: File, fileName: String, vararg subDirs: String): Boolean {

@ -8,7 +8,7 @@ import java.util.*
import java.util.logging.*
import java.util.logging.Formatter
@Suppress("unused")
object LogUtils {
const val TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"

@ -6,7 +6,7 @@ import java.security.NoSuchAlgorithmException
/**
* 将字符串转化为MD5
*/
@Suppress("unused")
object MD5Utils {
fun md5Encode(str: String?): String? {

@ -8,6 +8,7 @@ import java.net.URL
import java.util.*
import java.util.regex.Pattern
@Suppress("unused")
object NetworkUtils {
fun getUrl(response: Response<*>): String {
val networkResponse = response.raw().networkResponse

@ -12,6 +12,7 @@ import kotlin.math.abs
import kotlin.math.log10
import kotlin.math.pow
@Suppress("unused")
object StringUtils {
private const val HOUR_OF_DAY = 24
private const val DAY_OF_YESTERDAY = 2

@ -9,6 +9,8 @@ import android.net.Uri
import android.os.PowerManager
import android.provider.Settings
@Suppress("unused")
object SystemUtils {
fun getScreenOffTime(context: Context): Int {

@ -1,5 +1,6 @@
package io.legado.app.utils
@Suppress("unused")
object UTF8BOMFighter {
private val UTF8_BOM_BYTES = byteArrayOf(0xEF.toByte(), 0xBB.toByte(), 0xBF.toByte())

@ -7,14 +7,7 @@ import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import java.util.zip.ZipOutputStream
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/08/27
* desc : utils about zip
</pre> *
*/
@Suppress("unused")
object ZipUtils {
/**

Loading…
Cancel
Save