From 530b42608b9ddbf1edd6f3a88403d7608e5c27e4 Mon Sep 17 00:00:00 2001 From: Hemanth S Date: Mon, 25 May 2020 00:02:32 +0530 Subject: [PATCH] Kotlin code refactor --- .../activities/AlbumDetailsActivity.kt | 29 +++++-------------- .../activities/ArtistDetailActivity.kt | 15 +++------- .../tageditor/AlbumTagEditorActivity.kt | 4 +-- .../retromusic/adapter/album/AlbumAdapter.kt | 2 +- .../adapter/album/AlbumFullWidthAdapter.kt | 2 +- .../adapter/artist/ArtistAdapter.kt | 2 +- .../adapter/song/PlaylistSongAdapter.kt | 2 +- .../retromusic/adapter/song/SongAdapter.kt | 2 +- app/src/main/res/layout/activity_about.xml | 4 ++- .../res/layout/activity_artist_details.xml | 6 ++-- app/src/main/res/layout/card_credit.xml | 10 ++++--- app/src/main/res/layout/card_other.xml | 4 +-- app/src/main/res/layout/card_social.xml | 4 +-- app/src/main/res/layout/item_contributor.xml | 11 +++---- 14 files changed, 41 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt index 2a1185d4..8f2340c1 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt @@ -25,6 +25,7 @@ import code.name.monkey.retromusic.adapter.album.HorizontalAlbumAdapter import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog import code.name.monkey.retromusic.dialogs.DeleteSongsDialog +import code.name.monkey.retromusic.extensions.extraNotNull import code.name.monkey.retromusic.extensions.ripAlpha import code.name.monkey.retromusic.extensions.show import code.name.monkey.retromusic.extensions.surfaceColor @@ -101,34 +102,23 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C setLightNavigationBar(true) setBottomBarVisibility(View.GONE) window.sharedElementsUseOverlay = true + windowEnterTransition() App.musicComponent.inject(this) albumDetailsPresenter.attachView(this) + val albumId = extraNotNull(EXTRA_ALBUM_ID).value + albumDetailsPresenter.loadAlbum(albumId) - if (intent.extras!!.containsKey(EXTRA_ALBUM_ID)) { - intent.extras?.getInt(EXTRA_ALBUM_ID)?.let { - albumDetailsPresenter.loadAlbum(it) - albumCoverContainer?.transitionName = - "${getString(R.string.transition_album_art)}_$it" - } - } else { - finish() - } - - windowEnterTransition() ActivityCompat.postponeEnterTransition(this) - - - artistImage = findViewById(R.id.artistImage) - setupRecyclerView() + artistImage = findViewById(R.id.artistImage) artistImage.setOnClickListener { val artistPairs = ActivityOptions.makeSceneTransitionAnimation( this, UtilPair.create( artistImage, - "${getString(R.string.transition_artist_image)}_${album.artistId}" + getString(R.string.transition_artist_image) ) ) NavigationUtil.goToArtistOptions(this, album.artistId, artistPairs) @@ -394,11 +384,8 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C } private fun reload() { - if (intent.extras!!.containsKey(EXTRA_ALBUM_ID)) { - intent.extras?.getInt(EXTRA_ALBUM_ID)?.let { albumDetailsPresenter.loadAlbum(it) } - } else { - finish() - } + val albumId = extraNotNull(EXTRA_ALBUM_ID).value + albumDetailsPresenter.loadAlbum(albumId) } override fun onBackPressed() { diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt index 6b2154a6..f16f2871 100755 --- a/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt @@ -22,6 +22,7 @@ import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity import code.name.monkey.retromusic.adapter.album.HorizontalAlbumAdapter import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog +import code.name.monkey.retromusic.extensions.extraNotNull import code.name.monkey.retromusic.extensions.ripAlpha import code.name.monkey.retromusic.extensions.show import code.name.monkey.retromusic.extensions.surfaceColor @@ -95,21 +96,13 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView, setLightNavigationBar(true) setBottomBarVisibility(View.GONE) window.sharedElementsUseOverlay = true + windowEnterTransition() App.musicComponent.inject(this) artistDetailsPresenter.attachView(this) + val artistId = extraNotNull(EXTRA_ARTIST_ID).value + artistDetailsPresenter.loadArtist(artistId) - if (intent.extras!!.containsKey(EXTRA_ARTIST_ID)) { - intent.extras?.getInt(EXTRA_ARTIST_ID)?.let { - artistDetailsPresenter.loadArtist(it) - val name = "${getString(R.string.transition_artist_image)}_$it" - artistCoverContainer?.transitionName = name - } - } else { - finish() - } - - windowEnterTransition() ActivityCompat.postponeEnterTransition(this) setupRecyclerView() diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AlbumTagEditorActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AlbumTagEditorActivity.kt index b2968404..b66a0a49 100755 --- a/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AlbumTagEditorActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AlbumTagEditorActivity.kt @@ -91,7 +91,7 @@ class AlbumTagEditorActivity : AbsTagEditorActivity(), TextWatcher { setDrawUnderStatusBar() super.onCreate(savedInstanceState) window.sharedElementsUseOverlay = true - imageContainer?.transitionName = "${getString(R.string.transition_album_art)}_$id" + imageContainer?.transitionName = getString(R.string.transition_album_art) windowEnterTransition() setUpViews() setupToolbar() @@ -162,7 +162,7 @@ class AlbumTagEditorActivity : AbsTagEditorActivity(), TextWatcher { writeValuesToFiles( fieldKeyValueMap, - if (deleteAlbumArt) ArtworkInfo(id, null) + if (deleteAlbumArt) AbsTagEditorActivity.ArtworkInfo(id, null) else if (albumArtBitmap == null) null else ArtworkInfo(id, albumArtBitmap!!) ) } diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt index 83f97aee..691852b5 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt @@ -180,7 +180,7 @@ open class AlbumAdapter( val activityOptions = ActivityOptions.makeSceneTransitionAnimation( activity, imageContainerCard ?: image, - "${activity.getString(R.string.transition_album_art)}_${dataSet[layoutPosition].id}" + activity.getString(R.string.transition_album_art) ) NavigationUtil.goToAlbumOptions( activity, diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumFullWidthAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumFullWidthAdapter.kt index 9986fe28..5a774b20 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumFullWidthAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumFullWidthAdapter.kt @@ -100,7 +100,7 @@ class AlbumFullWidthAdapter( val activityOptions = ActivityOptions.makeSceneTransitionAnimation( activity, imageContainerCard ?: image, - "${activity.getString(R.string.transition_album_art)}_${dataSet[layoutPosition].id}" + activity.getString(R.string.transition_album_art) ) NavigationUtil.goToAlbumOptions(activity, dataSet[layoutPosition].id, activityOptions) } diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/artist/ArtistAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/artist/ArtistAdapter.kt index e85504d1..65aa15b5 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/artist/ArtistAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/artist/ArtistAdapter.kt @@ -142,7 +142,7 @@ class ArtistAdapter( val activityOptions = ActivityOptions.makeSceneTransitionAnimation( activity, imageContainerCard ?: image, - "${activity.getString(R.string.transition_artist_image)}_${dataSet[layoutPosition].id}" + activity.getString(R.string.transition_artist_image) ) NavigationUtil.goToArtistOptions( activity, dataSet[layoutPosition].id, activityOptions diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlaylistSongAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlaylistSongAdapter.kt index 6ffc8942..252c837a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlaylistSongAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlaylistSongAdapter.kt @@ -60,7 +60,7 @@ open class PlaylistSongAdapter( val activityOptions = ActivityOptions.makeSceneTransitionAnimation( activity, imageContainerCard ?: image, - "${activity.getString(R.string.transition_album_art)}_${song.albumId}" + activity.getString(R.string.transition_album_art) ) NavigationUtil.goToAlbumOptions(activity, song.albumId, activityOptions) return true diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/song/SongAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/song/SongAdapter.kt index e82d0513..86fbf94c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/song/SongAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/song/SongAdapter.kt @@ -186,7 +186,7 @@ open class SongAdapter( val activityOptions = ActivityOptions.makeSceneTransitionAnimation( activity, imageContainerCard ?: image, - "${activity.getString(R.string.transition_album_art)}_${song.albumId}" + activity.getString(R.string.transition_album_art) ) NavigationUtil.goToAlbumOptions(activity, song.albumId, activityOptions) return true diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 9189ab32..d7e87bb1 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -22,11 +22,13 @@ android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/colorSurface" app:liftOnScroll="true"> diff --git a/app/src/main/res/layout/activity_artist_details.xml b/app/src/main/res/layout/activity_artist_details.xml index fd82fb9c..fdbad70c 100755 --- a/app/src/main/res/layout/activity_artist_details.xml +++ b/app/src/main/res/layout/activity_artist_details.xml @@ -74,7 +74,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" - tools:srcCompat="@tools:sample/backgrounds/scenic[16]" /> + tools:srcCompat="@tools:sample/backgrounds/scenic" /> @@ -94,7 +94,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/artistCoverContainer" tools:ignore="MissingPrefix" - tools:text="Title" /> + tools:text="@tools:sample/full_names" /> + tools:text="@tools:sample/full_names" /> + android:layout_margin="4dp" + app:cardCornerRadius="@dimen/about_card_radius"> - + app:layout_constraintTop_toBottomOf="@+id/sb1" + tools:itemCount="3" + tools:listitem="@layout/item_contributor" /> \ No newline at end of file diff --git a/app/src/main/res/layout/card_other.xml b/app/src/main/res/layout/card_other.xml index b21e81d7..2900a941 100644 --- a/app/src/main/res/layout/card_other.xml +++ b/app/src/main/res/layout/card_other.xml @@ -3,8 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" - app:cardCornerRadius="@dimen/about_card_radius" - app:cardUseCompatPadding="true"> + android:layout_margin="4dp" + app:cardCornerRadius="@dimen/about_card_radius"> + android:layout_margin="4dp" + app:cardCornerRadius="@dimen/about_card_radius"> + tools:srcCompat="@tools:sample/backgrounds/scenic" /> + tools:text="@tools:sample/lorem/random" /> \ No newline at end of file