From 5ee566c09aef9a5cb26e6ad00dd822dc6066fb0e Mon Sep 17 00:00:00 2001 From: h4h13 Date: Mon, 4 Mar 2019 09:25:09 +0530 Subject: [PATCH] clean-arc --- app/build.gradle | 31 +++--- .../retromusic/appwidgets/AppWidgetClassic.kt | 9 +- .../retromusic/dialogs/AddToPlaylistDialog.kt | 6 +- .../dialogs/ClearSmartPlaylistDialog.kt | 2 +- .../dialogs/CreatePlaylistDialog.kt | 6 +- .../retromusic/dialogs/DeleteSongsDialog.kt | 4 +- .../dialogs/RemoveFromPlaylistDialog.kt | 6 +- .../dialogs/RenamePlaylistDialog.kt | 3 +- .../retromusic/dialogs/SongDetailDialog.kt | 3 +- .../retromusic/dialogs/SongShareDialog.kt | 6 +- .../retromusic/glide/RetroGlideExtension.java | 28 +++-- .../monkey/retromusic/helper/M3UWriter.kt | 12 +-- .../retromusic/helper/MusicPlayerRemote.kt | 3 +- .../retromusic/helper/SearchQueryHelper.kt | 8 +- .../retromusic/helper/menu/GenreMenuHelper.kt | 1 + .../helper/menu/PlaylistMenuHelper.kt | 1 + .../retromusic/helper/menu/SongMenuHelper.kt | 1 + .../retromusic/helper/menu/SongsMenuHelper.kt | 1 + .../monkey/retromusic/loaders/ArtistLoader.kt | 2 - .../loaders/LastAddedSongsLoader.kt | 4 +- .../retromusic/loaders/PlaylistSongsLoader.kt | 2 +- .../monkey/retromusic/loaders/SongLoader.kt | 2 +- .../retromusic/model/AbsCustomPlaylist.java | 15 +-- .../name/monkey/retromusic/model/Album.kt | 2 +- .../name/monkey/retromusic/model/Genre.java | 100 ------------------ .../name/monkey/retromusic/model/Genre.kt | 25 +++++ .../name/monkey/retromusic/model/Home.java | 66 ------------ .../code/name/monkey/retromusic/model/Home.kt | 31 ++++++ .../monkey/retromusic/model/Playlist.java | 86 --------------- .../name/monkey/retromusic/model/Playlist.kt | 21 ++++ .../monkey/retromusic/model/PlaylistSong.java | 84 +++++---------- .../name/monkey/retromusic/model/Song.java | 98 ----------------- .../code/name/monkey/retromusic/model/Song.kt | 31 ++++++ .../retromusic/model/lyrics/Lyrics.java | 34 +++--- .../model/smartplaylist/AbsSmartPlaylist.java | 53 ++-------- .../model/smartplaylist/HistoryPlaylist.java | 71 ------------- .../model/smartplaylist/HistoryPlaylist.kt | 36 +++++++ .../smartplaylist/LastAddedPlaylist.java | 71 ------------- .../model/smartplaylist/LastAddedPlaylist.kt | 32 ++++++ .../smartplaylist/MyTopTracksPlaylist.java | 73 ------------- .../smartplaylist/MyTopTracksPlaylist.kt | 36 +++++++ .../smartplaylist/ShuffleAllPlaylist.java | 71 ------------- .../model/smartplaylist/ShuffleAllPlaylist.kt | 35 ++++++ .../providers/MusicPlaybackQueueStore.java | 30 +++--- .../retromusic/service/MusicService.java | 51 +++++---- .../service/WearBrowserService.java | 28 ++--- .../ui/activities/ArtistDetailActivity.kt | 2 - .../ui/activities/LyricsActivity.kt | 2 +- .../adapter/album/AlbumCoverPagerAdapter.kt | 2 +- .../ui/adapter/playlist/PlaylistAdapter.kt | 2 - .../ui/adapter/song/AbsOffsetSongAdapter.kt | 2 +- .../retromusic/ui/adapter/song/SongAdapter.kt | 6 +- .../ui/fragments/base/AbsPlayerFragment.kt | 1 + .../fragments/mainactivity/SongsFragment.kt | 4 +- .../mainactivity/folders/FoldersFragment.java | 3 +- .../player/classic/ClassicPlayerFragment.kt | 2 +- .../fragments/player/color/ColorFragment.kt | 2 +- .../full/FullPlaybackControlsFragment.kt | 1 - .../monkey/retromusic/util/MusicUtil.java | 37 ++++--- .../retromusic/util/NavigationUtil.java | 5 +- .../monkey/retromusic/util/PlaylistsUtil.java | 20 ++-- settings.gradle | 2 +- 62 files changed, 477 insertions(+), 937 deletions(-) delete mode 100644 app/src/main/java/code/name/monkey/retromusic/model/Genre.java create mode 100644 app/src/main/java/code/name/monkey/retromusic/model/Genre.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/model/Home.java create mode 100644 app/src/main/java/code/name/monkey/retromusic/model/Home.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/model/Playlist.java create mode 100644 app/src/main/java/code/name/monkey/retromusic/model/Playlist.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/model/Song.java create mode 100644 app/src/main/java/code/name/monkey/retromusic/model/Song.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/HistoryPlaylist.java create mode 100644 app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/HistoryPlaylist.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/LastAddedPlaylist.java create mode 100644 app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/LastAddedPlaylist.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/MyTopTracksPlaylist.java create mode 100644 app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/MyTopTracksPlaylist.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/ShuffleAllPlaylist.java create mode 100644 app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/ShuffleAllPlaylist.kt diff --git a/app/build.gradle b/app/build.gradle index 2ad84892..1910568c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -93,7 +93,9 @@ android { configurations.all { resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9' } - + androidExtensions { + experimental = true + } } @@ -119,7 +121,7 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'androidx.multidex:multidex:2.0.1' implementation "androidx.fragment:fragment:$supportLibVersion" - implementation "androidx.appcompat:appcompat:1.0.2" + implementation 'androidx.appcompat:appcompat:1.0.2' implementation "androidx.recyclerview:recyclerview:$supportLibVersion" implementation "androidx.gridlayout:gridlayout:$supportLibVersion" implementation "androidx.cardview:cardview:$supportLibVersion" @@ -129,48 +131,39 @@ dependencies { implementation "androidx.legacy:legacy-support-v13:$supportLibVersion" implementation "androidx.legacy:legacy-preference-v14:$supportLibVersion" implementation "com.google.android.material:material:$supportLibVersion" - implementation "androidx.palette:palette-ktx:1.0.0" - - implementation "com.squareup.retrofit2:retrofit:2.5.0" - implementation "com.squareup.retrofit2:converter-gson:2.5.0" - implementation "com.squareup.retrofit2:adapter-rxjava2:2.5.0" - + implementation 'androidx.palette:palette-ktx:1.0.0' + implementation 'com.squareup.retrofit2:retrofit:2.5.0' + implementation 'com.squareup.retrofit2:converter-gson:2.5.0' + implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0' implementation "com.afollestad.material-dialogs:core:$materialDialog" implementation "com.afollestad.material-dialogs:core:$materialDialog" implementation 'com.afollestad.material-dialogs:input:2.0.0' implementation 'com.afollestad.material-dialogs:color:2.0.0' implementation 'com.afollestad:material-cab:0.1.12' - implementation 'com.github.bumptech.glide:glide:4.8.0' implementation 'com.github.bumptech.glide:okhttp3-integration:4.8.0' - - implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' - implementation 'io.reactivex.rxjava2:rxjava:2.2.6' - + implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' + implementation 'io.reactivex.rxjava2:rxjava:2.2.7' implementation('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0@aar') { transitive = true } implementation 'com.github.ksoichiro:android-observablescrollview:1.6.0' implementation 'com.github.kabouzeid:RecyclerView-FastScroll:1.0.16-kmod' implementation 'com.anjlab.android.iab.v3:library:1.0.44' - /*UI Library*/ implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2' implementation 'com.r0adkll:slidableactivity:2.0.6' /*Backend all*/ - implementation project(':appthemehelper') implementation 'com.github.kabouzeid:AndroidSlidingUpPanel:3.3.0-kmod3' implementation 'com.github.AdrienPoupa:jaudiotagger:2.2.3' implementation 'org.nanohttpd:nanohttpd:2.3.1' - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5' implementation 'com.github.jetradarmobile:android-snowfall:1.2.0' implementation 'com.github.takahirom.downloadable.calligraphy:downloadable-calligraphy:0.1.3' - kapt 'com.github.bumptech.glide:compiler:4.8.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - + implementation project(':appthemehelper') } repositories { mavenCentral() diff --git a/app/src/main/java/code/name/monkey/retromusic/appwidgets/AppWidgetClassic.kt b/app/src/main/java/code/name/monkey/retromusic/appwidgets/AppWidgetClassic.kt index fc88f3aa..ff27a6d7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/appwidgets/AppWidgetClassic.kt +++ b/app/src/main/java/code/name/monkey/retromusic/appwidgets/AppWidgetClassic.kt @@ -34,7 +34,6 @@ import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.ui.activities.MainActivity import code.name.monkey.retromusic.util.RetroUtil -import com.bumptech.glide.Glide import com.bumptech.glide.request.target.Target import com.bumptech.glide.request.transition.Transition @@ -50,9 +49,9 @@ class AppWidgetClassic : BaseAppWidget() { appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE) appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art) - appWidgetView.setImageViewBitmap(R.id.button_next, BaseAppWidget.Companion.createBitmap(RetroUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))!!, 1f)) - appWidgetView.setImageViewBitmap(R.id.button_prev, BaseAppWidget.Companion.createBitmap(RetroUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))!!, 1f)) - appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, BaseAppWidget.Companion.createBitmap(RetroUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))!!, 1f)) + appWidgetView.setImageViewBitmap(R.id.button_next, BaseAppWidget.createBitmap(RetroUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))!!, 1f)) + appWidgetView.setImageViewBitmap(R.id.button_prev, BaseAppWidget.createBitmap(RetroUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))!!, 1f)) + appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, BaseAppWidget.createBitmap(RetroUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))!!, 1f)) linkButtons(context, appWidgetView) pushUpdate(context, appWidgetIds, appWidgetView) @@ -106,7 +105,7 @@ class AppWidgetClassic : BaseAppWidget() { } override fun onLoadFailed(errorDrawable: Drawable?) { - super.onLoadFailed( errorDrawable) + super.onLoadFailed(errorDrawable) update(null, MaterialValueHelper.getSecondaryTextColor(appContext, true)) } diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt index dec8c254..e420bf1a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt @@ -21,13 +21,14 @@ import android.view.ViewGroup import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.LinearLayoutManager import code.name.monkey.appthemehelper.ThemeStore + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.loaders.PlaylistLoader import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.ui.adapter.playlist.AddToPlaylist import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment import kotlinx.android.synthetic.main.dialog_add_to_playlist.* -import java.util.* + class AddToPlaylistDialog : RoundedBottomSheetDialogFragment() { @@ -40,15 +41,14 @@ class AddToPlaylistDialog : RoundedBottomSheetDialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + val songs = arguments!!.getParcelableArrayList("songs") actionAddPlaylist.setOnClickListener { - val songs = arguments!!.getParcelableArrayList("songs") CreatePlaylistDialog.create(songs!!).show(activity!!.supportFragmentManager, "ADD_TO_PLAYLIST") dismiss() } bannerTitle.setTextColor(ThemeStore.textColorPrimary(context!!)) - val songs = arguments!!.getParcelableArrayList("songs") val playlists = PlaylistLoader.getAllPlaylists(activity!!).blockingFirst() val playlistAdapter = AddToPlaylist(activity!!, playlists, R.layout.item_playlist, songs!!, dialog) recyclerView.apply { diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/ClearSmartPlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/ClearSmartPlaylistDialog.kt index 6744ef4b..c3d340a7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/ClearSmartPlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/ClearSmartPlaylistDialog.kt @@ -39,7 +39,7 @@ class ClearSmartPlaylistDialog : DialogFragment() { if (activity == null) { return@positiveButton } - playlist.clear(activity) + playlist.clear(activity!!) } negativeButton { (android.R.string.cancel) } } diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt index 765bf2a8..53553fe1 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt @@ -22,11 +22,13 @@ import android.view.View import android.view.ViewGroup import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.MaterialUtil + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.PlaylistsUtil import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment import kotlinx.android.synthetic.main.dialog_playlist.* + import java.util.* class CreatePlaylistDialog : RoundedBottomSheetDialogFragment() { @@ -41,6 +43,8 @@ class CreatePlaylistDialog : RoundedBottomSheetDialogFragment() { super.onViewCreated(view, savedInstanceState) val accentColor = ThemeStore.accentColor(Objects.requireNonNull(context)) + val songs = arguments!!.getParcelableArrayList("songs") + MaterialUtil.setTint(actionCreate, true) MaterialUtil.setTint(actionCancel, false) MaterialUtil.setTint(actionNewPlaylistContainer, true) @@ -59,8 +63,6 @@ class CreatePlaylistDialog : RoundedBottomSheetDialogFragment() { val playlistId = PlaylistsUtil .createPlaylist(activity!!, actionNewPlaylist!!.text!!.toString()) if (playlistId != -1 && activity != null) { - - val songs = arguments!!.getParcelableArrayList("songs") if (songs != null) { PlaylistsUtil.addToPlaylist(activity!!, songs, playlistId, true) } diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/DeleteSongsDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/DeleteSongsDialog.kt index 8e88855f..4cd0a45b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/DeleteSongsDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/DeleteSongsDialog.kt @@ -22,12 +22,12 @@ import android.view.ViewGroup import androidx.core.content.ContextCompat import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.MaterialUtil + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment import kotlinx.android.synthetic.main.dialog_delete.* -import java.util.* class DeleteSongsDialog : RoundedBottomSheetDialogFragment() { @@ -40,7 +40,7 @@ class DeleteSongsDialog : RoundedBottomSheetDialogFragment() { val content: CharSequence if (songs != null) { content = if (songs.size > 1) { - getString(R.string.delete_x_songs, songs.size) + getString(R.string.delete_x_songs, songs.size) } else { getString(R.string.delete_song_x, songs[0].title) } diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveFromPlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveFromPlaylistDialog.kt index 0e78affe..d0bcce92 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveFromPlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveFromPlaylistDialog.kt @@ -23,10 +23,10 @@ import android.view.ViewGroup import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.retromusic.R import code.name.monkey.retromusic.model.PlaylistSong +import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.PlaylistsUtil import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment import kotlinx.android.synthetic.main.dialog_remove_from_playlist.* -import java.util.* class RemoveFromPlaylistDialog : RoundedBottomSheetDialogFragment() { @@ -38,7 +38,7 @@ class RemoveFromPlaylistDialog : RoundedBottomSheetDialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val songs = arguments!!.getParcelableArrayList("songs") + val songs = arguments!!.getParcelableArrayList("songs") val title: Int val content: CharSequence if (songs!!.size > 1) { @@ -56,7 +56,7 @@ class RemoveFromPlaylistDialog : RoundedBottomSheetDialogFragment() { text = content setTextColor(ThemeStore.textColorSecondary(context)) setOnClickListener { - PlaylistsUtil.removeFromPlaylist(activity!!, songs) + PlaylistsUtil.removeFromPlaylist(activity!!, songs as ArrayList) dismiss() } } diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/RenamePlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/RenamePlaylistDialog.kt index 3d3359a0..741a7345 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/RenamePlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/RenamePlaylistDialog.kt @@ -29,8 +29,7 @@ import kotlinx.android.synthetic.main.dialog_playlist.* class RenamePlaylistDialog : RoundedBottomSheetDialogFragment() { - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.dialog_playlist, container, false) } diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/SongDetailDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/SongDetailDialog.kt index c19a4a02..28497764 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/SongDetailDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/SongDetailDialog.kt @@ -24,6 +24,7 @@ import android.view.View import android.view.ViewGroup import android.widget.TextView import code.name.monkey.appthemehelper.ThemeStore + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.MusicUtil @@ -132,7 +133,7 @@ class SongDetailDialog : RoundedBottomSheetDialogFragment() { private fun getFileSizeString(sizeInBytes: Long): String { val fileSizeInKB = sizeInBytes / 1024 val fileSizeInMB = fileSizeInKB / 1024 - return fileSizeInMB.toString() + " MB" + return "$fileSizeInMB MB" } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/SongShareDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/SongShareDialog.kt index 8d7f5c85..cbda4e80 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/SongShareDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/SongShareDialog.kt @@ -23,12 +23,14 @@ import android.view.ViewGroup import androidx.core.content.ContextCompat import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.MaterialUtil + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment import kotlinx.android.synthetic.main.dialog_file_share.* + class SongShareDialog : RoundedBottomSheetDialogFragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.dialog_file_share, container, false) @@ -37,7 +39,7 @@ class SongShareDialog : RoundedBottomSheetDialogFragment() { @SuppressLint("StringFormatInvalid") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val song = arguments!!.getParcelable("song")!! + val song = arguments!!.getParcelable("song") dialogTitle.setTextColor(ThemeStore.textColorPrimary(context!!)) audioText.apply { @@ -57,7 +59,7 @@ class SongShareDialog : RoundedBottomSheetDialogFragment() { audioFile.apply { setTextColor(ThemeStore.textColorSecondary(context!!)) setOnClickListener { - activity!!.startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, activity), null)) + activity!!.startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, context), null)) dismiss() } icon = ContextCompat.getDrawable(context, R.drawable.ic_share_white_24dp) diff --git a/app/src/main/java/code/name/monkey/retromusic/glide/RetroGlideExtension.java b/app/src/main/java/code/name/monkey/retromusic/glide/RetroGlideExtension.java index 82969c34..ef4a333a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/glide/RetroGlideExtension.java +++ b/app/src/main/java/code/name/monkey/retromusic/glide/RetroGlideExtension.java @@ -70,23 +70,28 @@ public final class RetroGlideExtension { .signature(createSignature(song)); } - public static Key createSignature(Artist artist) { + @NonNull + public static Key createSignature(@NonNull Artist artist) { return ArtistSignatureUtil.getInstance().getArtistSignature(artist.getName()); } - public static Key createSignature(Song song) { - return new MediaStoreSignature("", song.dateModified, 0); + @NonNull + public static Key createSignature(@NonNull Song song) { + return new MediaStoreSignature("", song.getDateModified(), 0); } - public static Object getArtistModel(Artist artist) { + @NonNull + public static Object getArtistModel(@NonNull Artist artist) { return getArtistModel(artist, CustomArtistImageUtil.Companion.getInstance(App.Companion.getContext()).hasCustomArtistImage(artist), false); } - public static Object getArtistModel(Artist artist, boolean forceDownload) { + @NonNull + public static Object getArtistModel(@NonNull Artist artist, boolean forceDownload) { return getArtistModel(artist, CustomArtistImageUtil.Companion.getInstance(App.Companion.getContext()).hasCustomArtistImage(artist), forceDownload); } - public static Object getArtistModel(Artist artist, boolean hasCustomImage, boolean forceDownload) { + @NonNull + public static Object getArtistModel(@NonNull Artist artist, boolean hasCustomImage, boolean forceDownload) { if (!hasCustomImage) { return new ArtistImage(artist.getName(), forceDownload); } else { @@ -94,18 +99,21 @@ public final class RetroGlideExtension { } } - public static Object getSongModel(Song song) { + @NonNull + public static Object getSongModel(@NonNull Song song) { return getSongModel(song, PreferenceUtil.getInstance().ignoreMediaStoreArtwork()); } - public static Object getSongModel(Song song, boolean ignoreMediaStore) { + @NonNull + public static Object getSongModel(@NonNull Song song, boolean ignoreMediaStore) { if (ignoreMediaStore) { - return new AudioFileCover(song.data); + return new AudioFileCover(song.getData()); } else { - return MusicUtil.getMediaStoreAlbumCoverUri(song.albumId); + return MusicUtil.getMediaStoreAlbumCoverUri(song.getAlbumId()); } } + @NonNull public static GenericTransitionOptions getDefaultTransition() { return new GenericTransitionOptions().transition(android.R.anim.fade_in); } diff --git a/app/src/main/java/code/name/monkey/retromusic/helper/M3UWriter.kt b/app/src/main/java/code/name/monkey/retromusic/helper/M3UWriter.kt index e9b19bc1..0b40e7c2 100644 --- a/app/src/main/java/code/name/monkey/retromusic/helper/M3UWriter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/helper/M3UWriter.kt @@ -15,19 +15,17 @@ package code.name.monkey.retromusic.helper import android.content.Context - -import java.io.BufferedWriter -import java.io.File -import java.io.FileWriter -import java.io.IOException -import java.util.ArrayList - import code.name.monkey.retromusic.loaders.PlaylistSongsLoader import code.name.monkey.retromusic.model.AbsCustomPlaylist import code.name.monkey.retromusic.model.Playlist import code.name.monkey.retromusic.model.Song import io.reactivex.Observable import io.reactivex.ObservableEmitter +import java.io.BufferedWriter +import java.io.File +import java.io.FileWriter +import java.io.IOException +import java.util.* class M3UWriter : M3UConstants { companion object { diff --git a/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt b/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt index d4cbd414..443e973a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt +++ b/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt @@ -26,6 +26,7 @@ import android.provider.DocumentsContract import android.provider.MediaStore import android.util.Log import android.widget.Toast + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.loaders.SongLoader import code.name.monkey.retromusic.model.Song @@ -47,7 +48,7 @@ object MusicPlayerRemote { val currentSong: Song get() = if (musicService != null) { musicService!!.currentSong - } else Song.EMPTY_SONG + } else Song.emptySong /** * Async diff --git a/app/src/main/java/code/name/monkey/retromusic/helper/SearchQueryHelper.kt b/app/src/main/java/code/name/monkey/retromusic/helper/SearchQueryHelper.kt index 107da11b..9a6137ee 100644 --- a/app/src/main/java/code/name/monkey/retromusic/helper/SearchQueryHelper.kt +++ b/app/src/main/java/code/name/monkey/retromusic/helper/SearchQueryHelper.kt @@ -24,10 +24,10 @@ import java.util.* object SearchQueryHelper { - private val TITLE_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.TITLE + ") = ?" - private val ALBUM_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.ALBUM + ") = ?" - private val ARTIST_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.ARTIST + ") = ?" - private val AND = " AND " + private const val TITLE_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.TITLE + ") = ?" + private const val ALBUM_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.ALBUM + ") = ?" + private const val ARTIST_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.ARTIST + ") = ?" + private const val AND = " AND " var songs = ArrayList() fun getSongs(context: Context, extras: Bundle): ArrayList { diff --git a/app/src/main/java/code/name/monkey/retromusic/helper/menu/GenreMenuHelper.kt b/app/src/main/java/code/name/monkey/retromusic/helper/menu/GenreMenuHelper.kt index cee638d2..88f6616f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/helper/menu/GenreMenuHelper.kt +++ b/app/src/main/java/code/name/monkey/retromusic/helper/menu/GenreMenuHelper.kt @@ -17,6 +17,7 @@ package code.name.monkey.retromusic.helper.menu import android.app.Activity import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog import code.name.monkey.retromusic.helper.MusicPlayerRemote diff --git a/app/src/main/java/code/name/monkey/retromusic/helper/menu/PlaylistMenuHelper.kt b/app/src/main/java/code/name/monkey/retromusic/helper/menu/PlaylistMenuHelper.kt index 3ac1c0c1..064c57f8 100644 --- a/app/src/main/java/code/name/monkey/retromusic/helper/menu/PlaylistMenuHelper.kt +++ b/app/src/main/java/code/name/monkey/retromusic/helper/menu/PlaylistMenuHelper.kt @@ -20,6 +20,7 @@ import androidx.appcompat.app.AppCompatActivity import android.view.MenuItem import android.widget.Toast + import java.util.ArrayList import code.name.monkey.retromusic.R diff --git a/app/src/main/java/code/name/monkey/retromusic/helper/menu/SongMenuHelper.kt b/app/src/main/java/code/name/monkey/retromusic/helper/menu/SongMenuHelper.kt index 965c739a..4d8775ec 100644 --- a/app/src/main/java/code/name/monkey/retromusic/helper/menu/SongMenuHelper.kt +++ b/app/src/main/java/code/name/monkey/retromusic/helper/menu/SongMenuHelper.kt @@ -20,6 +20,7 @@ import android.view.View import android.widget.PopupMenu import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.FragmentActivity + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog import code.name.monkey.retromusic.dialogs.DeleteSongsDialog diff --git a/app/src/main/java/code/name/monkey/retromusic/helper/menu/SongsMenuHelper.kt b/app/src/main/java/code/name/monkey/retromusic/helper/menu/SongsMenuHelper.kt index 9a5f9600..cd0af61e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/helper/menu/SongsMenuHelper.kt +++ b/app/src/main/java/code/name/monkey/retromusic/helper/menu/SongsMenuHelper.kt @@ -15,6 +15,7 @@ package code.name.monkey.retromusic.helper.menu import androidx.fragment.app.FragmentActivity + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog import code.name.monkey.retromusic.dialogs.DeleteSongsDialog diff --git a/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt b/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt index 40231b93..ea54d9f3 100644 --- a/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt +++ b/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt @@ -18,10 +18,8 @@ import android.content.Context import android.provider.MediaStore.Audio.AudioColumns import code.name.monkey.retromusic.model.Album import code.name.monkey.retromusic.model.Artist -import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.PreferenceUtil import io.reactivex.Observable -import java.util.* import kotlin.collections.ArrayList object ArtistLoader { diff --git a/app/src/main/java/code/name/monkey/retromusic/loaders/LastAddedSongsLoader.kt b/app/src/main/java/code/name/monkey/retromusic/loaders/LastAddedSongsLoader.kt index ddecb0f5..0fbe79ee 100644 --- a/app/src/main/java/code/name/monkey/retromusic/loaders/LastAddedSongsLoader.kt +++ b/app/src/main/java/code/name/monkey/retromusic/loaders/LastAddedSongsLoader.kt @@ -17,15 +17,13 @@ package code.name.monkey.retromusic.loaders import android.content.Context import android.database.Cursor import android.provider.MediaStore - -import java.util.ArrayList - import code.name.monkey.retromusic.model.Album import code.name.monkey.retromusic.model.Artist import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.PreferenceUtil import io.reactivex.Observable import io.reactivex.annotations.NonNull +import java.util.* /** * Created by hemanths on 16/08/17. diff --git a/app/src/main/java/code/name/monkey/retromusic/loaders/PlaylistSongsLoader.kt b/app/src/main/java/code/name/monkey/retromusic/loaders/PlaylistSongsLoader.kt index 84230159..1f1af046 100644 --- a/app/src/main/java/code/name/monkey/retromusic/loaders/PlaylistSongsLoader.kt +++ b/app/src/main/java/code/name/monkey/retromusic/loaders/PlaylistSongsLoader.kt @@ -64,7 +64,7 @@ object PlaylistSongsLoader { val year = cursor.getInt(3) val duration = cursor.getLong(4) val data = cursor.getString(5) - val dateModified = cursor.getInt(6) + val dateModified = cursor.getLong(6) val albumId = cursor.getInt(7) val albumName = cursor.getString(8) val artistId = cursor.getInt(9) diff --git a/app/src/main/java/code/name/monkey/retromusic/loaders/SongLoader.kt b/app/src/main/java/code/name/monkey/retromusic/loaders/SongLoader.kt index 459ada7e..2d693a81 100644 --- a/app/src/main/java/code/name/monkey/retromusic/loaders/SongLoader.kt +++ b/app/src/main/java/code/name/monkey/retromusic/loaders/SongLoader.kt @@ -134,7 +134,7 @@ object SongLoader { val song: Song = if (cursor != null && cursor.moveToFirst()) { getSongFromCursorImpl(cursor) } else { - Song.EMPTY_SONG + Song.emptySong } cursor?.close() e.onNext(song) diff --git a/app/src/main/java/code/name/monkey/retromusic/model/AbsCustomPlaylist.java b/app/src/main/java/code/name/monkey/retromusic/model/AbsCustomPlaylist.java index 4e08ff29..99b889d4 100644 --- a/app/src/main/java/code/name/monkey/retromusic/model/AbsCustomPlaylist.java +++ b/app/src/main/java/code/name/monkey/retromusic/model/AbsCustomPlaylist.java @@ -15,27 +15,20 @@ package code.name.monkey.retromusic.model; import android.content.Context; -import android.os.Parcel; import java.util.ArrayList; import androidx.annotation.NonNull; import io.reactivex.Observable; +import kotlinx.android.parcel.Parcelize; - +@Parcelize public abstract class AbsCustomPlaylist extends Playlist { - public AbsCustomPlaylist(int id, String name) { + public AbsCustomPlaylist(int id, @NonNull String name) { super(id, name); } - public AbsCustomPlaylist() { - } - - public AbsCustomPlaylist(Parcel in) { - super(in); - } - @NonNull - public abstract Observable> getSongs(Context context); + public abstract Observable> getSongs(@NonNull Context context); } diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Album.kt b/app/src/main/java/code/name/monkey/retromusic/model/Album.kt index 68d42d95..af53ff0c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/model/Album.kt +++ b/app/src/main/java/code/name/monkey/retromusic/model/Album.kt @@ -50,6 +50,6 @@ class Album { } fun safeGetFirstSong(): Song { - return if (songs!!.isEmpty()) Song.EMPTY_SONG else songs[0] + return if (songs!!.isEmpty()) Song.emptySong else songs[0] } } diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Genre.java b/app/src/main/java/code/name/monkey/retromusic/model/Genre.java deleted file mode 100644 index 941b6d90..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/model/Genre.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2019 Hemanth Savarala. - * - * Licensed under the GNU General Public License v3 - * - * This is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by - * the Free Software Foundation either version 3 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - */ - -package code.name.monkey.retromusic.model; - -import android.os.Parcel; -import android.os.Parcelable; - -/** - * @author Hemanth S (h4h13). - */ - -public class Genre implements Parcelable { - - public static final Creator CREATOR = new Creator() { - @Override - public Genre createFromParcel(Parcel in) { - return new Genre(in); - } - - @Override - public Genre[] newArray(int size) { - return new Genre[size]; - } - }; - public final int id; - public final String name; - public final int songCount; - - public Genre(final int id, final String name, int songCount) { - this.id = id; - this.name = name; - this.songCount = songCount; - } - - - // For unknown genre - public Genre(final String name, final int songCount) { - this.id = -1; - this.name = name; - this.songCount = songCount; - } - - protected Genre(Parcel in) { - id = in.readInt(); - name = in.readString(); - songCount = in.readInt(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(id); - dest.writeString(name); - dest.writeInt(songCount); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Genre genre = (Genre) o; - - if (id != genre.id) return false; - return name != null ? name.equals(genre.name) : genre.name == null; - } - - @Override - public int hashCode() { - int result = id; - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "Genre{" + - "id=" + id + - ", name='" + name + '\'' + - '}'; - } - - -} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Genre.kt b/app/src/main/java/code/name/monkey/retromusic/model/Genre.kt new file mode 100644 index 00000000..2273b572 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/model/Genre.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2019 Hemanth Savarala. + * + * Licensed under the GNU General Public License v3 + * + * This is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by + * the Free Software Foundation either version 3 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + */ + +package code.name.monkey.retromusic.model + +import android.os.Parcelable +import kotlinx.android.parcel.Parcelize + +/** + * @author Hemanth S (h4h13). + */ + +@Parcelize +class Genre(val id: Int = -1, val name: String, val songCount: Int) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Home.java b/app/src/main/java/code/name/monkey/retromusic/model/Home.java deleted file mode 100644 index 042e9867..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/model/Home.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2019 Hemanth Savarala. - * - * Licensed under the GNU General Public License v3 - * - * This is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by - * the Free Software Foundation either version 3 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - */ - -package code.name.monkey.retromusic.model; - -import java.util.ArrayList; - -import androidx.annotation.DrawableRes; -import androidx.annotation.StringRes; -import code.name.monkey.retromusic.ui.adapter.HomeAdapter.Companion.HomeSection; - -public class Home { - @StringRes - int title; - @StringRes - int subtitle; - @HomeSection - int homeSection; - @DrawableRes - int icon; - - ArrayList arrayList; - - public Home(int title, int subtitle, ArrayList arrayList, @HomeSection int homeSection, @DrawableRes int icon) { - this.title = title; - this.subtitle = subtitle; - this.arrayList = arrayList; - this.homeSection = homeSection; - this.icon = icon; - } - - @HomeSection - public int getHomeSection() { - return homeSection; - } - - @StringRes - public int getTitle() { - return title; - } - - @StringRes - public int getSubtitle() { - return subtitle; - } - - public ArrayList getArrayList() { - return arrayList; - } - - @DrawableRes - public int getIcon() { - return icon; - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Home.kt b/app/src/main/java/code/name/monkey/retromusic/model/Home.kt new file mode 100644 index 00000000..48c12a94 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/model/Home.kt @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2019 Hemanth Savarala. + * + * Licensed under the GNU General Public License v3 + * + * This is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by + * the Free Software Foundation either version 3 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + */ + +package code.name.monkey.retromusic.model + +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes +import code.name.monkey.retromusic.ui.adapter.HomeAdapter.Companion.HomeSection + +/** + * Created by hemanths on 3/4/19 + */ + +class Home(@StringRes val title: Int, + @StringRes val subTitle: Int, + val arrayList: ArrayList<*>, + @HomeSection + val homeSection: Int, + @DrawableRes + val icon: Int) \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Playlist.java b/app/src/main/java/code/name/monkey/retromusic/model/Playlist.java deleted file mode 100644 index 89c94010..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/model/Playlist.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2019 Hemanth Savarala. - * - * Licensed under the GNU General Public License v3 - * - * This is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by - * the Free Software Foundation either version 3 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - */ - -package code.name.monkey.retromusic.model; - -import android.os.Parcel; -import android.os.Parcelable; - - -public class Playlist implements Parcelable { - public static final Creator CREATOR = new Creator() { - public Playlist createFromParcel(Parcel source) { - return new Playlist(source); - } - - public Playlist[] newArray(int size) { - return new Playlist[size]; - } - }; - public final int id; - public final String name; - - public Playlist(final int id, final String name) { - this.id = id; - this.name = name; - } - - public Playlist() { - this.id = -1; - this.name = ""; - } - - protected Playlist(Parcel in) { - this.id = in.readInt(); - this.name = in.readString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Playlist playlist = (Playlist) o; - - if (id != playlist.id) return false; - return name != null ? name.equals(playlist.name) : playlist.name == null; - - } - - @Override - public int hashCode() { - int result = id; - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "Playlist{" + - "id=" + id + - ", name='" + name + '\'' + - '}'; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(this.id); - dest.writeString(this.name); - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Playlist.kt b/app/src/main/java/code/name/monkey/retromusic/model/Playlist.kt new file mode 100644 index 00000000..3714b7d3 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/model/Playlist.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2019 Hemanth Savarala. + * + * Licensed under the GNU General Public License v3 + * + * This is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by + * the Free Software Foundation either version 3 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + */ + +package code.name.monkey.retromusic.model + +import android.os.Parcelable +import kotlinx.android.parcel.Parcelize + +@Parcelize +open class Playlist(val id: Int = -1, val name: String = "") : Parcelable \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/model/PlaylistSong.java b/app/src/main/java/code/name/monkey/retromusic/model/PlaylistSong.java index f1796412..e69ca3f8 100644 --- a/app/src/main/java/code/name/monkey/retromusic/model/PlaylistSong.java +++ b/app/src/main/java/code/name/monkey/retromusic/model/PlaylistSong.java @@ -14,72 +14,42 @@ package code.name.monkey.retromusic.model; -import android.os.Parcel; +import org.jetbrains.annotations.NotNull; +import kotlinx.android.parcel.Parcelize; + +/** + * Created by hemanths on 3/4/19 + */ +@Parcelize public class PlaylistSong extends Song { - public static final Creator CREATOR = new Creator() { - public PlaylistSong createFromParcel(Parcel source) { - return new PlaylistSong(source); - } + final int playlistId; + final int idInPlayList; - public PlaylistSong[] newArray(int size) { - return new PlaylistSong[size]; - } - }; - public final int playlistId; - public final int idInPlayList; - - public PlaylistSong(int id, String title, int trackNumber, int year, long duration, String data, int dateModified, int albumId, String albumName, int artistId, String artistName, final int playlistId, final int idInPlayList, String composer) { + public PlaylistSong(int id, + @NotNull String title, + int trackNumber, + int year, + long duration, + @NotNull String data, + long dateModified, + int albumId, + @NotNull String albumName, + int artistId, + @NotNull String artistName, + int playlistId, + int idInPlayList, + @NotNull String composer) { super(id, title, trackNumber, year, duration, data, dateModified, albumId, albumName, artistId, artistName, composer); this.playlistId = playlistId; this.idInPlayList = idInPlayList; } - protected PlaylistSong(Parcel in) { - super(in); - this.playlistId = in.readInt(); - this.idInPlayList = in.readInt(); + public int getPlaylistId() { + return playlistId; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - - PlaylistSong that = (PlaylistSong) o; - - if (playlistId != that.playlistId) return false; - return idInPlayList == that.idInPlayList; - - } - - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + playlistId; - result = 31 * result + idInPlayList; - return result; - } - - @Override - public String toString() { - return super.toString() + - "PlaylistSong{" + - "playlistId=" + playlistId + - ", idInPlayList=" + idInPlayList + - '}'; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeInt(this.playlistId); - dest.writeInt(this.idInPlayList); + public int getIdInPlayList() { + return idInPlayList; } } diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Song.java b/app/src/main/java/code/name/monkey/retromusic/model/Song.java deleted file mode 100644 index 6702c20b..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/model/Song.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2019 Hemanth Savarala. - * - * Licensed under the GNU General Public License v3 - * - * This is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by - * the Free Software Foundation either version 3 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - */ - -package code.name.monkey.retromusic.model; - -import android.os.Parcel; -import android.os.Parcelable; - -/** - * @author Karim Abou Zeid (kabouzeid) - */ -public class Song implements Parcelable { - public static final Song EMPTY_SONG = new Song(-1, "", -1, -1, -1, "", -1, -1, "", -1, "", ""); - public static final Creator CREATOR = new Creator() { - public Song createFromParcel(Parcel source) { - return new Song(source); - } - - public Song[] newArray(int size) { - return new Song[size]; - } - }; - public final int id; - public final String title; - public final int trackNumber; - public final int year; - public final long duration; - public final String data; - public final long dateModified; - public final int albumId; - public final String albumName; - public final int artistId; - public final String artistName; - public final String composer; - - public Song(int id, String title, int trackNumber, int year, long duration, String data, long dateModified, int albumId, String albumName, int artistId, String artistName, String composer) { - this.id = id; - this.title = title; - this.trackNumber = trackNumber; - this.year = year; - this.duration = duration; - this.data = data; - this.dateModified = dateModified; - this.albumId = albumId; - this.albumName = albumName; - this.artistId = artistId; - this.artistName = artistName; - this.composer = composer; - } - - protected Song(Parcel in) { - this.id = in.readInt(); - this.title = in.readString(); - this.trackNumber = in.readInt(); - this.year = in.readInt(); - this.duration = in.readLong(); - this.data = in.readString(); - this.dateModified = in.readLong(); - this.albumId = in.readInt(); - this.albumName = in.readString(); - this.artistId = in.readInt(); - this.artistName = in.readString(); - this.composer = in.readString(); - } - - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(this.id); - dest.writeString(this.title); - dest.writeInt(this.trackNumber); - dest.writeInt(this.year); - dest.writeLong(this.duration); - dest.writeString(this.data); - dest.writeLong(this.dateModified); - dest.writeInt(this.albumId); - dest.writeString(this.albumName); - dest.writeInt(this.artistId); - dest.writeString(this.artistName); - dest.writeString(this.composer); - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Song.kt b/app/src/main/java/code/name/monkey/retromusic/model/Song.kt new file mode 100644 index 00000000..7b0a0710 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/model/Song.kt @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2019 Hemanth Savarala. + * + * Licensed under the GNU General Public License v3 + * + * This is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by + * the Free Software Foundation either version 3 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + */ +package code.name.monkey.retromusic.model + +import android.os.Parcelable +import kotlinx.android.parcel.Parcelize + + +/** + * @author Karim Abou Zeid (kabouzeid) + */ +@Parcelize +open class Song(val id: Int, val title: String, val trackNumber: Int, val year: Int, val duration: Long, val data: String, val dateModified: Long, val albumId: Int, val albumName: String, val artistId: Int, val artistName: String, val composer: String?) : Parcelable { + + + companion object { + @JvmStatic + val emptySong = Song(-1, "", -1, -1, -1, "", -1, -1, "", -1, "", "") + } +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/model/lyrics/Lyrics.java b/app/src/main/java/code/name/monkey/retromusic/model/lyrics/Lyrics.java index a4e5bf4e..09599cdd 100644 --- a/app/src/main/java/code/name/monkey/retromusic/model/lyrics/Lyrics.java +++ b/app/src/main/java/code/name/monkey/retromusic/model/lyrics/Lyrics.java @@ -15,27 +15,29 @@ package code.name.monkey.retromusic.model.lyrics; -import code.name.monkey.retromusic.model.Song; - import java.util.ArrayList; +import androidx.annotation.NonNull; +import code.name.monkey.retromusic.model.Song; + public class Lyrics { private static final ArrayList> FORMATS = new ArrayList<>(); + static { + Lyrics.FORMATS.add(SynchronizedLyricsLRC.class); + } + + @NonNull public Song song; + @NonNull public String data; protected boolean parsed = false; protected boolean valid = false; - public Lyrics setData(Song song, String data) { - this.song = song; - this.data = data; - return this; - } - - public static Lyrics parse(Song song, String data) { + @NonNull + public static Lyrics parse(@NonNull Song song, @NonNull String data) { for (Class format : Lyrics.FORMATS) { try { Lyrics lyrics = format.newInstance().setData(song, data); @@ -47,7 +49,7 @@ public class Lyrics { return new Lyrics().setData(song, data).parse(false); } - public static boolean isSynchronized(String data) { + public static boolean isSynchronized(@NonNull String data) { for (Class format : Lyrics.FORMATS) { try { Lyrics lyrics = format.newInstance().setData(null, data); @@ -59,6 +61,13 @@ public class Lyrics { return false; } + public Lyrics setData(@NonNull Song song, @NonNull String data) { + this.song = song; + this.data = data; + return this; + } + + @NonNull public Lyrics parse(boolean check) { this.valid = true; this.parsed = true; @@ -74,11 +83,8 @@ public class Lyrics { return this.valid; } + @NonNull public String getText() { return this.data.trim().replaceAll("(\r?\n){3,}", "\r\n\r\n"); } - - static { - Lyrics.FORMATS.add(SynchronizedLyricsLRC.class); - } } diff --git a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/AbsSmartPlaylist.java b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/AbsSmartPlaylist.java index c9291117..d6b260c6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/AbsSmartPlaylist.java +++ b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/AbsSmartPlaylist.java @@ -15,63 +15,22 @@ package code.name.monkey.retromusic.model.smartplaylist; import android.content.Context; -import android.os.Parcel; + import androidx.annotation.DrawableRes; -import androidx.annotation.Nullable; - -import code.name.monkey.retromusic.R; +import androidx.annotation.NonNull; import code.name.monkey.retromusic.model.AbsCustomPlaylist; +import kotlinx.android.parcel.Parcelize; - +@Parcelize public abstract class AbsSmartPlaylist extends AbsCustomPlaylist { @DrawableRes public final int iconRes; - public AbsSmartPlaylist(final String name, final int iconRes) { + public AbsSmartPlaylist(final @NonNull String name, final int iconRes) { super(-Math.abs(31 * name.hashCode() + (iconRes * name.hashCode() * 31 * 31)), name); this.iconRes = iconRes; } - public AbsSmartPlaylist() { - super(); - this.iconRes = R.drawable.ic_playlist_play_white_24dp; - } + public abstract void clear(@NonNull Context context); - protected AbsSmartPlaylist(Parcel in) { - super(in); - this.iconRes = in.readInt(); - } - - public abstract void clear(Context context); - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + iconRes; - return result; - } - - @Override - public boolean equals(@Nullable final Object obj) { - if (super.equals(obj)) { - if (getClass() != obj.getClass()) { - return false; - } - final AbsSmartPlaylist other = (AbsSmartPlaylist) obj; - return iconRes == other.iconRes; - } - return false; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeInt(this.iconRes); - } } diff --git a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/HistoryPlaylist.java b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/HistoryPlaylist.java deleted file mode 100644 index cbef2058..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/HistoryPlaylist.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2019 Hemanth Savarala. - * - * Licensed under the GNU General Public License v3 - * - * This is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by - * the Free Software Foundation either version 3 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - */ - -package code.name.monkey.retromusic.model.smartplaylist; - -import android.content.Context; -import android.os.Parcel; -import android.os.Parcelable; -import androidx.annotation.NonNull; - -import java.util.ArrayList; - -import code.name.monkey.retromusic.R; -import code.name.monkey.retromusic.loaders.TopAndRecentlyPlayedTracksLoader; -import code.name.monkey.retromusic.model.Song; -import code.name.monkey.retromusic.providers.HistoryStore; -import io.reactivex.Observable; - - -public class HistoryPlaylist extends AbsSmartPlaylist { - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public HistoryPlaylist createFromParcel(Parcel source) { - return new HistoryPlaylist(source); - } - - public HistoryPlaylist[] newArray(int size) { - return new HistoryPlaylist[size]; - } - }; - - public HistoryPlaylist(@NonNull Context context) { - super(context.getString(R.string.history), R.drawable.ic_access_time_white_24dp); - } - - protected HistoryPlaylist(Parcel in) { - super(in); - } - - @NonNull - @Override - public Observable> getSongs(@NonNull Context context) { - return TopAndRecentlyPlayedTracksLoader.INSTANCE.getRecentlyPlayedTracks(context); - } - - @Override - public void clear(@NonNull Context context) { - HistoryStore.getInstance(context).clear(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/HistoryPlaylist.kt b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/HistoryPlaylist.kt new file mode 100644 index 00000000..ad3f1c02 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/HistoryPlaylist.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 Hemanth Savarala. + * + * Licensed under the GNU General Public License v3 + * + * This is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by + * the Free Software Foundation either version 3 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + */ + +package code.name.monkey.retromusic.model.smartplaylist + +import android.content.Context + +import java.util.ArrayList +import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.loaders.TopAndRecentlyPlayedTracksLoader +import code.name.monkey.retromusic.model.Song +import code.name.monkey.retromusic.providers.HistoryStore +import io.reactivex.Observable +import kotlinx.android.parcel.Parcelize + +class HistoryPlaylist(context: Context) : AbsSmartPlaylist(context.getString(R.string.history), R.drawable.ic_access_time_white_24dp) { + + override fun getSongs(context: Context): Observable> { + return TopAndRecentlyPlayedTracksLoader.getRecentlyPlayedTracks(context) + } + + override fun clear(context: Context) { + HistoryStore.getInstance(context).clear() + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/LastAddedPlaylist.java b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/LastAddedPlaylist.java deleted file mode 100644 index 10ac53e8..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/LastAddedPlaylist.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2019 Hemanth Savarala. - * - * Licensed under the GNU General Public License v3 - * - * This is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by - * the Free Software Foundation either version 3 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - */ - -package code.name.monkey.retromusic.model.smartplaylist; - -import android.content.Context; -import android.os.Parcel; -import android.os.Parcelable; -import androidx.annotation.NonNull; - - -import code.name.monkey.retromusic.R; -import code.name.monkey.retromusic.loaders.LastAddedSongsLoader; -import code.name.monkey.retromusic.model.Song; - -import java.util.ArrayList; - -import io.reactivex.Observable; - - -public class LastAddedPlaylist extends AbsSmartPlaylist { - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public LastAddedPlaylist createFromParcel(Parcel source) { - return new LastAddedPlaylist(source); - } - - public LastAddedPlaylist[] newArray(int size) { - return new LastAddedPlaylist[size]; - } - }; - - public LastAddedPlaylist(@NonNull Context context) { - super(context.getString(R.string.last_added), R.drawable.ic_library_add_white_24dp); - } - - protected LastAddedPlaylist(Parcel in) { - super(in); - } - - @NonNull - @Override - public Observable> getSongs(@NonNull Context context) { - return LastAddedSongsLoader.INSTANCE.getLastAddedSongs(context); - } - - @Override - public void clear(@NonNull Context context) { - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/LastAddedPlaylist.kt b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/LastAddedPlaylist.kt new file mode 100644 index 00000000..419e0245 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/LastAddedPlaylist.kt @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 Hemanth Savarala. + * + * Licensed under the GNU General Public License v3 + * + * This is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by + * the Free Software Foundation either version 3 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + */ + +package code.name.monkey.retromusic.model.smartplaylist + +import android.content.Context + +import java.util.ArrayList +import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.loaders.LastAddedSongsLoader +import code.name.monkey.retromusic.model.Song +import io.reactivex.Observable + +class LastAddedPlaylist(context: Context) : AbsSmartPlaylist(context.getString(R.string.last_added), R.drawable.ic_library_add_white_24dp) { + + override fun getSongs(context: Context): Observable> { + return LastAddedSongsLoader.getLastAddedSongs(context) + } + + override fun clear(context: Context) {} +} diff --git a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/MyTopTracksPlaylist.java b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/MyTopTracksPlaylist.java deleted file mode 100644 index 3d094885..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/MyTopTracksPlaylist.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2019 Hemanth Savarala. - * - * Licensed under the GNU General Public License v3 - * - * This is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by - * the Free Software Foundation either version 3 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - */ - -package code.name.monkey.retromusic.model.smartplaylist; - -import android.content.Context; -import android.os.Parcel; -import android.os.Parcelable; -import androidx.annotation.NonNull; - - -import code.name.monkey.retromusic.R; -import code.name.monkey.retromusic.loaders.TopAndRecentlyPlayedTracksLoader; -import code.name.monkey.retromusic.model.Song; -import code.name.monkey.retromusic.providers.SongPlayCountStore; - -import java.util.ArrayList; - -import io.reactivex.Observable; - - -public class MyTopTracksPlaylist extends AbsSmartPlaylist implements Parcelable { - public static final Creator CREATOR = new Creator() { - public MyTopTracksPlaylist createFromParcel(Parcel source) { - return new MyTopTracksPlaylist(source); - } - - public MyTopTracksPlaylist[] newArray(int size) { - return new MyTopTracksPlaylist[size]; - } - }; - - public MyTopTracksPlaylist(@NonNull Context context) { - super(context.getString(R.string.my_top_tracks), R.drawable.ic_trending_up_white_24dp); - } - - protected MyTopTracksPlaylist(Parcel in) { - super(in); - } - - @NonNull - @Override - public Observable> getSongs(@NonNull Context context) { - return TopAndRecentlyPlayedTracksLoader.INSTANCE.getTopTracks(context); - } - - @Override - public void clear(@NonNull Context context) { - SongPlayCountStore.getInstance(context).clear(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - } - -} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/MyTopTracksPlaylist.kt b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/MyTopTracksPlaylist.kt new file mode 100644 index 00000000..cd8ab1ff --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/MyTopTracksPlaylist.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 Hemanth Savarala. + * + * Licensed under the GNU General Public License v3 + * + * This is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by + * the Free Software Foundation either version 3 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + */ + +package code.name.monkey.retromusic.model.smartplaylist + +import android.content.Context + +import java.util.ArrayList +import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.loaders.TopAndRecentlyPlayedTracksLoader +import code.name.monkey.retromusic.model.Song +import code.name.monkey.retromusic.providers.SongPlayCountStore +import io.reactivex.Observable + + +class MyTopTracksPlaylist(context: Context) : AbsSmartPlaylist(context.getString(R.string.my_top_tracks), R.drawable.ic_trending_up_white_24dp) { + + override fun getSongs(context: Context): Observable> { + return TopAndRecentlyPlayedTracksLoader.getTopTracks(context) + } + + override fun clear(context: Context) { + SongPlayCountStore.getInstance(context).clear() + } +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/ShuffleAllPlaylist.java b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/ShuffleAllPlaylist.java deleted file mode 100644 index d751150c..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/ShuffleAllPlaylist.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2019 Hemanth Savarala. - * - * Licensed under the GNU General Public License v3 - * - * This is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by - * the Free Software Foundation either version 3 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - */ - -package code.name.monkey.retromusic.model.smartplaylist; - -import android.content.Context; -import android.os.Parcel; -import android.os.Parcelable; -import androidx.annotation.NonNull; - - -import code.name.monkey.retromusic.R; -import code.name.monkey.retromusic.loaders.SongLoader; -import code.name.monkey.retromusic.model.Song; - -import java.util.ArrayList; - -import io.reactivex.Observable; - -public class ShuffleAllPlaylist extends AbsSmartPlaylist { - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public ShuffleAllPlaylist createFromParcel(Parcel source) { - return new ShuffleAllPlaylist(source); - } - - public ShuffleAllPlaylist[] newArray(int size) { - return new ShuffleAllPlaylist[size]; - } - }; - - public ShuffleAllPlaylist(@NonNull Context context) { - super(context.getString(R.string.action_shuffle_all), R.drawable.ic_shuffle_white_24dp); - } - - protected ShuffleAllPlaylist(Parcel in) { - super(in); - } - - @NonNull - @Override - public Observable> getSongs(@NonNull Context context) { - return SongLoader.INSTANCE.getAllSongs(context); - } - - @Override - public void clear(@NonNull Context context) { - // Shuffle all is not a real "Smart Playlist" - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/ShuffleAllPlaylist.kt b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/ShuffleAllPlaylist.kt new file mode 100644 index 00000000..3cc1abbf --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/ShuffleAllPlaylist.kt @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 Hemanth Savarala. + * + * Licensed under the GNU General Public License v3 + * + * This is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by + * the Free Software Foundation either version 3 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + */ + +package code.name.monkey.retromusic.model.smartplaylist + +import android.content.Context + +import java.util.ArrayList +import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.loaders.SongLoader +import code.name.monkey.retromusic.model.Song +import io.reactivex.Observable + +class ShuffleAllPlaylist(context: Context) : AbsSmartPlaylist(context.getString(R.string.action_shuffle_all), R.drawable.ic_shuffle_white_24dp) { + + + override fun getSongs(context: Context): Observable> { + return SongLoader.getAllSongs(context) + } + + override fun clear(context: Context) { + // Shuffle all is not a real "Smart Playlist" + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/providers/MusicPlaybackQueueStore.java b/app/src/main/java/code/name/monkey/retromusic/providers/MusicPlaybackQueueStore.java index b36a03bb..229c570a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/providers/MusicPlaybackQueueStore.java +++ b/app/src/main/java/code/name/monkey/retromusic/providers/MusicPlaybackQueueStore.java @@ -24,10 +24,10 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import code.name.monkey.retromusic.loaders.SongLoader; -import code.name.monkey.retromusic.model.Song; import java.util.ArrayList; +import code.name.monkey.retromusic.model.Song; import io.reactivex.Observable; /** @@ -39,7 +39,7 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper { public static final String DATABASE_NAME = "music_playback_state.db"; public static final String PLAYING_QUEUE_TABLE_NAME = "playing_queue"; public static final String ORIGINAL_PLAYING_QUEUE_TABLE_NAME = "original_playing_queue"; - private static final int VERSION = 7; + private static final int VERSION = 10; @Nullable private static MusicPlaybackQueueStore sInstance = null; @@ -111,7 +111,7 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper { builder.append(" STRING NOT NULL,"); builder.append(AudioColumns.COMPOSER); - builder.append(" STRING NOT NULL);"); + builder.append(" STRING);"); db.execSQL(builder.toString()); } @@ -163,18 +163,18 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper { Song song = queue.get(i); ContentValues values = new ContentValues(4); - values.put(BaseColumns._ID, song.id); - values.put(AudioColumns.TITLE, song.title); - values.put(AudioColumns.TRACK, song.trackNumber); - values.put(AudioColumns.YEAR, song.year); - values.put(AudioColumns.DURATION, song.duration); - values.put(AudioColumns.DATA, song.data); - values.put(AudioColumns.DATE_MODIFIED, song.dateModified); - values.put(AudioColumns.ALBUM_ID, song.albumId); - values.put(AudioColumns.ALBUM, song.albumName); - values.put(AudioColumns.ARTIST_ID, song.artistId); - values.put(AudioColumns.ARTIST, song.artistName); - values.put(AudioColumns.COMPOSER, song.composer); + values.put(BaseColumns._ID, song.getId()); + values.put(AudioColumns.TITLE, song.getTitle()); + values.put(AudioColumns.TRACK, song.getTrackNumber()); + values.put(AudioColumns.YEAR, song.getYear()); + values.put(AudioColumns.DURATION, song.getDuration()); + values.put(AudioColumns.DATA, song.getData()); + values.put(AudioColumns.DATE_MODIFIED, song.getDateModified()); + values.put(AudioColumns.ALBUM_ID, song.getAlbumId()); + values.put(AudioColumns.ALBUM, song.getAlbumName()); + values.put(AudioColumns.ARTIST_ID, song.getArtistId()); + values.put(AudioColumns.ARTIST, song.getArtistName()); + values.put(AudioColumns.COMPOSER, song.getComposer()); database.insert(tableName, null, values); } diff --git a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java index ec6a166b..795ba4f5 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java +++ b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java @@ -49,7 +49,6 @@ import android.telephony.TelephonyManager; import android.util.Log; import android.widget.Toast; -import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.transition.Transition; import java.lang.ref.WeakReference; @@ -262,7 +261,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP }; private static String getTrackUri(@NonNull Song song) { - return MusicUtil.getSongFileUri(song.id).toString(); + return MusicUtil.getSongFileUri(song.getId()).toString(); } private static Bitmap copy(Bitmap bitmap) { @@ -423,7 +422,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP playlistSongs = ((AbsCustomPlaylist) playlist).getSongs(getApplicationContext()).blockingFirst(); } else { //noinspection unchecked - playlistSongs = PlaylistSongsLoader.INSTANCE.getPlaylistSongList(getApplicationContext(), playlist.id).blockingFirst(); + playlistSongs = PlaylistSongsLoader.INSTANCE.getPlaylistSongList(getApplicationContext(), playlist.getId()).blockingFirst(); } if (!playlistSongs.isEmpty()) { if (shuffleMode == SHUFFLE_MODE_SHUFFLE) { @@ -663,7 +662,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP } public void updateNotification() { - if (playingNotification != null && getCurrentSong().id != -1) { + if (playingNotification != null && getCurrentSong().getId() != -1) { playingNotification.update(); } } @@ -680,19 +679,19 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP private void updateMediaSessionMetaData() { final Song song = getCurrentSong(); - if (song.id == -1) { + if (song.getId() == -1) { mediaSession.setMetadata(null); return; } final MediaMetadataCompat.Builder metaData = new MediaMetadataCompat.Builder() - .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, song.artistName) - .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, song.artistName) - .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, song.albumName) - .putString(MediaMetadataCompat.METADATA_KEY_TITLE, song.title) - .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, song.duration) + .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, song.getArtistName()) + .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, song.getArtistName()) + .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, song.getAlbumName()) + .putString(MediaMetadataCompat.METADATA_KEY_TITLE, song.getTitle()) + .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, song.getDuration()) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, getPosition() + 1) - .putLong(MediaMetadataCompat.METADATA_KEY_YEAR, song.year) + .putLong(MediaMetadataCompat.METADATA_KEY_YEAR, song.getYear()) .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -744,7 +743,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP if (position >= 0 && position < getPlayingQueue().size()) { return getPlayingQueue().get(position); } else { - return Song.EMPTY_SONG; + return Song.Companion.getEmptySong(); } } @@ -861,13 +860,13 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP public void removeSong(@NonNull Song song) { for (int i = 0; i < playingQueue.size(); i++) { - if (playingQueue.get(i).id == song.id) { + if (playingQueue.get(i).getId() == song.getId()) { playingQueue.remove(i); rePosition(i); } } for (int i = 0; i < originalPlayingQueue.size(); i++) { - if (originalPlayingQueue.get(i).id == song.id) { + if (originalPlayingQueue.get(i).getId() == song.getId()) { originalPlayingQueue.remove(i); } } @@ -1033,7 +1032,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP public long getQueueDurationMillis(int position) { long duration = 0; for (int i = position + 1; i < playingQueue.size(); i++) - duration += playingQueue.get(i).duration; + duration += playingQueue.get(i).getDuration(); return duration; } @@ -1087,11 +1086,11 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP break; case SHUFFLE_MODE_NONE: this.shuffleMode = shuffleMode; - int currentSongId = getCurrentSong().id; + int currentSongId = getCurrentSong().getId(); playingQueue = new ArrayList<>(originalPlayingQueue); int newPosition = 0; for (Song song : getPlayingQueue()) { - if (song.id == currentSongId) { + if (song.getId() == currentSongId) { newPosition = getPlayingQueue().indexOf(song); } } @@ -1118,11 +1117,11 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP final Song song = getCurrentSong(); - intent.putExtra("id", song.id); - intent.putExtra("artist", song.artistName); - intent.putExtra("album", song.albumName); - intent.putExtra("track", song.title); - intent.putExtra("duration", song.duration); + intent.putExtra("id", song.getId()); + intent.putExtra("artist", song.getArtistName()); + intent.putExtra("album", song.getAlbumName()); + intent.putExtra("track", song.getTitle()); + intent.putExtra("duration", song.getDuration()); intent.putExtra("position", (long) getSongProgressMillis()); intent.putExtra("playing", isPlaying()); intent.putExtra("scrobbling_source", RETRO_MUSIC_PACKAGE_NAME); @@ -1157,9 +1156,9 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP savePosition(); savePositionInTrack(); final Song currentSong = getCurrentSong(); - HistoryStore.getInstance(this).addSongId(currentSong.id); + HistoryStore.getInstance(this).addSongId(currentSong.getId()); if (songPlayCountHelper.shouldBumpPlayCount()) { - SongPlayCountStore.getInstance(this).bumpPlayCount(songPlayCountHelper.getSong().id); + SongPlayCountStore.getInstance(this).bumpPlayCount(songPlayCountHelper.getSong().getId()); } songPlayCountHelper.notifySongChanged(currentSong); break; @@ -1389,14 +1388,14 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP public static final String TAG = SongPlayCountHelper.class.getSimpleName(); private StopWatch stopWatch = new StopWatch(); - private Song song = Song.EMPTY_SONG; + private Song song = Song.getEmptySong(); public Song getSong() { return song; } boolean shouldBumpPlayCount() { - return song.duration * 0.5d < stopWatch.getElapsedTime(); + return song.getDuration() * 0.5d < stopWatch.getElapsedTime(); } void notifySongChanged(Song song) { diff --git a/app/src/main/java/code/name/monkey/retromusic/service/WearBrowserService.java b/app/src/main/java/code/name/monkey/retromusic/service/WearBrowserService.java index 4e6689a5..94217386 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/WearBrowserService.java +++ b/app/src/main/java/code/name/monkey/retromusic/service/WearBrowserService.java @@ -241,9 +241,9 @@ public class WearBrowserService extends MediaBrowserService { List songList = SongLoader.INSTANCE.getAllSongs(mContext).blockingFirst(); for (Song song : songList) { fillMediaItems(mediaItems, - String.valueOf(song.id), - song.title, - song.albumName, + String.valueOf(song.getId()), + song.getTitle(), + song.getAlbumName(), Uri.parse("android.resource://code.name.monkey.retromusic/drawable/default_album_art"), MediaBrowser.MediaItem.FLAG_PLAYABLE); } @@ -253,9 +253,9 @@ public class WearBrowserService extends MediaBrowserService { List albumSongList = AlbumLoader.Companion.getAlbum(mContext, Integer.parseInt(parentId.substring(1))).blockingFirst().getSongs(); for (Song song : albumSongList) { fillMediaItems(mediaItems, - String.valueOf(song.id), - song.title, - song.albumName, + String.valueOf(song.getId()), + song.getTitle(), + song.getAlbumName(), Uri.parse("android.resource://code.name.monkey.retromusic/drawable/default_album_art"), MediaBrowser.MediaItem.FLAG_PLAYABLE); } @@ -264,9 +264,9 @@ public class WearBrowserService extends MediaBrowserService { List artistSongs = ArtistLoader.INSTANCE.getArtist(mContext, Integer.parseInt(parentId.substring(1))).blockingFirst().getSongs(); for (Song song : artistSongs) { fillMediaItems(mediaItems, - String.valueOf(song.id), - song.title, - song.albumName, + String.valueOf(song.getId()), + song.getTitle(), + song.getAlbumName(), Uri.parse("android.resource://code.name.monkey.retromusic/drawable/default_album_art"), MediaBrowser.MediaItem.FLAG_PLAYABLE); } @@ -277,8 +277,8 @@ public class WearBrowserService extends MediaBrowserService { int size = PlaylistSongsLoader.INSTANCE.getPlaylistSongList(mContext, playlist).blockingFirst().size(); String songCount = String.format("%d %s", size, size > 1 ? "Songs" : "Song"); fillMediaItems(mediaItems, - Integer.toString(TYPE_PLAYLIST_ALL_SONGS) + Long.toString(playlist.id), - playlist.name, + Integer.toString(TYPE_PLAYLIST_ALL_SONGS) + Long.toString(playlist.getId()), + playlist.getName(), songCount, Uri.parse("android.resource://code.name.monkey.retromusic/drawable/ic_queue_music_white_24dp"), MediaBrowser.MediaItem.FLAG_BROWSABLE); @@ -288,9 +288,9 @@ public class WearBrowserService extends MediaBrowserService { List playlistSongs = PlaylistSongsLoader.INSTANCE.getPlaylistSongList(mContext, Integer.parseInt(parentId.substring(1))).blockingFirst(); for (Song song : playlistSongs) { fillMediaItems(mediaItems, - String.valueOf(song.id), - song.title, - song.albumName, + String.valueOf(song.getId()), + song.getTitle(), + song.getAlbumName(), Uri.parse("android.resource://code.name.monkey.retromusic/drawable/default_album_art"), MediaBrowser.MediaItem.FLAG_PLAYABLE); } diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/ArtistDetailActivity.kt b/app/src/main/java/code/name/monkey/retromusic/ui/activities/ArtistDetailActivity.kt index 056a2e6f..11e91bb6 100755 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/ArtistDetailActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/ArtistDetailActivity.kt @@ -27,9 +27,7 @@ import code.name.monkey.retromusic.glide.RetroGlideExtension import code.name.monkey.retromusic.glide.RetroMusicColoredTarget import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.misc.AppBarStateChangeListener -import code.name.monkey.retromusic.model.Album import code.name.monkey.retromusic.model.Artist -import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.mvp.contract.ArtistDetailContract import code.name.monkey.retromusic.mvp.presenter.ArtistDetailsPresenter import code.name.monkey.retromusic.rest.LastFMRestClient diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/LyricsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/ui/activities/LyricsActivity.kt index 47b6b158..a95fcbf2 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/LyricsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/LyricsActivity.kt @@ -243,7 +243,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage val data = MusicUtil.getLyrics(song) return if (TextUtils.isEmpty(data)) { null - } else Lyrics.parse(song, data) + } else Lyrics.parse(song, data!!) } override fun onPreExecute() { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/adapter/album/AlbumCoverPagerAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/ui/adapter/album/AlbumCoverPagerAdapter.kt index ea3f837c..3051ebc7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/adapter/album/AlbumCoverPagerAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/adapter/album/AlbumCoverPagerAdapter.kt @@ -111,7 +111,7 @@ class AlbumCoverPagerAdapter(fm: FragmentManager, private val dataSet: ArrayList private fun loadAlbumCover() { GlideApp.with(context!!) .asBitmapPalette() - .load(RetroGlideExtension.getSongModel(song)) + .load(RetroGlideExtension.getSongModel(song!!)) .transition(RetroGlideExtension.getDefaultTransition()) .songOptions(song) .dontAnimate() diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/adapter/playlist/PlaylistAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/ui/adapter/playlist/PlaylistAdapter.kt index 07dcdebd..832baa5e 100755 --- a/app/src/main/java/code/name/monkey/retromusic/ui/adapter/playlist/PlaylistAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/adapter/playlist/PlaylistAdapter.kt @@ -1,6 +1,5 @@ package code.name.monkey.retromusic.ui.adapter.playlist -import android.graphics.PorterDuff import android.graphics.drawable.Drawable import android.view.LayoutInflater import android.view.MenuItem @@ -152,7 +151,6 @@ class PlaylistAdapter(protected val activity: AppCompatActivity, dataSet: ArrayL for (playlist in playlists) { if (playlist is AbsCustomPlaylist) { songs.addAll(playlist.getSongs(activity).blockingFirst()) - //((AbsCustomPlaylist) playlist).getSongs(activity).subscribe(this::setSongs); } else { songs .addAll(PlaylistSongsLoader.getPlaylistSongList(activity, playlist.id).blockingFirst()) diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/adapter/song/AbsOffsetSongAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/ui/adapter/song/AbsOffsetSongAdapter.kt index 7d49591a..935867e7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/adapter/song/AbsOffsetSongAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/adapter/song/AbsOffsetSongAdapter.kt @@ -61,7 +61,7 @@ abstract class AbsOffsetSongAdapter : SongAdapter { override// could also return null, just to be safe return empty song val song: Song - get() = if (itemViewType == OFFSET_ITEM) Song.EMPTY_SONG else dataSet[adapterPosition - 1] + get() = if (itemViewType == OFFSET_ITEM) Song.emptySong else dataSet[adapterPosition - 1] override fun onClick(v: View?) { if (isInQuickSelectMode && itemViewType != OFFSET_ITEM) { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/adapter/song/SongAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/ui/adapter/song/SongAdapter.kt index 2381d564..91dece63 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/adapter/song/SongAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/adapter/song/SongAdapter.kt @@ -10,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.util.Pair import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.glide.GlideApp import code.name.monkey.retromusic.glide.RetroGlideExtension @@ -148,7 +149,7 @@ open class SongAdapter @JvmOverloads constructor(protected val activity: AppComp } override fun getName(song: Song): String { - return song.title!! + return song.title } override fun onMultipleItemAction(menuItem: MenuItem, @@ -158,13 +159,14 @@ open class SongAdapter @JvmOverloads constructor(protected val activity: AppComp override fun getSectionName(position: Int): String { if (!showSectionName) { - return ""; + return "" } val sectionName: String? = when (PreferenceUtil.getInstance().songSortOrder) { SortOrder.SongSortOrder.SONG_A_Z, SortOrder.SongSortOrder.SONG_Z_A -> dataSet[position].title SortOrder.SongSortOrder.SONG_ALBUM -> dataSet[position].albumName SortOrder.SongSortOrder.SONG_ARTIST -> dataSet[position].artistName SortOrder.SongSortOrder.SONG_YEAR -> return MusicUtil.getYearString(dataSet[position].year) + SortOrder.SongSortOrder.COMPOSER -> dataSet[position].composer else -> { return "" } diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/base/AbsPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/base/AbsPlayerFragment.kt index fbb9aeec..d0e7c214 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/base/AbsPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/base/AbsPlayerFragment.kt @@ -13,6 +13,7 @@ import android.view.View import android.widget.Toast import androidx.appcompat.widget.Toolbar import code.name.monkey.appthemehelper.ThemeStore + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.dialogs.* import code.name.monkey.retromusic.helper.MusicPlayerRemote diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/SongsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/SongsFragment.kt index ff433459..412eb42c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/SongsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/SongsFragment.kt @@ -2,6 +2,7 @@ package code.name.monkey.retromusic.ui.fragments.mainactivity import android.os.Bundle import androidx.recyclerview.widget.GridLayoutManager + import code.name.monkey.retromusic.R import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.mvp.contract.SongContract @@ -14,7 +15,8 @@ import java.util.* class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), SongContract.SongView { - private var presenter: SongPresenter? = null + + private lateinit var presenter: SongPresenter override val emptyMessage: Int get() = R.string.no_songs diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/folders/FoldersFragment.java b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/folders/FoldersFragment.java index fa07aec0..429fa510 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/folders/FoldersFragment.java +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/folders/FoldersFragment.java @@ -48,6 +48,7 @@ import code.name.monkey.appthemehelper.util.ATHUtil; import code.name.monkey.appthemehelper.util.ColorUtil; import code.name.monkey.appthemehelper.util.TintHelper; import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper; + import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.helper.MusicPlayerRemote; import code.name.monkey.retromusic.helper.menu.SongMenuHelper; @@ -365,7 +366,7 @@ public class FoldersFragment extends AbsMainActivityFragment implements File file1 = (File) extra; int startIndex = -1; for (int i = 0; i < songs.size(); i++) { - if (file1.getPath().equals(songs.get(i).data)) { // path is already canonical here + if (file1.getPath().equals(songs.get(i).getData())) { // path is already canonical here startIndex = i; break; } diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/classic/ClassicPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/classic/ClassicPlayerFragment.kt index 887e81b5..4985e0db 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/classic/ClassicPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/classic/ClassicPlayerFragment.kt @@ -374,7 +374,7 @@ class PortraitImpl(private val fragment: ClassicPlayerFragment) : BaseImpl(fragm } private var currentSongViewHolder: MediaEntryViewHolder? = null - var currentSong = Song.EMPTY_SONG!! + var currentSong = Song.emptySong } diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt index 578ec7bd..798e5b1a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt @@ -258,7 +258,7 @@ class ColorFragment : AbsPlayerFragment() { val data = MusicUtil.getLyrics(song) return if (TextUtils.isEmpty(data)) { null - } else Lyrics.parse(song, data) + } else Lyrics.parse(song, data!!) } override fun onPostExecute(l: Lyrics?) { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/full/FullPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/full/FullPlaybackControlsFragment.kt index 66f26f5f..70867933 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/full/FullPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/full/FullPlaybackControlsFragment.kt @@ -2,7 +2,6 @@ package code.name.monkey.retromusic.ui.fragments.player.full import android.animation.ObjectAnimator import android.annotation.SuppressLint -import android.app.AlertDialog import android.content.res.ColorStateList import android.graphics.Color import android.graphics.PorterDuff diff --git a/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.java index 84f99c6b..841f8995 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.java @@ -71,10 +71,10 @@ public class MusicUtil { } @NonNull - public static Intent createShareSongFileIntent(@NonNull final Song song, Context context) { + public static Intent createShareSongFileIntent(@NonNull final Song song, @NonNull Context context) { try { return new Intent().setAction(Intent.ACTION_SEND).putExtra(Intent.EXTRA_STREAM, - FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName(), new File(song.data))) + FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName(), new File(song.getData()))) .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) .setType("audio/*"); } catch (IllegalArgumentException e) { @@ -120,10 +120,10 @@ public class MusicUtil { } @NonNull - public static String getSongInfoString(@NonNull final Song song) { + public static String getSongInfoString(@NonNull Song song) { return MusicUtil.buildInfoString( - song.artistName, - song.albumName + song.getArtistName(), + song.getAlbumName() ); } @@ -182,7 +182,7 @@ public class MusicUtil { long duration = 0; for (int i = 0; i < songs.size(); i++) { - duration += songs.get(i).duration; + duration += songs.get(i).getDuration(); } return songCount + " " + songString + " • " + MusicUtil.getReadableDurationString(duration); @@ -247,7 +247,7 @@ public class MusicUtil { final StringBuilder selection = new StringBuilder(); selection.append(BaseColumns._ID + " IN ("); for (int i = 0; i < songs.size(); i++) { - selection.append(songs.get(i).id); + selection.append(songs.get(i).getId()); if (i < songs.size() - 1) { selection.append(","); } @@ -308,10 +308,10 @@ public class MusicUtil { @Nullable - public static String getLyrics(Song song) { + public static String getLyrics(@NonNull Song song) { String lyrics = null; - File file = new File(song.data); + File file = new File(song.getData()); try { lyrics = AudioFileIO.read(file).getTagOrCreateDefault().getFirst(FieldKey.LYRICS); @@ -326,7 +326,7 @@ public class MusicUtil { if (dir != null && dir.exists() && dir.isDirectory()) { String format = ".*%s.*\\.(lrc|txt)"; String filename = Pattern.quote(FileUtil.stripExtension(file.getName())); - String songtitle = Pattern.quote(song.title); + String songtitle = Pattern.quote(song.getTitle()); final ArrayList patterns = new ArrayList<>(); patterns.add(Pattern.compile(String.format(format, filename), @@ -366,18 +366,16 @@ public class MusicUtil { public static void toggleFavorite(@NonNull final Context context, @NonNull final Song song) { if (isFavorite(context, song)) { - PlaylistsUtil - .removeFromPlaylist(context, song, getFavoritesPlaylist(context).blockingFirst().id); + PlaylistsUtil.removeFromPlaylist(context, song, getFavoritesPlaylist(context).blockingFirst().getId()); } else { - PlaylistsUtil - .addToPlaylist(context, song, getOrCreateFavoritesPlaylist(context).blockingFirst().id, - false); + PlaylistsUtil.addToPlaylist(context, song, getOrCreateFavoritesPlaylist(context).blockingFirst().getId(), + false); } } public static boolean isFavoritePlaylist(@NonNull final Context context, @NonNull final Playlist playlist) { - return playlist.name != null && playlist.name.equals(context.getString(R.string.favorites)); + return playlist.getName() != null && playlist.getName().equals(context.getString(R.string.favorites)); } private static Observable getFavoritesPlaylist(@NonNull final Context context) { @@ -399,7 +397,7 @@ public class MusicUtil { //getFavoritesPlaylist(context).blockingFirst().id.subscribe(MusicUtil::setPlaylist); //return PlaylistsUtil.doPlaylistContains(context, getFavoritesPlaylist(context).blockingFirst().id, song.id); return PlaylistsUtil - .doPlaylistContains(context, getFavoritesPlaylist(context).blockingFirst().id, song.id); + .doPlaylistContains(context, getFavoritesPlaylist(context).blockingFirst().getId(), song.getId()); } public static boolean isArtistNameUnknown(@Nullable String artistName) { @@ -430,18 +428,19 @@ public class MusicUtil { return String.valueOf(musicMediaTitle.charAt(0)).toUpperCase(); } + @NonNull public static Playlist getPlaylist() { return playlist; } - public static void setPlaylist(Playlist playlist) { + public static void setPlaylist(@NonNull Playlist playlist) { MusicUtil.playlist = playlist; } public static long getTotalDuration(@NonNull final Context context, @NonNull List songs) { long duration = 0; for (int i = 0; i < songs.size(); i++) { - duration += songs.get(i).duration; + duration += songs.get(i).getDuration(); } return duration; } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/NavigationUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/NavigationUtil.java index 737f10dd..005e373e 100755 --- a/app/src/main/java/code/name/monkey/retromusic/util/NavigationUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/NavigationUtil.java @@ -19,6 +19,7 @@ import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.media.audiofx.AudioEffect; +import android.view.View; import android.widget.Toast; import androidx.annotation.NonNull; @@ -75,10 +76,10 @@ public class NavigationUtil { intent.putExtra(ArtistDetailActivity.EXTRA_ARTIST_ID, i); //noinspection unchecked ActivityCompat.startActivity(activity, intent, - ActivityOptionsCompat.makeSceneTransitionAnimation(activity, null).toBundle()); + ActivityOptionsCompat.makeSceneTransitionAnimation(activity, (Pair) null).toBundle()); } - public static void goToPlaylistNew(@NonNull Activity activity, Playlist playlist) { + public static void goToPlaylistNew(@NonNull Activity activity, @NonNull Playlist playlist) { Intent intent = new Intent(activity, PlaylistDetailActivity.class); intent.putExtra(PlaylistDetailActivity.Companion.getEXTRA_PLAYLIST(), playlist); ActivityCompat.startActivity(activity, intent, null); diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java index 2c1b68c3..b3096f24 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java @@ -22,14 +22,14 @@ import android.net.Uri; import android.os.Environment; import android.provider.BaseColumns; import android.provider.MediaStore; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import android.widget.Toast; import java.io.File; import java.util.ArrayList; import java.util.List; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.helper.M3UWriter; import code.name.monkey.retromusic.model.Playlist; @@ -99,7 +99,7 @@ public class PlaylistsUtil { final StringBuilder selection = new StringBuilder(); selection.append(MediaStore.Audio.Playlists._ID + " IN ("); for (int i = 0; i < playlists.size(); i++) { - selection.append(playlists.get(i).id); + selection.append(playlists.get(i).getId()); if (i < playlists.size() - 1) { selection.append(","); } @@ -120,9 +120,7 @@ public class PlaylistsUtil { public static void addToPlaylist(@NonNull final Context context, @NonNull final List songs, final int playlistId, final boolean showToastOnFinish) { final int size = songs.size(); final ContentResolver resolver = context.getContentResolver(); - final String[] projection = new String[]{ - "max(" + MediaStore.Audio.Playlists.Members.PLAY_ORDER + ")", - }; + final String[] projection = new String[]{"max(" + MediaStore.Audio.Playlists.Members.PLAY_ORDER + ")",}; final Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId); Cursor cursor = null; int base = 0; @@ -153,7 +151,7 @@ public class PlaylistsUtil { } @NonNull - public static ContentValues[] makeInsertItems(@NonNull final List songs, final int offset, int len, final int base) { + private static ContentValues[] makeInsertItems(@NonNull final List songs, final int offset, int len, final int base) { if (offset + len > songs.size()) { len = songs.size() - offset; } @@ -163,7 +161,7 @@ public class PlaylistsUtil { for (int i = 0; i < len; i++) { contentValues[i] = new ContentValues(); contentValues[i].put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, base + offset + i); - contentValues[i].put(MediaStore.Audio.Playlists.Members.AUDIO_ID, songs.get(offset + i).id); + contentValues[i].put(MediaStore.Audio.Playlists.Members.AUDIO_ID, songs.get(offset + i).getAlbumId()); } return contentValues; } @@ -172,7 +170,7 @@ public class PlaylistsUtil { Uri uri = MediaStore.Audio.Playlists.Members.getContentUri( "external", playlistId); String selection = MediaStore.Audio.Playlists.Members.AUDIO_ID + " =?"; - String[] selectionArgs = new String[]{String.valueOf(song.id)}; + String[] selectionArgs = new String[]{String.valueOf(song.getId())}; try { context.getContentResolver().delete(uri, selection, selectionArgs); @@ -181,12 +179,12 @@ public class PlaylistsUtil { } public static void removeFromPlaylist(@NonNull final Context context, @NonNull final List songs) { - final int playlistId = songs.get(0).playlistId; + final int playlistId = songs.get(0).getPlaylistId(); Uri uri = MediaStore.Audio.Playlists.Members.getContentUri( "external", playlistId); String selectionArgs[] = new String[songs.size()]; for (int i = 0; i < selectionArgs.length; i++) { - selectionArgs[i] = String.valueOf(songs.get(i).idInPlayList); + selectionArgs[i] = String.valueOf(songs.get(i).getIdInPlayList()); } String selection = MediaStore.Audio.Playlists.Members._ID + " in ("; //noinspection unused diff --git a/settings.gradle b/settings.gradle index f3f0c306..91441848 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':appthemehelper', ':models' \ No newline at end of file +include ':app', ':appthemehelper' \ No newline at end of file