pull/1403/head
gedoor 3 years ago
parent ffc11d7604
commit a57eaf6303
  1. 8
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  2. 26
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  3. 16
      app/src/main/java/io/legado/app/utils/SystemUtils.kt

@ -2,11 +2,9 @@ package io.legado.app.ui.config
import android.annotation.SuppressLint
import android.content.ComponentName
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.Process
import android.view.View
import androidx.preference.ListPreference
import androidx.preference.Preference
@ -21,7 +19,6 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.primaryColor
import io.legado.app.receiver.SharedReceiverActivity
import io.legado.app.service.WebService
import io.legado.app.ui.main.MainActivity
import io.legado.app.ui.widget.number.NumberPickerDialog
import io.legado.app.utils.*
import splitties.init.appCtx
@ -113,10 +110,7 @@ class OtherConfigFragment : BasePreferenceFragment(),
}
PreferKey.showDiscovery, PreferKey.showRss -> postEvent(EventBus.NOTIFY_MAIN, true)
PreferKey.language -> listView.postDelayed({
val intent = Intent(appCtx, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
appCtx.startActivity(intent)
Process.killProcess(Process.myPid())
appCtx.restart()
}, 1000)
PreferKey.userAgent -> listView.post {
upPreferenceSummary(PreferKey.userAgent, AppConfig.userAgent)

@ -15,6 +15,7 @@ import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.BatteryManager
import android.os.Build
import android.os.Process
import android.provider.Settings
import android.widget.Toast
import androidx.annotation.ColorRes
@ -148,19 +149,30 @@ fun Context.getCompatDrawable(@DrawableRes id: Int): Drawable? = ContextCompat.g
fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? =
ContextCompat.getColorStateList(this, id)
fun Context.restart() {
val intent: Intent? = packageManager.getLaunchIntentForPackage(packageName)
intent?.let {
intent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK
or Intent.FLAG_ACTIVITY_CLEAR_TASK
or Intent.FLAG_ACTIVITY_CLEAR_TOP
)
startActivity(intent)
//杀掉以前进程
Process.killProcess(Process.myPid())
}
}
/**
* 系统息屏时间
*/
val Context.sysScreenOffTime: Int
get() {
var screenOffTime = 0
try {
screenOffTime =
return kotlin.runCatching {
Settings.System.getInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT)
} catch (e: Exception) {
Timber.e(e)
}
return screenOffTime
}.onFailure {
Timber.e(it)
}.getOrDefault(0)
}
val Context.statusBarHeight: Int

@ -2,32 +2,16 @@ package io.legado.app.utils
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Context.POWER_SERVICE
import android.content.Intent
import android.net.Uri
import android.os.PowerManager
import android.provider.Settings
import timber.log.Timber
@Suppress("unused")
object SystemUtils {
fun getScreenOffTime(context: Context): Int {
var screenOffTime = 0
kotlin.runCatching {
screenOffTime = Settings.System.getInt(
context.contentResolver,
Settings.System.SCREEN_OFF_TIMEOUT
)
}.onFailure {
Timber.e(it)
}
return screenOffTime
}
fun ignoreBatteryOptimization(activity: Activity) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) return

Loading…
Cancel
Save