|
|
@ -1,7 +1,6 @@ |
|
|
|
package io.legado.app.ui.book.info |
|
|
|
package io.legado.app.ui.book.info |
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
import android.annotation.SuppressLint |
|
|
|
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 |
|
|
@ -9,6 +8,7 @@ import android.view.Menu |
|
|
|
import android.view.MenuItem |
|
|
|
import android.view.MenuItem |
|
|
|
import android.widget.CheckBox |
|
|
|
import android.widget.CheckBox |
|
|
|
import android.widget.LinearLayout |
|
|
|
import android.widget.LinearLayout |
|
|
|
|
|
|
|
import androidx.activity.result.contract.ActivityResultContracts |
|
|
|
import androidx.activity.viewModels |
|
|
|
import androidx.activity.viewModels |
|
|
|
import com.bumptech.glide.RequestBuilder |
|
|
|
import com.bumptech.glide.RequestBuilder |
|
|
|
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions |
|
|
|
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions |
|
|
@ -35,7 +35,7 @@ import io.legado.app.ui.book.info.edit.BookInfoEditActivity |
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
import io.legado.app.ui.book.search.SearchActivity |
|
|
|
import io.legado.app.ui.book.search.SearchActivity |
|
|
|
import io.legado.app.ui.book.source.edit.BookSourceEditActivity |
|
|
|
import io.legado.app.ui.book.source.edit.BookSourceEditActivity |
|
|
|
import io.legado.app.ui.book.toc.ChapterListActivity |
|
|
|
import io.legado.app.ui.book.toc.TocActivityResult |
|
|
|
import io.legado.app.ui.widget.image.CoverImageView |
|
|
|
import io.legado.app.ui.widget.image.CoverImageView |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.* |
|
|
|
|
|
|
|
|
|
|
@ -47,9 +47,37 @@ class BookInfoActivity : |
|
|
|
ChangeSourceDialog.CallBack, |
|
|
|
ChangeSourceDialog.CallBack, |
|
|
|
ChangeCoverDialog.CallBack { |
|
|
|
ChangeCoverDialog.CallBack { |
|
|
|
|
|
|
|
|
|
|
|
private val requestCodeChapterList = 568 |
|
|
|
private val tocActivityResult = registerForActivityResult(TocActivityResult()) { |
|
|
|
private val requestCodeInfoEdit = 562 |
|
|
|
it?.let { |
|
|
|
private val requestCodeRead = 432 |
|
|
|
viewModel.bookData.value?.let { book -> |
|
|
|
|
|
|
|
if (book.durChapterIndex != it.first) { |
|
|
|
|
|
|
|
book.durChapterIndex = it.first |
|
|
|
|
|
|
|
book.durChapterPos = it.second |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
startReadActivity(book) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} ?: let { |
|
|
|
|
|
|
|
if (!viewModel.inBookshelf) { |
|
|
|
|
|
|
|
viewModel.delBook() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private val readBookResult = registerForActivityResult( |
|
|
|
|
|
|
|
ActivityResultContracts.StartActivityForResult() |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
if (it.resultCode == RESULT_OK) { |
|
|
|
|
|
|
|
viewModel.inBookshelf = true |
|
|
|
|
|
|
|
upTvBookshelf() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private val infoEditResult = registerForActivityResult( |
|
|
|
|
|
|
|
ActivityResultContracts.StartActivityForResult() |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
if (it.resultCode == RESULT_OK) { |
|
|
|
|
|
|
|
viewModel.upEditBook() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override val viewModel: BookInfoViewModel by viewModels() |
|
|
|
override val viewModel: BookInfoViewModel by viewModels() |
|
|
|
|
|
|
|
|
|
|
@ -82,11 +110,10 @@ class BookInfoActivity : |
|
|
|
R.id.menu_edit -> { |
|
|
|
R.id.menu_edit -> { |
|
|
|
if (viewModel.inBookshelf) { |
|
|
|
if (viewModel.inBookshelf) { |
|
|
|
viewModel.bookData.value?.let { |
|
|
|
viewModel.bookData.value?.let { |
|
|
|
startActivityForResult<BookInfoEditActivity>( |
|
|
|
infoEditResult.launch( |
|
|
|
requestCodeInfoEdit |
|
|
|
Intent(this, BookInfoEditActivity::class.java) |
|
|
|
) { |
|
|
|
.putExtra("bookUrl", it.bookUrl) |
|
|
|
putExtra("bookUrl", it.bookUrl) |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
toastOnUi(R.string.after_add_bookshelf) |
|
|
|
toastOnUi(R.string.after_add_bookshelf) |
|
|
@ -303,11 +330,7 @@ class BookInfoActivity : |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
viewModel.bookData.value?.let { |
|
|
|
viewModel.bookData.value?.let { |
|
|
|
startActivityForResult<ChapterListActivity>( |
|
|
|
tocActivityResult.launch(it.bookUrl) |
|
|
|
requestCodeChapterList |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
putExtra("bookUrl", it.bookUrl) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -327,19 +350,17 @@ class BookInfoActivity : |
|
|
|
|
|
|
|
|
|
|
|
private fun startReadActivity(book: Book) { |
|
|
|
private fun startReadActivity(book: Book) { |
|
|
|
when (book.type) { |
|
|
|
when (book.type) { |
|
|
|
BookType.audio -> startActivityForResult<AudioPlayActivity>( |
|
|
|
BookType.audio -> readBookResult.launch( |
|
|
|
requestCodeRead |
|
|
|
Intent(this, AudioPlayActivity::class.java) |
|
|
|
) { |
|
|
|
.putExtra("bookUrl", book.bookUrl) |
|
|
|
putExtra("bookUrl", book.bookUrl) |
|
|
|
.putExtra("inBookshelf", viewModel.inBookshelf) |
|
|
|
putExtra("inBookshelf", viewModel.inBookshelf) |
|
|
|
) |
|
|
|
} |
|
|
|
else -> readBookResult.launch( |
|
|
|
else -> startActivityForResult<ReadBookActivity>( |
|
|
|
Intent(this, ReadBookActivity::class.java) |
|
|
|
requestCodeRead |
|
|
|
.putExtra("bookUrl", book.bookUrl) |
|
|
|
) { |
|
|
|
.putExtra("inBookshelf", viewModel.inBookshelf) |
|
|
|
putExtra("bookUrl", book.bookUrl) |
|
|
|
.putExtra("key", IntentDataHelp.putData(book)) |
|
|
|
putExtra("inBookshelf", viewModel.inBookshelf) |
|
|
|
) |
|
|
|
putExtra("key", IntentDataHelp.putData(book)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -381,33 +402,4 @@ class BookInfoActivity : |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data) |
|
|
|
|
|
|
|
when (requestCode) { |
|
|
|
|
|
|
|
requestCodeInfoEdit -> |
|
|
|
|
|
|
|
if (resultCode == Activity.RESULT_OK) { |
|
|
|
|
|
|
|
viewModel.upEditBook() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
requestCodeChapterList -> |
|
|
|
|
|
|
|
if (resultCode == Activity.RESULT_OK) { |
|
|
|
|
|
|
|
viewModel.bookData.value?.let { |
|
|
|
|
|
|
|
data?.getIntExtra("index", it.durChapterIndex)?.let { index -> |
|
|
|
|
|
|
|
if (it.durChapterIndex != index) { |
|
|
|
|
|
|
|
it.durChapterIndex = index |
|
|
|
|
|
|
|
it.durChapterPos = 0 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
startReadActivity(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (!viewModel.inBookshelf) { |
|
|
|
|
|
|
|
viewModel.delBook() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
requestCodeRead -> if (resultCode == Activity.RESULT_OK) { |
|
|
|
|
|
|
|
viewModel.inBookshelf = true |
|
|
|
|
|
|
|
upTvBookshelf() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |