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:
@@ -5,15 +5,12 @@ import android.os.Bundle
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.app.ActivityCompat
|
||||
import org.oxycblt.auxio.theme.accent
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
|
||||
// Debug placeholder, ignore
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
|
||||
// Apply the theme
|
||||
setTheme(accent.second)
|
||||
|
||||
@@ -22,9 +19,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
ActivityCompat.postponeEnterTransition(this)
|
||||
setContentView(R.layout.activity_main)
|
||||
}
|
||||
}
|
||||
|
||||
// I wish I knew somewhere else to put this
|
||||
class ClickListener<T>(val onClick: (T) -> Unit)
|
||||
class ClickListener<T>(val onClick: (T) -> Unit)
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.oxycblt.auxio.theme.applyDivider
|
||||
class LibraryFragment : Fragment() {
|
||||
|
||||
private val musicModel: MusicViewModel by activityViewModels()
|
||||
private val libraryModel: LibraryViewModel by activityViewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@@ -29,8 +30,11 @@ class LibraryFragment : Fragment() {
|
||||
|
||||
binding.libraryRecycler.adapter = ArtistAdapter(
|
||||
musicModel.artists.value!!,
|
||||
ClickListener { navToArtist(it) }
|
||||
ClickListener {
|
||||
navToArtist(it)
|
||||
}
|
||||
)
|
||||
|
||||
binding.libraryRecycler.applyDivider()
|
||||
binding.libraryRecycler.setHasFixedSize(true)
|
||||
|
||||
@@ -39,11 +43,21 @@ class LibraryFragment : Fragment() {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
private fun navToArtist(artist: Artist) {
|
||||
// Don't navigate to a fragment multiple times if multiple items are accepted.
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
findNavController().navigate(
|
||||
MainFragmentDirections.actionShowArtist(artist.id)
|
||||
)
|
||||
libraryModel.isAlreadyNavigating = false
|
||||
}
|
||||
|
||||
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)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.ClickListener
|
||||
import org.oxycblt.auxio.databinding.ItemAlbumBinding
|
||||
import org.oxycblt.auxio.databinding.ItemArtistBinding
|
||||
import org.oxycblt.auxio.music.models.Album
|
||||
import org.oxycblt.auxio.music.models.Artist
|
||||
|
||||
class ArtistAdapter(
|
||||
@@ -47,9 +45,7 @@ class ArtistAdapter(
|
||||
fun bind(artist: Artist) {
|
||||
binding.artist = artist
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
listener.onClick(artist)
|
||||
}
|
||||
binding.root.setOnClickListener { listener.onClick(artist) }
|
||||
|
||||
// Force-update the layout so ellipsizing works.
|
||||
binding.artistName.requestLayout()
|
||||
|
||||
@@ -103,9 +103,8 @@ class LoadingFragment : Fragment(R.layout.fragment_loading) {
|
||||
binding.loadingBar.visibility = View.GONE
|
||||
|
||||
if (response == MusicLoaderResponse.DONE) {
|
||||
exitTransition = TransitionInflater.from(requireContext()).inflateTransition(
|
||||
R.transition.transition_to_main
|
||||
)
|
||||
exitTransition = TransitionInflater.from(requireContext())
|
||||
.inflateTransition(R.transition.transition_to_main)
|
||||
|
||||
findNavController().navigate(
|
||||
LoadingFragmentDirections.actionToMain()
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.oxycblt.auxio.coil
|
||||
package org.oxycblt.auxio.music.coil
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.oxycblt.auxio.coil
|
||||
package org.oxycblt.auxio.music.coil
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
@@ -4,9 +4,7 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.ClickListener
|
||||
import org.oxycblt.auxio.databinding.ItemAlbumBinding
|
||||
import org.oxycblt.auxio.databinding.ItemSongBinding
|
||||
import org.oxycblt.auxio.music.models.Album
|
||||
import org.oxycblt.auxio.music.models.Song
|
||||
|
||||
class SongAdapter(
|
||||
|
||||
@@ -5,11 +5,9 @@ import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import org.oxycblt.auxio.ClickListener
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentSongsBinding
|
||||
import org.oxycblt.auxio.music.MusicViewModel
|
||||
import org.oxycblt.auxio.theme.applyDivider
|
||||
@@ -25,9 +23,7 @@ class SongsFragment : Fragment() {
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val binding = DataBindingUtil.inflate<FragmentSongsBinding>(
|
||||
inflater, R.layout.fragment_songs, container, false
|
||||
)
|
||||
val binding = FragmentSongsBinding.inflate(inflater)
|
||||
|
||||
binding.songRecycler.adapter = SongAdapter(
|
||||
musicModel.songs.value!!,
|
||||
|
||||
@@ -33,10 +33,7 @@ private val ACCENTS = listOf(
|
||||
|
||||
val accent = ACCENTS[5]
|
||||
|
||||
fun getInactiveAlpha(color: Int): Int {
|
||||
return if (color == R.color.yellow) 100 else 150
|
||||
}
|
||||
|
||||
// Get the transparent variant of a color int
|
||||
fun getTransparentAccent(context: Context, color: Int, alpha: Int): Int {
|
||||
return ColorUtils.setAlphaComponent(
|
||||
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 {
|
||||
return try {
|
||||
ContextCompat.getColor(context, this)
|
||||
|
||||
Reference in New Issue
Block a user