@ -4,6 +4,8 @@ import android.os.Bundle
import android.view.Menu
import android.view.Menu
import android.view.MenuItem
import android.view.MenuItem
import android.view.View
import android.view.View
import androidx.appcompat.widget.SearchView
import androidx.lifecycle.LiveData
import io.legado.app.App
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
@ -11,6 +13,7 @@ import io.legado.app.data.entities.RssSource
import io.legado.app.databinding.FragmentRssBinding
import io.legado.app.databinding.FragmentRssBinding
import io.legado.app.databinding.ItemRssBinding
import io.legado.app.databinding.ItemRssBinding
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.rss.article.RssSortActivity
import io.legado.app.ui.rss.article.RssSortActivity
import io.legado.app.ui.rss.favorites.RssFavoritesActivity
import io.legado.app.ui.rss.favorites.RssFavoritesActivity
import io.legado.app.ui.rss.read.ReadRssActivity
import io.legado.app.ui.rss.read.ReadRssActivity
@ -30,11 +33,15 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
RssAdapter . CallBack {
RssAdapter . CallBack {
private val binding by viewBinding ( FragmentRssBinding :: bind )
private val binding by viewBinding ( FragmentRssBinding :: bind )
private lateinit var adapter : RssAdapter
private lateinit var adapter : RssAdapter
private lateinit var searchView : SearchView
override val viewModel : RssSourceViewModel
override val viewModel : RssSourceViewModel
get ( ) = getViewModel ( RssSourceViewModel :: class . java )
get ( ) = getViewModel ( RssSourceViewModel :: class . java )
private var liveRssData : LiveData < List < RssSource > > ? = null
override fun onFragmentCreated ( view : View , savedInstanceState : Bundle ? ) {
override fun onFragmentCreated ( view : View , savedInstanceState : Bundle ? ) {
searchView = binding . titleBar . findViewById ( R . id . search _view )
setSupportToolbar ( binding . titleBar . toolbar )
setSupportToolbar ( binding . titleBar . toolbar )
initSearchView ( )
initRecyclerView ( )
initRecyclerView ( )
initData ( )
initData ( )
}
}
@ -51,6 +58,24 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
}
}
}
}
private fun initSearchView ( ) {
ATH . setTint ( searchView , primaryTextColor )
searchView . onActionViewExpanded ( )
searchView . isSubmitButtonEnabled = true
searchView . queryHint = getString ( R . string . rss )
searchView . clearFocus ( )
searchView . setOnQueryTextListener ( object : SearchView . OnQueryTextListener {
override fun onQueryTextSubmit ( query : String ? ) : Boolean {
return false
}
override fun onQueryTextChange ( newText : String ? ) : Boolean {
initData ( newText ?: " " )
return false
}
} )
}
private fun initRecyclerView ( ) {
private fun initRecyclerView ( ) {
ATH . applyEdgeEffectColor ( binding . recyclerView )
ATH . applyEdgeEffectColor ( binding . recyclerView )
adapter = RssAdapter ( requireContext ( ) , this )
adapter = RssAdapter ( requireContext ( ) , this )
@ -66,10 +91,13 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
}
}
}
}
private fun initData ( ) {
private fun initData ( searchKey : String = " " ) {
App . db . rssSourceDao . liveEnabled ( ) . observe ( viewLifecycleOwner , {
liveRssData ?. removeObservers ( this )
adapter . setItems ( it )
liveRssData = App . db . rssSourceDao . liveEnabled ( searchKey ) . apply {
} )
observe ( viewLifecycleOwner , {
adapter . setItems ( it )
} )
}
}
}
override fun openRss ( rssSource : RssSource ) {
override fun openRss ( rssSource : RssSource ) {