Merge remote-tracking branch 'origin/master'

pull/32/head
Administrator 5 years ago
commit 270751d3ce
  1. 18
      app/src/main/java/io/legado/app/ui/chapterlist/BookmarkAdapter.kt
  2. 30
      app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt
  3. 53
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt
  4. 28
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt
  5. 2
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt
  6. 14
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  7. 27
      app/src/main/res/layout/activity_read.xml
  8. 2
      app/src/main/res/layout/fragment_bookmark.xml
  9. 2
      app/src/main/res/layout/fragment_chapter_list.xml

@ -8,6 +8,8 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.Bookmark import io.legado.app.data.entities.Bookmark
import kotlinx.android.synthetic.main.item_bookmark.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class BookmarkAdapter : PagedListAdapter<Bookmark, BookmarkAdapter.MyViewHolder>(DIFF_CALLBACK) { class BookmarkAdapter : PagedListAdapter<Bookmark, BookmarkAdapter.MyViewHolder>(DIFF_CALLBACK) {
@ -27,20 +29,30 @@ class BookmarkAdapter : PagedListAdapter<Bookmark, BookmarkAdapter.MyViewHolder>
} }
} }
var callback: Callback? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bookmark, parent, false)) return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bookmark, parent, false))
} }
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
getItem(position)?.let { getItem(position)?.let {
holder.bind(it) holder.bind(it, callback)
} }
} }
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(bookmark: Bookmark) { fun bind(bookmark: Bookmark, callback: Callback?) = with(itemView) {
tv_chapter_name.text = bookmark.chapterName
tv_content.text = bookmark.content
itemView.onClick {
callback?.open(bookmark)
}
} }
} }
interface Callback {
fun open(bookmark: Bookmark)
}
} }

@ -1,12 +1,42 @@
package io.legado.app.ui.chapterlist package io.legado.app.ui.chapterlist
import android.os.Bundle
import android.view.View
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseFragment import io.legado.app.base.VMBaseFragment
import io.legado.app.data.entities.Bookmark
import io.legado.app.lib.theme.ATH
import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.getViewModelOfActivity
import kotlinx.android.synthetic.main.fragment_bookmark.*
class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_bookmark) { class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_bookmark) {
override val viewModel: ChapterListViewModel override val viewModel: ChapterListViewModel
get() = getViewModelOfActivity(ChapterListViewModel::class.java) get() = getViewModelOfActivity(ChapterListViewModel::class.java)
private lateinit var adapter: BookmarkAdapter
private var bookmarkLiveData: LiveData<PagedList<Bookmark>>? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRecyclerView()
}
private fun initRecyclerView() {
ATH.applyEdgeEffectColor(recycler_view)
adapter = BookmarkAdapter()
recycler_view.layoutManager = LinearLayoutManager(requireContext())
recycler_view.adapter = adapter
}
private fun initData() {
bookmarkLiveData?.removeObservers(viewLifecycleOwner)
bookmarkLiveData = LivePagedListBuilder(App.db.bookmarkDao().observeByBook(""), 20).build()
bookmarkLiveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) })
}
} }

@ -1,2 +1,55 @@
package io.legado.app.ui.chapterlist package io.legado.app.ui.chapterlist
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.data.entities.BookChapter
import kotlinx.android.synthetic.main.item_bookmark.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class ChapterListAdapter : PagedListAdapter<BookChapter, ChapterListAdapter.MyViewHolder>(DIFF_CALLBACK) {
companion object {
@JvmField
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<BookChapter>() {
override fun areItemsTheSame(oldItem: BookChapter, newItem: BookChapter): Boolean =
oldItem.bookUrl == newItem.bookUrl
&& oldItem.url == newItem.url
override fun areContentsTheSame(oldItem: BookChapter, newItem: BookChapter): Boolean =
oldItem.title == newItem.title
}
}
var callback: Callback? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_chapter_list, parent, false))
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
getItem(position)?.let {
holder.bind(it, callback)
}
}
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(bookChapter: BookChapter, callback: Callback?) = with(itemView) {
tv_chapter_name.text = bookChapter.title
itemView.onClick {
callback?.openChapter()
}
}
}
interface Callback {
fun openChapter()
}
}

