pull/45/head
kunfei 5 years ago
parent aae7e41281
commit 7de42ef988
  1. 16
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  2. 6
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt
  3. 14
      app/src/main/java/io/legado/app/ui/book/read/Help.kt
  4. 11
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  5. 10
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -3,10 +3,13 @@ package io.legado.app.ui.audio
import android.os.Bundle import android.os.Bundle
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.BookChapter
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_audio_play) { class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_audio_play),
AudioPlayViewModel.CallBack {
override val viewModel: AudioPlayViewModel override val viewModel: AudioPlayViewModel
get() = getViewModel(AudioPlayViewModel::class.java) get() = getViewModel(AudioPlayViewModel::class.java)
@ -15,5 +18,16 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
viewModel.initData(intent) viewModel.initData(intent)
} }
override fun loadContent() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun contentLoadFinish(bookChapter: BookChapter, content: String) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun upContent() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
} }

@ -107,4 +107,10 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
} }
} }
} }
interface CallBack {
fun loadContent()
fun contentLoadFinish(bookChapter: BookChapter, content: String)
fun upContent()
}
} }

@ -1,9 +1,12 @@
package io.legado.app.ui.book.read package io.legado.app.ui.book.read
import android.app.Activity import android.app.Activity
import android.os.Build
import android.view.View import android.view.View
import android.view.View.NO_ID import android.view.View.NO_ID
import android.view.ViewGroup import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
@ -67,4 +70,15 @@ object Help {
return false return false
} }
/**
* 适配刘海
*/
fun uplayoutInDisplayCutoutMode(window: Window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
window.attributes = window.attributes.apply {
layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
}
}
}
} }

@ -3,13 +3,11 @@ package io.legado.app.ui.book.read
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import android.view.KeyEvent import android.view.KeyEvent
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
@ -71,16 +69,11 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override var readAloudStatus = Status.STOP override var readAloudStatus = Status.STOP
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { Help.uplayoutInDisplayCutoutMode(window)
window.attributes = window.attributes.apply {
layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
}
}
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
initView() initView()
viewModel.callBack = this viewModel.callBack = this
viewModel.bookData.observe(this, Observer { title_bar.title = it.name }) viewModel.bookData.observe(this, Observer { title_bar.title = it.name })
viewModel.chapterListFinish.observe(this, Observer { loadContent() })
viewModel.initData(intent) viewModel.initData(intent)
} }
@ -260,7 +253,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
/** /**
* 加载章节内容 * 加载章节内容
*/ */
private fun loadContent() { override fun loadContent() {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
viewModel.loadContent(it, viewModel.durChapterIndex) viewModel.loadContent(it, viewModel.durChapterIndex)
viewModel.loadContent(it, viewModel.durChapterIndex + 1) viewModel.loadContent(it, viewModel.durChapterIndex + 1)

@ -23,7 +23,6 @@ import kotlinx.coroutines.withContext
class ReadBookViewModel(application: Application) : BaseViewModel(application) { class ReadBookViewModel(application: Application) : BaseViewModel(application) {
var inBookshelf = false var inBookshelf = false
var bookData = MutableLiveData<Book>() var bookData = MutableLiveData<Book>()
val chapterListFinish = MutableLiveData<Boolean>()
var chapterSize = 0 var chapterSize = 0
var callBack: CallBack? = null var callBack: CallBack? = null
var durChapterIndex = 0 var durChapterIndex = 0
@ -71,7 +70,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
durChapterIndex = count - 1 durChapterIndex = count - 1
} }
chapterSize = count chapterSize = count
chapterListFinish.postValue(true) callBack?.loadContent()
} }
if (inBookshelf) { if (inBookshelf) {
saveRead(book) saveRead(book)
@ -101,7 +100,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
if (changeDruChapterIndex == null) { if (changeDruChapterIndex == null) {
App.db.bookChapterDao().insert(*cList.toTypedArray()) App.db.bookChapterDao().insert(*cList.toTypedArray())
chapterSize = cList.size chapterSize = cList.size
chapterListFinish.postValue(true) callBack?.loadContent()
} else { } else {
changeDruChapterIndex(cList) changeDruChapterIndex(cList)
} }
@ -276,7 +275,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
App.db.bookDao().update(book) App.db.bookDao().update(book)
App.db.bookChapterDao().insert(*chapters.toTypedArray()) App.db.bookChapterDao().insert(*chapters.toTypedArray())
chapterSize = chapters.size chapterSize = chapters.size
chapterListFinish.postValue(true) callBack?.loadContent()
} }
} }
@ -289,7 +288,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
durPageIndex = 0 durPageIndex = 0
} }
saveRead() saveRead()
chapterListFinish.postValue(true) callBack?.loadContent()
} }
fun saveRead(book: Book? = bookData.value) { fun saveRead(book: Book? = bookData.value) {
@ -342,6 +341,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
interface CallBack { interface CallBack {
fun loadContent()
fun contentLoadFinish(bookChapter: BookChapter, content: String) fun contentLoadFinish(bookChapter: BookChapter, content: String)
fun upContent() fun upContent()
} }

Loading…
Cancel
Save