Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

feat: collect new UI events #116

Merged
merged 4 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.provider.DocumentFile;
import android.util.Log;
import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog;
import com.annimon.stream.Collectors;
Expand All @@ -22,6 +23,7 @@
import com.simplecity.amp_library.data.Repository;
import com.simplecity.amp_library.model.Album;
import com.simplecity.amp_library.model.AlbumArtist;
import com.simplecity.amp_library.model.Artist;
import com.simplecity.amp_library.model.Song;
import com.simplecity.amp_library.playback.MediaManager;
import com.simplecity.amp_library.saf.SafManager;
Expand All @@ -32,6 +34,10 @@
import com.simplecity.amp_library.utils.extensions.AlbumExtKt;
import com.simplecity.amp_library.utils.extensions.SongExtKt;
import dagger.android.support.AndroidSupportInjection;
import edu.usf.sas.pal.muser.model.UiEvent;
import edu.usf.sas.pal.muser.model.UiEventType;
import edu.usf.sas.pal.muser.util.EventUtils;
import edu.usf.sas.pal.muser.util.FirebaseIOUtils;
import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.Single;
Expand Down Expand Up @@ -282,6 +288,26 @@ void deleteSongsOrShowSafDialog() {
.subscribe(deletedSongs -> {
if (DeleteDialog.this.isAdded()) {
if (deletedSongs > 0) {
switch(type) {
case Type.ALBUMS:
for (Album album : albums) {
UiEvent uiEvent = EventUtils.newUiAlbumEvent
(album, UiEventType.DELETE_ALBUM);
FirebaseIOUtils.saveUiEvent(uiEvent);
}
case Type.ARTISTS:
for (AlbumArtist artist : artists) {
UiEvent uiEvent = EventUtils.newUiAlbumArtistEvent
(artist, UiEventType.DELETE_ALBUM_ARTIST);
FirebaseIOUtils.saveUiEvent(uiEvent);
}
case Type.SONGS:
for (Song song : songs) {
UiEvent uiEvent = EventUtils.newUiEvent
(song, UiEventType.DELETE, getContext());
FirebaseIOUtils.saveUiEvent(uiEvent);
}
}
Toast.makeText(getContext(), getString(R.string.delete_songs_success_toast, deletedSongs), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getContext(), getString(R.string.delete_songs_failure_toast), Toast.LENGTH_SHORT).show();
Expand Down Expand Up @@ -319,6 +345,7 @@ Single<Integer> deleteSongs() {
});
}


void tidyUp(@NonNull List<Song> deletedSongs) {
if (deletedSongs.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class AlbumMenuPresenter @Inject constructor(
view?.onSongsAddedToPlaylist(playlist, numSongs)
}
}
albums.forEach {
newUiAlbumEvent(it, UiEventType.ADD_TO_PLAYLIST_ALBUM)
}
}

override fun addAlbumsToQueue(albums: List<Album>) {
Expand All @@ -68,11 +71,14 @@ class AlbumMenuPresenter @Inject constructor(
view?.onSongsAddedToQueue(numSongs)
}
}
albums.forEach{
newUiAlbumEvent(it, UiEventType.PLAY_ALBUM_NEXT)
}
}

override fun play(album: Album) {
mediaManager.playAll(album.getSongsSingle(songsRepository)) { view?.onPlaybackFailed() }
newUiAlbumEvent(album)
newUiAlbumEvent(album, UiEventType.PLAY_ALBUM)
}

override fun editTags(album: Album) {
Expand Down Expand Up @@ -136,8 +142,8 @@ class AlbumMenuPresenter @Inject constructor(
const val TAG = "AlbumMenuContract"
}

private fun newUiAlbumEvent(album: Album){
val uiEvent = EventUtils.newUiAlbumEvent(album, UiEventType.PLAY_ALBUM)
private fun newUiAlbumEvent(album: Album, uiEventType: UiEventType){
val uiEvent = EventUtils.newUiAlbumEvent(album, uiEventType)
FirebaseIOUtils.saveUiEvent(uiEvent)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.simplecity.amp_library.utils.Operators
import com.simplecity.amp_library.utils.extensions.getSongs
import com.simplecity.amp_library.utils.playlists.PlaylistManager
import com.simplecity.amp_library.utils.sorting.SortManager
import edu.usf.sas.pal.muser.model.UiEvent
import edu.usf.sas.pal.muser.model.UiEventType
import edu.usf.sas.pal.muser.util.EventUtils
import edu.usf.sas.pal.muser.util.FirebaseIOUtils
Expand Down Expand Up @@ -54,6 +55,9 @@ class AlbumArtistMenuPresenter @Inject constructor(
view?.onSongsAddedToPlaylist(playlist, numSongs)
}
}
albumArtists.forEach {
newUiAlbumArtistEvent(it, UiEventType.ADD_TO_PLAYLIST_ALBUM_ARTIST)
}
}

override fun addArtistsToQueue(albumArtists: List<AlbumArtist>) {
Expand All @@ -70,11 +74,14 @@ class AlbumArtistMenuPresenter @Inject constructor(
view?.onSongsAddedToQueue(numSongs)
}
}
albumArtists.forEach{
newUiAlbumArtistEvent(it, UiEventType.PLAY_ALBUM_ARTIST_NEXT)
}
}

override fun play(albumArtist: AlbumArtist) {
mediaManager.playAll(albumArtist.getSongsSingle(songsRepository)) { view?.onPlaybackFailed() }
newUiAlbumArtistEvent(albumArtist)
newUiAlbumArtistEvent(albumArtist, UiEventType.PLAY_ALBUM_ARTIST)
}

override fun editTags(albumArtist: AlbumArtist) {
Expand Down Expand Up @@ -107,6 +114,7 @@ class AlbumArtistMenuPresenter @Inject constructor(
view?.onPlaybackFailed()
Unit
}
newUiAlbumArtistEvent(albumArtist, UiEventType.ALBUM_SHUFFLE)
}

override fun <T> transform(src: Single<List<T>>, dst: (List<T>) -> Unit) {
Expand Down Expand Up @@ -137,8 +145,8 @@ class AlbumArtistMenuPresenter @Inject constructor(
const val TAG = "AlbumMenuContract"
}

private fun newUiAlbumArtistEvent(albumArtist: AlbumArtist){
val uiEvent = EventUtils.newUiAlbumArtistEvent(albumArtist, UiEventType.PLAY_ALBUM_ARTIST)
private fun newUiAlbumArtistEvent(albumArtist: AlbumArtist, uiEventType: UiEventType){
val uiEvent = EventUtils.newUiAlbumArtistEvent(albumArtist, uiEventType)
FirebaseIOUtils.saveUiEvent(uiEvent)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class GenreMenuPresenter @Inject constructor(
view?.onSongsAddedToPlaylist(playlist, numSongs)
}
}
newUiGenreEvent(genre, UiEventType.ADD_TO_PLAYLIST_GENRE)
}

override fun addToQueue(genre: Genre) {
Expand All @@ -51,13 +52,14 @@ class GenreMenuPresenter @Inject constructor(
}

override fun play(genre: Genre) {
newUiGenreEvent(genre)
newUiGenreEvent(genre, UiEventType.PLAY_GENRE)
mediaManager.playAll(genre.getSongs(context)) {
view?.onPlaybackFailed()
}
}

override fun playNext(genre: Genre) {
newUiGenreEvent(genre, UiEventType.PLAY_GENRE_NEXT)
getSongs(genre) { songs ->
mediaManager.playNext(songs) { numSongs ->
view?.onSongsAddedToQueue(numSongs)
Expand All @@ -76,8 +78,8 @@ class GenreMenuPresenter @Inject constructor(
)
)
}
private fun newUiGenreEvent(genre: Genre){
val uiEvent = EventUtils.newUiGenreEvent(genre, UiEventType.PLAY_GENRE)
private fun newUiGenreEvent(genre: Genre, uiEventType: UiEventType){
val uiEvent = EventUtils.newUiGenreEvent(genre, uiEventType)
FirebaseIOUtils.saveUiEvent(uiEvent)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.simplecity.amp_library.ui.screens.songs.menu.SongMenuContract.View
import com.simplecity.amp_library.utils.LogUtils
import com.simplecity.amp_library.utils.RingtoneManager
import com.simplecity.amp_library.utils.playlists.PlaylistManager
import edu.usf.sas.pal.muser.model.UiEvent
import edu.usf.sas.pal.muser.model.UiEventType
import edu.usf.sas.pal.muser.util.EventUtils
import edu.usf.sas.pal.muser.util.FirebaseIOUtils
Expand Down Expand Up @@ -41,12 +42,15 @@ open class SongMenuPresenter @Inject constructor(
override fun addToPlaylist(context: Context, playlist: Playlist, songs: List<Song>) {
if (playlist.type == Playlist.Type.FAVORITES) {
songs.forEach {
newUiEvent(it)
newUiEvent(it, UiEventType.FAVORITE)
}
}
playlistManager.addToPlaylist(context, playlist, songs) { numSongs ->
view?.onSongsAddedToPlaylist(playlist, numSongs)
}
songs.forEach {
newUiEvent(it, UiEventType.ADD_TO_PLAYLIST)
}
}

override fun addToQueue(songs: List<Song>) {
Expand All @@ -59,6 +63,9 @@ open class SongMenuPresenter @Inject constructor(
mediaManager.playNext(songs) { numSongs ->
view?.onSongsAddedToQueue(numSongs)
}
songs.forEach {
newUiEvent(it, UiEventType.PLAY_NEXT)
}
}

override fun blacklist(songs: List<Song>) {
Expand Down Expand Up @@ -141,8 +148,8 @@ open class SongMenuPresenter @Inject constructor(
const val TAG = "SongMenuPresenter"
}

private fun newUiEvent(song: Song){
val uiEvent = EventUtils.newUiEvent(song, UiEventType.FAVORITE, ShuttleApplication.get())
private fun newUiEvent(song: Song, uiEventType: UiEventType){
val uiEvent = EventUtils.newUiEvent(song, uiEventType, ShuttleApplication.get())
FirebaseIOUtils.saveUiEvent(uiEvent)
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/edu/usf/sas/pal/muser/model/UiEventType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ public enum UiEventType {
PLAY_ALBUM,
PLAY_ALBUM_ARTIST,
PLAY_GENRE,
PLAY_NEXT,
PLAY_ALBUM_NEXT,
PLAY_ALBUM_ARTIST_NEXT,
PLAY_GENRE_NEXT,
ADD_TO_PLAYLIST,
ADD_TO_PLAYLIST_ALBUM,
ADD_TO_PLAYLIST_ALBUM_ARTIST,
ADD_TO_PLAYLIST_GENRE,
ALBUM_SHUFFLE,
DELETE,
DELETE_ALBUM,
DELETE_ALBUM_ARTIST,
PAUSE,
NEXT,
PREV,
Expand Down