feat(Media List view): switch between grid and list view

This commit is contained in:
aayush262 2024-05-02 14:34:49 +05:30
parent 3a88656e21
commit e9551be62d
6 changed files with 75 additions and 19 deletions

View file

@ -232,9 +232,9 @@ class HomeFragment : Fragment() {
LinearLayoutManager.HORIZONTAL, LinearLayoutManager.HORIZONTAL,
false false
) )
more.setOnClickListener { _ -> more.setOnClickListener { i ->
ContextCompat.startActivity( ContextCompat.startActivity(
requireActivity(), Intent(requireActivity(), MediaListViewActivity::class.java) i.context, Intent(i.context, MediaListViewActivity::class.java)
.putExtra("title", string) .putExtra("title", string)
.putExtra("media", it), .putExtra("media", it),
null null

View file

@ -221,7 +221,6 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
media media
) )
} }
} }
fun updateTopRated(adaptor: MediaAdaptor, media: MutableList<Media>) { fun updateTopRated(adaptor: MediaAdaptor, media: MutableList<Media>) {
@ -254,7 +253,15 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
} }
} }
fun init(adaptor: MediaAdaptor, recyclerView: RecyclerView, progress: View, title: View , more: View , string: String, media : MutableList<Media>) { fun init(
adaptor: MediaAdaptor,
recyclerView: RecyclerView,
progress: View,
title: View ,
more: View ,
string: String,
media : MutableList<Media>
) {
progress.visibility = View.GONE progress.visibility = View.GONE
recyclerView.adapter = adaptor recyclerView.adapter = adaptor
recyclerView.layoutManager = recyclerView.layoutManager =

View file

@ -1,6 +1,7 @@
package ani.dantotsu.media package ani.dantotsu.media
import android.os.Bundle import android.os.Bundle
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.Window import android.view.Window
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
@ -52,11 +53,36 @@ class MediaListViewActivity: AppCompatActivity() {
binding.listTitle.setTextColor(primaryTextColor) binding.listTitle.setTextColor(primaryTextColor)
val screenWidth = resources.displayMetrics.run { widthPixels / density } val screenWidth = resources.displayMetrics.run { widthPixels / density }
val mediaList = intent.getSerialized("media") as? ArrayList<Media> ?: ArrayList() val mediaList = intent.getSerialized("media") as? ArrayList<Media> ?: ArrayList()
val view = PrefManager.getCustomVal("mediaView", 0)
var mediaView: View = when (view) {
1 -> binding.mediaList
0 -> binding.mediaGrid
else -> binding.mediaGrid
}
mediaView.alpha = 1f
fun changeView(mode: Int, current: View) {
mediaView.alpha = 0.33f
mediaView = current
current.alpha = 1f
PrefManager.setCustomVal("mediaView", mode)
binding.mediaRecyclerView.adapter = MediaAdaptor(mode, mediaList, this)
binding.mediaRecyclerView.layoutManager = GridLayoutManager(
this,
if (mode == 1) 1 else (screenWidth / 120f).toInt()
)
}
binding.mediaList.setOnClickListener {
changeView(1, binding.mediaList)
}
binding.mediaGrid.setOnClickListener {
changeView(0, binding.mediaGrid)
}
binding.listTitle.text = intent.getStringExtra("title") binding.listTitle.text = intent.getStringExtra("title")
binding.mediaRecyclerView.adapter = MediaAdaptor(0, mediaList, this) binding.mediaRecyclerView.adapter = MediaAdaptor(view, mediaList, this)
binding.mediaRecyclerView.layoutManager = GridLayoutManager( binding.mediaRecyclerView.layoutManager = GridLayoutManager(
this, this,
(screenWidth / 120f).toInt() if (view == 1) 1 else (screenWidth / 120f).toInt()
) )
} }
} }

View file

@ -2,7 +2,8 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -18,12 +19,13 @@
android:id="@+id/settingsContainer" android:id="@+id/settingsContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="horizontal">
<TextView <TextView
android:id="@+id/listTitle" android:id="@+id/listTitle"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_weight="1"
android:layout_marginStart="32dp" android:layout_marginStart="32dp"
android:ellipsize="end" android:ellipsize="end"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
@ -33,7 +35,28 @@
android:textColor="?attr/colorOnBackground" android:textColor="?attr/colorOnBackground"
android:textSize="16sp" android:textSize="16sp"
tools:text="@string/app_name" /> tools:text="@string/app_name" />
<ImageView
android:id="@+id/mediaList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:alpha="0.33"
android:padding="8dp"
app:srcCompat="@drawable/ic_round_view_list_24"
app:tint="?attr/colorOnBackground"
tools:ignore="ContentDescription,ImageContrastCheck" />
<ImageView
android:id="@+id/mediaGrid"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:alpha="0.33"
android:padding="8dp"
android:layout_marginEnd="12dp"
app:srcCompat="@drawable/ic_round_grid_view_24"
app:tint="?attr/colorOnBackground"
tools:ignore="ContentDescription,ImageContrastCheck" />
</LinearLayout> </LinearLayout>

View file

@ -207,12 +207,12 @@
android:id="@+id/animeRecentlyMore" android:id="@+id/animeRecentlyMore"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="24dp" android:layout_marginEnd="12dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/arrow_mark" android:src="@drawable/arrow_mark"
android:textSize="16sp" android:textSize="16sp"
android:visibility="invisible"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
</LinearLayout> </LinearLayout>
@ -270,7 +270,7 @@
android:id="@+id/animeMoviesMore" android:id="@+id/animeMoviesMore"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="24dp" android:layout_marginEnd="12dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/arrow_mark" android:src="@drawable/arrow_mark"
@ -331,7 +331,7 @@
android:id="@+id/animeTopRatedMore" android:id="@+id/animeTopRatedMore"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="24dp" android:layout_marginEnd="12dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/arrow_mark" android:src="@drawable/arrow_mark"
@ -391,7 +391,7 @@
android:id="@+id/animeMostFavMore" android:id="@+id/animeMostFavMore"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="24dp" android:layout_marginEnd="12dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/arrow_mark" android:src="@drawable/arrow_mark"

View file

@ -148,7 +148,7 @@
android:id="@+id/mangaTrendingMangaMore" android:id="@+id/mangaTrendingMangaMore"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="24dp" android:layout_marginEnd="12dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/arrow_mark" android:src="@drawable/arrow_mark"
@ -208,7 +208,7 @@
android:id="@+id/mangaTrendingManhwaMore" android:id="@+id/mangaTrendingManhwaMore"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="24dp" android:layout_marginEnd="12dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/arrow_mark" android:src="@drawable/arrow_mark"
@ -267,7 +267,7 @@
android:id="@+id/mangaNovelMore" android:id="@+id/mangaNovelMore"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="24dp" android:layout_marginEnd="12dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/arrow_mark" android:src="@drawable/arrow_mark"
@ -326,7 +326,7 @@
android:id="@+id/mangaTopRatedMore" android:id="@+id/mangaTopRatedMore"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="24dp" android:layout_marginEnd="12dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/arrow_mark" android:src="@drawable/arrow_mark"
@ -383,7 +383,7 @@
android:id="@+id/mangaMostFavMore" android:id="@+id/mangaMostFavMore"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="24dp" android:layout_marginEnd="12dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/arrow_mark" android:src="@drawable/arrow_mark"