pull/47/head
kunfei 5 years ago
parent 90e52cc3fe
commit 9ef0a3a77c
  1. 64
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  2. 13
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  4. 1
      app/src/main/res/values/strings.xml

@ -4,10 +4,12 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Bundle import android.os.Bundle
import android.view.KeyEvent
import android.widget.SeekBar import android.widget.SeekBar
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import com.bumptech.glide.RequestBuilder import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import io.legado.app.BuildConfig
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.constant.Bus import io.legado.app.constant.Bus
@ -15,15 +17,24 @@ import io.legado.app.constant.Status
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BlurTransformation import io.legado.app.help.BlurTransformation
import io.legado.app.help.ImageLoader import io.legado.app.help.ImageLoader
import io.legado.app.help.storage.Backup
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.help.AudioPlay import io.legado.app.service.help.AudioPlay
import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.chapterlist.ChapterListActivity
import io.legado.app.ui.main.MainActivity
import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import io.legado.app.utils.snackbar
import kotlinx.android.synthetic.main.activity_audio_play.* import kotlinx.android.synthetic.main.activity_audio_play.*
import kotlinx.android.synthetic.main.activity_book_read.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import org.apache.commons.lang3.time.DateFormatUtils import org.apache.commons.lang3.time.DateFormatUtils
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick import org.jetbrains.anko.sdk27.listeners.onLongClick
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_audio_play), class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_audio_play),
@ -136,6 +147,7 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
} }
} }
observeEvent<Int>(Bus.AUDIO_PROGRESS) { observeEvent<Int>(Bus.AUDIO_PROGRESS) {
viewModel.durPageIndex = it
if (!adjustProgress) player_progress.progress = it if (!adjustProgress) player_progress.progress = it
tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss")
} }
@ -145,6 +157,58 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
} }
} }
override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_BACK -> {
page_view.snackbar(R.string.to_backstage, R.string.ok) {
startActivity<MainActivity>()
}
return true
}
}
return super.onKeyLongPress(keyCode, event)
}
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_BACK -> {
event?.let {
if ((event.flags and KeyEvent.FLAG_CANCELED_LONG_PRESS == 0)
&& event.isTracking
&& !event.isCanceled
) {
if (status == Status.PLAY) {
AudioPlay.pause(this)
return true
}
}
}
}
}
return super.onKeyUp(keyCode, event)
}
override fun finish() {
viewModel.book?.let {
if (!viewModel.inBookshelf) {
this.alert(title = getString(R.string.add_to_shelf)) {
message = getString(R.string.check_add_bookshelf, it.name)
okButton { viewModel.inBookshelf = true }
noButton { viewModel.removeFromBookshelf { super.finish() } }
}.show().applyTint()
} else {
super.finish()
}
} ?: super.finish()
}
override fun onDestroy() {
super.onDestroy()
if (!BuildConfig.DEBUG) {
Backup.autoBackup()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {

@ -6,7 +6,6 @@ import androidx.lifecycle.MutableLiveData
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
@ -24,7 +23,6 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
var callBack: CallBack? = null var callBack: CallBack? = null
var durChapterIndex = 0 var durChapterIndex = 0
var durPageIndex = 0 var durPageIndex = 0
var isLocalBook = true
var webBook: WebBook? = null var webBook: WebBook? = null
private val loadingChapters = arrayListOf<Int>() private val loadingChapters = arrayListOf<Int>()
@ -42,7 +40,6 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
coverData.postValue(book.getDisplayCover()) coverData.postValue(book.getDisplayCover())
durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
durPageIndex = book.durChapterPos durPageIndex = book.durChapterPos
isLocalBook = book.origin == BookType.local
App.db.bookSourceDao().getBookSource(book.origin)?.let { App.db.bookSourceDao().getBookSource(book.origin)?.let {
webBook = WebBook(it) webBook = WebBook(it)
} }
@ -223,6 +220,16 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun removeFromBookshelf(success: (() -> Unit)?) {
execute {
book?.let {
App.db.bookDao().delete(it.bookUrl)
}
}.onSuccess {
success?.invoke()
}
}
interface CallBack { interface CallBack {
fun contentLoadFinish(bookChapter: BookChapter, content: String) fun contentLoadFinish(bookChapter: BookChapter, content: String)
} }

@ -199,7 +199,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean { override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) { when (keyCode) {
KeyEvent.KEYCODE_BACK -> { KeyEvent.KEYCODE_BACK -> {
page_view.snackbar("转到后台", "确定") { page_view.snackbar(R.string.to_backstage, R.string.ok) {
startActivity<MainActivity>() startActivity<MainActivity>()
} }
return true return true

@ -556,5 +556,6 @@
<string name="book_type">类型:</string> <string name="book_type">类型:</string>
<string name="book_type_text">文本</string> <string name="book_type_text">文本</string>
<string name="book_type_audio">音频</string> <string name="book_type_audio">音频</string>
<string name="to_backstage">转到后台</string>
</resources> </resources>

Loading…
Cancel
Save