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

@ -15,6 +15,7 @@ import android.graphics.drawable.Drawable
import android.net.Uri import android.net.Uri
import android.os.BatteryManager import android.os.BatteryManager
import android.os.Build import android.os.Build
import android.os.Process
import android.provider.Settings import android.provider.Settings
import android.widget.Toast import android.widget.Toast
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
@ -148,19 +149,30 @@ fun Context.getCompatDrawable(@DrawableRes id: Int): Drawable? = ContextCompat.g
fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? =
ContextCompat.getColorStateList(this, id) 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 val Context.sysScreenOffTime: Int
get() { get() {
var screenOffTime = 0 return kotlin.runCatching {
try {
screenOffTime =
Settings.System.getInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT) Settings.System.getInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT)
} catch (e: Exception) { }.onFailure {
Timber.e(e) Timber.e(it)
} }.getOrDefault(0)
return screenOffTime
} }
val Context.statusBarHeight: Int val Context.statusBarHeight: Int

@ -2,32 +2,16 @@ package io.legado.app.utils
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Context
import android.content.Context.POWER_SERVICE import android.content.Context.POWER_SERVICE
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.PowerManager import android.os.PowerManager
import android.provider.Settings import android.provider.Settings
import timber.log.Timber
@Suppress("unused") @Suppress("unused")
object SystemUtils { 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) { fun ignoreBatteryOptimization(activity: Activity) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) return if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) return

Loading…
Cancel
Save