From 160793f3ae2008c57271abdac2e0b5c5684e0629 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 6 Jun 2019 21:12:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/base/BaseFragment.kt | 4 +++- .../ui/main/booksource/BookSourceAdapter.kt | 3 ++- .../ui/main/booksource/BookSourceFragment.kt | 20 +++++++++++++++++++ .../main/res/layout/fragment_book_source.xml | 5 +++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/base/BaseFragment.kt b/app/src/main/java/io/legado/app/base/BaseFragment.kt index 0a35d8a1f..559631422 100644 --- a/app/src/main/java/io/legado/app/base/BaseFragment.kt +++ b/app/src/main/java/io/legado/app/base/BaseFragment.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt index 83fa15094..ae5a9d506 100644 --- a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt @@ -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(DIFF_CALLBACK) { +class BookSourceAdapter(context : Context) : PagedListAdapter(DIFF_CALLBACK) { companion object { diff --git a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt index 55e9eb9e3..3729409af 100644 --- a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt @@ -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>? = 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() { + + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_book_source.xml b/app/src/main/res/layout/fragment_book_source.xml index d1ec2da0a..1fd3e5cd8 100644 --- a/app/src/main/res/layout/fragment_book_source.xml +++ b/app/src/main/res/layout/fragment_book_source.xml @@ -14,4 +14,9 @@ app:layout_constraintTop_toTopOf="parent" app:title="@string/book_source"/> + + \ No newline at end of file