Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Commit

Permalink
HomeFragment: Redesigned some stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Shinjo Akane <akane@akanework.org>
  • Loading branch information
AkaneTan committed Jul 17, 2023
1 parent e251017 commit 34d2e7f
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Copyright (C) 2023 Akane Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.akanework.symphonica.ui.adapter

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.google.android.material.card.MaterialCardView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.akanework.symphonica.MainActivity
import org.akanework.symphonica.MainActivity.Companion.controllerViewModel
import org.akanework.symphonica.MainActivity.Companion.fullSheetShuffleButton
import org.akanework.symphonica.R
import org.akanework.symphonica.SymphonicaApplication
import org.akanework.symphonica.logic.data.Song
import org.akanework.symphonica.logic.util.addToNext
import org.akanework.symphonica.logic.util.broadcastMetaDataUpdate
import org.akanework.symphonica.logic.util.replacePlaylist
import org.akanework.symphonica.ui.fragment.LibraryAlbumDisplayFragment

/**
* This is the carousel adapter used for
* songs.
*/
class SongHorizontalRecyclerViewAdapter(private val songList: MutableList<Song>) :
RecyclerView.Adapter<SongHorizontalRecyclerViewAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.home_carousel_card_recent, parent, false)
return ViewHolder(view)
}

override fun getItemCount(): Int = songList.size

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
Glide.with(holder.songCover.context)
.load(songList[position].imgUri)
.diskCacheStrategy(MainActivity.diskCacheStrategyCustom)
.placeholder(R.drawable.ic_song_outline_default_cover)
.into(holder.songCover)

holder.songName.text = songList[position].title
holder.songAuthor.text = songList[position].artist

holder.container.setOnClickListener {
if (controllerViewModel.shuffleState) {
controllerViewModel.shuffleState = false
fullSheetShuffleButton!!.isChecked = false
}
replacePlaylist(songList, position)
}

holder.itemView.setOnLongClickListener {
val rootView = MaterialAlertDialogBuilder(
holder.itemView.context,
com.google.android.material.R.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered
)
.setTitle(holder.itemView.context.getString(R.string.dialog_long_press_title))
.setView(R.layout.alert_dialog_long_press)
.setNeutralButton(SymphonicaApplication.context.getString(R.string.dialog_song_dismiss)) { dialog, _ ->
dialog.dismiss()
}
.show()

val addToNextButton = rootView.findViewById<FrameLayout>(R.id.dialog_add_to_next)
val checkAlbumButton = rootView.findViewById<FrameLayout>(R.id.dialog_check_album)

checkAlbumButton!!.setOnClickListener {
val albumBundle = Bundle().apply {
if (MainActivity.libraryViewModel.librarySortedAlbumList.isNotEmpty()) {
putInt("Position",
MainActivity.libraryViewModel.librarySortedAlbumList.indexOf(
MainActivity.libraryViewModel.librarySortedAlbumList.find {
it.songList.contains(songList[position])
}
))
} else {
putInt("Position", MainActivity.libraryViewModel.libraryAlbumList.indexOf(
MainActivity.libraryViewModel.libraryAlbumList.find {
it.songList.contains(songList[position])
}
))
}
}
val albumFragment = LibraryAlbumDisplayFragment().apply {
arguments = albumBundle
}

MainActivity.customFragmentManager.beginTransaction()
.replace(R.id.fragmentContainer, albumFragment)
.addToBackStack(null)
.commit()
rootView.dismiss()
}

addToNextButton!!.setOnClickListener {
addToNext(songList[position])

broadcastMetaDataUpdate()

rootView.dismiss()
}

true
}
}

