pull/32/head
kunfei 5 years ago
parent 2bdca6ed64
commit d024b60d03
  1. 4
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 4
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  3. 4
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  4. 4
      app/src/main/java/io/legado/app/model/webbook/BookList.kt
  5. 4
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  6. 4
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditActivity.kt
  7. 19
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt
  8. 2
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt
  9. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  10. 2
      app/src/main/res/menu/main_bookshelf.xml
  11. 2
      app/src/main/res/menu/search_view.xml

@ -22,8 +22,8 @@ data class Book(
var tocUrl: String = "", // 目录页Url (toc=table of Contents) var tocUrl: String = "", // 目录页Url (toc=table of Contents)
var origin: String = BookType.local, // 书源URL(默认BookType.local) var origin: String = BookType.local, // 书源URL(默认BookType.local)
var originName: String = "", //书源名称 var originName: String = "", //书源名称
var name: String? = null, // 书籍名称(书源获取) var name: String = "", // 书籍名称(书源获取)
var author: String? = null, // 作者名称(书源获取) var author: String = "", // 作者名称(书源获取)
var kind: String? = null, // 分类信息(书源获取) var kind: String? = null, // 分类信息(书源获取)
var customTag: String? = null, // 分类信息(用户修改) var customTag: String? = null, // 分类信息(用户修改)
var coverUrl: String? = null, // 封面Url(书源获取) var coverUrl: String? = null, // 封面Url(书源获取)

@ -18,8 +18,8 @@ data class SearchBook(
var bookUrl: String = "", var bookUrl: String = "",
var origin: String = "", // 书源规则 var origin: String = "", // 书源规则
var originName: String = "", var originName: String = "",
var name: String? = null, var name: String = "",
var author: String? = null, var author: String = "",
var kind: String? = null, var kind: String? = null,
var coverUrl: String? = null, var coverUrl: String? = null,
var intro: String? = null, var intro: String? = null,

@ -47,14 +47,14 @@ object Restore {
val book = Book() val book = Book()
book.bookUrl = jsonItem.readString("$.noteUrl") ?: "" book.bookUrl = jsonItem.readString("$.noteUrl") ?: ""
if (book.bookUrl.isBlank()) continue if (book.bookUrl.isBlank()) continue
book.name = jsonItem.readString("$.bookInfoBean.name") book.name = jsonItem.readString("$.bookInfoBean.name") ?: ""
if (book.bookUrl in existingBooks) { if (book.bookUrl in existingBooks) {
Log.d(AppConst.APP_TAG, "Found existing book: ${book.name}") Log.d(AppConst.APP_TAG, "Found existing book: ${book.name}")
continue continue
} }
book.origin = jsonItem.readString("$.tag") ?: "" book.origin = jsonItem.readString("$.tag") ?: ""
book.originName = jsonItem.readString("$.bookInfoBean.origin") ?: "" book.originName = jsonItem.readString("$.bookInfoBean.origin") ?: ""
book.author = jsonItem.readString("$.bookInfoBean.author") book.author = jsonItem.readString("$.bookInfoBean.author") ?: ""
book.type = if (jsonItem.readString("$.bookInfoBean.bookSourceType") == "AUDIO") 1 else 0 book.type = if (jsonItem.readString("$.bookInfoBean.bookSourceType") == "AUDIO") 1 else 0
book.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.bookUrl book.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.bookUrl
book.coverUrl = jsonItem.readString("$.bookInfoBean.coverUrl") book.coverUrl = jsonItem.readString("$.bookInfoBean.coverUrl")

@ -111,7 +111,7 @@ object BookList {
analyzeRule.setContent(analyzeRule.getElement(it)) analyzeRule.setContent(analyzeRule.getElement(it))
} }
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名") SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名")
searchBook.name = analyzeRule.getString(name ?: "") searchBook.name = analyzeRule.getString(name ?: "") ?: ""
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.name ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.name ?: "")
if (!searchBook.name.isNullOrEmpty()) { if (!searchBook.name.isNullOrEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取作者") SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取作者")
@ -162,7 +162,7 @@ object BookList {
analyzeRule.setContent(item) analyzeRule.setContent(item)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名", printLog)
searchBook.name = analyzeRule.getString(ruleName) searchBook.name = analyzeRule.getString(ruleName)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.name ?: "", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.name, printLog)
if (!searchBook.name.isNullOrEmpty()) { if (!searchBook.name.isNullOrEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书籍Url", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书籍Url", printLog)
searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true) searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true)

