fix: banner crash

This commit is contained in:
aayush262 2024-05-02 00:39:27 +05:30
parent 31c509f88c
commit 71870ff235
10 changed files with 366 additions and 127 deletions

View file

@ -204,22 +204,22 @@ class AnimeFragment : Fragment() {
if (i) {
model.getUpdated().observe(viewLifecycleOwner) {
if (it != null) {
animePageAdapter.updateRecent(MediaAdaptor(0, it, requireActivity()))
animePageAdapter.updateRecent(MediaAdaptor(0, it, requireActivity()), it)
}
}
model.getMovies().observe(viewLifecycleOwner) {
if (it != null) {
animePageAdapter.updateMovies(MediaAdaptor(0, it, requireActivity()))
animePageAdapter.updateMovies(MediaAdaptor(0, it, requireActivity()), it)
}
}
model.getTopRated().observe(viewLifecycleOwner) {
if (it != null) {
animePageAdapter.updateTopRated(MediaAdaptor(0, it, requireActivity()))
animePageAdapter.updateTopRated(MediaAdaptor(0, it, requireActivity()), it)
}
}
model.getMostFav().observe(viewLifecycleOwner) {
if (it != null) {
animePageAdapter.updateMostFav(MediaAdaptor(0, it, requireActivity()))
animePageAdapter.updateMostFav(MediaAdaptor(0, it, requireActivity()), it)
}
}
if (animePageAdapter.trendingViewPager != null) {

View file

@ -13,6 +13,7 @@ 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
@ -23,11 +24,14 @@ import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.currContext
import ani.dantotsu.databinding.ItemAnimePageBinding
import ani.dantotsu.databinding.LayoutTrendingBinding
import ani.dantotsu.getAppString
import ani.dantotsu.getThemeColor
import ani.dantotsu.loadImage
import ani.dantotsu.media.CalendarActivity
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
@ -193,13 +197,16 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
LayoutAnimationController(setSlideIn(), 0.25f)
}
fun updateRecent(adaptor: MediaAdaptor) {
fun updateRecent(adaptor: MediaAdaptor, media: MutableList<Media>) {
binding.apply {
init(
adaptor,
animeUpdatedRecyclerView,
animeUpdatedProgressBar,
animeRecently
animeRecently,
animeRecentlyMore,
getAppString(R.string.updated),
media
)
animePopular.visibility = View.VISIBLE
animePopular.startAnimation(setSlideUp())
@ -210,40 +217,49 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
}
fun updateMovies(adaptor: MediaAdaptor) {
fun updateMovies(adaptor: MediaAdaptor, media: MutableList<Media>) {
binding.apply {
init(
adaptor,
animeMoviesRecyclerView,
animeMoviesProgressBar,
animeMovies
animeMovies,
animeMoviesMore,
getAppString(R.string.trending_movies),
media
)
}
}
fun updateTopRated(adaptor: MediaAdaptor) {
fun updateTopRated(adaptor: MediaAdaptor, media: MutableList<Media>) {
binding.apply {
init(
adaptor,
animeTopRatedRecyclerView,
animeTopRatedProgressBar,
animeTopRated
animeTopRated,
animeTopRatedMore,
getAppString(R.string.top_rated),
media
)
}
}
fun updateMostFav(adaptor: MediaAdaptor) {
fun updateMostFav(adaptor: MediaAdaptor, media: MutableList<Media>) {
binding.apply {
init(
adaptor,
animeMostFavRecyclerView,
animeMostFavProgressBar,
animeMostFav
animeMostFav,
animeMostFavMore,
getAppString(R.string.most_favourite),
media
)
}
}
fun init(adaptor: MediaAdaptor, recyclerView: RecyclerView, progress: View, title: View) {
fun init(adaptor: MediaAdaptor, recyclerView: RecyclerView, progress: View, title: View , more: View , string: String, media : MutableList<Media>) {
progress.visibility = View.GONE
recyclerView.adapter = adaptor
recyclerView.layoutManager =
@ -252,9 +268,19 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
LinearLayoutManager.HORIZONTAL,
false
)
more.setOnClickListener {
ContextCompat.startActivity(
it.context, Intent(it.context, MediaListViewActivity::class.java)
.putExtra("title", string)
.putExtra("media", media as ArrayList<Media>),
null
)
}
recyclerView.visibility = View.VISIBLE
title.visibility = View.VISIBLE
more.visibility = View.VISIBLE
title.startAnimation(setSlideUp())
more.startAnimation(setSlideUp())
recyclerView.layoutAnimation =
LayoutAnimationController(setSlideIn(), 0.25f)
}

View file

@ -233,10 +233,10 @@ class HomeFragment : Fragment() {
false
)
more.setOnClickListener { _ ->
MediaListViewActivity.mediaList = it
ContextCompat.startActivity(
requireActivity(), Intent(requireActivity(), MediaListViewActivity::class.java)
.putExtra("title", string),
.putExtra("title", string)
.putExtra("media", it),
null
)
}
@ -249,6 +249,7 @@ class HomeFragment : Fragment() {
}
more.visibility = View.VISIBLE
title.visibility = View.VISIBLE
more.startAnimation(setSlideUp())
title.startAnimation(setSlideUp())
progress.visibility = View.GONE
}

View file

@ -162,12 +162,12 @@ class MangaFragment : Fragment() {
if (i == true) {
model.getPopularNovel().observe(viewLifecycleOwner) {
if (it != null) {
mangaPageAdapter.updateNovel(MediaAdaptor(0, it, requireActivity()))
mangaPageAdapter.updateNovel(MediaAdaptor(0, it, requireActivity()), it)
}
}
model.getPopularManga().observe(viewLifecycleOwner) {
if (it != null) {
mangaPageAdapter.updateTrendingManga(MediaAdaptor(0, it, requireActivity()))
mangaPageAdapter.updateTrendingManga(MediaAdaptor(0, it, requireActivity()), it)
}
}
model.getPopularManhwa().observe(viewLifecycleOwner) {
@ -177,18 +177,18 @@ class MangaFragment : Fragment() {
0,
it,
requireActivity()
)
), it
)
}
}
model.getTopRated().observe(viewLifecycleOwner) {
if (it != null) {
mangaPageAdapter.updateTopRated(MediaAdaptor(0, it, requireActivity()))
mangaPageAdapter.updateTopRated(MediaAdaptor(0, it, requireActivity()), it)
}
}
model.getMostFav().observe(viewLifecycleOwner) {
if (it != null) {
mangaPageAdapter.updateMostFav(MediaAdaptor(0, it, requireActivity()))
mangaPageAdapter.updateMostFav(MediaAdaptor(0, it, requireActivity()), it)
}
}
if (mangaPageAdapter.trendingViewPager != null) {

View file

@ -22,10 +22,13 @@ import ani.dantotsu.R
import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.databinding.ItemMangaPageBinding
import ani.dantotsu.databinding.LayoutTrendingBinding
import ani.dantotsu.getAppString
import ani.dantotsu.getThemeColor
import ani.dantotsu.loadImage
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
@ -178,65 +181,80 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
}
fun updateTrendingManga(adaptor: MediaAdaptor) {
fun updateTrendingManga(adaptor: MediaAdaptor, media: MutableList<Media>) {
binding.apply {
init(
adaptor,
mangaTrendingMangaRecyclerView,
mangaTrendingMangaProgressBar,
mangaTrendingManga
mangaTrendingManga,
mangaTrendingMangaMore,
getAppString(R.string.trending_manga),
media
)
}
}
fun updateTrendingManhwa(adaptor: MediaAdaptor) {
fun updateTrendingManhwa(adaptor: MediaAdaptor, media: MutableList<Media>) {
binding.apply {
init(
adaptor,
mangaTrendingManhwaRecyclerView,
mangaTrendingManhwaProgressBar,
mangaTrendingManhwa
mangaTrendingManhwa,
mangaTrendingManhwaMore,
getAppString(R.string.trending_manhwa),
media
)
}
}
fun updateNovel(adaptor: MediaAdaptor) {
fun updateNovel(adaptor: MediaAdaptor, media: MutableList<Media>) {
binding.apply {
init(
adaptor,
mangaNovelRecyclerView,
mangaNovelProgressBar,
mangaNovel
mangaNovel,
mangaNovelMore,
getAppString(R.string.trending_novel),
media
)
}
}
fun updateTopRated(adaptor: MediaAdaptor) {
fun updateTopRated(adaptor: MediaAdaptor, media: MutableList<Media>) {
binding.apply {
init(
adaptor,
mangaTopRatedRecyclerView,
mangaTopRatedProgressBar,
mangaTopRated
mangaTopRated,
mangaTopRatedMore,
getAppString(R.string.top_rated),
media
)
}
}
fun updateMostFav(adaptor: MediaAdaptor) {
fun updateMostFav(adaptor: MediaAdaptor, media: MutableList<Media>) {
binding.apply {
init(
adaptor,
mangaMostFavRecyclerView,
mangaMostFavProgressBar,
mangaMostFav
mangaMostFav,
mangaMostFavMore,
getAppString(R.string.most_favourite),
media
)
mangaPopular.visibility = View.VISIBLE
mangaPopular.startAnimation(setSlideUp())
}
}
fun init(adaptor: MediaAdaptor, recyclerView: RecyclerView, progress: View, title: View) {
fun init(adaptor: MediaAdaptor, recyclerView: RecyclerView, progress: View, title: View , more: View , string: String, media : MutableList<Media>) {
progress.visibility = View.GONE
recyclerView.adapter = adaptor
recyclerView.layoutManager =
@ -245,9 +263,19 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
LinearLayoutManager.HORIZONTAL,
false
)
more.setOnClickListener {
ContextCompat.startActivity(
it.context, Intent(it.context, MediaListViewActivity::class.java)
.putExtra("title", string)
.putExtra("media", media as ArrayList<Media>),
null
)
}
recyclerView.visibility = View.VISIBLE
title.visibility = View.VISIBLE
more.visibility = View.VISIBLE
title.startAnimation(setSlideUp())
more.startAnimation(setSlideUp())
recyclerView.layoutAnimation =
LayoutAnimationController(setSlideIn(), 0.25f)
}