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