From 7de42ef988d49e97a78a35fe25d89039c20d7b46 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 2 Nov 2019 17:15:39 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/audio/AudioPlayActivity.kt | 16 +++++++++++++++- .../io/legado/app/ui/audio/AudioPlayViewModel.kt | 6 ++++++ .../main/java/io/legado/app/ui/book/read/Help.kt | 14 ++++++++++++++ .../legado/app/ui/book/read/ReadBookActivity.kt | 11 ++--------- .../legado/app/ui/book/read/ReadBookViewModel.kt | 10 +++++----- 5 files changed, 42 insertions(+), 15 deletions(-) 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 3fd5a8965..9cf576e38 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 @@ -3,10 +3,13 @@ package io.legado.app.ui.audio import android.os.Bundle import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.data.entities.BookChapter import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.view_title_bar.* -class AudioPlayActivity : VMBaseActivity(R.layout.activity_audio_play) { +class AudioPlayActivity : VMBaseActivity(R.layout.activity_audio_play), + AudioPlayViewModel.CallBack { + override val viewModel: AudioPlayViewModel get() = getViewModel(AudioPlayViewModel::class.java) @@ -15,5 +18,16 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a 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. + } } \ No newline at end of file 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 9367b5922..3a340f617 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 @@ -107,4 +107,10 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) } } } + + interface CallBack { + fun loadContent() + fun contentLoadFinish(bookChapter: BookChapter, content: String) + fun upContent() + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/Help.kt b/app/src/main/java/io/legado/app/ui/book/read/Help.kt index f522df279..b741cf430 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/Help.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/Help.kt @@ -1,9 +1,12 @@ package io.legado.app.ui.book.read import android.app.Activity +import android.os.Build import android.view.View import android.view.View.NO_ID import android.view.ViewGroup +import android.view.Window +import android.view.WindowManager import io.legado.app.App import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig @@ -67,4 +70,15 @@ object Help { 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 + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index d42299fe5..f295f28f7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -3,13 +3,11 @@ package io.legado.app.ui.book.read import android.app.Activity import android.content.Intent import android.net.Uri -import android.os.Build import android.os.Bundle import android.text.SpannableStringBuilder import android.view.KeyEvent import android.view.Menu import android.view.MenuItem -import android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES import androidx.core.view.isVisible import androidx.lifecycle.Observer import com.jaredrummler.android.colorpicker.ColorPickerDialogListener @@ -71,16 +69,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override var readAloudStatus = Status.STOP override fun onActivityCreated(savedInstanceState: Bundle?) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - window.attributes = window.attributes.apply { - layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES - } - } + Help.uplayoutInDisplayCutoutMode(window) setSupportActionBar(toolbar) initView() viewModel.callBack = this viewModel.bookData.observe(this, Observer { title_bar.title = it.name }) - viewModel.chapterListFinish.observe(this, Observer { loadContent() }) viewModel.initData(intent) } @@ -260,7 +253,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 加载章节内容 */ - private fun loadContent() { + override fun loadContent() { viewModel.bookData.value?.let { viewModel.loadContent(it, viewModel.durChapterIndex) viewModel.loadContent(it, viewModel.durChapterIndex + 1) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 667afb8ef..e294c0153 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -23,7 +23,6 @@ import kotlinx.coroutines.withContext class ReadBookViewModel(application: Application) : BaseViewModel(application) { var inBookshelf = false var bookData = MutableLiveData() - val chapterListFinish = MutableLiveData() var chapterSize = 0 var callBack: CallBack? = null var durChapterIndex = 0 @@ -71,7 +70,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { durChapterIndex = count - 1 } chapterSize = count - chapterListFinish.postValue(true) + callBack?.loadContent() } if (inBookshelf) { saveRead(book) @@ -101,7 +100,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { if (changeDruChapterIndex == null) { App.db.bookChapterDao().insert(*cList.toTypedArray()) chapterSize = cList.size - chapterListFinish.postValue(true) + callBack?.loadContent() } else { changeDruChapterIndex(cList) } @@ -276,7 +275,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { App.db.bookDao().update(book) App.db.bookChapterDao().insert(*chapters.toTypedArray()) chapterSize = chapters.size - chapterListFinish.postValue(true) + callBack?.loadContent() } } @@ -289,7 +288,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { durPageIndex = 0 } saveRead() - chapterListFinish.postValue(true) + callBack?.loadContent() } fun saveRead(book: Book? = bookData.value) { @@ -342,6 +341,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } interface CallBack { + fun loadContent() fun contentLoadFinish(bookChapter: BookChapter, content: String) fun upContent() }