pull/49/head
kunfei 5 years ago
parent eec12f99a1
commit d20096da1a
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  2. 23
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  3. 14
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  4. 6
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  5. 4
      app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt
  6. 4
      app/src/main/res/layout/activity_book_info.xml
  7. 2
      app/src/main/res/values/strings.xml

@ -7,6 +7,9 @@ import io.legado.app.data.entities.BookGroup
@Dao
interface BookGroupDao {
@Query("select * from book_groups where groupId = :id")
fun getByID(id: Int): BookGroup?
@Query("SELECT * FROM book_groups ORDER BY `order`")
fun liveDataAll(): LiveData<List<BookGroup>>

@ -18,6 +18,7 @@ import io.legado.app.ui.book.info.edit.BookInfoEditActivity
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.changesource.ChangeSourceDialog
import io.legado.app.ui.chapterlist.ChapterListActivity
import io.legado.app.utils.getViewModel
import io.legado.app.utils.gone
import io.legado.app.utils.visible
@ -39,6 +40,9 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
viewModel.bookData.observe(this, Observer { showBook(it) })
viewModel.isLoadingData.observe(this, Observer { upLoading(it) })
viewModel.chapterListData.observe(this, Observer { showChapter(it) })
viewModel.groupData.observe(this, Observer {
tv_group.text = getString(R.string.group_s, it.groupName)
})
viewModel.initData(intent)
initOnClick()
}
@ -56,7 +60,7 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
startActivity<BookInfoEditActivity>(Pair("bookUrl", it.bookUrl))
}
} else {
toast("未加入书架,不能编辑")
toast(R.string.after_add_bookshelf)
}
}
R.id.menu_refresh -> {
@ -74,6 +78,7 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
tv_author.text = getString(R.string.author_show, book.author)
tv_origin.text = getString(R.string.origin_show, book.originName)
tv_lasted.text = getString(R.string.lasted_show, book.latestChapterTitle)
tv_toc.text = getString(R.string.toc_s, book.latestChapterTitle)
tv_intro.text =
book.getDisplayIntro() // getString(R.string.intro_show, book.getDisplayIntro())
book.getDisplayCover()?.let {
@ -117,9 +122,9 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
private fun showChapter(chapterList: List<BookChapter>) {
viewModel.bookData.value?.let {
if (it.durChapterIndex < chapterList.size) {
tv_chapter.text = chapterList[it.durChapterIndex].title
tv_toc.text = chapterList[it.durChapterIndex].title
} else {
tv_chapter.text = chapterList.last().title
tv_toc.text = chapterList.last().title
}
}
upLoading(false)
@ -170,8 +175,16 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
ChangeSourceDialog.show(supportFragmentManager, it.name, it.author)
}
}
tv_chapter.onClick {
tv_toc.onClick {
if (!viewModel.inBookshelf) {
toast(R.string.after_add_bookshelf)
return@onClick
}
viewModel.bookData.value?.let {
startActivity<ChapterListActivity>(
Pair("bookUrl", it.bookUrl)
)
}
}
tv_group.onClick {

@ -8,8 +8,8 @@ import io.legado.app.R
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookGroup
import io.legado.app.help.BookHelp
import io.legado.app.help.IntentDataHelp
import io.legado.app.model.WebBook
import kotlinx.coroutines.Dispatchers.IO
@ -20,17 +20,16 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
val isLoadingData = MutableLiveData<Boolean>()
var durChapterIndex = 0
var inBookshelf = false
var groupData = MutableLiveData<BookGroup>()
fun initData(intent: Intent) {
execute {
IntentDataHelp.getData<Book>(intent.getStringExtra("key"))?.let { book ->
setBook(book)
} ?: intent.getStringExtra("bookUrl")?.let {
intent.getStringExtra("bookUrl")?.let {
App.db.bookDao().getBook(it)?.let { book ->
groupData.postValue(App.db.bookGroupDao().getByID(book.group))
inBookshelf = true
setBook(book)
}
} ?: intent.getStringExtra("searchBookUrl")?.let {
App.db.searchBookDao().getSearchBook(it)?.toBook()?.let { book ->
} ?: App.db.searchBookDao().getSearchBook(it)?.toBook()?.let { book ->
setBook(book)
}
}
@ -38,7 +37,6 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
}
private fun setBook(book: Book) {
inBookshelf = App.db.bookDao().getBook(book.bookUrl) != null
durChapterIndex = book.durChapterIndex
bookData.postValue(book)
if (book.tocUrl.isEmpty()) {

@ -14,7 +14,6 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchKeyword
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.book.info.BookInfoActivity
@ -235,15 +234,14 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
override fun showBookInfo(name: String, author: String) {
viewModel.getSearchBook(name, author) { searchBook ->
searchBook?.let {
startActivity<BookInfoActivity>(Pair("searchBookUrl", it.bookUrl))
startActivity<BookInfoActivity>(Pair("bookUrl", it.bookUrl))
}
}
}
override fun showBookInfo(book: Book) {
startActivity<BookInfoActivity>(
Pair("bookUrl", book.bookUrl),
Pair("key", IntentDataHelp.putData(book))
Pair("bookUrl", book.bookUrl)
)
}

@ -9,7 +9,6 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook
import io.legado.app.help.IntentDataHelp
import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.widget.LoadMoreView
import io.legado.app.utils.getViewModel
@ -73,8 +72,7 @@ class ExploreShowActivity : VMBaseActivity<ExploreShowViewModel>(R.layout.activi
override fun showBookInfo(book: Book) {
startActivity<BookInfoActivity>(
Pair("searchBookUrl", book.bookUrl),
Pair("key", IntentDataHelp.putData(book))
Pair("bookUrl", book.bookUrl)
)
}
}

@ -194,12 +194,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="@string/group_s"
android:text="@string/group"
android:textColor="@color/tv_text_default"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_chapter"
android:id="@+id/tv_toc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"

@ -565,5 +565,7 @@
<string name="custom_page_key">自定义翻页按键</string>
<string name="prev_page_key">上一页按键</string>
<string name="next_page_key">下一页按键</string>
<string name="after_add_bookshelf">先将书籍加入书架</string>
<string name="no_group">未分组</string>
</resources>

Loading…
Cancel
Save