pull/32/head
gedoor 6 years ago
parent 510bf82283
commit 160793f3ae
  1. 4
      app/src/main/java/io/legado/app/base/BaseFragment.kt
  2. 3
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt
  3. 20
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt
  4. 5
      app/src/main/res/layout/fragment_book_source.xml

@ -6,9 +6,11 @@ import android.view.MenuItem
import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import io.legado.app.utils.setIconColor
abstract class BaseFragment(contentLayoutId: Int = 0) : Fragment(contentLayoutId) {
abstract class BaseFragment(contentLayoutId: Int = 0) : Fragment(contentLayoutId){
var supportToolbar: Toolbar? = null
private set

@ -1,5 +1,6 @@
package io.legado.app.ui.main.booksource
import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.paging.PagedListAdapter
@ -7,7 +8,7 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.data.entities.Source
class BookSourceAdapter : PagedListAdapter<Source, BookSourceAdapter.MyViewHolder>(DIFF_CALLBACK) {
class BookSourceAdapter(context : Context) : PagedListAdapter<Source, BookSourceAdapter.MyViewHolder>(DIFF_CALLBACK) {
companion object {

@ -4,14 +4,23 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.lifecycle.LiveData
import androidx.paging.PagedList
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.base.BaseFragment
import io.legado.app.data.entities.Source
import kotlinx.android.synthetic.main.fragment_book_source.*
import kotlinx.android.synthetic.main.view_titlebar.*
class BookSourceFragment : BaseFragment(R.layout.fragment_book_source) {
private lateinit var adapter : BookSourceAdapter
private var sourceLiveDate : LiveData<PagedList<Source>>? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar)
initRecyclerView()
}
override fun onCompatCreateOptionsMenu(menu: Menu) {
@ -22,5 +31,16 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source) {
}
private fun initRecyclerView() {
recycler_view.layoutManager = LinearLayoutManager(context)
context?.let {
adapter = BookSourceAdapter(it)
recycler_view.adapter = adapter
}
}
private fun initDataObservers() {
}
}

@ -14,4 +14,9 @@
app:layout_constraintTop_toTopOf="parent"
app:title="@string/book_source"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save