@ -119,7 +119,9 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
tv_loading.onClick { } tv_loading.onClick { }
tv_change_source.onClick { tv_change_source.onClick {
if (changeSourceDialog == null) { if (changeSourceDialog == null) {
changeSourceDialog = ChangeSourceDialog() viewModel.bookData.value?.let {
changeSourceDialog = ChangeSourceDialog(it.name, it.author)
}
} }
changeSourceDialog?.show(supportFragmentManager, "changeSource") changeSourceDialog?.show(supportFragmentManager, "changeSource")
} }

@ -45,8 +45,8 @@ class BookInfoEditActivity : VMBaseActivity<BookInfoEditViewModel>(R.layout.acti
private fun saveData() { private fun saveData() {
viewModel.bookData.value?.let { book -> viewModel.bookData.value?.let { book ->
book.name = tie_book_name.text?.toString() book.name = tie_book_name.text?.toString() ?: ""
book.author = tie_book_author.text?.toString() book.author = tie_book_author.text?.toString() ?: ""
val customCoverUrl = tie_cover_url.text?.toString() val customCoverUrl = tie_cover_url.text?.toString()
book.customCoverUrl = if (customCoverUrl == book.coverUrl) null else customCoverUrl book.customCoverUrl = if (customCoverUrl == book.coverUrl) null else customCoverUrl
book.customIntro = tie_book_intro.text?.toString() book.customIntro = tie_book_intro.text?.toString()

@ -4,13 +4,13 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.SearchView
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import io.legado.app.R import io.legado.app.R
import kotlinx.android.synthetic.main.dialog_change_source.* import kotlinx.android.synthetic.main.dialog_change_source.*
class ChangeSourceDialog : DialogFragment() { class ChangeSourceDialog(val name: String, val author: String) : DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_change_source, container) return inflater.inflate(R.layout.dialog_change_source, container)
@ -19,7 +19,22 @@ class ChangeSourceDialog : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
tool_bar.inflateMenu(R.menu.search_view) tool_bar.inflateMenu(R.menu.search_view)
tool_bar.title = name
tool_bar.subtitle = author
initSearchView()
} }
private fun initSearchView() {
val searchView = tool_bar.menu.findItem(R.id.menu_search).actionView as SearchView
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return false
}
override fun onQueryTextChange(newText: String?): Boolean {
return false
}
})
}
} }

@ -34,7 +34,7 @@ class ChapterListActivity : VMBaseActivity<ChapterListViewModel>(R.layout.activi
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.search_view, menu) menuInflater.inflate(R.menu.search_view, menu)
val search = menu.findItem(R.id.action_search) val search = menu.findItem(R.id.menu_search)
searchView = search.actionView as SearchView searchView = search.actionView as SearchView
ATH.setTint(searchView!!, primaryTextColor) ATH.setTint(searchView!!, primaryTextColor)
searchView?.maxWidth = resources.displayMetrics.widthPixels searchView?.maxWidth = resources.displayMetrics.widthPixels

@ -62,7 +62,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
override fun onCompatOptionsItemSelected(item: MenuItem) { override fun onCompatOptionsItemSelected(item: MenuItem) {
super.onCompatOptionsItemSelected(item) super.onCompatOptionsItemSelected(item)
when (item.itemId) { when (item.itemId) {
R.id.action_search -> startActivity<SearchActivity>() R.id.menu_search -> startActivity<SearchActivity>()
} }
} }

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/action_search" android:id="@+id/menu_search"
android:icon="@drawable/ic_search" android:icon="@drawable/ic_search"
android:title="@string/search" android:title="@string/search"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/action_search" android:id="@+id/menu_search"
android:title="@string/search" android:title="@string/search"
app:actionViewClass="androidx.appcompat.widget.SearchView" app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="always" /> app:showAsAction="always" />

Loading…
Cancel
Save