Add artist image to DetailFragment

Add the artist image to the DetailFragment. Still considering what I want to do design-wise with this.
This commit is contained in:
OxygenCobalt 2020-09-13 19:32:33 -06:00
parent 860033ac14
commit 26b53bd502
21 changed files with 94 additions and 103 deletions

View file

@ -76,7 +76,7 @@ dependencies {
// Lint // Lint
ktlint "com.pinterest:ktlint:0.37.2" ktlint "com.pinterest:ktlint:0.37.2"
// Memory Leak checkin // Memory Leak checking
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4' debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
} }

View file

@ -5,15 +5,12 @@ import android.os.Bundle
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate import androidx.core.app.ActivityCompat
import org.oxycblt.auxio.theme.accent import org.oxycblt.auxio.theme.accent
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? { override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
// Debug placeholder, ignore
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
// Apply the theme // Apply the theme
setTheme(accent.second) setTheme(accent.second)
@ -22,9 +19,10 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
ActivityCompat.postponeEnterTransition(this)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
} }
} }
// I wish I knew somewhere else to put this // I wish I knew somewhere else to put this
class ClickListener<T>(val onClick: (T) -> Unit) class ClickListener<T>(val onClick: (T) -> Unit)

View file

@ -19,6 +19,7 @@ import org.oxycblt.auxio.theme.applyDivider
class LibraryFragment : Fragment() { class LibraryFragment : Fragment() {
private val musicModel: MusicViewModel by activityViewModels() private val musicModel: MusicViewModel by activityViewModels()
private val libraryModel: LibraryViewModel by activityViewModels()
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
@ -29,8 +30,11 @@ class LibraryFragment : Fragment() {
binding.libraryRecycler.adapter = ArtistAdapter( binding.libraryRecycler.adapter = ArtistAdapter(
musicModel.artists.value!!, musicModel.artists.value!!,
ClickListener { navToArtist(it) } ClickListener {
navToArtist(it)
}
) )
binding.libraryRecycler.applyDivider() binding.libraryRecycler.applyDivider()
binding.libraryRecycler.setHasFixedSize(true) binding.libraryRecycler.setHasFixedSize(true)
@ -39,11 +43,21 @@ class LibraryFragment : Fragment() {
return binding.root return binding.root
} }
private fun navToArtist(artist: Artist) { override fun onResume() {
// Don't navigate to a fragment multiple times if multiple items are accepted. super.onResume()
findNavController().navigate( libraryModel.isAlreadyNavigating = false
MainFragmentDirections.actionShowArtist(artist.id) }
)
private fun navToArtist(artist: Artist) {
if (!libraryModel.isAlreadyNavigating) {
libraryModel.isAlreadyNavigating = true
// When navigation, pass the artistImage of the item as a shared element to create
// the image popup.
findNavController().navigate(
MainFragmentDirections.actionShowArtist(artist.id)
)
}
} }
} }

View file

