Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Aug 30, 2024
1 parent ae4b362 commit 30ec233
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ android {
defaultConfig {
applicationId "io.legado.app"
minSdk 21
targetSdk 34
targetSdk 35
versionCode 10000 + gitCommits
versionName version
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/io/legado/app/constant/AppConst.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ object AppConst {
@Suppress("DEPRECATION")
appCtx.packageManager.getPackageInfo(appCtx.packageName, PackageManager.GET_ACTIVITIES)
?.let {
appInfo.versionName = it.versionName
appInfo.versionName = it.versionName!!
appInfo.appVariant = when {
it.packageName.contains("releaseA") -> AppVariant.BETA_RELEASEA
isBeta -> AppVariant.BETA_RELEASE
Expand All @@ -86,7 +86,7 @@ object AppConst {
private val sha256Signature: String by lazy {
val packageInfo =
appCtx.packageManager.getPackageInfo(appCtx.packageName, PackageManager.GET_SIGNATURES)
DigestUtil.sha256Hex(packageInfo.signatures[0].toByteArray()).uppercase()
DigestUtil.sha256Hex(packageInfo.signatures!![0].toByteArray()).uppercase()
}

private val isOfficial = sha256Signature == OFFICIAL_SIGNATURE
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/io/legado/app/constant/IntentAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ object IntentAction {
const val moveTo = "moveTo"
const val init = "init"
const val remove = "remove"
const val stopPlay = "stopPlay"
}
14 changes: 11 additions & 3 deletions app/src/main/java/io/legado/app/model/AudioPlay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ object AudioPlay : CoroutineScope by MainScope() {

fun skipTo(index: Int) {
Coroutine.async {
stop()
stopPlay()
durChapterIndex = index
durChapterPos = 0
durPlayUrl = ""
Expand All @@ -244,7 +244,7 @@ object AudioPlay : CoroutineScope by MainScope() {

fun prev() {
Coroutine.async {
stop()
stopPlay()
if (durChapterIndex > 0) {
durChapterIndex -= 1
durChapterPos = 0
Expand All @@ -256,7 +256,7 @@ object AudioPlay : CoroutineScope by MainScope() {
}

fun next() {
stop()
stopPlay()
if (durChapterIndex + 1 < simulatedChapterSize) {
durChapterIndex += 1
durChapterPos = 0
Expand Down Expand Up @@ -284,6 +284,14 @@ object AudioPlay : CoroutineScope by MainScope() {
context.startService(intent)
}

fun stopPlay() {
if (AudioPlayService.isRun) {
context.startService<AudioPlayService> {
action = IntentAction.stopPlay
}
}
}

fun saveRead() {
val book = book ?: return
Coroutine.async {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/io/legado/app/service/AudioPlayService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ class AudioPlayService : BaseService(),
play()
}

IntentAction.stopPlay -> {
exoPlayer.stop()
upPlayProgressJob?.cancel()
AudioPlay.status = Status.STOP
postEvent(EventBus.AUDIO_STATE, Status.STOP)
}

IntentAction.pause -> pause()
IntentAction.resume -> resume()
IntentAction.prev -> AudioPlay.prev()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification
transition: Transition<in Bitmap>?
) {
view ?: return
val bitmap = resource.copy(resource.config, true)
val bitmap = resource.copy(resource.config ?: Bitmap.Config.ARGB_8888, true)
ImageProvider.bitmapLruCache.put(url, bitmap)
binding.verificationCodeImageView.setImageBitmap(bitmap)
}
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/io/legado/app/utils/ActivityExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.*
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import android.view.WindowInsetsController
import android.view.WindowManager
import android.view.WindowMetrics
import android.widget.FrameLayout
import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -54,14 +60,13 @@ val WindowManager.windowSize: DisplayMetrics
return displayMetrics
}

@Suppress("DEPRECATION")
fun Activity.fullScreen() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.setDecorFitsSystemWindows(true)
}
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
@Suppress("DEPRECATION")
window.clearFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
Expand All @@ -72,6 +77,7 @@ fun Activity.fullScreen() {
/**
* 设置状态栏颜色
*/
@Suppress("DEPRECATION")
fun Activity.setStatusBarColorAuto(
@ColorInt color: Int,
isTransparent: Boolean,
Expand Down Expand Up @@ -124,6 +130,7 @@ fun Activity.setLightStatusBar(isLightBar: Boolean) {
/**
* 设置导航栏颜色
*/
@Suppress("DEPRECATION")
fun Activity.setNavigationBarColorAuto(@ColorInt color: Int) {
val isLightBor = ColorUtils.isColorLight(color)
window.navigationBarColor = color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object BitmapPool {
/**
* A helper function to return the byte usage per pixel of a bitmap based on its configuration.
*/
private fun getBytesPerPixel(config: Bitmap.Config): Int {
private fun getBytesPerPixel(config: Bitmap.Config?): Int {
return when (config) {
Bitmap.Config.ARGB_8888 -> 4
Bitmap.Config.RGB_565, Bitmap.Config.ARGB_4444 -> 2
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

buildscript {
ext{
compile_sdk_version = 34
compile_sdk_version = 35
build_tool_version = '34.0.0'
// kotlin_version = '1.9.22'
// ksp_version = "1.0.17"
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

kotlin = "2.0.20"
ksp = "2.0.20-1.0.24"
agp = "8.5.2"
agp = "8.6.0"
appcompat = "1.7.0"
colorpicker = "1.1.0"
commonsText = "1.12.0"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Aug 27 18:19:17 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion modules/book/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
}
defaultConfig {
minSdk 21
targetSdk 34
targetSdk 35

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down
2 changes: 1 addition & 1 deletion modules/rhino/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
}
defaultConfig {
minSdk 21
targetSdk 34
targetSdk 35

consumerProguardFiles "consumer-rules.pro"
}
Expand Down

0 comments on commit 30ec233

Please sign in to comment.