mirror of
https://github.com/rebelonion/Dantotsu.git
synced 2026-01-30 16:01:01 +00:00
feat: searching
This commit is contained in:
@@ -24,7 +24,7 @@ import ani.dantotsu.Refresh
|
||||
import ani.dantotsu.bottomBar
|
||||
import ani.dantotsu.connections.anilist.Anilist
|
||||
import ani.dantotsu.connections.anilist.AnilistAnimeViewModel
|
||||
import ani.dantotsu.connections.anilist.SearchResults
|
||||
import ani.dantotsu.connections.anilist.AniMangaSearchResults
|
||||
import ani.dantotsu.connections.anilist.getUserId
|
||||
import ani.dantotsu.databinding.FragmentAnimeBinding
|
||||
import ani.dantotsu.media.MediaAdaptor
|
||||
@@ -100,7 +100,7 @@ class AnimeFragment : Fragment() {
|
||||
var loading = true
|
||||
if (model.notSet) {
|
||||
model.notSet = false
|
||||
model.searchResults = SearchResults(
|
||||
model.aniMangaSearchResults = AniMangaSearchResults(
|
||||
"ANIME",
|
||||
isAdult = false,
|
||||
onList = false,
|
||||
@@ -109,7 +109,7 @@ class AnimeFragment : Fragment() {
|
||||
sort = Anilist.sortBy[1]
|
||||
)
|
||||
}
|
||||
val popularAdaptor = MediaAdaptor(1, model.searchResults.results, requireActivity())
|
||||
val popularAdaptor = MediaAdaptor(1, model.aniMangaSearchResults.results, requireActivity())
|
||||
val progressAdaptor = ProgressAdapter(searched = model.searched)
|
||||
val adapter = ConcatAdapter(animePageAdapter, popularAdaptor, progressAdaptor)
|
||||
binding.animePageRecyclerView.adapter = adapter
|
||||
@@ -142,7 +142,7 @@ class AnimeFragment : Fragment() {
|
||||
animePageAdapter.onIncludeListClick = { checked ->
|
||||
oldIncludeList = !checked
|
||||
loading = true
|
||||
model.searchResults.results.clear()
|
||||
model.aniMangaSearchResults.results.clear()
|
||||
popularAdaptor.notifyDataSetChanged()
|
||||
scope.launch(Dispatchers.IO) {
|
||||
model.loadPopular("ANIME", sort = Anilist.sortBy[1], onList = checked)
|
||||
@@ -152,17 +152,17 @@ class AnimeFragment : Fragment() {
|
||||
model.getPopular().observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
if (oldIncludeList == (it.onList != false)) {
|
||||
val prev = model.searchResults.results.size
|
||||
model.searchResults.results.addAll(it.results)
|
||||
val prev = model.aniMangaSearchResults.results.size
|
||||
model.aniMangaSearchResults.results.addAll(it.results)
|
||||
popularAdaptor.notifyItemRangeInserted(prev, it.results.size)
|
||||
} else {
|
||||
model.searchResults.results.addAll(it.results)
|
||||
model.aniMangaSearchResults.results.addAll(it.results)
|
||||
popularAdaptor.notifyDataSetChanged()
|
||||
oldIncludeList = it.onList ?: true
|
||||
}
|
||||
model.searchResults.onList = it.onList
|
||||
model.searchResults.hasNextPage = it.hasNextPage
|
||||
model.searchResults.page = it.page
|
||||
model.aniMangaSearchResults.onList = it.onList
|
||||
model.aniMangaSearchResults.hasNextPage = it.hasNextPage
|
||||
model.aniMangaSearchResults.page = it.page
|
||||
if (it.hasNextPage)
|
||||
progressAdaptor.bar?.visibility = View.VISIBLE
|
||||
else {
|
||||
@@ -177,10 +177,10 @@ class AnimeFragment : Fragment() {
|
||||
RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(v: RecyclerView, dx: Int, dy: Int) {
|
||||
if (!v.canScrollVertically(1)) {
|
||||
if (model.searchResults.hasNextPage && model.searchResults.results.isNotEmpty() && !loading) {
|
||||
if (model.aniMangaSearchResults.hasNextPage && model.aniMangaSearchResults.results.isNotEmpty() && !loading) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
loading = true
|
||||
model.loadNextPage(model.searchResults)
|
||||
model.loadNextPage(model.aniMangaSearchResults)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@@ -21,7 +20,6 @@ import androidx.viewpager2.widget.ViewPager2
|
||||
import ani.dantotsu.MediaPageTransformer
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.connections.anilist.Anilist
|
||||
import ani.dantotsu.currContext
|
||||
import ani.dantotsu.databinding.ItemAnimePageBinding
|
||||
import ani.dantotsu.databinding.LayoutTrendingBinding
|
||||
import ani.dantotsu.getAppString
|
||||
@@ -32,7 +30,6 @@ import ani.dantotsu.media.GenreActivity
|
||||
import ani.dantotsu.media.Media
|
||||
import ani.dantotsu.media.MediaAdaptor
|
||||
import ani.dantotsu.media.MediaListViewActivity
|
||||
import ani.dantotsu.media.SearchActivity
|
||||
import ani.dantotsu.profile.ProfileActivity
|
||||
import ani.dantotsu.px
|
||||
import ani.dantotsu.setSafeOnClickListener
|
||||
@@ -83,12 +80,11 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
|
||||
|
||||
updateAvatar()
|
||||
|
||||
trendingBinding.searchBar.hint = "ANIME"
|
||||
trendingBinding.searchBar.hint = binding.root.context.getString(R.string.search)
|
||||
trendingBinding.searchBarText.setOnClickListener {
|
||||
ContextCompat.startActivity(
|
||||
it.context,
|
||||
Intent(it.context, SearchActivity::class.java).putExtra("type", "ANIME"),
|
||||
null
|
||||
SearchBottomSheet.newInstance().show(
|
||||
(binding.root.context as AppCompatActivity).supportFragmentManager,
|
||||
"search"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import ani.dantotsu.Refresh
|
||||
import ani.dantotsu.bottomBar
|
||||
import ani.dantotsu.connections.anilist.Anilist
|
||||
import ani.dantotsu.connections.anilist.AnilistMangaViewModel
|
||||
import ani.dantotsu.connections.anilist.SearchResults
|
||||
import ani.dantotsu.connections.anilist.AniMangaSearchResults
|
||||
import ani.dantotsu.connections.anilist.getUserId
|
||||
import ani.dantotsu.databinding.FragmentMangaBinding
|
||||
import ani.dantotsu.media.MediaAdaptor
|
||||
@@ -94,7 +94,7 @@ class MangaFragment : Fragment() {
|
||||
var loading = true
|
||||
if (model.notSet) {
|
||||
model.notSet = false
|
||||
model.searchResults = SearchResults(
|
||||
model.aniMangaSearchResults = AniMangaSearchResults(
|
||||
"MANGA",
|
||||
isAdult = false,
|
||||
onList = false,
|
||||
@@ -103,7 +103,7 @@ class MangaFragment : Fragment() {
|
||||
sort = Anilist.sortBy[1]
|
||||
)
|
||||
}
|
||||
val popularAdaptor = MediaAdaptor(1, model.searchResults.results, requireActivity())
|
||||
val popularAdaptor = MediaAdaptor(1, model.aniMangaSearchResults.results, requireActivity())
|
||||
val progressAdaptor = ProgressAdapter(searched = model.searched)
|
||||
binding.mangaPageRecyclerView.adapter =
|
||||
ConcatAdapter(mangaPageAdapter, popularAdaptor, progressAdaptor)
|
||||
@@ -135,10 +135,10 @@ class MangaFragment : Fragment() {
|
||||
RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(v: RecyclerView, dx: Int, dy: Int) {
|
||||
if (!v.canScrollVertically(1)) {
|
||||
if (model.searchResults.hasNextPage && model.searchResults.results.isNotEmpty() && !loading) {
|
||||
if (model.aniMangaSearchResults.hasNextPage && model.aniMangaSearchResults.results.isNotEmpty() && !loading) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
loading = true
|
||||
model.loadNextPage(model.searchResults)
|
||||
model.loadNextPage(model.aniMangaSearchResults)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,7 @@ class MangaFragment : Fragment() {
|
||||
mangaPageAdapter.onIncludeListClick = { checked ->
|
||||
oldIncludeList = !checked
|
||||
loading = true
|
||||
model.searchResults.results.clear()
|
||||
model.aniMangaSearchResults.results.clear()
|
||||
popularAdaptor.notifyDataSetChanged()
|
||||
scope.launch(Dispatchers.IO) {
|
||||
model.loadPopular("MANGA", sort = Anilist.sortBy[1], onList = checked)
|
||||
@@ -230,17 +230,17 @@ class MangaFragment : Fragment() {
|
||||
model.getPopular().observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
if (oldIncludeList == (it.onList != false)) {
|
||||
val prev = model.searchResults.results.size
|
||||
model.searchResults.results.addAll(it.results)
|
||||
val prev = model.aniMangaSearchResults.results.size
|
||||
model.aniMangaSearchResults.results.addAll(it.results)
|
||||
popularAdaptor.notifyItemRangeInserted(prev, it.results.size)
|
||||
} else {
|
||||
model.searchResults.results.addAll(it.results)
|
||||
model.aniMangaSearchResults.results.addAll(it.results)
|
||||
popularAdaptor.notifyDataSetChanged()
|
||||
oldIncludeList = it.onList ?: true
|
||||
}
|
||||
model.searchResults.onList = it.onList
|
||||
model.searchResults.hasNextPage = it.hasNextPage
|
||||
model.searchResults.page = it.page
|
||||
model.aniMangaSearchResults.onList = it.onList
|
||||
model.aniMangaSearchResults.hasNextPage = it.hasNextPage
|
||||
model.aniMangaSearchResults.page = it.page
|
||||
if (it.hasNextPage)
|
||||
progressAdaptor.bar?.visibility = View.VISIBLE
|
||||
else {
|
||||
|
||||
@@ -82,12 +82,11 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
|
||||
trendingBinding.notificationCount.isVisible = Anilist.unreadNotificationCount > 0
|
||||
&& PrefManager.getVal<Boolean>(PrefName.ShowNotificationRedDot) == true
|
||||
trendingBinding.notificationCount.text = Anilist.unreadNotificationCount.toString()
|
||||
trendingBinding.searchBar.hint = "MANGA"
|
||||
trendingBinding.searchBar.hint = binding.root.context.getString(R.string.search)
|
||||
trendingBinding.searchBarText.setOnClickListener {
|
||||
ContextCompat.startActivity(
|
||||
it.context,
|
||||
Intent(it.context, SearchActivity::class.java).putExtra("type", "MANGA"),
|
||||
null
|
||||
SearchBottomSheet.newInstance().show(
|
||||
(binding.root.context as AppCompatActivity).supportFragmentManager,
|
||||
"search"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
74
app/src/main/java/ani/dantotsu/home/SearchBottomSheet.kt
Normal file
74
app/src/main/java/ani/dantotsu/home/SearchBottomSheet.kt
Normal file
@@ -0,0 +1,74 @@
|
||||
package ani.dantotsu.home
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import ani.dantotsu.BottomSheetDialogFragment
|
||||
import ani.dantotsu.connections.anilist.AnilistSearch.SearchType
|
||||
import ani.dantotsu.connections.anilist.AnilistSearch.SearchType.Companion.toAnilistString
|
||||
import ani.dantotsu.databinding.BottomSheetSearchBinding
|
||||
import ani.dantotsu.media.SearchActivity
|
||||
|
||||
class SearchBottomSheet : BottomSheetDialogFragment() {
|
||||
private var _binding: BottomSheetSearchBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = BottomSheetSearchBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.animeSearch.setOnClickListener {
|
||||
startActivity(requireContext(), SearchType.ANIME)
|
||||
dismiss()
|
||||
}
|
||||
binding.mangaSearch.setOnClickListener {
|
||||
startActivity(requireContext(), SearchType.MANGA)
|
||||
dismiss()
|
||||
}
|
||||
binding.characterSearch.setOnClickListener {
|
||||
startActivity(requireContext(), SearchType.CHARACTER)
|
||||
dismiss()
|
||||
}
|
||||
binding.staffSearch.setOnClickListener {
|
||||
startActivity(requireContext(), SearchType.STAFF)
|
||||
dismiss()
|
||||
}
|
||||
binding.studioSearch.setOnClickListener {
|
||||
startActivity(requireContext(), SearchType.STUDIO)
|
||||
dismiss()
|
||||
}
|
||||
binding.userSearch.setOnClickListener {
|
||||
startActivity(requireContext(), SearchType.USER)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun startActivity(context: Context, type: SearchType) {
|
||||
ContextCompat.startActivity(
|
||||
context,
|
||||
Intent(context, SearchActivity::class.java).putExtra("type", type.toAnilistString()),
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun newInstance() = SearchBottomSheet()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user