Skip to content

Commit

Permalink
chore: Add song data POJO (timusus#41)
Browse files Browse the repository at this point in the history
Step 1 to implement timusus#17.
  • Loading branch information
BumbleFlash committed Aug 17, 2020
1 parent ee699db commit 393df18
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void setResumed() {
*
* @return the elapsed time of this track (in millis)
*/
private long getElapsedTime() {
public long getElapsedTime() {
if (isPaused) {
return elapsedTime;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import com.simplecity.amp_library.ui.views.SnowfallView;
import com.simplecity.amp_library.ui.views.multisheet.MultiSheetSlideEventRelay;
import com.simplecity.amp_library.utils.LogUtils;
import com.simplecity.amp_library.utils.MusicServiceConnectionUtils;
import com.simplecity.amp_library.utils.PlaceholderProvider;
import com.simplecity.amp_library.utils.RingtoneManager;
import com.simplecity.amp_library.utils.SettingsManager;
Expand All @@ -76,6 +77,8 @@
import com.simplecity.amp_library.utils.color.ArgbEvaluator;
import com.simplecity.amp_library.utils.menu.song.SongMenuUtils;
import dagger.android.support.AndroidSupportInjection;
import edu.usf.sas.pal.muser.model.EventType;
import edu.usf.sas.pal.muser.util.EventUtils;
import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.Observable;
Expand Down Expand Up @@ -224,6 +227,14 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
if (playPauseView != null) {
playPauseView.setOnClickListener(v -> playPauseView.toggle(() -> {
presenter.togglePlayback();
Song song = getSong();
EventType eventType;
if (isPlaying())
eventType = EventType.PLAY_MANUAL;
else
eventType = EventType.PAUSE_MANUAL;
Log.d(TAG, "onViewCreated: " + eventType);
EventUtils.newEvent(song, eventType, getContext());
return Unit.INSTANCE;
}));
}
Expand Down Expand Up @@ -753,4 +764,19 @@ public void presentRingtonePermissionDialog() {
public void showRingtoneSetMessage() {
Toast.makeText(getContext(), R.string.ringtone_set_new, Toast.LENGTH_SHORT).show();
}

@Nullable
private Song getSong() {
if (MusicServiceConnectionUtils.serviceBinder != null && MusicServiceConnectionUtils.serviceBinder.getService() != null) {
return MusicServiceConnectionUtils.serviceBinder.getService().getSong();
}
return null;
}

private boolean isPlaying(){
if (MusicServiceConnectionUtils.serviceBinder != null && MusicServiceConnectionUtils.serviceBinder.getService() != null) {
return MusicServiceConnectionUtils.serviceBinder.getService().isPlaying();
}
return false;
}
}
24 changes: 24 additions & 0 deletions app/src/main/java/edu/usf/sas/pal/muser/model/Event.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package edu.usf.sas.pal.muser.model

/**
* A model class that stores the actions performed on the song track. The actions like play, pause,
* skip, repeat and seek are stored along with the nested [SongData] class.
*/

data class Event

/**
* [event] - The event attribute includes events like play, pause, skip, repeat and seek.
* [currentTimeMs] - Stores the timestamp of the action recorded.
* [nanoTime] - Stores the value of the running JVM's time source in nanoseconds.
* [startTime] - Start time of the song.
* [elapsedTime] - Elapsed time of the song when the event occurred.
* [song] - Song on which the action was performed.
*/
(val event:EventType,
val currentTimeMs: Long,
val nanoTime: Long,
val startTime: Long,
val elapsedTime: Long,
val song: SongData
)
18 changes: 18 additions & 0 deletions app/src/main/java/edu/usf/sas/pal/muser/model/EventType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package edu.usf.sas.pal.muser.model;

import org.jetbrains.annotations.NotNull;

/**
* The provider enumerator that stores different types of action that can be performed by the user
* on a sound track.
*/
public enum EventType {

PLAY,
PLAY_MANUAL,
PAUSE,
PAUSE_MANUAL,
SKIP,
REPEAT,
SEEK
}
60 changes: 60 additions & 0 deletions app/src/main/java/edu/usf/sas/pal/muser/model/SongData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package edu.usf.sas.pal.muser.model

import android.content.Context
import com.simplecity.amp_library.model.Song


/**
* A model class that holds the information about the song that is currently being played by the
* user.
*/
data class SongData

/**
* [id] - The id of the track.
* [name] - Name of the track.
* [artistID] - The id of the artist.
* [artistName] - Name of the Artist who composed the track.
* [albumID] - The id of the album.
* [albumName] - Name of the album that the current track belongs to.
* [playlistID] - The id of the playlist that track belongs to.
* [playlistPlayOrder] - The queue number of the song in a playlist.
* [discNumber] - The disc number that the track belongs to.
* [bitrateLabel] - The bitrate of the song.
* [fileSizeLabel] - The file size of the song.
* [isPodCast] - Boolean value to determine if the current audio file is a pod cast or not.
* [duration] - The length of the track.
* [dateAdded] - The date on which the track was added.
* [year] - The year during which the track was released.
* [playCount] - The number of times the user played this track.
* [sampleRateLabel] - The sample rate of the song.
* [formatLabel] - The format of the song. (mp3 or wav etc.)
*/
(val id: Long,
val name: String,
val artistID: Long,
val artistName: String,
val albumID: Long,
val albumName: String,
val playlistID: Long,
val playlistPlayOrder: Long,
val lastPlayed: Long,
val track: Int,
val discNumber: Int,
val bitrateLabel: String,
val fileSizeLabel: String,
val isPodCast: Boolean,
val duration: Long,
val dateAdded: Int,
val year: Int,
val path: String,
val playCount: Int,
val sampleRateLabel: String,
val formatLabel: String
){
constructor(song: Song, context: Context): this(song.id, song.name, song.artistId, song.albumName, song.albumId,
song.albumName, song.playlistSongId, song.playlistSongPlayOrder, song.lastPlayed,
song.track, song.discNumber, song.getBitrateLabel(context), song.getFileSizeLabel(),
song.isPodcast, song.duration, song.dateAdded, song.year, song.path, song.playCount,
song.getSampleRateLabel(context), song.getFormatLabel())
}
30 changes: 30 additions & 0 deletions app/src/main/java/edu/usf/sas/pal/muser/util/EventUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.usf.sas.pal.muser.util;

import android.content.Context;

import com.simplecity.amp_library.ShuttleApplication;
import com.simplecity.amp_library.model.Song;

import edu.usf.sas.pal.muser.model.Event;
import edu.usf.sas.pal.muser.model.EventType;
import edu.usf.sas.pal.muser.model.SongData;



public class EventUtils {

/**
* Function to populate the Event data class.
* @param song - The song for which the event occurred.
* @param capturedEvent - The event that was captured.
* @param context - The context of the Fragment.
* @return - Event object
*/
public static Event newEvent(Song song, EventType capturedEvent, Context context){
long currentTimeMS = System.currentTimeMillis();
long nanoTime = System.nanoTime();
SongData songData = new SongData(song, context);
long elapsedTime = song.getElapsedTime();
return new Event(capturedEvent, currentTimeMS, nanoTime, song.startTime, elapsedTime, songData);
}
}

0 comments on commit 393df18

Please sign in to comment.