diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 2274a973c..fb3027435 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -22,8 +22,8 @@ data class Book( var tocUrl: String = "", // 目录页Url (toc=table of Contents) var origin: String = BookType.local, // 书源URL(默认BookType.local) var originName: String = "", //书源名称 - var name: String? = null, // 书籍名称(书源获取) - var author: String? = null, // 作者名称(书源获取) + var name: String = "", // 书籍名称(书源获取) + var author: String = "", // 作者名称(书源获取) var kind: String? = null, // 分类信息(书源获取) var customTag: String? = null, // 分类信息(用户修改) var coverUrl: String? = null, // 封面Url(书源获取) diff --git a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt index 770fb4117..45e905847 100644 --- a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt @@ -18,8 +18,8 @@ data class SearchBook( var bookUrl: String = "", var origin: String = "", // 书源规则 var originName: String = "", - var name: String? = null, - var author: String? = null, + var name: String = "", + var author: String = "", var kind: String? = null, var coverUrl: String? = null, var intro: String? = null, diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index c10908dcd..0e9b73dbf 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -47,14 +47,14 @@ object Restore { val book = Book() book.bookUrl = jsonItem.readString("$.noteUrl") ?: "" if (book.bookUrl.isBlank()) continue - book.name = jsonItem.readString("$.bookInfoBean.name") + book.name = jsonItem.readString("$.bookInfoBean.name") ?: "" if (book.bookUrl in existingBooks) { Log.d(AppConst.APP_TAG, "Found existing book: ${book.name}") continue } book.origin = jsonItem.readString("$.tag") ?: "" 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.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.bookUrl book.coverUrl = jsonItem.readString("$.bookInfoBean.coverUrl") diff --git a/app/src/main/java/io/legado/app/model/webbook/BookList.kt b/app/src/main/java/io/legado/app/model/webbook/BookList.kt index 635f8e249..b5af7027f 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookList.kt @@ -111,7 +111,7 @@ object BookList { analyzeRule.setContent(analyzeRule.getElement(it)) } SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名") - searchBook.name = analyzeRule.getString(name ?: "") + searchBook.name = analyzeRule.getString(name ?: "") ?: "" SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.name ?: "") if (!searchBook.name.isNullOrEmpty()) { SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取作者") @@ -162,7 +162,7 @@ object BookList { analyzeRule.setContent(item) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名", printLog) 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()) { SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书籍Url", printLog) searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true) diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt index b1275721f..c72da24b6 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt @@ -119,7 +119,9 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo tv_loading.onClick { } tv_change_source.onClick { if (changeSourceDialog == null) { - changeSourceDialog = ChangeSourceDialog() + viewModel.bookData.value?.let { + changeSourceDialog = ChangeSourceDialog(it.name, it.author) + } } changeSourceDialog?.show(supportFragmentManager, "changeSource") } diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditActivity.kt index fc15bd18b..11cbbe490 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditActivity.kt @@ -45,8 +45,8 @@ class BookInfoEditActivity : VMBaseActivity(R.layout.acti private fun saveData() { viewModel.bookData.value?.let { book -> - book.name = tie_book_name.text?.toString() - book.author = tie_book_author.text?.toString() + book.name = tie_book_name.text?.toString() ?: "" + book.author = tie_book_author.text?.toString() ?: "" val customCoverUrl = tie_cover_url.text?.toString() book.customCoverUrl = if (customCoverUrl == book.coverUrl) null else customCoverUrl book.customIntro = tie_book_intro.text?.toString() diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index 197e8df5d..2649ecb7c 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -4,13 +4,13 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.appcompat.widget.SearchView import androidx.fragment.app.DialogFragment import io.legado.app.R 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? { return inflater.inflate(R.layout.dialog_change_source, container) @@ -19,7 +19,22 @@ class ChangeSourceDialog : DialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) 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 + } + }) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt index 70367f9f8..ef5be2761 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt @@ -34,7 +34,7 @@ class ChapterListActivity : VMBaseActivity(R.layout.activi override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { 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 ATH.setTint(searchView!!, primaryTextColor) searchView?.maxWidth = resources.displayMetrics.widthPixels diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index aba0b214c..8ed1d310b 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -62,7 +62,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b override fun onCompatOptionsItemSelected(item: MenuItem) { super.onCompatOptionsItemSelected(item) when (item.itemId) { - R.id.action_search -> startActivity() + R.id.menu_search -> startActivity() } } diff --git a/app/src/main/res/menu/main_bookshelf.xml b/app/src/main/res/menu/main_bookshelf.xml index 6c69069c1..e4bc08efe 100644 --- a/app/src/main/res/menu/main_bookshelf.xml +++ b/app/src/main/res/menu/main_bookshelf.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> diff --git a/app/src/main/res/menu/search_view.xml b/app/src/main/res/menu/search_view.xml index ee23fae6b..0b897362d 100644 --- a/app/src/main/res/menu/search_view.xml +++ b/app/src/main/res/menu/search_view.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto">