diff --git a/app/build.gradle b/app/build.gradle index f19373953..1edcc0755 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -111,20 +111,20 @@ kapt { dependencies { implementation project(path: ':epublib') - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' implementation fileTree(dir: 'libs', include: ['*.jar','*.aar']) testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test:runner:1.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - implementation "com.android.support:multidex:1.0.3" + implementation 'androidx.multidex:multidex:2.0.1' //kotlin implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" //androidX implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.core:core-ktx:1.3.2' - implementation "androidx.activity:activity-ktx:1.2.0" - implementation "androidx.fragment:fragment-ktx:1.3.0" + implementation "androidx.activity:activity-ktx:1.2.3" + implementation "androidx.fragment:fragment-ktx:1.3.3" implementation 'androidx.preference:preference-ktx:1.1.1' implementation "androidx.collection:collection-ktx:1.1.0" implementation 'androidx.constraintlayout:constraintlayout:2.0.4' @@ -135,8 +135,9 @@ dependencies { implementation 'com.google.code.gson:gson:2.8.6' //media - def media2_version = "1.1.2" + def media2_version = "1.1.3" implementation "androidx.media2:media2-session:$media2_version" + implementation "androidx.media:media:1.3.1" //implementation "androidx.media2:media2-player:$media2_version" //implementation 'com.google.android.exoplayer:exoplayer:2.13.0' @@ -147,8 +148,9 @@ dependencies { implementation("com.louiscad.splitties:splitties-views:$splitties_version") //lifecycle - def lifecycle_version = '2.2.0' - implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" + def lifecycle_version = '2.3.1' + //2.3.0 弃用lifecycle-extensions + //implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" //room @@ -158,13 +160,13 @@ dependencies { testImplementation "androidx.room:room-testing:$room_version" //paging - implementation 'androidx.paging:paging-runtime-ktx:2.1.2' + implementation 'androidx.paging:paging-runtime-ktx:3.0.0' //liveEventBus implementation 'com.jeremyliao:live-event-bus-x:1.5.7' //协程 - def coroutines_version = '1.4.2' + def coroutines_version = '1.4.3' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" diff --git a/app/src/main/java/io/legado/app/help/MediaHelp.kt b/app/src/main/java/io/legado/app/help/MediaHelp.kt index 3ec860a4d..31272d1d6 100644 --- a/app/src/main/java/io/legado/app/help/MediaHelp.kt +++ b/app/src/main/java/io/legado/app/help/MediaHelp.kt @@ -1,12 +1,12 @@ package io.legado.app.help import android.content.Context -import android.media.AudioAttributes -import android.media.AudioFocusRequest import android.media.AudioManager import android.media.MediaPlayer -import android.os.Build import android.support.v4.media.session.PlaybackStateCompat +import androidx.media.AudioAttributesCompat +import androidx.media.AudioFocusRequestCompat +import androidx.media.AudioManagerCompat import io.legado.app.R object MediaHelp { @@ -32,20 +32,16 @@ object MediaHelp { or PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE or PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED) - fun getFocusRequest(audioFocusChangeListener: AudioManager.OnAudioFocusChangeListener): AudioFocusRequest? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val mPlaybackAttributes = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_MEDIA) - .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) - .build() - AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN) - .setAudioAttributes(mPlaybackAttributes) - .setAcceptsDelayedFocusGain(true) - .setOnAudioFocusChangeListener(audioFocusChangeListener) - .build() - } else { - null - } + fun getFocusRequest(audioFocusChangeListener: AudioManager.OnAudioFocusChangeListener): AudioFocusRequestCompat? { + val mPlaybackAttributes = AudioAttributesCompat.Builder() + .setUsage(AudioAttributesCompat.USAGE_MEDIA) + .setContentType(AudioAttributesCompat.CONTENT_TYPE_MUSIC) + .build() + return AudioFocusRequestCompat.Builder(AudioManagerCompat.AUDIOFOCUS_GAIN) + .setAudioAttributes(mPlaybackAttributes) + //.setAcceptsDelayedFocusGain(true) + .setOnAudioFocusChangeListener(audioFocusChangeListener) + .build() } /** @@ -53,21 +49,11 @@ object MediaHelp { */ fun requestFocus( audioManager: AudioManager, - listener: AudioManager.OnAudioFocusChangeListener, - focusRequest: AudioFocusRequest? + focusRequest: AudioFocusRequestCompat? ): Boolean { - val request: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - focusRequest?.let { - audioManager.requestAudioFocus(focusRequest) - } ?: AudioManager.AUDIOFOCUS_REQUEST_GRANTED - } else { - @Suppress("DEPRECATION") - audioManager.requestAudioFocus( - listener, - AudioManager.STREAM_MUSIC, - AudioManager.AUDIOFOCUS_GAIN - ) - } + val request: Int = + focusRequest?.let { AudioManagerCompat.requestAudioFocus(audioManager, focusRequest) } + ?: AudioManager.AUDIOFOCUS_REQUEST_GRANTED return request == AudioManager.AUDIOFOCUS_REQUEST_GRANTED } diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index c2659337f..a971ab95e 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -16,6 +16,7 @@ import android.os.Looper import android.support.v4.media.session.MediaSessionCompat import android.support.v4.media.session.PlaybackStateCompat import androidx.core.app.NotificationCompat +import androidx.media.AudioFocusRequestCompat import io.legado.app.R import io.legado.app.base.BaseService import io.legado.app.constant.AppConst @@ -52,7 +53,7 @@ class AudioPlayService : BaseService(), private val handler = Handler(Looper.getMainLooper()) private lateinit var audioManager: AudioManager - private var mFocusRequest: AudioFocusRequest? = null + private var mFocusRequest: AudioFocusRequestCompat? = null private var title: String = "" private var subtitle: String = "" private val mediaPlayer = MediaPlayer() @@ -479,7 +480,7 @@ class AudioPlayService : BaseService(), * @return 音频焦点 */ private fun requestFocus(): Boolean { - return MediaHelp.requestFocus(audioManager, this, mFocusRequest) + return MediaHelp.requestFocus(audioManager, mFocusRequest) } private fun thisPendingIntent(action: String): PendingIntent? { diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index 541a2d99e..c62bca0b6 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -6,7 +6,6 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.graphics.BitmapFactory -import android.media.AudioFocusRequest import android.media.AudioManager import android.os.Handler import android.os.Looper @@ -14,6 +13,7 @@ import android.support.v4.media.session.MediaSessionCompat import android.support.v4.media.session.PlaybackStateCompat import androidx.annotation.CallSuper import androidx.core.app.NotificationCompat +import androidx.media.AudioFocusRequestCompat import io.legado.app.R import io.legado.app.base.BaseService import io.legado.app.constant.* @@ -43,7 +43,7 @@ abstract class BaseReadAloudService : BaseService(), internal val handler = Handler(Looper.getMainLooper()) private lateinit var audioManager: AudioManager - private var mFocusRequest: AudioFocusRequest? = null + private var mFocusRequest: AudioFocusRequestCompat? = null private var broadcastReceiver: BroadcastReceiver? = null private lateinit var mediaSessionCompat: MediaSessionCompat private var title: String = "" @@ -202,7 +202,7 @@ abstract class BaseReadAloudService : BaseService(), * @return 音频焦点 */ fun requestFocus(): Boolean { - return MediaHelp.requestFocus(audioManager, this, mFocusRequest) + return MediaHelp.requestFocus(audioManager, mFocusRequest) } /** diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index aec10c2fa..fa14fbcf2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -236,15 +236,16 @@ class PageView(context: Context) : FrameLayout(context) { } fun scroll(offset: Int) { - if (offset > 0) { - for (i in 1..offset) { - binding.contentTextView.scroll(1) - } - } else { - for (i in offset..-1) { - binding.contentTextView.scroll(-1) - } - } + binding.contentTextView.scroll(offset) +// if (offset > 0) { +// for (i in 1..offset) { +// binding.contentTextView.scroll(1) +// } +// } else { +// for (i in offset..-1) { +// binding.contentTextView.scroll(-1) +// } +// } } fun upSelectAble(selectAble: Boolean) { diff --git a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt index 78491d904..c5da5c98b 100644 --- a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt +++ b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt @@ -29,10 +29,10 @@ object BitmapUtils { fun decodeBitmap(path: String, width: Int, height: Int): Bitmap? { val op = BitmapFactory.Options() op.inPreferredConfig = Config.RGB_565 - var ips = FileInputStream(path) + val ips = FileInputStream(path) // inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight; op.inJustDecodeBounds = true - BitmapFactory.decodeStream(ips, null, op) + BitmapFactory.decodeFileDescriptor(ips.fd,null,op) //获取比例大小 val wRatio = ceil((op.outWidth / width).toDouble()).toInt() val hRatio = ceil((op.outHeight / height).toDouble()).toInt() @@ -45,8 +45,8 @@ object BitmapUtils { } } op.inJustDecodeBounds = false - ips = FileInputStream(path) - return BitmapFactory.decodeStream(ips, null, op) + return BitmapFactory.decodeFileDescriptor(ips.fd,null,op) + } /** 从path中获取Bitmap图片 @@ -57,14 +57,12 @@ object BitmapUtils { val opts = BitmapFactory.Options() opts.inPreferredConfig = Config.RGB_565 - var ips = FileInputStream(path) + val ips = FileInputStream(path) opts.inJustDecodeBounds = true - BitmapFactory.decodeStream(ips, null, opts) + BitmapFactory.decodeFileDescriptor(ips.fd,null,opts) opts.inSampleSize = computeSampleSize(opts, -1, 128 * 128) opts.inJustDecodeBounds = false - ips = FileInputStream(path) - - return BitmapFactory.decodeStream(ips, null, opts) + return BitmapFactory.decodeFileDescriptor(ips.fd,null,opts) } /** diff --git a/build.gradle b/build.gradle index dbf616d77..7305a5fc4 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ allprojects { maven { url "https://maven.aliyun.com/nexus/content/groups/public/" } maven { url "https://jitpack.io" } maven { url "https://maven.google.com/" } - maven { url "https://github.com/psiegman/mvn-repo/raw/master/releases" } + //maven { url "https://github.com/psiegman/mvn-repo/raw/master/releases" } } }