/**
* Upon creation, viewbinding everything.
*/
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val songCover: ImageView = view.findViewById(R.id.carousel_image_view)
val container: MaterialCardView = view.findViewById(R.id.carousel_item_container)
val songName: TextView = view.findViewById(R.id.carousel_song_name)
val songAuthor: TextView = view.findViewById(R.id.carousel_author_name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.google.android.material.card.MaterialCardView
Expand Down Expand Up @@ -59,6 +60,8 @@ class SongRecyclerViewAdapter(private val songList: MutableList<Song>) :
.placeholder(R.drawable.ic_song_outline_default_cover)
.into(holder.songCover)

holder.songName.text = songList[position].title

holder.container.setOnClickListener {
if (controllerViewModel.shuffleState) {
controllerViewModel.shuffleState = false
Expand Down Expand Up @@ -128,5 +131,6 @@ class SongRecyclerViewAdapter(private val songList: MutableList<Song>) :
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val songCover: ImageView = view.findViewById(R.id.carousel_image_view)
val container: MaterialCardView = view.findViewById(R.id.carousel_item_container)
val songName: TextView = view.findViewById(R.id.carousel_song_name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import android.widget.ImageView
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.CollapsingToolbarLayout
import com.google.android.material.appbar.MaterialToolbar
Expand All @@ -54,6 +55,7 @@ import org.akanework.symphonica.PAGE_TRANSITION_DURATION
import org.akanework.symphonica.R
import org.akanework.symphonica.logic.data.Song
import org.akanework.symphonica.logic.util.replacePlaylist
import org.akanework.symphonica.ui.adapter.SongHorizontalRecyclerViewAdapter
import org.akanework.symphonica.ui.adapter.SongRecyclerViewAdapter
import kotlin.math.abs

Expand Down Expand Up @@ -186,10 +188,9 @@ class HomeFragment : Fragment() {
shuffleAdapter = SongRecyclerViewAdapter(shuffleList)
shuffleRecyclerView.adapter = shuffleAdapter

val recentLayoutManager = LinearLayoutManager(context)
recentLayoutManager.orientation = RecyclerView.HORIZONTAL
val recentLayoutManager = StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.HORIZONTAL)
recentRecyclerView.layoutManager = recentLayoutManager
recentAdapter = SongRecyclerViewAdapter(recentList)
recentAdapter = SongHorizontalRecyclerViewAdapter(recentList)
recentRecyclerView.adapter = recentAdapter

loadingPrompt = rootView.findViewById(R.id.loading_prompt_list)
Expand Down Expand Up @@ -277,7 +278,7 @@ class HomeFragment : Fragment() {
private var isInitialized: Boolean = true
private lateinit var loadingPrompt: MaterialCardView
private lateinit var shuffleAdapter: SongRecyclerViewAdapter
private lateinit var recentAdapter: SongRecyclerViewAdapter
private lateinit var recentAdapter: SongHorizontalRecyclerViewAdapter

/**
* This is used for outer class to switch [loadingPrompt].
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@
app:iconGravity="textStart"
app:iconPadding="0dp"
app:iconSize="30sp"
app:iconTint="?attr/colorControlNormal" />
app:iconTint="?attr/colorOnSurface" />
</FrameLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/shuffle_recycler_view"
android:layout_width="match_parent"
android:layout_height="196dp"
android:layout_height="180dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" />

Expand All @@ -235,12 +235,10 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recent_recycler_view"
android:layout_width="match_parent"
android:layout_height="196dp"
android:layout_height="204dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom

="32dp" />
android:layout_marginBottom="32dp" />
</LinearLayout>

</androidx.core.widget.NestedScrollView>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/global_bottom_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:strokeWidth="0dp">
style="?attr/materialCardViewElevatedStyle">

<ImageView
android:layout_width="match_parent"
Expand Down
46 changes: 36 additions & 10 deletions app/src/main/res/layout/home_carousel_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,41 @@
android:id="@+id/carousel_item_container"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_width="150dp"
android:layout_height="196dp"
android:foreground="?attr/selectableItemBackground">
android:layout_width="wrap_content"
android:layout_height="180dp"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="4dp"
app:strokeWidth="0dp">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<com.google.android.material.card.MaterialCardView
android:layout_width="150dp"
android:layout_height="150dp"
app:cardCornerRadius="12dp">
<ImageView
android:id="@+id/carousel_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:importantForAccessibility="no"
android:scaleType="centerCrop"
android:src="@drawable/ic_song_outline_default_cover" />
</com.google.android.material.card.MaterialCardView>

<TextView
android:id="@+id/carousel_song_name"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/unknown_song"
android:singleLine="true"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="?attr/colorOnSurface"/>

</LinearLayout>

<ImageView
android:id="@+id/carousel_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:importantForAccessibility="no"
android:scaleType="centerCrop"
android:src="@drawable/ic_song_outline_default_cover" />
</com.google.android.material.card.MaterialCardView>
74 changes: 74 additions & 0 deletions app/src/main/res/layout/home_carousel_card_recent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2023 Akane Foundation
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/carousel_item_container"
android:layout_marginStart="4dp"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="4dp"
app:strokeWidth="0dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<com.google.android.material.card.MaterialCardView
android:layout_width="60dp"
android:layout_height="60dp"
app:cardCornerRadius="6dp">
<ImageView
android:id="@+id/carousel_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:importantForAccessibility="no"
android:scaleType="centerCrop"
android:src="@drawable/ic_song_outline_default_cover" />
</com.google.android.material.card.MaterialCardView>

<LinearLayout
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/carousel_song_name"
android:layout_marginStart="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/unknown_song"
android:singleLine="true"
android:textSize="14sp"
android:textColor="?attr/colorOnSurface"/>

<TextView
android:id="@+id/carousel_author_name"
android:layout_marginStart="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/unknown_song"
android:singleLine="true"
android:textSize="14sp"
android:textColor="?attr/colorOnSurfaceVariant"/>
</LinearLayout>

</LinearLayout>

</com.google.android.material.card.MaterialCardView>

0 comments on commit 34d2e7f

Please sign in to comment.