Code refactor

main
h4h13 2020-02-17 20:38:20 +05:30
parent 87954b43f2
commit dac7bd16b7
20 changed files with 91 additions and 74 deletions

View File

@ -22,8 +22,8 @@ android {
vectorDrawables.useSupportLibrary = true
applicationId "code.name.monkey.retromusic"
versionCode 405
versionName '3.4.900'
versionCode 409
versionName '3.5.000'
multiDexEnabled true

View File

@ -22,6 +22,8 @@ import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.MainActivity
import code.name.monkey.retromusic.extensions.hide
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.views.OptionMenuItemView
@ -72,6 +74,10 @@ class OptionsSheetDialogFragment : DialogFragment(), View.OnClickListener {
actionFolders.setOnClickListener(this)
actionDriveMode.setOnClickListener(this)
if (MusicPlayerRemote.playingQueue.isEmpty()) {
actionDriveMode.hide()
}
materialDialog = MaterialDialog(requireActivity(), BottomSheet(LayoutMode.WRAP_CONTENT))
.show {
icon(R.mipmap.ic_launcher_round)

View File

@ -34,6 +34,7 @@ abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerVie
fun setAndSaveLayoutRes(layoutRes: Int) {
setLayoutRes(layoutRes)
saveLayoutRes(layoutRes)
invalidateAdapter()
}
private val maxGridSizeForList: Int

View File

@ -31,7 +31,7 @@ class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<AlbumAd
override fun onResume() {
super.onResume()
if (adapter!!.dataSet.isEmpty()) {
if (adapter!!.dataSet.isNullOrEmpty()) {
albumsPresenter.loadAlbums()
}
}

View File

@ -38,7 +38,7 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
override fun onResume() {
super.onResume()
if (adapter!!.dataSet.isEmpty()) {
if (adapter!!.dataSet.isNullOrEmpty()) {
artistsPresenter.loadArtists()
}
}

View File

@ -61,7 +61,7 @@ class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearL
override fun onResume() {
super.onResume()
if (adapter!!.dataSet.isEmpty()) {
if (adapter!!.dataSet.isNullOrEmpty()) {
genresPresenter.loadGenres()
}
}

View File

@ -27,7 +27,9 @@ import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog;
import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment;
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment;
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment;
import code.name.monkey.retromusic.helper.SortOrder;
import code.name.monkey.retromusic.helper.SortOrder.AlbumSortOrder;
import code.name.monkey.retromusic.helper.SortOrder.ArtistSortOrder;
import code.name.monkey.retromusic.helper.SortOrder.SongSortOrder;
import code.name.monkey.retromusic.interfaces.CabHolder;
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks;
import code.name.monkey.retromusic.util.NavigationUtil;
@ -301,49 +303,49 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
if (fragment instanceof AlbumsFragment) {
switch (item.getItemId()) {
case R.id.action_album_sort_order_asc:
sortOrder = SortOrder.AlbumSortOrder.ALBUM_A_Z;
sortOrder = AlbumSortOrder.ALBUM_A_Z;
break;
case R.id.action_album_sort_order_desc:
sortOrder = SortOrder.AlbumSortOrder.ALBUM_Z_A;
sortOrder = AlbumSortOrder.ALBUM_Z_A;
break;
case R.id.action_album_sort_order_artist:
sortOrder = SortOrder.AlbumSortOrder.ALBUM_ARTIST;
sortOrder = AlbumSortOrder.ALBUM_ARTIST;
break;
case R.id.action_album_sort_order_year:
sortOrder = SortOrder.AlbumSortOrder.ALBUM_YEAR;
sortOrder = AlbumSortOrder.ALBUM_YEAR;
break;
}
} else if (fragment instanceof ArtistsFragment) {
switch (item.getItemId()) {
case R.id.action_artist_sort_order_asc:
sortOrder = SortOrder.ArtistSortOrder.ARTIST_A_Z;
sortOrder = ArtistSortOrder.ARTIST_A_Z;
break;
case R.id.action_artist_sort_order_desc:
sortOrder = SortOrder.ArtistSortOrder.ARTIST_Z_A;
sortOrder = ArtistSortOrder.ARTIST_Z_A;
break;
}
} else if (fragment instanceof SongsFragment) {
switch (item.getItemId()) {
case R.id.action_song_sort_order_asc:
sortOrder = SortOrder.SongSortOrder.SONG_A_Z;
sortOrder = SongSortOrder.SONG_A_Z;
break;
case R.id.action_song_sort_order_desc:
sortOrder = SortOrder.SongSortOrder.SONG_Z_A;
sortOrder = SongSortOrder.SONG_Z_A;
break;
case R.id.action_song_sort_order_artist:
sortOrder = SortOrder.SongSortOrder.SONG_ARTIST;
sortOrder = SongSortOrder.SONG_ARTIST;
break;
case R.id.action_song_sort_order_album:
sortOrder = SortOrder.SongSortOrder.SONG_ALBUM;
sortOrder = SongSortOrder.SONG_ALBUM;
break;
case R.id.action_song_sort_order_year:
sortOrder = SortOrder.SongSortOrder.SONG_YEAR;
sortOrder = SongSortOrder.SONG_YEAR;
break;
case R.id.action_song_sort_order_date:
sortOrder = SortOrder.SongSortOrder.SONG_DATE;
sortOrder = SongSortOrder.SONG_DATE;
break;
case R.id.action_song_sort_order_composer:
sortOrder = SortOrder.SongSortOrder.COMPOSER;
sortOrder = SongSortOrder.COMPOSER;
break;
}
@ -452,33 +454,33 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
if (fragment instanceof AlbumsFragment) {
sortOrderMenu.add(0, R.id.action_album_sort_order_asc, 0, R.string.sort_order_a_z)
.setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_A_Z));
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_A_Z));
sortOrderMenu.add(0, R.id.action_album_sort_order_desc, 1, R.string.sort_order_z_a)
.setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_Z_A));
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_Z_A));
sortOrderMenu.add(0, R.id.action_album_sort_order_artist, 2, R.string.sort_order_artist)
.setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_ARTIST));
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_ARTIST));
sortOrderMenu.add(0, R.id.action_album_sort_order_year, 3, R.string.sort_order_year)
.setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_YEAR));
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_YEAR));
} else if (fragment instanceof ArtistsFragment) {
sortOrderMenu.add(0, R.id.action_artist_sort_order_asc, 0, R.string.sort_order_a_z)
.setChecked(currentSortOrder.equals(SortOrder.ArtistSortOrder.ARTIST_A_Z));
.setChecked(currentSortOrder.equals(ArtistSortOrder.ARTIST_A_Z));
sortOrderMenu.add(0, R.id.action_artist_sort_order_desc, 1, R.string.sort_order_z_a)
.setChecked(currentSortOrder.equals(SortOrder.ArtistSortOrder.ARTIST_Z_A));
.setChecked(currentSortOrder.equals(ArtistSortOrder.ARTIST_Z_A));
} else if (fragment instanceof SongsFragment) {
sortOrderMenu.add(0, R.id.action_song_sort_order_asc, 0, R.string.sort_order_a_z)
.setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_A_Z));
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_A_Z));
sortOrderMenu.add(0, R.id.action_song_sort_order_desc, 1, R.string.sort_order_z_a)
.setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_Z_A));
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_Z_A));
sortOrderMenu.add(0, R.id.action_song_sort_order_artist, 2, R.string.sort_order_artist)
.setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ARTIST));
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_ARTIST));
sortOrderMenu.add(0, R.id.action_song_sort_order_album, 3, R.string.sort_order_album)
.setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ALBUM));
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_ALBUM));
sortOrderMenu.add(0, R.id.action_song_sort_order_year, 4, R.string.sort_order_year)
.setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_YEAR));
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_YEAR));
sortOrderMenu.add(0, R.id.action_song_sort_order_date, 5, R.string.sort_order_date)
.setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_DATE));
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_DATE));
sortOrderMenu.add(0, R.id.action_song_sort_order_composer, 6, R.string.sort_order_composer)
.setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.COMPOSER));
.setChecked(currentSortOrder.equals(SongSortOrder.COMPOSER));
}
sortOrderMenu.setGroupCheckable(0, true, true);

