Skip to content

Commit

Permalink
migrate to media1, link heart button to rating, profile pic fixes, no…
Browse files Browse the repository at this point in the history
…n intrusive "Scrobbler disabled" message, session tag blocklist, secure fileprovider, fixes
  • Loading branch information
kawaiiDango committed Feb 20, 2024
1 parent f0c2a81 commit adc3b53
Show file tree
Hide file tree
Showing 29 changed files with 606 additions and 288 deletions.
Binary file removed app/libs/acrcloud-universal-sdk-1.3.20.jar
Binary file not shown.
Binary file added app/libs/acrcloud-universal-sdk-1.3.24.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion app/src/main/java/com/arn/scrobble/BugReportUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ object BugReportUtils {
//keep the email in english

val log = Stuff.exec("logcat -d")
val logFile = File(App.context.filesDir, "log.txt")
val logFile = File(App.context.cacheDir, "share/log.txt")
logFile.parentFile!!.mkdirs()
logFile.writeText(log)
val logUri =
FileProvider.getUriForFile(
Expand Down
18 changes: 1 addition & 17 deletions app/src/main/java/com/arn/scrobble/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@ class MainActivity : AppCompatActivity(),

private suspend fun showSnackbarIfNeeded() {
delay(1500)
val nlsEnabled = Stuff.isNotificationListenerEnabled()

if (nlsEnabled && !Stuff.isScrobblerRunning()) {
if (Stuff.isNotificationListenerEnabled() && prefs.scrobblerEnabled && !Stuff.isScrobblerRunning()) {
Snackbar.make(
binding.root,
R.string.not_running,
Expand All @@ -306,20 +304,6 @@ class MainActivity : AppCompatActivity(),
.focusOnTv()
.show()
Timber.tag(Stuff.TAG).w(Exception("${Stuff.SCROBBLER_PROCESS_NAME} not running"))
} else if (!nlsEnabled || !prefs.scrobblerEnabled) {
Snackbar.make(
binding.root,
R.string.scrobbler_off,
Snackbar.LENGTH_INDEFINITE
)
.setAction(R.string.enable) {
if (!prefs.scrobblerEnabled)
prefs.scrobblerEnabled = true
else
navController.navigate(R.id.onboardingFragment)
}
.focusOnTv()
.show()
} else
Updater(this).withSnackbar()
}
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/java/com/arn/scrobble/NLService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,8 @@ class NLService : NotificationListenerService() {

trackInfo.userLoved = loved
notifyScrobble(trackInfo)
if (BuildConfig.DEBUG)

if (prefs.linkHeartButtonToRating && prefs.proStatus)
sessListener?.findControllersByPackage(trackInfo.packageName)?.apply {
if (loved)
love()
Expand Down Expand Up @@ -1033,13 +1034,6 @@ class NLService : NotificationListenerService() {
}

private fun submitScrobble(trackInfoCopy: PlayingTrackInfo) {
if (!prefs.scrobbleSpotifyRemote &&
// !isRemotePlayback &&
trackInfoCopy.packageName == Stuff.PACKAGE_SPOTIFY &&
!audioManager.isMusicActive
)
return

LFMRequester(coroutineScope)
.scrobble(false, trackInfoCopy)

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/arn/scrobble/NavUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ object NavUtils {
navNumEntriesList.forEach { it.isVisible = false }
}

val profilePicUrl = currentUser.getWebpImageURL(ImageSize.EXTRALARGE) ?: ""
val profilePicUrl = if (currentUser.isSelf)
App.prefs.drawerDataCached.profilePicUrl
else
currentUser.getWebpImageURL(ImageSize.EXTRALARGE)
?: ""
if (headerNavBinding.navProfilePic.getTag(R.id.img_url) != profilePicUrl + username) // todo prevent flash
headerNavBinding.navProfilePic.load(profilePicUrl) {
allowHardware(false)
Expand Down
133 changes: 113 additions & 20 deletions app/src/main/java/com/arn/scrobble/PlayerActions.kt
Original file line number Diff line number Diff line change
@@ -1,45 +1,138 @@
package com.arn.scrobble

import android.media.Rating
import android.media.session.MediaController
import android.support.v4.media.RatingCompat
import android.support.v4.media.session.MediaControllerCompat

object PlayerActions {

fun List<MediaController>.skip() {
class CustomRatingAction(
val love: String,
val unlove: String,
val unlovedLabel: String? = null,
val extrasIsArgs: Boolean = false
) {
init {
if (love == unlove && unlovedLabel == null)
throw IllegalArgumentException("Love and unlove actions must be different or unlovedLabel must be provided.")
}
}

private val customRatingActions = mapOf(
Stuff.PACKAGE_SPOTIFY to CustomRatingAction("ADD_TO", "CHECK_FILL"),
Stuff.PACKAGE_SOUNDCLOUD to CustomRatingAction(
"com.soundcloud.android.playback.action.ACTION_LIKE_TRACK",
"com.soundcloud.android.playback.action.ACTION_LIKE_TRACK",
"UnLikeRatingAction"
),
// Stuff.PACKAGE_OTO_MUSIC to CustomRatingAction(
// "com.piyush.music.togglefavorite",
// ),
// Stuff.PACKAGE_PI_MUSIC to CustomRatingAction("action_favorite"),
// Stuff.PACKAGE_SYMFONIUM to CustomRatingAction("symfonium.action_favorite"),
Stuff.PACKAGE_PLEXAMP to CustomRatingAction(
"tv.plex.labs.commonandroid.LOVE_TRACK",
"tv.plex.labs.commonandroid.INDIFFERENCE_TRACK"
),
// Stuff.PACKAGE_BANDCAMP to CustomRatingAction(
// "bandcamp_wishlist",
// "bandcamp_wishlist",
// true
// ),
)

fun List<MediaControllerCompat>.skip() {
forEach {
it.transportControls.skipToNext()
}
}

// doesn't work in spotify, s2
// works in youtube, yt music, poweramp,
fun List<MediaController>.love() {
// default rating tested working on:
// youtube, yt music, poweramp, aimp, musicolet, neutron, doubletwist, playerpro, pandora,
// amazon music, iHeartRadio, apple music, nyx,

// rating does not heart individual tracks on:
// bandcamp (wishists the entire album), tunein radio (favorites the station),

// tested not working on:
// vlc, bandcamp, retro, vocacolle, shuttle 2, blackplayer, phonograph, pulsar, foobar,
// jet audio, n7, plex, subtracks, listenbrainz, radio japan, media monkey, omnia,
// gonemad, deezer, tidal, podcast addict, gensokyo radio, gaana, wynk, jiosaavn, DIFM,
// antenna pod, hiby, fiio,

fun List<MediaControllerCompat>.love() {
forEach {
// custom actions override the rating
if (it.packageName in customRatingActions) {
val customAction = customRatingActions[it.packageName]!!

val customActionFromPlayer = it.playbackState?.customActions?.find {
it.action == customAction.love &&
(customAction.unlovedLabel == null ||
customAction.unlovedLabel == it.name)
} ?: return@forEach

val args = if (customRatingActions[it.packageName]!!.extrasIsArgs)
customActionFromPlayer.extras
else
null

it.transportControls.sendCustomAction(customActionFromPlayer, args)

return@forEach
}

val rating = when (it.ratingType) {
Rating.RATING_THUMB_UP_DOWN -> Rating.newThumbRating(true)
Rating.RATING_HEART -> Rating.newHeartRating(true)
Rating.RATING_3_STARS -> Rating.newStarRating(
Rating.RATING_3_STARS,
3F
)

Rating.RATING_4_STARS -> Rating.newStarRating(Rating.RATING_4_STARS, 4F)
Rating.RATING_5_STARS -> Rating.newStarRating(Rating.RATING_5_STARS, 5F)
Rating.RATING_PERCENTAGE -> Rating.newPercentageRating(100F)
RatingCompat.RATING_THUMB_UP_DOWN ->
RatingCompat.newThumbRating(true)

RatingCompat.RATING_HEART ->
RatingCompat.newHeartRating(true)

RatingCompat.RATING_3_STARS ->
RatingCompat.newStarRating(RatingCompat.RATING_3_STARS, 3F)

RatingCompat.RATING_4_STARS ->
RatingCompat.newStarRating(RatingCompat.RATING_4_STARS, 4F)

RatingCompat.RATING_5_STARS ->
RatingCompat.newStarRating(RatingCompat.RATING_5_STARS, 5F)

RatingCompat.RATING_PERCENTAGE ->
RatingCompat.newPercentageRating(100F)

else -> null
}
if (rating != null)
it.transportControls.setRating(rating)

Stuff.logD { "Rating type for ${it.packageName}: ${it.ratingType}" }
Stuff.log("Rating type: ${it.ratingType}")
}
}

fun List<MediaController>.unlove() {
fun List<MediaControllerCompat>.unlove() {
forEach {
val ratingSupported = it.ratingType != Rating.RATING_NONE
// custom actions override the rating
if (it.packageName in customRatingActions) {
val customAction = customRatingActions[it.packageName]!!

val customActionFromPlayer = it.playbackState?.customActions?.find {
it.action == customAction.unlove &&
(customAction.unlovedLabel == null ||
customAction.unlovedLabel != it.name)
} ?: return@forEach

val args = if (customRatingActions[it.packageName]!!.extrasIsArgs)
customActionFromPlayer.extras
else
null
it.transportControls.sendCustomAction(customActionFromPlayer, args)

return@forEach
}

val ratingSupported = it.ratingType != RatingCompat.RATING_NONE
if (ratingSupported)
it.transportControls.setRating(Rating.newUnratedRating(it.ratingType))
it.transportControls.setRating(RatingCompat.newUnratedRating(it.ratingType))
}
}
}
Loading

0 comments on commit adc3b53

Please sign in to comment.