diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 569f6d190..721545ff0 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,6 +4,10 @@ * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。 * 注意:由于安卓10更改了权限策略,还需要给「允许安装其他应用」的权限才能导入源。MIUI11也需要此权限。 +**2019/12/16** +* 添加几个主题选择 +* 音频播放添加header支持 + **2019/12/15** * 修复清理缓存会把其他文件删除的问题 * 详情页模糊背景 diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 9f13a4f39..f76ed3d13 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -75,7 +75,7 @@ interface BookSourceDao { fun update(vararg bookSource: BookSource) @Delete - fun delete(vararg bookSource: BookSource) + fun delete(bookSource: BookSource) @Query("delete from book_sources where bookSourceUrl = :key") fun delete(key: String) 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 3304cbe83..2cedf7542 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -9,6 +9,7 @@ import android.graphics.BitmapFactory import android.media.AudioFocusRequest import android.media.AudioManager import android.media.MediaPlayer +import android.net.Uri import android.os.Build import android.os.Handler import android.support.v4.media.session.MediaSessionCompat @@ -44,10 +45,10 @@ class AudioPlayService : BaseService(), companion object { var isRun = false + var pause = false var timeMinute: Int = 0 } - var pause = false private val handler = Handler() private lateinit var audioManager: AudioManager private var mFocusRequest: AudioFocusRequest? = null @@ -91,7 +92,6 @@ class AudioPlayService : BaseService(), Action.prev -> moveToPrev() Action.next -> moveToNext() Action.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f)) - Action.moveTo -> moveTo(intent.getIntExtra("index", AudioPlay.durChapterIndex)) Action.addTimer -> addTimer() Action.setTimer -> setTimer(intent.getIntExtra("minute", 0)) Action.adjustProgress -> adjustProgress(intent.getIntExtra("position", position)) @@ -121,7 +121,8 @@ class AudioPlayService : BaseService(), AudioPlay.status = Status.PLAY postEvent(Bus.AUDIO_STATE, Status.PLAY) mediaPlayer.reset() - mediaPlayer.setDataSource(url) + val uri = Uri.parse(url) + mediaPlayer.setDataSource(this, uri, AudioPlay.headers()) mediaPlayer.prepareAsync() } catch (e: Exception) { launch { @@ -133,7 +134,7 @@ class AudioPlayService : BaseService(), } private fun pause(pause: Boolean) { - this.pause = pause + AudioPlayService.pause = pause handler.removeCallbacks(mpRunnable) position = mediaPlayer.currentPosition mediaPlayer.pause() @@ -311,16 +312,6 @@ class AudioPlayService : BaseService(), } } - private fun moveTo(index: Int) { - mediaPlayer.pause() - AudioPlay.durChapterIndex = index - AudioPlay.durPageIndex = 0 - AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex - saveRead() - position = 0 - loadContent(AudioPlay.durChapterIndex) - } - private fun moveToPrev() { if (AudioPlay.durChapterIndex > 0) { mediaPlayer.pause() @@ -354,6 +345,7 @@ class AudioPlayService : BaseService(), book.durChapterTime = System.currentTimeMillis() book.durChapterIndex = AudioPlay.durChapterIndex book.durChapterPos = AudioPlay.durPageIndex + book.durChapterTitle = subtitle App.db.bookDao().update(book) } } diff --git a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt index 98e62606d..add1a3fab 100644 --- a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt +++ b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt @@ -21,6 +21,10 @@ object AudioPlay { var webBook: WebBook? = null val loadingChapters = arrayListOf() + fun headers(): Map? { + return webBook?.bookSource?.getHeaderMap() + } + fun play(context: Context) { val intent = Intent(context, AudioPlayService::class.java) intent.action = Action.play @@ -85,12 +89,4 @@ object AudioPlay { } } - fun moveTo(context: Context, index: Int) { - if (AudioPlayService.isRun) { - val intent = Intent(context, AudioPlayService::class.java) - intent.action = Action.moveTo - intent.putExtra("index", index) - context.startService(intent) - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index 47d15704e..2b27a1600 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -10,6 +10,7 @@ import android.view.MenuItem import android.widget.SeekBar import androidx.lifecycle.Observer import com.bumptech.glide.RequestBuilder +import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.request.RequestOptions import io.legado.app.R import io.legado.app.base.VMBaseActivity @@ -21,6 +22,7 @@ import io.legado.app.help.ImageLoader import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.okButton +import io.legado.app.service.AudioPlayService import io.legado.app.service.help.AudioPlay import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity @@ -117,6 +119,7 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a .centerCrop() .into(iv_cover) ImageLoader.load(this, path) + .transition(DrawableTransitionOptions.withCrossFade(1500)) .thumbnail(defaultCover()) .centerCrop() .apply(RequestOptions.bitmapTransform(BlurTransformation(this, 25))) @@ -170,7 +173,16 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a when (requestCode) { requestCodeChapter -> data?.getIntExtra("index", AudioPlay.durChapterIndex)?.let { if (it != AudioPlay.durChapterIndex) { - AudioPlay.moveTo(this, it) + val isPlay = !AudioPlayService.pause + AudioPlay.pause(this) + AudioPlay.status = Status.STOP + AudioPlay.durChapterIndex = it + AudioPlay.durPageIndex = 0 + AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex + viewModel.saveRead() + if (isPlay) { + AudioPlay.play(this) + } } } } diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt index c236ef787..5adc2c7be 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt @@ -124,13 +124,16 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) } } - private fun saveRead() { + fun saveRead() { execute { AudioPlay.book?.let { book -> book.lastCheckCount = 0 book.durChapterTime = System.currentTimeMillis() book.durChapterIndex = AudioPlay.durChapterIndex book.durChapterPos = AudioPlay.durPageIndex + App.db.bookChapterDao().getChapter(book.bookUrl, book.durChapterIndex)?.let { + book.durChapterTitle = it.title + } App.db.bookDao().update(book) } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 00a2ca315..485b3d02b 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -7,7 +7,6 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import androidx.lifecycle.Observer -import com.bumptech.glide.Glide import com.bumptech.glide.RequestBuilder import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.request.RequestOptions.bitmapTransform @@ -115,7 +114,7 @@ class BookInfoActivity : .error(R.drawable.image_cover_default) .centerCrop() .into(iv_cover) - Glide.with(this).load(it) + ImageLoader.load(this, it) .transition(DrawableTransitionOptions.withCrossFade(1500)) .thumbnail(defaultCover()) .centerCrop() diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 99e32c556..982476466 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -91,7 +91,8 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) App.db.bookSourceDao().getBookSource(it) }.let { val json = GSON.toJson(it) - val file = FileHelp.getFile(Backup.exportPath + File.separator + "exportBookSource.json") + val file = + FileHelp.getFile(Backup.exportPath + File.separator + "exportBookSource.json") file.writeText(json) } }.onSuccess { diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 18449147e..8a1990b88 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -48,9 +48,9 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme viewModel.bookUrl?.let { bookUrl -> App.db.bookChapterDao().observeByBook(bookUrl).observe(viewLifecycleOwner, Observer { adapter.setItems(it) - viewModel.book?.let { - durChapterIndex = it.durChapterIndex - tv_current_chapter_info.text = it.durChapterTitle + viewModel.book?.let { book -> + durChapterIndex = book.durChapterIndex + tv_current_chapter_info.text = book.durChapterTitle recycler_view.scrollToPosition(durChapterIndex) } }) diff --git a/app/src/main/java/io/legado/app/web/controller/SourceController.kt b/app/src/main/java/io/legado/app/web/controller/SourceController.kt index 3711092fc..90c774370 100644 --- a/app/src/main/java/io/legado/app/web/controller/SourceController.kt +++ b/app/src/main/java/io/legado/app/web/controller/SourceController.kt @@ -71,7 +71,9 @@ class SourceController { fun deleteSources(postData: String?): ReturnData { kotlin.runCatching { GSON.fromJsonArray(postData)?.let { - App.db.bookSourceDao().delete(*it.toTypedArray()) + it.forEach { source -> + App.db.bookSourceDao().delete(source) + } } } return ReturnData().setData("已执行"/*okSources*/)