pull/1615/head
kunfei 3 years ago
parent bd002a5ad7
commit 48bc3f42e8
  1. 11
      app/src/main/java/io/legado/app/App.kt
  2. 4
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  3. 4
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  4. 10
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  5. 4
      app/src/main/java/io/legado/app/utils/SystemUtils.kt
  6. 6
      app/src/main/java/io/legado/app/utils/ViewExtensions.kt

@ -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,7 +56,6 @@ 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),
@ -87,8 +87,13 @@ class App : MultiDexApplication() {
}
//向notification manager 提交channel
it.createNotificationChannels(listOf(downloadChannel, readAloudChannel, webChannel))
}
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)
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 {

Loading…
Cancel
Save