|
|
@ -1,11 +1,11 @@ |
|
|
|
package io.legado.app.ui.main.bookshelf.style2 |
|
|
|
package io.legado.app.ui.main.bookshelf.style2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.view.Menu |
|
|
|
import android.view.Menu |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import androidx.appcompat.widget.SearchView |
|
|
|
import androidx.appcompat.widget.SearchView |
|
|
|
import androidx.core.view.isGone |
|
|
|
import androidx.core.view.isGone |
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager |
|
|
|
import androidx.recyclerview.widget.GridLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
@ -21,7 +21,6 @@ import io.legado.app.databinding.FragmentBookshelf1Binding |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
import io.legado.app.lib.theme.primaryTextColor |
|
|
|
|
|
|
|
import io.legado.app.ui.book.audio.AudioPlayActivity |
|
|
|
import io.legado.app.ui.book.audio.AudioPlayActivity |
|
|
|
import io.legado.app.ui.book.info.BookInfoActivity |
|
|
|
import io.legado.app.ui.book.info.BookInfoActivity |
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
@ -48,7 +47,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), |
|
|
|
private lateinit var searchView: SearchView |
|
|
|
private lateinit var searchView: SearchView |
|
|
|
private lateinit var booksAdapter: BaseBooksAdapter<*> |
|
|
|
private lateinit var booksAdapter: BaseBooksAdapter<*> |
|
|
|
override var groupId = AppConst.bookGroupNoneId |
|
|
|
override var groupId = AppConst.bookGroupNoneId |
|
|
|
private var bookGroupLiveData: LiveData<List<BookGroup>>? = null |
|
|
|
|
|
|
|
private var booksFlowJob: Job? = null |
|
|
|
private var booksFlowJob: Job? = null |
|
|
|
private var bookGroups: List<BookGroup> = emptyList() |
|
|
|
private var bookGroups: List<BookGroup> = emptyList() |
|
|
|
override var books: List<Book> = emptyList() |
|
|
|
override var books: List<Book> = emptyList() |
|
|
@ -56,7 +54,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), |
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
searchView = binding.titleBar.findViewById(R.id.search_view) |
|
|
|
searchView = binding.titleBar.findViewById(R.id.search_view) |
|
|
|
setSupportToolbar(binding.titleBar.toolbar) |
|
|
|
setSupportToolbar(binding.titleBar.toolbar) |
|
|
|
initSearchView() |
|
|
|
|
|
|
|
initRecyclerView() |
|
|
|
initRecyclerView() |
|
|
|
initGroupData() |
|
|
|
initGroupData() |
|
|
|
initBooksData() |
|
|
|
initBooksData() |
|
|
@ -64,25 +61,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), |
|
|
|
|
|
|
|
|
|
|
|
override fun onCompatCreateOptionsMenu(menu: Menu) { |
|
|
|
override fun onCompatCreateOptionsMenu(menu: Menu) { |
|
|
|
menuInflater.inflate(R.menu.main_bookshelf, menu) |
|
|
|
menuInflater.inflate(R.menu.main_bookshelf, menu) |
|
|
|
menu.findItem(R.id.menu_search).isVisible = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun initSearchView() { |
|
|
|
|
|
|
|
ATH.setTint(searchView, primaryTextColor) |
|
|
|
|
|
|
|
searchView.onActionViewExpanded() |
|
|
|
|
|
|
|
searchView.isSubmitButtonEnabled = true |
|
|
|
|
|
|
|
searchView.queryHint = getString(R.string.screen_find) |
|
|
|
|
|
|
|
searchView.clearFocus() |
|
|
|
|
|
|
|
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { |
|
|
|
|
|
|
|
override fun onQueryTextSubmit(query: String?): Boolean { |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onQueryTextChange(newText: String?): Boolean { |
|
|
|
|
|
|
|
SearchActivity.start(requireContext(), newText) |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initRecyclerView() { |
|
|
|
private fun initRecyclerView() { |
|
|
@ -120,6 +98,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged") |
|
|
|
private fun initGroupData() { |
|
|
|
private fun initGroupData() { |
|
|
|
launch { |
|
|
|
launch { |
|
|
|
appDb.bookGroupDao.flowShow().collect { |
|
|
|
appDb.bookGroupDao.flowShow().collect { |
|
|
@ -131,6 +110,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged") |
|
|
|
private fun initBooksData() { |
|
|
|
private fun initBooksData() { |
|
|
|
booksFlowJob?.cancel() |
|
|
|
booksFlowJob?.cancel() |
|
|
|
booksFlowJob = launch { |
|
|
|
booksFlowJob = launch { |
|
|
@ -199,8 +179,8 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), |
|
|
|
|
|
|
|
|
|
|
|
override fun onItemLongClick(position: Int) { |
|
|
|
override fun onItemLongClick(position: Int) { |
|
|
|
if (position < bookGroups.size) { |
|
|
|
if (position < bookGroups.size) { |
|
|
|
val bookGroup = bookGroups[position] |
|
|
|
groupId = bookGroups[position].groupId |
|
|
|
|
|
|
|
initBooksData() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val book = books[position - bookGroups.size] |
|
|
|
val book = books[position - bookGroups.size] |
|
|
|
startActivity<BookInfoActivity> { |
|
|
|
startActivity<BookInfoActivity> { |
|
|
@ -215,17 +195,26 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getItemCount(): Int { |
|
|
|
override fun getItemCount(): Int { |
|
|
|
return bookGroups.size + books.size |
|
|
|
return if (groupId == AppConst.bookGroupNoneId) { |
|
|
|
|
|
|
|
bookGroups.size + books.size |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
books.size |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getItem(position: Int): Any { |
|
|
|
override fun getItem(position: Int): Any { |
|
|
|
return if (position < bookGroups.size) { |
|
|
|
return if (groupId == AppConst.bookGroupNoneId) { |
|
|
|
bookGroups[position] |
|
|
|
if (position < bookGroups.size) { |
|
|
|
|
|
|
|
bookGroups[position] |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
books[position - bookGroups.size] |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
books[position - bookGroups.size] |
|
|
|
books[position] |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged") |
|
|
|
override fun observeLiveBus() { |
|
|
|
override fun observeLiveBus() { |
|
|
|
super.observeLiveBus() |
|
|
|
super.observeLiveBus() |
|
|
|
observeEvent<String>(EventBus.UP_BOOKSHELF) { |
|
|
|
observeEvent<String>(EventBus.UP_BOOKSHELF) { |
|
|
|