View File

@ -14,7 +14,6 @@ import code.name.monkey.retromusic.mvp.presenter.PlaylistView
import code.name.monkey.retromusic.mvp.presenter.PlaylistsPresenter
import javax.inject.Inject
class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, LinearLayoutManager>(), PlaylistView {
@Inject
@ -38,13 +37,15 @@ class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, L
}
override fun createAdapter(): PlaylistAdapter {
return PlaylistAdapter(libraryFragment.mainActivity, ArrayList(),
R.layout.item_list, libraryFragment)
return PlaylistAdapter(
libraryFragment.mainActivity, ArrayList(),
R.layout.item_list, libraryFragment
)
}
override fun onResume() {
super.onResume()
if (adapter!!.dataSet.isEmpty()) {
if (adapter!!.dataSet.isNullOrEmpty()) {
playlistsPresenter.playlists()
}
}

View File

@ -79,7 +79,7 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
override fun onResume() {
super.onResume()
if (adapter?.itemCount != 0)
if (adapter?.dataSet.isNullOrEmpty())
songPresenter.loadSongs()
}

View File

@ -27,6 +27,7 @@ import code.name.monkey.retromusic.misc.SimpleOnSeekbarChangeListener
import code.name.monkey.retromusic.service.MusicService
import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.RetroUtil
import code.name.monkey.retromusic.util.ViewUtil
import kotlinx.android.synthetic.main.fragment_player_playback_controls.nextButton
import kotlinx.android.synthetic.main.fragment_player_playback_controls.playPauseButton
@ -158,10 +159,20 @@ class PlayerPlaybackControlsFragment : AbsPlayerControlsFragment(), OnSharedPref
}
private fun updatePlayPauseDrawableState() {
if (MusicPlayerRemote.isPlaying) {
playPauseButton.setImageResource(R.drawable.ic_pause_white_24dp)
val playResIcon = if (RetroUtil.isTablet()) {
R.drawable.ic_play_arrow_white_64dp
} else {
playPauseButton.setImageResource(R.drawable.ic_play_arrow_white_24dp)
R.drawable.ic_play_arrow_white_24dp
}
val pauseResIcon = if (RetroUtil.isTablet()) {
R.drawable.ic_pause_white_64dp
} else {
R.drawable.ic_pause_white_64dp
}
if (MusicPlayerRemote.isPlaying) {
playPauseButton.setImageResource(playResIcon)
} else {
playPauseButton.setImageResource(pauseResIcon)
}
}

View File

@ -103,7 +103,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:textAppearance="@style/TextViewHeadline4"
android:textAppearance="@style/TextViewHeadline5"
android:textStyle="bold"
tools:ignore="MissingPrefix"
tools:text="Album name" />

View File

@ -90,7 +90,7 @@
android:layout_height="wrap_content"
android:maxLines="2"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="@style/TextViewHeadline4"
android:textAppearance="@style/TextViewHeadline5"
android:textStyle="bold"
tools:ignore="MissingPrefix"
tools:text="Title" />

View File

@ -71,7 +71,6 @@
android:id="@+id/previousButton"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_centerVertical="true"
android:layout_marginStart="24dp"
android:background="?attr/roundSelector"
android:padding="16dp"
@ -85,14 +84,13 @@
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/playPauseButton"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:fabCustomSize="96dp"
app:maxImageSize="52dp"
android:background="@drawable/color_circle_gradient"
android:elevation="4dp"
android:padding="12dp"
app:layout_constraintBottom_toTopOf="@+id/volumeFragmentContainer"
app:layout_constraintStart_toEndOf="@id/previousButton"
app:layout_constraintTop_toBottomOf="@+id/songInfo"
@ -103,7 +101,6 @@
android:id="@+id/nextButton"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:background="?attr/roundSelector"
android:padding="16dp"

View File

@ -96,7 +96,7 @@
android:layout_marginEnd="16dp"
android:maxLines="3"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="@style/TextViewHeadline4"
android:textAppearance="@style/TextViewHeadline5"
android:textStyle="bold"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"

View File

@ -48,7 +48,7 @@
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/songs"
android:textAppearance="@style/TextViewHeadline5"
android:textAppearance="@style/TextViewHeadline6"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@ -71,7 +71,7 @@
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/songs"
android:textAppearance="@style/TextViewHeadline5"
android:textAppearance="@style/TextViewHeadline6"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
@ -102,7 +102,7 @@
android:layout_height="wrap_content"
android:padding="12dp"
android:text="@string/songs"
android:textAppearance="@style/TextViewHeadline5"
android:textAppearance="@style/TextViewHeadline6"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"

View File

@ -43,7 +43,7 @@
android:layout_height="wrap_content"
android:padding="12dp"
android:text="@string/albums"
android:textAppearance="@style/TextViewHeadline5"
android:textAppearance="@style/TextViewHeadline6"
android:textStyle="bold"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
@ -69,7 +69,7 @@
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/songs"
android:textAppearance="@style/TextViewHeadline5"
android:textAppearance="@style/TextViewHeadline6"
android:textStyle="bold"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
@ -83,8 +83,7 @@
android:nestedScrollingEnabled="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/songTitle"
tools:listitem="@layout/item_song"
tools:visibility="gone" />
tools:listitem="@layout/item_song" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/biographyTitle"
@ -92,7 +91,7 @@
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/biography"
android:textAppearance="@style/TextViewHeadline5"
android:textAppearance="@style/TextViewHeadline6"
android:textStyle="bold"
android:visibility="gone"
app:layout_constrainedWidth="true"

View File

@ -85,7 +85,7 @@
android:layout_marginEnd="16dp"
android:maxLines="2"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="@style/TextViewHeadline4"
android:textAppearance="@style/TextViewHeadline5"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

View File

@ -26,19 +26,6 @@
<include layout="@layout/status_bar" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/playerToolbar"
style="@style/Toolbar"
android:layout_gravity="bottom"
android:navigationIcon="@drawable/ic_keyboard_arrow_down_black_24dp"
app:navigationIcon="@drawable/ic_keyboard_arrow_down_black_24dp" />
</FrameLayout>
<code.name.monkey.retromusic.views.WidthFitSquareLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -63,5 +50,18 @@
android:layout_height="match_parent"
tools:layout="@layout/fragment_material_playback_controls" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/playerToolbar"
style="@style/Toolbar"
android:layout_gravity="bottom"
android:navigationIcon="@drawable/ic_keyboard_arrow_down_black_24dp"
app:navigationIcon="@drawable/ic_keyboard_arrow_down_black_24dp" />
</FrameLayout>
</LinearLayout>
</FrameLayout>

View File

@ -162,7 +162,7 @@
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/previousButton"
app:layout_constraintTop_toBottomOf="@+id/songInfo"
app:srcCompat="@drawable/ic_pause_white_64dp"
app:srcCompat="@drawable/ic_pause_white_24dp"
tools:tint="@color/md_black_1000" />
<androidx.appcompat.widget.AppCompatImageButton

View File

@ -30,7 +30,7 @@
app:cardUseCompatPadding="false"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
app:strokeWidth="0dp">
<FrameLayout
android:id="@+id/playerFragmentContainer"
android:layout_width="match_parent"