From d20096da1a816266671b7f85b24af13fe533af82 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 22 Nov 2019 16:13:59 +0800 Subject: [PATCH] up --- .../io/legado/app/data/dao/BookGroupDao.kt | 3 +++ .../app/ui/book/info/BookInfoActivity.kt | 23 +++++++++++++++---- .../app/ui/book/info/BookInfoViewModel.kt | 14 +++++------ .../app/ui/book/search/SearchActivity.kt | 6 ++--- .../app/ui/explore/ExploreShowActivity.kt | 4 +--- .../main/res/layout/activity_book_info.xml | 4 ++-- app/src/main/res/values/strings.xml | 2 ++ 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index 6162ffc5a..0078eb26b 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -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> diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index ac28de108..722fd0aef 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -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(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(R.layout.activity_boo startActivity(Pair("bookUrl", it.bookUrl)) } } else { - toast("未加入书架,不能编辑") + toast(R.string.after_add_bookshelf) } } R.id.menu_refresh -> { @@ -74,6 +78,7 @@ class BookInfoActivity : VMBaseActivity(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(R.layout.activity_boo private fun showChapter(chapterList: List) { 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(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( + Pair("bookUrl", it.bookUrl) + ) + } } tv_group.onClick { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index e643b0b91..7673458de 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -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() var durChapterIndex = 0 var inBookshelf = false + var groupData = MutableLiveData() fun initData(intent: Intent) { execute { - IntentDataHelp.getData(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()) { diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 36d0fefe6..72008b68a 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -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(R.layout.activity_book_se override fun showBookInfo(name: String, author: String) { viewModel.getSearchBook(name, author) { searchBook -> searchBook?.let { - startActivity(Pair("searchBookUrl", it.bookUrl)) + startActivity(Pair("bookUrl", it.bookUrl)) } } } override fun showBookInfo(book: Book) { startActivity( - Pair("bookUrl", book.bookUrl), - Pair("key", IntentDataHelp.putData(book)) + Pair("bookUrl", book.bookUrl) ) } diff --git a/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt b/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt index 90333bd5f..312129fd7 100644 --- a/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt +++ b/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt @@ -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(R.layout.activi override fun showBookInfo(book: Book) { startActivity( - Pair("searchBookUrl", book.bookUrl), - Pair("key", IntentDataHelp.putData(book)) + Pair("bookUrl", book.bookUrl) ) } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml index 316035ec0..ac79317e4 100644 --- a/app/src/main/res/layout/activity_book_info.xml +++ b/app/src/main/res/layout/activity_book_info.xml @@ -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" /> 自定义翻页按键 上一页按键 下一页按键 + 先将书籍加入书架 + 未分组