@ -1,13 +1,41 @@
package io.legado.app.ui.chapterlist package io.legado.app.ui.chapterlist
import android.os.Bundle
import android.view.View
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseFragment import io.legado.app.base.VMBaseFragment
import io.legado.app.data.entities.BookChapter
import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.getViewModelOfActivity
import kotlinx.android.synthetic.main.fragment_chapter_list.*
class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list) { class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list) {
override val viewModel: ChapterListViewModel override val viewModel: ChapterListViewModel
get() = getViewModelOfActivity(ChapterListViewModel::class.java) get() = getViewModelOfActivity(ChapterListViewModel::class.java)
lateinit var adapter: ChapterListAdapter
var liveData: LiveData<PagedList<BookChapter>>? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRecyclerView()
initData()
}
private fun initRecyclerView() {
adapter = ChapterListAdapter()
recycler_view.layoutManager = LinearLayoutManager(requireContext())
recycler_view.adapter = adapter
}
private fun initData() {
liveData?.removeObservers(viewLifecycleOwner)
liveData = LivePagedListBuilder(App.db.bookChapterDao().observeByBook(""), 30).build()
liveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) })
}
} }

@ -5,4 +5,6 @@ import io.legado.app.base.BaseViewModel
class ChapterListViewModel : BaseViewModel(App.INSTANCE) { class ChapterListViewModel : BaseViewModel(App.INSTANCE) {
var bookUrl: String? = null
} }

@ -26,7 +26,10 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.bookshelf.BookshelfActivity import io.legado.app.ui.bookshelf.BookshelfActivity
import io.legado.app.ui.read.ReadActivity import io.legado.app.ui.read.ReadActivity
import io.legado.app.ui.search.SearchActivity import io.legado.app.ui.search.SearchActivity
import io.legado.app.utils.* import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.startActivity
import kotlinx.android.synthetic.main.dialog_edittext.view.* import kotlinx.android.synthetic.main.dialog_edittext.view.*
import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.fragment_bookshelf.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
@ -48,7 +51,6 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar) setSupportToolbar(toolbar)
// initSearchView()
initRecyclerView() initRecyclerView()
initBookGroupData() initBookGroupData()
initBookshelfData() initBookshelfData()
@ -65,14 +67,6 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
} }
} }
private fun initSearchView() {
// search_view.onActionViewExpanded()
// search_view.isSubmitButtonEnabled = true
// search_view.queryHint = getString(R.string.search_book_key)
// search_view.clearFocus()
// search_view.setOnQueryTextListener(this)
}
private fun initRecyclerView() { private fun initRecyclerView() {
ATH.applyEdgeEffectColor(rv_bookshelf) ATH.applyEdgeEffectColor(rv_bookshelf)
refresh_layout.setColorSchemeColors(accentColor) refresh_layout.setColorSchemeColors(accentColor)

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -8,4 +9,26 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>
</LinearLayout> <io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/tv_chapter_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="@+id/tv_chapter_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp" />
</io.legado.app.ui.widget.TitleBar>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -5,7 +5,7 @@
android:descendantFocusability="blocksDescendants"> android:descendantFocusability="blocksDescendants">
<io.legado.app.ui.widget.recycler.scroller.FastScrollRecyclerView <io.legado.app.ui.widget.recycler.scroller.FastScrollRecyclerView
android:id="@+id/rv_list" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:overScrollMode="never" /> android:overScrollMode="never" />

@ -6,7 +6,7 @@
android:descendantFocusability="blocksDescendants"> android:descendantFocusability="blocksDescendants">
<io.legado.app.ui.widget.recycler.scroller.FastScrollRecyclerView <io.legado.app.ui.widget.recycler.scroller.FastScrollRecyclerView
android:id="@+id/rv_list" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:overScrollMode="never" android:overScrollMode="never"

Loading…
Cancel
Save