feat: Jam-Song zu den eigenen Lieblingssongs (Herz am laufenden Song) (1.8.0)
Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
@@ -19,8 +19,8 @@ android {
|
||||
applicationId = "de.fojadrachi.playtube"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 12
|
||||
versionName = "1.7.0"
|
||||
versionCode = 13
|
||||
versionName = "1.8.0"
|
||||
|
||||
// Update-Quelle: eigener Gitea-Server (kein GitHub/Google Play).
|
||||
buildConfigField("String", "UPDATE_SERVER", "\"https://git.fojadrachi.de\"")
|
||||
|
||||
@@ -83,6 +83,11 @@ class JamActivity : AppCompatActivity() {
|
||||
codeInput.setOnEditorActionListener { _, _, _ -> joinJam(codeInput.text.toString()); true }
|
||||
leave.setOnClickListener { JamHub.leave() }
|
||||
findViewById<View>(R.id.jamPlayPause).setOnClickListener { JamHub.playPause() }
|
||||
findViewById<View>(R.id.jamNowLike).setOnClickListener {
|
||||
if (JamHub.state?.current == null) return@setOnClickListener
|
||||
// Herz zaehlt fuer den laufenden Song, der in der WebView spielt - mit deinem Login.
|
||||
PlaybackHub.send(PlayerCommand.Like)
|
||||
}
|
||||
findViewById<View>(R.id.jamNext).setOnClickListener { JamHub.send("skip") }
|
||||
findViewById<View>(R.id.jamPrevious).setOnClickListener { JamHub.send("previous") }
|
||||
addButton.setOnClickListener { add() }
|
||||
@@ -253,6 +258,9 @@ class JamActivity : AppCompatActivity() {
|
||||
val state = JamHub.state ?: return
|
||||
|
||||
val item = state.current
|
||||
val like = findViewById<ImageButton>(R.id.jamNowLike)
|
||||
like.visibility = if (item != null) View.VISIBLE else View.GONE
|
||||
like.setImageResource(if (PlaybackHub.nowPlaying.likeStatus == "like") R.drawable.ic_like else R.drawable.ic_favorite_border)
|
||||
findViewById<TextView>(R.id.jamNowTitle).text = item?.title ?: getString(R.string.jam_nothing)
|
||||
findViewById<TextView>(R.id.jamNowArtist).text = item?.let { subtitle(it) } ?: ""
|
||||
val cover = findViewById<ImageView>(R.id.jamCover)
|
||||
@@ -355,6 +363,10 @@ class JamActivity : AppCompatActivity() {
|
||||
findViewById<TextView>(R.id.jamTime).text = JamSync.formatTime(pos)
|
||||
findViewById<TextView>(R.id.jamDuration).text = JamSync.formatTime(dur)
|
||||
if (!seeking) seek.progress = if (dur > 0) (pos / dur * 1000).toInt() else 0
|
||||
val like = findViewById<ImageButton>(R.id.jamNowLike)
|
||||
if (like.visibility == View.VISIBLE) {
|
||||
like.setImageResource(if (PlaybackHub.nowPlaying.likeStatus == "like") R.drawable.ic_like else R.drawable.ic_favorite_border)
|
||||
}
|
||||
}
|
||||
|
||||
private fun subtitle(item: JamSync.Item): String {
|
||||
|
||||
@@ -363,6 +363,8 @@ object JamHub {
|
||||
*/
|
||||
fun intercept(command: PlayerCommand): Boolean {
|
||||
val s = state ?: return false
|
||||
// Like gilt fuer den laufenden Song in der WebView (eigener Login) - nicht in den Jam umleiten.
|
||||
if (command == PlayerCommand.Like) return false
|
||||
if (!s.canControl) return true
|
||||
when (command) {
|
||||
PlayerCommand.PlayPause -> playPause()
|
||||
@@ -370,6 +372,7 @@ object JamHub {
|
||||
PlayerCommand.Pause -> send("pause")
|
||||
PlayerCommand.Next -> send("skip")
|
||||
PlayerCommand.Previous -> send("previous")
|
||||
PlayerCommand.Like -> return false
|
||||
is PlayerCommand.SeekTo -> send("seek", "pos" to command.positionMs / 1000.0)
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -62,13 +62,23 @@ object MediaScripts {
|
||||
var sliderOk = isFinite(now) && isFinite(max) && max > 0;
|
||||
var current = sliderOk ? now : (video ? video.currentTime : 0);
|
||||
var duration = sliderOk ? max : ((video && isFinite(video.duration)) ? video.duration : 0);
|
||||
var likeStatus = null;
|
||||
try {
|
||||
var renderer = document.querySelector('ytmusic-player-bar ytmusic-like-button-renderer');
|
||||
likeStatus = renderer ? (renderer.getAttribute('like-status') || '').toLowerCase() : null;
|
||||
if (!likeStatus) {
|
||||
var pressed = document.querySelector('like-button-view-model button[aria-pressed=true], #segmented-like-button button[aria-pressed=true]');
|
||||
if (pressed) likeStatus = 'like';
|
||||
}
|
||||
} catch (e) { likeStatus = null; }
|
||||
return JSON.stringify({
|
||||
title: title || '',
|
||||
artist: artist || '',
|
||||
artwork: artwork,
|
||||
playing: !!video && !video.paused && !video.ended && video.readyState > 2,
|
||||
currentTime: current || 0,
|
||||
duration: duration || 0
|
||||
duration: duration || 0,
|
||||
likeStatus: likeStatus
|
||||
});
|
||||
})();
|
||||
"""
|
||||
@@ -85,6 +95,8 @@ object MediaScripts {
|
||||
action("nexttrack", "['ytmusic-player-bar .next-button','.next-button']")
|
||||
PlayerCommand.Previous ->
|
||||
action("previoustrack", "['ytmusic-player-bar .previous-button','.previous-button']")
|
||||
PlayerCommand.Like ->
|
||||
action("like", "['ytmusic-player-bar ytmusic-like-button-renderer #button-shape-like button','like-button-view-model button','#segmented-like-button button']")
|
||||
is PlayerCommand.SeekTo -> {
|
||||
val seconds = command.positionMs / 1000.0
|
||||
"(function(){var v=document.querySelector('video');if(v){v.currentTime=$seconds;}})();"
|
||||
|
||||
@@ -11,11 +11,12 @@ data class NowPlaying(
|
||||
val playing: Boolean,
|
||||
val positionMs: Long,
|
||||
val durationMs: Long,
|
||||
val likeStatus: String? = null,
|
||||
) {
|
||||
val hasTrack: Boolean get() = title.isNotBlank()
|
||||
|
||||
companion object {
|
||||
val EMPTY = NowPlaying("", "", null, playing = false, positionMs = 0L, durationMs = 0L)
|
||||
val EMPTY = NowPlaying("", "", null, playing = false, positionMs = 0L, durationMs = 0L, likeStatus = null)
|
||||
|
||||
private const val ARTIST_SEPARATOR = " • "
|
||||
|
||||
@@ -34,6 +35,7 @@ data class NowPlaying(
|
||||
playing = json.optBoolean("playing", false),
|
||||
positionMs = seconds(json.optDouble("currentTime", 0.0)),
|
||||
durationMs = seconds(json.optDouble("duration", 0.0)),
|
||||
likeStatus = json.optString("likeStatus").takeIf { it.isNotBlank() && it != "null" },
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ sealed class PlayerCommand {
|
||||
data object Pause : PlayerCommand()
|
||||
data object Next : PlayerCommand()
|
||||
data object Previous : PlayerCommand()
|
||||
data object Like : PlayerCommand()
|
||||
data class SeekTo(val positionMs: Long) : PlayerCommand()
|
||||
}
|
||||
|
||||
|
||||
@@ -207,6 +207,15 @@
|
||||
android:textColor="@color/text_muted"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/jamNowLike"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="44dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/jam_like"
|
||||
android:src="@drawable/ic_favorite_border"
|
||||
android:tint="@color/brand_to" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
<string name="jam_kick">Entfernen</string>
|
||||
<string name="jam_kick_confirm">%1$s aus dem Jam entfernen?</string>
|
||||
<string name="jam_make_host">Zum Host machen</string>
|
||||
<string name="jam_like">Zu Lieblingssongs</string>
|
||||
<string name="jam_make_host_confirm">%1$s zum Host machen? Du gibst damit die Host-Rechte ab.</string>
|
||||
<string name="jam_error_offline">Diese Person ist gerade nicht verbunden.</string>
|
||||
<string name="jam_play_now">Jetzt spielen</string>
|
||||
|
||||
Reference in New Issue
Block a user