@ -4,9 +4,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import org.oxycblt.auxio.ClickListener import org.oxycblt.auxio.ClickListener
import org.oxycblt.auxio.databinding.ItemAlbumBinding
import org.oxycblt.auxio.databinding.ItemArtistBinding import org.oxycblt.auxio.databinding.ItemArtistBinding
import org.oxycblt.auxio.music.models.Album
import org.oxycblt.auxio.music.models.Artist import org.oxycblt.auxio.music.models.Artist
class ArtistAdapter( class ArtistAdapter(
@ -47,9 +45,7 @@ class ArtistAdapter(
fun bind(artist: Artist) { fun bind(artist: Artist) {
binding.artist = artist binding.artist = artist
binding.root.setOnClickListener { binding.root.setOnClickListener { listener.onClick(artist) }
listener.onClick(artist)
}
// Force-update the layout so ellipsizing works. // Force-update the layout so ellipsizing works.
binding.artistName.requestLayout() binding.artistName.requestLayout()

View file

@ -103,9 +103,8 @@ class LoadingFragment : Fragment(R.layout.fragment_loading) {
binding.loadingBar.visibility = View.GONE binding.loadingBar.visibility = View.GONE
if (response == MusicLoaderResponse.DONE) { if (response == MusicLoaderResponse.DONE) {
exitTransition = TransitionInflater.from(requireContext()).inflateTransition( exitTransition = TransitionInflater.from(requireContext())
R.transition.transition_to_main .inflateTransition(R.transition.transition_to_main)
)
findNavController().navigate( findNavController().navigate(
LoadingFragmentDirections.actionToMain() LoadingFragmentDirections.actionToMain()

View file

@ -1,4 +1,4 @@
package org.oxycblt.auxio.coil package org.oxycblt.auxio.music.coil
import android.content.Context import android.content.Context
import android.graphics.Bitmap import android.graphics.Bitmap

View file

@ -1,4 +1,4 @@
package org.oxycblt.auxio.coil package org.oxycblt.auxio.music.coil
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri

View file

@ -4,9 +4,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import org.oxycblt.auxio.ClickListener import org.oxycblt.auxio.ClickListener
import org.oxycblt.auxio.databinding.ItemAlbumBinding
import org.oxycblt.auxio.databinding.ItemSongBinding import org.oxycblt.auxio.databinding.ItemSongBinding
import org.oxycblt.auxio.music.models.Album
import org.oxycblt.auxio.music.models.Song import org.oxycblt.auxio.music.models.Song
class SongAdapter( class SongAdapter(

View file

@ -5,11 +5,9 @@ import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import org.oxycblt.auxio.ClickListener import org.oxycblt.auxio.ClickListener
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentSongsBinding import org.oxycblt.auxio.databinding.FragmentSongsBinding
import org.oxycblt.auxio.music.MusicViewModel import org.oxycblt.auxio.music.MusicViewModel
import org.oxycblt.auxio.theme.applyDivider import org.oxycblt.auxio.theme.applyDivider
@ -25,9 +23,7 @@ class SongsFragment : Fragment() {
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
val binding = DataBindingUtil.inflate<FragmentSongsBinding>( val binding = FragmentSongsBinding.inflate(inflater)
inflater, R.layout.fragment_songs, container, false
)
binding.songRecycler.adapter = SongAdapter( binding.songRecycler.adapter = SongAdapter(
musicModel.songs.value!!, musicModel.songs.value!!,

View file

@ -33,10 +33,7 @@ private val ACCENTS = listOf(
val accent = ACCENTS[5] val accent = ACCENTS[5]
fun getInactiveAlpha(color: Int): Int { // Get the transparent variant of a color int
return if (color == R.color.yellow) 100 else 150
}
fun getTransparentAccent(context: Context, color: Int, alpha: Int): Int { fun getTransparentAccent(context: Context, color: Int, alpha: Int): Int {
return ColorUtils.setAlphaComponent( return ColorUtils.setAlphaComponent(
ContextCompat.getColor(context, color), ContextCompat.getColor(context, color),
@ -44,6 +41,12 @@ fun getTransparentAccent(context: Context, color: Int, alpha: Int): Int {
) )
} }
// Get the inactive transparency of an accent
fun getInactiveAlpha(color: Int): Int {
return if (color == R.color.yellow) 100 else 150
}
// Convert an integer to a color
fun Int.toColor(context: Context): Int { fun Int.toColor(context: Context): Int {
return try { return try {
ContextCompat.getColor(context, this) ContextCompat.getColor(context, this)

View file

@ -10,7 +10,7 @@
type="org.oxycblt.auxio.music.models.Artist" /> type="org.oxycblt.auxio.music.models.Artist" />
</data> </data>
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
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="vertical"
@ -22,14 +22,22 @@
android:layout_height="?android:attr/actionBarSize" android:layout_height="?android:attr/actionBarSize"
android:background="?android:attr/windowBackground" android:background="?android:attr/windowBackground"
android:elevation="@dimen/elevation_normal" android:elevation="@dimen/elevation_normal"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Bold" app:layout_constraintTop_toTopOf="parent"
app:title="@string/title_library_fragment" app:title="@string/title_library_fragment"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Bold"
tools:titleTextColor="@color/blue" /> tools:titleTextColor="@color/blue" />
<TextView <ImageView
android:layout_width="wrap_content" android:id="@+id/artist_image"
android:layout_height="wrap_content" android:layout_width="@dimen/cover_size_huge"
android:text="@{artist.name}" /> android:layout_height="@dimen/cover_size_huge"
android:layout_margin="@dimen/margin_medium"
app:artistImage="@{artist}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
tools:ignore="ContentDescription"
tools:src="@drawable/ic_artist"
tools:tint="@color/blue" />
</LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</layout> </layout>

View file

@ -25,6 +25,6 @@
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_album" /> tools:listitem="@layout/item_artist" />
</LinearLayout> </LinearLayout>
</layout> </layout>

View file

@ -26,8 +26,9 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:src="@tools:sample/backgrounds/scenic" tools:ignore="ContentDescription"
tools:ignore="ContentDescription" /> tools:src="@drawable/ic_album"
tools:tint="@color/blue" />
<TextView <TextView
android:id="@+id/album_name" android:id="@+id/album_name"

View file

@ -22,12 +22,14 @@
android:id="@+id/artist_image" android:id="@+id/artist_image"
android:layout_width="@dimen/cover_size_normal" android:layout_width="@dimen/cover_size_normal"
android:layout_height="@dimen/cover_size_normal" android:layout_height="@dimen/cover_size_normal"
app:artistImage="@{artist}" android:src="@drawable/ic_exit"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:src="@tools:sample/backgrounds/scenic" app:artistImage="@{artist}"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription"
tools:src="@drawable/ic_artist"
tools:tint="@color/blue" />
<TextView <TextView
android:id="@+id/artist_name" android:id="@+id/artist_name"

View file

@ -26,8 +26,9 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:src="@tools:sample/backgrounds/scenic" tools:ignore="ContentDescription"
tools:ignore="ContentDescription" /> tools:src="@drawable/ic_song"
tools:tint="@color/blue" />
<TextView <TextView
android:id="@+id/song_name" android:id="@+id/song_name"

View file

@ -22,7 +22,11 @@
tools:layout="@layout/fragment_main"> tools:layout="@layout/fragment_main">
<action <action
android:id="@+id/action_show_artist" android:id="@+id/action_show_artist"
app:destination="@id/artist_detail_fragment" /> app:destination="@id/artist_detail_fragment"
app:enterAnim="@anim/fragment_fade_enter"
app:exitAnim="@anim/fragment_fade_exit"
app:popEnterAnim="@anim/fragment_fade_enter"
app:popExitAnim="@anim/fragment_fade_exit" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/artist_detail_fragment" android:id="@+id/artist_detail_fragment"

View file

@ -1,3 +1,3 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<fade xmlns:android="http://schemas.android.com/apk/res/android" <fade xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"/> android:duration="@android:integer/config_mediumAnimTime" />

View file

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background">#151515</color>
<color name="divider_color">#323232</color>
<color name="selection_color">#484848</color>
<!--
Base color set derived from Music Player GO.
https://github.com/enricocid/Music-Player-GO
-->
<color name="red">#ef9a9a</color>
<color name="pink">#f48fb1</color>
<color name="purple">#ce93d8</color>
<color name="deep_purple">#b39ddb</color>
<color name="indigo">#9fa8da</color>
<color name="blue">#90caf9</color>
<color name="light_blue">#81d4fa</color>
<color name="cyan">#80deea</color>
<color name="teal">#80cbc4</color>
<color name="green">#a5d6a7</color>
<color name="light_green">#c5e1a5</color>
<color name="lime">#e6ee9c</color>
<color name="yellow">#fff59d</color>
<color name="amber">#ffe082</color>
<color name="orange">#ffcc80</color>
<color name="deep_orange">#ffab91</color>
<color name="brown">#bcaaa4</color>
<color name="grey">#eeeeee</color>
<color name="blue_grey">#b0bec5</color>
</resources>

View file

@ -1,30 +1,30 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="background">#fafafa</color> <color name="background">#151515</color>
<color name="divider_color">#cbcbcb</color> <color name="divider_color">#323232</color>
<color name="selection_color">#cbcbcb</color> <color name="selection_color">#484848</color>
<!-- <!--
Base color set derived from Music Player GO. Base color set derived from Music Player GO.
https://github.com/enricocid/Music-Player-GO https://github.com/enricocid/Music-Player-GO
--> -->
<color name="red">#f44336</color> <color name="red">#ef9a9a</color>
<color name="pink">#e91e63</color> <color name="pink">#f48fb1</color>
<color name="purple">#9c27b0</color> <color name="purple">#ce93d8</color>
<color name="deep_purple">#673ab7</color> <color name="deep_purple">#b39ddb</color>
<color name="indigo">#3f51b5</color> <color name="indigo">#9fa8da</color>
<color name="blue">#2196f3</color> <color name="blue">#90caf9</color>
<color name="light_blue">#03a9f4</color> <color name="light_blue">#81d4fa</color>
<color name="cyan">#00bcd4</color> <color name="cyan">#80deea</color>
<color name="teal">#009688</color> <color name="teal">#80cbc4</color>
<color name="green">#4caf50</color> <color name="green">#a5d6a7</color>
<color name="light_green">#8bc34a</color> <color name="light_green">#c5e1a5</color>
<color name="lime">#cddc39</color> <color name="lime">#e6ee9c</color>
<color name="yellow">#ffeb3b</color> <color name="yellow">#fff59d</color>
<color name="amber">#ffc107</color> <color name="amber">#ffe082</color>
<color name="orange">#ff9800</color> <color name="orange">#ffcc80</color>
<color name="deep_orange">#ff5722</color> <color name="deep_orange">#ffab91</color>
<color name="brown">#795548</color> <color name="brown">#bcaaa4</color>
<color name="grey">#9e9e9e</color> <color name="grey">#eeeeee</color>
<color name="blue_grey">#607d8b</color> <color name="blue_grey">#b0bec5</color>
</resources> </resources>

View file

@ -13,6 +13,7 @@
<dimen name="cover_size_compact">44dp</dimen> <dimen name="cover_size_compact">44dp</dimen>
<dimen name="cover_size_normal">56dp</dimen> <dimen name="cover_size_normal">56dp</dimen>
<dimen name="cover_size_huge">168dp</dimen>
<dimen name="elevation_normal">4dp</dimen> <dimen name="elevation_normal">4dp</dimen>
</resources> </resources>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<!-- Base theme --> <!-- Base theme -->
<style name="Theme.Base" parent="Theme.AppCompat.DayNight.NoActionBar"> <style name="Theme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@color/background</item> <item name="android:windowBackground">@color/background</item>
<item name="android:statusBarColor">@android:color/black</item> <item name="android:statusBarColor">@android:color/black</item>
<item name="android:fontFamily">@font/inter</item> <item name="android:fontFamily">@font/inter</item>