Code Cleanup

This commit is contained in:
Prathamesh More 2022-01-29 00:04:46 +05:30
parent 2bffff1eaa
commit 5c1a88b32b
17 changed files with 46 additions and 43 deletions

View file

@ -351,10 +351,10 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
}
private fun updateColor() {
libraryViewModel.paletteColor.observe(this, { color ->
libraryViewModel.paletteColor.observe(this) { color ->
this.paletteColor = color
onPaletteColorChanged()
})
}
}
fun setBottomNavVisibility(visible: Boolean, animate: Boolean = false, hideBottomSheet: Boolean = MusicPlayerRemote.playingQueue.isEmpty()) {

View file

@ -122,9 +122,9 @@ class AboutFragment : Fragment(R.layout.fragment_about), View.OnClickListener {
itemAnimator = DefaultItemAnimator()
adapter = contributorAdapter
}
libraryViewModel.fetchContributors().observe(viewLifecycleOwner, { contributors ->
libraryViewModel.fetchContributors().observe(viewLifecycleOwner) { contributors ->
contributorAdapter.swapData(contributors)
})
}
}
override fun onDestroyView() {

View file

@ -122,7 +122,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
binding.toolbar.title = " "
ViewCompat.setTransitionName(binding.albumCoverContainer, arguments.extraAlbumId.toString())
postponeEnterTransition()
detailsViewModel.getAlbum().observe(viewLifecycleOwner, {
detailsViewModel.getAlbum().observe(viewLifecycleOwner) {
requireView().doOnPreDraw {
startPostponedEnterTransition()
}
@ -133,7 +133,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
} else {
ViewCompat.setTransitionName(binding.artistImage, album.artistId.toString())
}
})
}
setupRecyclerView()
binding.artistImage.setOnClickListener { artistView ->
@ -236,17 +236,17 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
simpleSongAdapter.swapDataSet(album.songs)
if (albumArtistExists) {
detailsViewModel.getAlbumArtist(album.albumArtist.toString())
.observe(viewLifecycleOwner, {
.observe(viewLifecycleOwner) {
loadArtistImage(it)
})
}
} else {
detailsViewModel.getArtist(album.artistId).observe(viewLifecycleOwner, {
detailsViewModel.getArtist(album.artistId).observe(viewLifecycleOwner) {
loadArtistImage(it)
})
}
}
detailsViewModel.getAlbumInfo(album).observe(viewLifecycleOwner, { result ->
detailsViewModel.getAlbumInfo(album).observe(viewLifecycleOwner) { result ->
when (result) {
is Result.Loading -> {
println("Loading")
@ -258,7 +258,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
aboutAlbum(result.data)
}
}
})
}
}
private fun moreAlbums(albums: List<Album>) {
@ -305,9 +305,9 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
}
private fun loadArtistImage(artist: Artist) {
detailsViewModel.getMoreAlbums(artist).observe(viewLifecycleOwner, {
detailsViewModel.getMoreAlbums(artist).observe(viewLifecycleOwner) {
moreAlbums(it)
})
}
GlideApp.with(requireContext()).asBitmapPalette().artistImageOptions(artist)
//.forceDownload(PreferenceUtil.isAllowedToDownloadMetadata())
.load(

View file

@ -48,12 +48,12 @@ class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridL
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
libraryViewModel.getAlbums().observe(viewLifecycleOwner, {
libraryViewModel.getAlbums().observe(viewLifecycleOwner) {
if (it.isNotEmpty())
adapter?.swapDataSet(it)
else
adapter?.swapDataSet(listOf())
})
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
if (!handleBackPress()) {
remove()

View file

@ -92,12 +92,12 @@ abstract class AbsArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragm
(artistId ?: artistName).toString()
)
postponeEnterTransition()
detailsViewModel.getArtist().observe(viewLifecycleOwner, {
detailsViewModel.getArtist().observe(viewLifecycleOwner) {
requireView().doOnPreDraw {
startPostponedEnterTransition()
}
showArtist(it)
})
}
setupRecyclerView()
binding.fragmentArtistContent.playAction.apply {
@ -180,13 +180,13 @@ abstract class AbsArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragm
biography = null
this.lang = lang
detailsViewModel.getArtistInfo(name, lang, null)
.observe(viewLifecycleOwner, { result ->
.observe(viewLifecycleOwner) { result ->
when (result) {
is Result.Loading -> println("Loading")
is Result.Error -> println("Error")
is Result.Success -> artistInfo(result.data)
}
})
}
}
private fun artistInfo(lastFmArtist: LastFmArtist?) {

View file

@ -49,12 +49,12 @@ class ArtistsFragment : AbsRecyclerViewCustomGridSizeFragment<ArtistAdapter, Gri
IArtistClickListener, IAlbumArtistClickListener, ICabHolder {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
libraryViewModel.getArtists().observe(viewLifecycleOwner, {
libraryViewModel.getArtists().observe(viewLifecycleOwner) {
if (it.isNotEmpty())
adapter?.swapDataSet(it)
else
adapter?.swapDataSet(listOf())
})
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
if (!handleBackPress()) {
remove()

View file

@ -41,7 +41,7 @@ class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupC
_binding = FragmentBackupBinding.bind(view)
initAdapter()
setupRecyclerview()
backupViewModel.backupsLiveData.observe(this) {
backupViewModel.backupsLiveData.observe(viewLifecycleOwner) {
if (it.isNotEmpty())
backupAdapter?.swapDataset(it)
else

View file

@ -86,11 +86,11 @@ abstract class AbsRecyclerViewFragment<A : RecyclerView.Adapter<*>, LM : Recycle
} else {
binding.shuffleButton.isVisible = false
}
libraryViewModel.getFabMargin().observe(viewLifecycleOwner, {
libraryViewModel.getFabMargin().observe(viewLifecycleOwner) {
binding.shuffleButton.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = it
}
})
}
}
open fun onShuffleClicked() {

View file

@ -62,9 +62,9 @@ class GenreDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playlist_
genre = arguments.extraGenre
binding.toolbar.title = arguments.extraGenre.name
setupRecyclerView()
detailsViewModel.getSongs().observe(viewLifecycleOwner, {
detailsViewModel.getSongs().observe(viewLifecycleOwner) {
songs(it)
})
}
postponeEnterTransition()
view.doOnPreDraw {
startPostponedEnterTransition()

View file

@ -40,12 +40,12 @@ GenresFragment : AbsRecyclerViewFragment<GenreAdapter, LinearLayoutManager>(),
IGenreClickListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
libraryViewModel.getGenre().observe(viewLifecycleOwner, {
libraryViewModel.getGenre().observe(viewLifecycleOwner) {
if (it.isNotEmpty())
adapter?.swapDataSet(it)
else
adapter?.swapDataSet(listOf())
})
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
remove()
requireActivity().onBackPressed()

View file

@ -77,12 +77,12 @@ class HomeFragment :
layoutManager = LinearLayoutManager(mainActivity)
adapter = homeAdapter
}
libraryViewModel.getHome().observe(viewLifecycleOwner, {
libraryViewModel.getHome().observe(viewLifecycleOwner) {
homeAdapter.swapData(it)
})
libraryViewModel.getSuggestions().observe(viewLifecycleOwner, {
}
libraryViewModel.getSuggestions().observe(viewLifecycleOwner) {
loadSuggestions(it)
})
}
loadProfile()
setupTitle()

View file

@ -114,11 +114,11 @@ class UserInfoFragment : Fragment() {
view.doOnPreDraw {
startPostponedEnterTransition()
}
libraryViewModel.getFabMargin().observe(viewLifecycleOwner, {
libraryViewModel.getFabMargin().observe(viewLifecycleOwner) {
binding.next.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = it
}
})
}
}
private fun loadProfile() {

View file

@ -132,7 +132,7 @@ class FullPlayerFragment : AbsPlayerFragment(R.layout.fragment_full) {
private fun updateArtistImage() {
libraryViewModel.artist(MusicPlayerRemote.currentSong.artistId)
.observe(viewLifecycleOwner, { artist ->
.observe(viewLifecycleOwner) { artist ->
if (artist.id != -1L) {
GlideApp.with(requireActivity()).asBitmapPalette().artistImageOptions(artist)
.load(RetroGlideExtension.getArtistModel(artist))
@ -142,7 +142,7 @@ class FullPlayerFragment : AbsPlayerFragment(R.layout.fragment_full) {
})
}
})
}
}
override fun onQueueChanged() {

View file

@ -88,9 +88,9 @@ class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWa
if (savedInstanceState != null) {
query = savedInstanceState.getString(QUERY)
}
libraryViewModel.getSearchResult().observe(viewLifecycleOwner, {
libraryViewModel.getSearchResult().observe(viewLifecycleOwner) {
showData(it)
})
}
setupChips()
postponeEnterTransition()
view.doOnPreDraw {

View file

@ -42,12 +42,12 @@ class SongsFragment : AbsRecyclerViewCustomGridSizeFragment<SongAdapter, GridLay
ICabHolder {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
libraryViewModel.getSongs().observe(viewLifecycleOwner, {
libraryViewModel.getSongs().observe(viewLifecycleOwner) {
if (it.isNotEmpty())
adapter?.swapDataSet(it)
else
adapter?.swapDataSet(listOf())
})
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
if (!handleBackPress()) {
remove()

View file

@ -30,6 +30,7 @@ import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.res.ResourcesCompat;
import java.io.File;
import java.io.FileOutputStream;
@ -100,7 +101,7 @@ public class ImageUtil {
public static Drawable getVectorDrawable(
@NonNull Resources res, @DrawableRes int resId, @Nullable Resources.Theme theme) {
return res.getDrawable(resId, theme);
return ResourcesCompat.getDrawable(res,resId, theme);
}
/** Makes sure that {@code mTempBuffer} has at least length {@code size}. */

View file

@ -25,6 +25,8 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import androidx.core.content.res.ResourcesCompat;
import code.name.monkey.retromusic.R;
/**
@ -222,7 +224,7 @@ public class SeekArc extends View {
* provides notifications of when the user starts and stops a touch gesture within the SeekArc.
*
* @param l The seek bar notification listener
* @see SeekArc.OnSeekBarChangeListener
* @see SeekArc.OnSeekArcChangeListener
*/
public void setOnSeekArcChangeListener(OnSeekArcChangeListener l) {
mOnSeekArcChangeListener = l;