-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from 07jasjeet/listen-scrobble-refactor-beta-1
Listen Scrobble Service Beta-1
- Loading branch information
Showing
32 changed files
with
844 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/listenbrainz/android/model/OnTimerListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.listenbrainz.android.model | ||
|
||
interface OnTimerListener { | ||
fun onTimerRun(milliseconds: Long) {} | ||
fun onTimerStarted() | ||
fun onTimerPaused(remainingMillis: Long) | ||
fun onTimerStopped() {} | ||
fun onTimerEnded() | ||
} |
105 changes: 105 additions & 0 deletions
105
app/src/main/java/org/listenbrainz/android/model/PlayingTrack.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package org.listenbrainz.android.model | ||
|
||
import android.media.MediaMetadata | ||
import org.listenbrainz.android.util.ListenSubmissionState.Companion.DEFAULT_DURATION | ||
import org.listenbrainz.android.util.ListenSubmissionState.Companion.extractArtist | ||
import org.listenbrainz.android.util.ListenSubmissionState.Companion.extractDuration | ||
import org.listenbrainz.android.util.ListenSubmissionState.Companion.extractReleaseName | ||
import org.listenbrainz.android.util.ListenSubmissionState.Companion.extractTitle | ||
|
||
/** Track metadata class for Listen Scrobble service.*/ | ||
data class PlayingTrack( | ||
var artist: String? = null, | ||
var title: String? = null, | ||
var releaseName: String? = null, | ||
var timestamp: Long = 0, | ||
var duration: Long = 0, | ||
var pkgName: String? = null, | ||
var playingNowSubmitted: Boolean = false, | ||
var submitted: Boolean = false, | ||
var playbackState: Int? = null | ||
) { | ||
val timestampSeconds: Long | ||
get() = timestamp / 1000 | ||
|
||
/** This means there's no track playing.*/ | ||
fun isNothing(): Boolean = artist == null && title == null | ||
|
||
fun isSubmitted(): Boolean = submitted | ||
|
||
/** Determines if this track is a notification scrobbled track or not.*/ | ||
fun isNotificationTrack(): Boolean = artist != null && title != null && duration == 0L | ||
|
||
fun isCallbackTrack(): Boolean = !isNotificationTrack() | ||
|
||
fun reset() { | ||
artist = null | ||
title = null | ||
releaseName = null | ||
timestamp = 0 | ||
duration = 0 | ||
pkgName = null | ||
playingNowSubmitted = false | ||
submitted = false | ||
} | ||
|
||
/** Similar means that the basic metadata matches. A song if replayed will be similar.*/ | ||
fun isSimilarTo(other: Any): Boolean { | ||
return when (other) { | ||
is PlayingTrack -> artist == other.artist | ||
&& title == other.title | ||
&& pkgName == other.pkgName | ||
is MediaMetadata -> artist == other.extractArtist() | ||
&& title == other.extractTitle() | ||
else -> { | ||
throw IllegalStateException( | ||
"${other.javaClass.simpleName} is not supported for use in this function." | ||
) | ||
} | ||
} | ||
} | ||
|
||
/** Determines if *this* track is outdated in comparison to [newTrack]. | ||
* | ||
* Covers case where a track being replayed is similar but is actually outdated.*/ | ||
fun isOutdated(newTrack: PlayingTrack): Boolean { | ||
return when { | ||
this.isSimilarTo(newTrack) -> { | ||
// If track is similar. | ||
// If the difference in timestamps is greater than duration of the whole track, it | ||
// means our track is outdated for sure. | ||
when { | ||
newTrack.duration != 0L -> { | ||
// New track is callback track, duration data available. | ||
newTrack.timestamp - timestamp >= newTrack.duration | ||
} | ||
this.duration != 0L -> { | ||
// New track is callback track, duration data available. | ||
newTrack.timestamp - timestamp >= this.duration | ||
} | ||
submitted -> true | ||
else -> { | ||
// New track and old track both are notification track. So, no duration | ||
// available. We use default duration. | ||
newTrack.timestamp - timestamp >= DEFAULT_DURATION | ||
} | ||
} | ||
} | ||
else -> true | ||
} | ||
} | ||
|
||
companion object { | ||
fun MediaMetadata.toPlayingTrack(pkgName: String): PlayingTrack { | ||
return PlayingTrack( | ||
timestamp = System.currentTimeMillis(), | ||
artist = extractArtist(), | ||
title = extractTitle(), | ||
duration = extractDuration(), | ||
releaseName = extractReleaseName(), | ||
pkgName = pkgName, | ||
playingNowSubmitted = false | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.listenbrainz.android.model | ||
|
||
enum class Status { | ||
RUN, | ||
PAUSE, | ||
START, | ||
STOP, | ||
END | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/src/main/java/org/listenbrainz/android/repository/scrobblemanager/ScrobbleManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.listenbrainz.android.repository.scrobblemanager | ||
|
||
import android.media.MediaMetadata | ||
import android.media.session.PlaybackState | ||
import android.service.notification.StatusBarNotification | ||
|
||
interface ScrobbleManager { | ||
|
||
fun onMetadataChanged(metadata: MediaMetadata?, player: String) | ||
|
||
fun onPlaybackStateChanged(state: PlaybackState?) | ||
|
||
fun onNotificationPosted(sbn: StatusBarNotification?) | ||
|
||
fun onNotificationRemoved(sbn: StatusBarNotification?) | ||
} |
Oops, something went wrong.