Merge pull request #5 from gedoor/master

up
pull/61/head^2
口口吕 5 years ago committed by GitHub
commit f3a77af3f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/src/main/assets/updateLog.md
  2. 2
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  3. 20
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  4. 12
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  5. 14
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  6. 5
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt
  7. 3
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  8. 3
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  9. 6
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt
  10. 4
      app/src/main/java/io/legado/app/web/controller/SourceController.kt

@ -4,6 +4,10 @@
* 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。
* 注意:由于安卓10更改了权限策略,还需要给「允许安装其他应用」的权限才能导入源。MIUI11也需要此权限。
**2019/12/16**
* 添加几个主题选择
* 音频播放添加header支持
**2019/12/15**
* 修复清理缓存会把其他文件删除的问题
* 详情页模糊背景

@ -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)

@ -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)
}
}

@ -21,6 +21,10 @@ object AudioPlay {
var webBook: WebBook? = null
val loadingChapters = arrayListOf<Int>()
fun headers(): Map<String, String>? {
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)
}
}
}

@ -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<AudioPlayViewModel>(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<AudioPlayViewModel>(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)
}
}
}
}

@ -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)
}
}

@ -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()

@ -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 {

@ -48,9 +48,9 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(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)
}
})

@ -71,7 +71,9 @@ class SourceController {
fun deleteSources(postData: String?): ReturnData {
kotlin.runCatching {
GSON.fromJsonArray<BookSource>(postData)?.let {
App.db.bookSourceDao().delete(*it.toTypedArray())
it.forEach { source ->
App.db.bookSourceDao().delete(source)
}
}
}
return ReturnData().setData("已执行"/*okSources*/)

Loading…
Cancel
Save