优化
This commit is contained in:
@@ -17,6 +17,7 @@ import io.legado.app.help.LifecycleHelp
|
|||||||
import io.legado.app.help.ThemeConfig.applyDayNight
|
import io.legado.app.help.ThemeConfig.applyDayNight
|
||||||
import io.legado.app.help.http.cronet.CronetLoader
|
import io.legado.app.help.http.cronet.CronetLoader
|
||||||
import io.legado.app.utils.defaultSharedPreferences
|
import io.legado.app.utils.defaultSharedPreferences
|
||||||
|
import splitties.systemservices.notificationManager
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class App : MultiDexApplication() {
|
class App : MultiDexApplication() {
|
||||||
@@ -55,40 +56,44 @@ class App : MultiDexApplication() {
|
|||||||
*/
|
*/
|
||||||
private fun createNotificationChannels() {
|
private fun createNotificationChannels() {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
|
||||||
(getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager)?.let {
|
val downloadChannel = NotificationChannel(
|
||||||
val downloadChannel = NotificationChannel(
|
channelIdDownload,
|
||||||
channelIdDownload,
|
getString(R.string.action_download),
|
||||||
getString(R.string.action_download),
|
NotificationManager.IMPORTANCE_DEFAULT
|
||||||
NotificationManager.IMPORTANCE_DEFAULT
|
).apply {
|
||||||
).apply {
|
enableLights(false)
|
||||||
enableLights(false)
|
enableVibration(false)
|
||||||
enableVibration(false)
|
setSound(null, null)
|
||||||
setSound(null, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
val readAloudChannel = NotificationChannel(
|
|
||||||
channelIdReadAloud,
|
|
||||||
getString(R.string.read_aloud),
|
|
||||||
NotificationManager.IMPORTANCE_DEFAULT
|
|
||||||
).apply {
|
|
||||||
enableLights(false)
|
|
||||||
enableVibration(false)
|
|
||||||
setSound(null, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
val webChannel = NotificationChannel(
|
|
||||||
channelIdWeb,
|
|
||||||
getString(R.string.web_service),
|
|
||||||
NotificationManager.IMPORTANCE_DEFAULT
|
|
||||||
).apply {
|
|
||||||
enableLights(false)
|
|
||||||
enableVibration(false)
|
|
||||||
setSound(null, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
//向notification manager 提交channel
|
|
||||||
it.createNotificationChannels(listOf(downloadChannel, readAloudChannel, webChannel))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val readAloudChannel = NotificationChannel(
|
||||||
|
channelIdReadAloud,
|
||||||
|
getString(R.string.read_aloud),
|
||||||
|
NotificationManager.IMPORTANCE_DEFAULT
|
||||||
|
).apply {
|
||||||
|
enableLights(false)
|
||||||
|
enableVibration(false)
|
||||||
|
setSound(null, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
val webChannel = NotificationChannel(
|
||||||
|
channelIdWeb,
|
||||||
|
getString(R.string.web_service),
|
||||||
|
NotificationManager.IMPORTANCE_DEFAULT
|
||||||
|
).apply {
|
||||||
|
enableLights(false)
|
||||||
|
enableVibration(false)
|
||||||
|
setSound(null, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
//向notification manager 提交channel
|
||||||
|
notificationManager.createNotificationChannels(
|
||||||
|
listOf(
|
||||||
|
downloadChannel,
|
||||||
|
readAloudChannel,
|
||||||
|
webChannel
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import io.legado.app.ui.book.audio.AudioPlayActivity
|
|||||||
import io.legado.app.utils.*
|
import io.legado.app.utils.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
|
import splitties.systemservices.audioManager
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
|
|
||||||
@@ -50,9 +51,6 @@ class AudioPlayService : BaseService(),
|
|||||||
private set
|
private set
|
||||||
}
|
}
|
||||||
|
|
||||||
private val audioManager: AudioManager by lazy {
|
|
||||||
getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
|
||||||
}
|
|
||||||
private val mFocusRequest: AudioFocusRequestCompat by lazy {
|
private val mFocusRequest: AudioFocusRequestCompat by lazy {
|
||||||
MediaHelp.getFocusRequest(this)
|
MediaHelp.getFocusRequest(this)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import kotlinx.coroutines.Job
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import splitties.systemservices.audioManager
|
||||||
|
|
||||||
abstract class BaseReadAloudService : BaseService(),
|
abstract class BaseReadAloudService : BaseService(),
|
||||||
AudioManager.OnAudioFocusChangeListener {
|
AudioManager.OnAudioFocusChangeListener {
|
||||||
@@ -44,9 +45,6 @@ abstract class BaseReadAloudService : BaseService(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val audioManager: AudioManager by lazy {
|
|
||||||
getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
|
||||||
}
|
|
||||||
private val mFocusRequest: AudioFocusRequestCompat by lazy {
|
private val mFocusRequest: AudioFocusRequestCompat by lazy {
|
||||||
MediaHelp.getFocusRequest(this)
|
MediaHelp.getFocusRequest(this)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
|
|||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.constant.AppConst
|
import io.legado.app.constant.AppConst
|
||||||
import io.legado.app.help.IntentHelp
|
import io.legado.app.help.IntentHelp
|
||||||
|
import splitties.systemservices.clipboardManager
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
@@ -252,18 +253,13 @@ fun Context.shareWithQr(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Context.sendToClip(text: String) {
|
fun Context.sendToClip(text: String) {
|
||||||
val clipboard =
|
|
||||||
getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
|
|
||||||
val clipData = ClipData.newPlainText(null, text)
|
val clipData = ClipData.newPlainText(null, text)
|
||||||
clipboard?.let {
|
clipboardManager.setPrimaryClip(clipData)
|
||||||
clipboard.setPrimaryClip(clipData)
|
longToastOnUi(R.string.copy_complete)
|
||||||
longToastOnUi(R.string.copy_complete)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getClipText(): String? {
|
fun Context.getClipText(): String? {
|
||||||
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?
|
clipboardManager.primaryClip?.let {
|
||||||
clipboard?.primaryClip?.let {
|
|
||||||
if (it.itemCount > 0) {
|
if (it.itemCount > 0) {
|
||||||
return it.getItemAt(0).text.toString().trim()
|
return it.getItemAt(0).text.toString().trim()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ 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.POWER_SERVICE
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.PowerManager
|
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
|
import splitties.systemservices.powerManager
|
||||||
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@@ -15,7 +14,6 @@ object SystemUtils {
|
|||||||
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
|
||||||
|
|
||||||
val powerManager = activity.getSystemService(POWER_SERVICE) as PowerManager
|
|
||||||
val hasIgnored = powerManager.isIgnoringBatteryOptimizations(activity.packageName)
|
val hasIgnored = powerManager.isIgnoringBatteryOptimizations(activity.packageName)
|
||||||
// 判断当前APP是否有加入电池优化的白名单,如果没有,弹出加入电池优化的白名单的设置对话框。
|
// 判断当前APP是否有加入电池优化的白名单,如果没有,弹出加入电池优化的白名单的设置对话框。
|
||||||
if (!hasIgnored) {
|
if (!hasIgnored) {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import android.os.Build
|
|||||||
import android.text.Html
|
import android.text.Html
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.View.*
|
import android.view.View.*
|
||||||
import android.view.inputmethod.InputMethodManager
|
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@@ -21,7 +20,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import androidx.viewpager.widget.ViewPager
|
import androidx.viewpager.widget.ViewPager
|
||||||
import io.legado.app.help.AppConfig
|
import io.legado.app.help.AppConfig
|
||||||
import io.legado.app.lib.theme.TintHelper
|
import io.legado.app.lib.theme.TintHelper
|
||||||
import splitties.init.appCtx
|
import splitties.systemservices.inputMethodManager
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
|
|
||||||
@@ -39,8 +38,7 @@ val View.activity: AppCompatActivity?
|
|||||||
get() = getCompatActivity(context)
|
get() = getCompatActivity(context)
|
||||||
|
|
||||||
fun View.hideSoftInput() = run {
|
fun View.hideSoftInput() = run {
|
||||||
val imm = appCtx.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
|
inputMethodManager.hideSoftInputFromWindow(this.windowToken, 0)
|
||||||
imm?.hideSoftInputFromWindow(this.windowToken, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun View.disableAutoFill() = run {
|
fun View.disableAutoFill() = run {
|
||||||
|
|||||||
Reference in New Issue
Block a user