Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce8af7a9c4 | ||
|
|
7f55699657 | ||
|
|
341155bc6b |
@@ -19,8 +19,8 @@ android {
|
|||||||
applicationId = "de.fojadrachi.playtube"
|
applicationId = "de.fojadrachi.playtube"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 12
|
versionCode = 15
|
||||||
versionName = "1.7.0"
|
versionName = "1.10.0"
|
||||||
|
|
||||||
// Update-Quelle: eigener Gitea-Server (kein GitHub/Google Play).
|
// Update-Quelle: eigener Gitea-Server (kein GitHub/Google Play).
|
||||||
buildConfigField("String", "UPDATE_SERVER", "\"https://git.fojadrachi.de\"")
|
buildConfigField("String", "UPDATE_SERVER", "\"https://git.fojadrachi.de\"")
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.content.Context
|
||||||
|
import android.text.Editable
|
||||||
|
import android.text.TextWatcher
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import android.widget.EditText
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.ListView
|
||||||
|
import android.widget.TextView
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Calendar
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
/** Verlauf als Liste mit Suchfeld (Handy-Verlauf und Verlauf am PC). */
|
||||||
|
object HistoryDialog {
|
||||||
|
fun show(
|
||||||
|
context: Context,
|
||||||
|
title: String,
|
||||||
|
entries: List<HistoryEntry>,
|
||||||
|
onPick: (HistoryEntry) -> Unit,
|
||||||
|
onClear: (() -> Unit)? = null,
|
||||||
|
) {
|
||||||
|
val pad = (16 * context.resources.displayMetrics.density).toInt()
|
||||||
|
val search = EditText(context).apply {
|
||||||
|
hint = context.getString(R.string.history_search)
|
||||||
|
isSingleLine = true
|
||||||
|
}
|
||||||
|
val empty = TextView(context).apply {
|
||||||
|
text = context.getString(R.string.history_empty)
|
||||||
|
alpha = 0.7f
|
||||||
|
setPadding(0, pad, 0, pad)
|
||||||
|
}
|
||||||
|
var shown = entries
|
||||||
|
val adapter = object : ArrayAdapter<HistoryEntry>(context, android.R.layout.simple_list_item_2, android.R.id.text1, ArrayList(entries)) {
|
||||||
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
|
val view = super.getView(position, convertView, parent)
|
||||||
|
val entry = getItem(position) ?: return view
|
||||||
|
view.findViewById<TextView>(android.R.id.text1).text = entry.title
|
||||||
|
view.findViewById<TextView>(android.R.id.text2).text =
|
||||||
|
listOf(entry.artist, timeText(context, entry.playedAt)).filter { it.isNotBlank() }.joinToString(" · ")
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val list = ListView(context).apply {
|
||||||
|
this.adapter = adapter
|
||||||
|
layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (360 * context.resources.displayMetrics.density).toInt())
|
||||||
|
}
|
||||||
|
fun refresh() {
|
||||||
|
val q = search.text.toString().trim().lowercase()
|
||||||
|
shown = entries.filter { q.isEmpty() || it.title.lowercase().contains(q) || it.artist.lowercase().contains(q) }
|
||||||
|
adapter.clear()
|
||||||
|
adapter.addAll(shown)
|
||||||
|
empty.visibility = if (shown.isEmpty()) View.VISIBLE else View.GONE
|
||||||
|
}
|
||||||
|
search.addTextChangedListener(object : TextWatcher {
|
||||||
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit
|
||||||
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) = Unit
|
||||||
|
override fun afterTextChanged(s: Editable?) = refresh()
|
||||||
|
})
|
||||||
|
val content = LinearLayout(context).apply {
|
||||||
|
orientation = LinearLayout.VERTICAL
|
||||||
|
setPadding(pad, pad / 2, pad, 0)
|
||||||
|
addView(search)
|
||||||
|
addView(empty)
|
||||||
|
addView(list)
|
||||||
|
}
|
||||||
|
refresh()
|
||||||
|
val builder = AlertDialog.Builder(context)
|
||||||
|
.setTitle(title)
|
||||||
|
.setView(content)
|
||||||
|
.setPositiveButton(R.string.history_close, null)
|
||||||
|
if (onClear != null && entries.isNotEmpty()) {
|
||||||
|
builder.setNeutralButton(R.string.history_clear) { _, _ ->
|
||||||
|
AlertDialog.Builder(context)
|
||||||
|
.setMessage(R.string.history_clear_confirm)
|
||||||
|
.setPositiveButton(R.string.history_clear) { _, _ -> onClear() }
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val dialog = builder.show()
|
||||||
|
list.setOnItemClickListener { _, _, position, _ ->
|
||||||
|
shown.getOrNull(position)?.let(onPick)
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "Heute, 14:32" bzw. "15.11., 14:32". */
|
||||||
|
private fun timeText(context: Context, millis: Long): String {
|
||||||
|
if (millis <= 0) return ""
|
||||||
|
val time = android.text.format.DateFormat.getTimeFormat(context).format(Date(millis))
|
||||||
|
val then = Calendar.getInstance().apply { timeInMillis = millis }
|
||||||
|
val now = Calendar.getInstance()
|
||||||
|
val sameDay = then.get(Calendar.YEAR) == now.get(Calendar.YEAR) && then.get(Calendar.DAY_OF_YEAR) == now.get(Calendar.DAY_OF_YEAR)
|
||||||
|
return if (sameDay) context.getString(R.string.history_today, time)
|
||||||
|
else SimpleDateFormat("d.M.", Locale.GERMANY).format(Date(millis)) + ", " + time
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -83,6 +83,11 @@ class JamActivity : AppCompatActivity() {
|
|||||||
codeInput.setOnEditorActionListener { _, _, _ -> joinJam(codeInput.text.toString()); true }
|
codeInput.setOnEditorActionListener { _, _, _ -> joinJam(codeInput.text.toString()); true }
|
||||||
leave.setOnClickListener { JamHub.leave() }
|
leave.setOnClickListener { JamHub.leave() }
|
||||||
findViewById<View>(R.id.jamPlayPause).setOnClickListener { JamHub.playPause() }
|
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.jamNext).setOnClickListener { JamHub.send("skip") }
|
||||||
findViewById<View>(R.id.jamPrevious).setOnClickListener { JamHub.send("previous") }
|
findViewById<View>(R.id.jamPrevious).setOnClickListener { JamHub.send("previous") }
|
||||||
addButton.setOnClickListener { add() }
|
addButton.setOnClickListener { add() }
|
||||||
@@ -253,6 +258,9 @@ class JamActivity : AppCompatActivity() {
|
|||||||
val state = JamHub.state ?: return
|
val state = JamHub.state ?: return
|
||||||
|
|
||||||
val item = state.current
|
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.jamNowTitle).text = item?.title ?: getString(R.string.jam_nothing)
|
||||||
findViewById<TextView>(R.id.jamNowArtist).text = item?.let { subtitle(it) } ?: ""
|
findViewById<TextView>(R.id.jamNowArtist).text = item?.let { subtitle(it) } ?: ""
|
||||||
val cover = findViewById<ImageView>(R.id.jamCover)
|
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.jamTime).text = JamSync.formatTime(pos)
|
||||||
findViewById<TextView>(R.id.jamDuration).text = JamSync.formatTime(dur)
|
findViewById<TextView>(R.id.jamDuration).text = JamSync.formatTime(dur)
|
||||||
if (!seeking) seek.progress = if (dur > 0) (pos / dur * 1000).toInt() else 0
|
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 {
|
private fun subtitle(item: JamSync.Item): String {
|
||||||
|
|||||||
@@ -363,6 +363,8 @@ object JamHub {
|
|||||||
*/
|
*/
|
||||||
fun intercept(command: PlayerCommand): Boolean {
|
fun intercept(command: PlayerCommand): Boolean {
|
||||||
val s = state ?: return false
|
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
|
if (!s.canControl) return true
|
||||||
when (command) {
|
when (command) {
|
||||||
PlayerCommand.PlayPause -> playPause()
|
PlayerCommand.PlayPause -> playPause()
|
||||||
@@ -370,6 +372,7 @@ object JamHub {
|
|||||||
PlayerCommand.Pause -> send("pause")
|
PlayerCommand.Pause -> send("pause")
|
||||||
PlayerCommand.Next -> send("skip")
|
PlayerCommand.Next -> send("skip")
|
||||||
PlayerCommand.Previous -> send("previous")
|
PlayerCommand.Previous -> send("previous")
|
||||||
|
PlayerCommand.Like -> return false
|
||||||
is PlayerCommand.SeekTo -> send("seek", "pos" to command.positionMs / 1000.0)
|
is PlayerCommand.SeekTo -> send("seek", "pos" to command.positionMs / 1000.0)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import android.os.Build
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.os.SystemClock
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.CheckBox
|
import android.widget.CheckBox
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
@@ -57,6 +58,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verlauf (auf dem Handy gehoerte Songs) und Schlaf-Timer
|
||||||
|
private lateinit var history: PlayHistory
|
||||||
|
private var sleepTimer: SleepTimer? = null
|
||||||
|
|
||||||
private val notificationPermission =
|
private val notificationPermission =
|
||||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { /* ohne Erlaubnis: nur keine Benachrichtigung */ }
|
registerForActivityResult(ActivityResultContracts.RequestPermission()) { /* ohne Erlaubnis: nur keine Benachrichtigung */ }
|
||||||
|
|
||||||
@@ -69,7 +74,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
keepContentBetweenSystemBars()
|
keepContentBetweenSystemBars()
|
||||||
findViewById<View>(R.id.pcRemoteButton).setOnClickListener { PcRemoteActivity.start(this) }
|
findViewById<View>(R.id.pcRemoteButton).setOnClickListener { PcRemoteActivity.start(this) }
|
||||||
findViewById<View>(R.id.jamButton).setOnClickListener { JamActivity.start(this) }
|
findViewById<View>(R.id.jamButton).setOnClickListener { JamActivity.start(this) }
|
||||||
findViewById<View>(R.id.settingsButton).setOnClickListener { showSettings() }
|
findViewById<View>(R.id.settingsButton).setOnClickListener { showMenu() }
|
||||||
|
history = PlayHistory.fromJson(runCatching { historyFile().readText() }.getOrNull())
|
||||||
JamHub.init(this)
|
JamHub.init(this)
|
||||||
|
|
||||||
configureWebView()
|
configureWebView()
|
||||||
@@ -196,6 +202,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// Fuer "Jam starten": der gerade laufende Song wird der erste im Jam.
|
// Fuer "Jam starten": der gerade laufende Song wird der erste im Jam.
|
||||||
val videoId = JamSync.parseVideoId(webView.url)
|
val videoId = JamSync.parseVideoId(webView.url)
|
||||||
JamHub.pageVideo = if (videoId != null && info.hasTrack) JamHub.PageVideo(videoId, info.title, info.artist) else null
|
JamHub.pageVideo = if (videoId != null && info.hasTrack) JamHub.PageVideo(videoId, info.title, info.artist) else null
|
||||||
|
if (history.observe(videoId, info, info.playing, SystemClock.elapsedRealtime(), System.currentTimeMillis())) saveHistory()
|
||||||
|
sleepTick(if (info.playing && info.hasTrack) videoId else null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,6 +261,113 @@ class MainActivity : AppCompatActivity() {
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Menue, Schlaf-Timer, Verlauf
|
||||||
|
|
||||||
|
/** Der kleine Knopf rechts: Schlaf-Timer, Verlauf, Einstellungen. */
|
||||||
|
private fun showMenu() {
|
||||||
|
val timer = sleepTimer
|
||||||
|
val sleepLabel = if (timer == null) getString(R.string.sleep_title)
|
||||||
|
else getString(R.string.sleep_title_active, sleepText(timer))
|
||||||
|
val items = arrayOf(sleepLabel, getString(R.string.history_title), getString(R.string.settings_open))
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.menu_title)
|
||||||
|
.setItems(items) { _, which ->
|
||||||
|
when (which) {
|
||||||
|
0 -> showSleepDialog()
|
||||||
|
1 -> showHistory()
|
||||||
|
else -> showSettings()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sleepText(timer: SleepTimer): String =
|
||||||
|
if (timer.endOfTrack) getString(R.string.sleep_end_short)
|
||||||
|
else SleepTimer.format(timer.remainingSeconds(SystemClock.elapsedRealtime()))
|
||||||
|
|
||||||
|
private fun showSleepDialog() {
|
||||||
|
val minutes = SleepTimer.CHOICES
|
||||||
|
val labels = minutes.map { getString(R.string.sleep_minutes, it) } +
|
||||||
|
getString(R.string.sleep_end) + getString(R.string.sleep_off)
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.sleep_title)
|
||||||
|
.setItems(labels.toTypedArray()) { _, which ->
|
||||||
|
when {
|
||||||
|
which < minutes.size -> setSleep(SleepTimer.minutes(minutes[which], SystemClock.elapsedRealtime()))
|
||||||
|
which == minutes.size -> setSleep(SleepTimer.endOfTrack(currentVideo()))
|
||||||
|
else -> setSleep(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun currentVideo(): String? =
|
||||||
|
JamSync.parseVideoId(webView.url)?.takeIf { PlaybackHub.nowPlaying.playing && PlaybackHub.nowPlaying.hasTrack }
|
||||||
|
|
||||||
|
private fun setSleep(timer: SleepTimer?) {
|
||||||
|
restoreVolume()
|
||||||
|
sleepTimer = timer
|
||||||
|
val text = if (timer == null) getString(R.string.sleep_cleared) else getString(R.string.sleep_set, sleepText(timer))
|
||||||
|
Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Bei jeder Abfrage der Seite (alle 1,5 s). */
|
||||||
|
private fun sleepTick(track: String?) {
|
||||||
|
val timer = sleepTimer ?: return
|
||||||
|
when (val step = timer.tick(SystemClock.elapsedRealtime(), track)) {
|
||||||
|
SleepTimer.Step.Wait -> Unit
|
||||||
|
is SleepTimer.Step.Fade -> webView.evaluateJavascript(
|
||||||
|
"(function(){var v=document.querySelector('video');if(!v)return;" +
|
||||||
|
"if(window.__ptSleepVol===undefined){window.__ptSleepVol=v.volume;}" +
|
||||||
|
"v.volume=Math.max(0,window.__ptSleepVol*${step.factor});})();",
|
||||||
|
null,
|
||||||
|
)
|
||||||
|
SleepTimer.Step.Stop -> {
|
||||||
|
sleepTimer = null
|
||||||
|
// Im Jam nur fuer sich aufhoeren: den Jam verlassen statt ihn fuer alle anzuhalten.
|
||||||
|
if (JamHub.state != null) JamHub.leave()
|
||||||
|
webView.evaluateJavascript(MediaScripts.forCommand(PlayerCommand.Pause), null)
|
||||||
|
handler.postDelayed({ restoreVolume() }, 1500)
|
||||||
|
Diagnostics.line("sleep: Schlaf-Timer abgelaufen")
|
||||||
|
Toast.makeText(this, R.string.sleep_done, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun restoreVolume() {
|
||||||
|
webView.evaluateJavascript(
|
||||||
|
"(function(){var v=document.querySelector('video');if(v&&window.__ptSleepVol!==undefined){" +
|
||||||
|
"v.volume=window.__ptSleepVol;}delete window.__ptSleepVol;})();",
|
||||||
|
null,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun historyFile() = java.io.File(filesDir, "history.json")
|
||||||
|
|
||||||
|
private fun saveHistory() {
|
||||||
|
val text = history.toJson()
|
||||||
|
Thread {
|
||||||
|
runCatching {
|
||||||
|
val tmp = java.io.File(filesDir, "history.json.tmp")
|
||||||
|
tmp.writeText(text)
|
||||||
|
tmp.renameTo(historyFile())
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showHistory() {
|
||||||
|
HistoryDialog.show(
|
||||||
|
this,
|
||||||
|
getString(R.string.history_title),
|
||||||
|
history.search(""),
|
||||||
|
onPick = { webView.loadUrl("$MUSIC_ORIGIN/watch?v=${it.videoId}") },
|
||||||
|
onClear = {
|
||||||
|
history.clear()
|
||||||
|
saveHistory()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun showSettings() {
|
private fun showSettings() {
|
||||||
val pad = (20 * resources.displayMetrics.density).toInt()
|
val pad = (20 * resources.displayMetrics.density).toInt()
|
||||||
val box = CheckBox(this).apply {
|
val box = CheckBox(this).apply {
|
||||||
|
|||||||
@@ -62,13 +62,23 @@ object MediaScripts {
|
|||||||
var sliderOk = isFinite(now) && isFinite(max) && max > 0;
|
var sliderOk = isFinite(now) && isFinite(max) && max > 0;
|
||||||
var current = sliderOk ? now : (video ? video.currentTime : 0);
|
var current = sliderOk ? now : (video ? video.currentTime : 0);
|
||||||
var duration = sliderOk ? max : ((video && isFinite(video.duration)) ? video.duration : 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({
|
return JSON.stringify({
|
||||||
title: title || '',
|
title: title || '',
|
||||||
artist: artist || '',
|
artist: artist || '',
|
||||||
artwork: artwork,
|
artwork: artwork,
|
||||||
playing: !!video && !video.paused && !video.ended && video.readyState > 2,
|
playing: !!video && !video.paused && !video.ended && video.readyState > 2,
|
||||||
currentTime: current || 0,
|
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']")
|
action("nexttrack", "['ytmusic-player-bar .next-button','.next-button']")
|
||||||
PlayerCommand.Previous ->
|
PlayerCommand.Previous ->
|
||||||
action("previoustrack", "['ytmusic-player-bar .previous-button','.previous-button']")
|
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 -> {
|
is PlayerCommand.SeekTo -> {
|
||||||
val seconds = command.positionMs / 1000.0
|
val seconds = command.positionMs / 1000.0
|
||||||
"(function(){var v=document.querySelector('video');if(v){v.currentTime=$seconds;}})();"
|
"(function(){var v=document.querySelector('video');if(v){v.currentTime=$seconds;}})();"
|
||||||
|
|||||||
@@ -11,11 +11,12 @@ data class NowPlaying(
|
|||||||
val playing: Boolean,
|
val playing: Boolean,
|
||||||
val positionMs: Long,
|
val positionMs: Long,
|
||||||
val durationMs: Long,
|
val durationMs: Long,
|
||||||
|
val likeStatus: String? = null,
|
||||||
) {
|
) {
|
||||||
val hasTrack: Boolean get() = title.isNotBlank()
|
val hasTrack: Boolean get() = title.isNotBlank()
|
||||||
|
|
||||||
companion object {
|
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 = " • "
|
private const val ARTIST_SEPARATOR = " • "
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ data class NowPlaying(
|
|||||||
playing = json.optBoolean("playing", false),
|
playing = json.optBoolean("playing", false),
|
||||||
positionMs = seconds(json.optDouble("currentTime", 0.0)),
|
positionMs = seconds(json.optDouble("currentTime", 0.0)),
|
||||||
durationMs = seconds(json.optDouble("duration", 0.0)),
|
durationMs = seconds(json.optDouble("duration", 0.0)),
|
||||||
|
likeStatus = json.optString("likeStatus").takeIf { it.isNotBlank() && it != "null" },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ data class PcState(
|
|||||||
val liked: Boolean,
|
val liked: Boolean,
|
||||||
/** "NONE", "ALL" oder "ONE" (leer = unbekannt). */
|
/** "NONE", "ALL" oder "ONE" (leer = unbekannt). */
|
||||||
val repeatMode: String = "",
|
val repeatMode: String = "",
|
||||||
|
/** Schlaf-Timer am PC: Restsekunden, -1 = Songende, null = aus (oder Playtube zu alt). */
|
||||||
|
val sleepTimer: Long? = null,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
val EMPTY = PcState("music", "music", "", "", "", false, 0.0, 0.0, 100, false)
|
val EMPTY = PcState("music", "music", "", "", "", false, 0.0, 0.0, 100, false)
|
||||||
@@ -82,6 +84,7 @@ object PcRemote {
|
|||||||
volume = (tab?.optDouble("volume")?.takeIf { it.isFinite() } ?: 100.0).toInt().coerceIn(0, 100),
|
volume = (tab?.optDouble("volume")?.takeIf { it.isFinite() } ?: 100.0).toInt().coerceIn(0, 100),
|
||||||
liked = tab?.optString("likeStatus").equals("LIKE", ignoreCase = true),
|
liked = tab?.optString("likeStatus").equals("LIKE", ignoreCase = true),
|
||||||
repeatMode = tab.text("repeatMode").uppercase(),
|
repeatMode = tab.text("repeatMode").uppercase(),
|
||||||
|
sleepTimer = if (state.isNull("sleepTimer")) null else state.optLong("sleepTimer", Long.MIN_VALUE).takeIf { it >= -1 },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,9 @@ class PcRemoteActivity : AppCompatActivity(), PcSession.Listener {
|
|||||||
findViewById<ImageButton>(R.id.listBack).setOnClickListener { closeList() }
|
findViewById<ImageButton>(R.id.listBack).setOnClickListener { closeList() }
|
||||||
findViewById<Button>(R.id.queueButton).setOnClickListener { openList(ListMode.QUEUE) }
|
findViewById<Button>(R.id.queueButton).setOnClickListener { openList(ListMode.QUEUE) }
|
||||||
findViewById<Button>(R.id.playlistsButton).setOnClickListener { openList(ListMode.PLAYLISTS) }
|
findViewById<Button>(R.id.playlistsButton).setOnClickListener { openList(ListMode.PLAYLISTS) }
|
||||||
|
sleepButton = findViewById(R.id.sleepButton)
|
||||||
|
sleepButton.setOnClickListener { showPcSleepDialog() }
|
||||||
|
findViewById<Button>(R.id.historyButton).setOnClickListener { showPcHistory() }
|
||||||
|
|
||||||
findViewById<ImageButton>(R.id.previousButton).setOnClickListener { PcSession.send("previous") }
|
findViewById<ImageButton>(R.id.previousButton).setOnClickListener { PcSession.send("previous") }
|
||||||
findViewById<ImageButton>(R.id.nextButton).setOnClickListener { PcSession.send("next") }
|
findViewById<ImageButton>(R.id.nextButton).setOnClickListener { PcSession.send("next") }
|
||||||
@@ -413,6 +416,7 @@ class PcRemoteActivity : AppCompatActivity(), PcSession.Listener {
|
|||||||
findViewById<ImageButton>(R.id.shuffleButton).imageTintList = tint(R.color.text_muted)
|
findViewById<ImageButton>(R.id.shuffleButton).imageTintList = tint(R.color.text_muted)
|
||||||
tabYoutube.alpha = if (state.visibleTab == "youtube") 1f else 0.45f
|
tabYoutube.alpha = if (state.visibleTab == "youtube") 1f else 0.45f
|
||||||
tabMusic.alpha = if (state.visibleTab == "music") 1f else 0.45f
|
tabMusic.alpha = if (state.visibleTab == "music") 1f else 0.45f
|
||||||
|
renderSleep(state.sleepTimer)
|
||||||
|
|
||||||
if (state.thumbnail != coverUrl) loadCover(state.thumbnail)
|
if (state.thumbnail != coverUrl) loadCover(state.thumbnail)
|
||||||
}
|
}
|
||||||
@@ -469,6 +473,57 @@ class PcRemoteActivity : AppCompatActivity(), PcSession.Listener {
|
|||||||
loadList(mode, scrollToCurrent = true)
|
loadList(mode, scrollToCurrent = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Schlaf-Timer und Verlauf am PC
|
||||||
|
|
||||||
|
private lateinit var sleepButton: Button
|
||||||
|
|
||||||
|
private fun renderSleep(seconds: Long?) {
|
||||||
|
sleepButton.text = when (seconds) {
|
||||||
|
null -> getString(R.string.pc_sleep)
|
||||||
|
-1L -> getString(R.string.sleep_end_short)
|
||||||
|
else -> SleepTimer.format(seconds)
|
||||||
|
}
|
||||||
|
sleepButton.compoundDrawableTintList = tint(if (seconds != null) R.color.brand_to else R.color.text)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showPcSleepDialog() {
|
||||||
|
val minutes = SleepTimer.CHOICES
|
||||||
|
val labels = minutes.map { getString(R.string.sleep_minutes, it) } +
|
||||||
|
getString(R.string.sleep_end) + getString(R.string.sleep_off)
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.sleep_title)
|
||||||
|
.setItems(labels.toTypedArray()) { _, which ->
|
||||||
|
val value = when {
|
||||||
|
which < minutes.size -> minutes[which]
|
||||||
|
which == minutes.size -> -1
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
PcSession.request("sleep_timer", { put("value", value) }) { result ->
|
||||||
|
result.onFailure { error ->
|
||||||
|
val text = if (PcRemote.isUnknownCommand(error.message)) getString(R.string.pc_too_old)
|
||||||
|
else error.message ?: error.javaClass.simpleName
|
||||||
|
android.widget.Toast.makeText(this, text, android.widget.Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showPcHistory() {
|
||||||
|
PcSession.request("history", { put("value", 200) }) { result ->
|
||||||
|
if (isDestroyed) return@request
|
||||||
|
result.onSuccess { reply ->
|
||||||
|
HistoryDialog.show(this, getString(R.string.history_pc_title), PlayHistory.parsePcHistory(reply), onPick = { entry ->
|
||||||
|
PcSession.request("play_video", { put("video", entry.videoId) })
|
||||||
|
})
|
||||||
|
}.onFailure { error ->
|
||||||
|
val text = if (PcRemote.isUnknownCommand(error.message)) getString(R.string.pc_too_old)
|
||||||
|
else error.message ?: error.javaClass.simpleName
|
||||||
|
android.widget.Toast.makeText(this, text, android.widget.Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun closeList() {
|
private fun closeList() {
|
||||||
listMode = null
|
listMode = null
|
||||||
listPanel.visibility = View.GONE
|
listPanel.visibility = View.GONE
|
||||||
|
|||||||
@@ -0,0 +1,154 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import org.json.JSONArray
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
/** Ein gehoerter Song. */
|
||||||
|
data class HistoryEntry(
|
||||||
|
val videoId: String,
|
||||||
|
val title: String,
|
||||||
|
val artist: String,
|
||||||
|
val artwork: String?,
|
||||||
|
/** Beginn (Unix-Millisekunden) */
|
||||||
|
val playedAt: Long,
|
||||||
|
/** Gehoerte Sekunden */
|
||||||
|
val listened: Int,
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verlauf der auf dem Handy gehoerten Songs. Ein Song zaehlt nach 30 s (bei kuerzeren Songs nach der
|
||||||
|
* Haelfte) - wie am PC (playtube-desktop/src/history.rs). Reine Logik; gespeichert wird ueber [toJson].
|
||||||
|
*/
|
||||||
|
class PlayHistory(entries: List<HistoryEntry> = emptyList()) {
|
||||||
|
private val list = ArrayList(entries)
|
||||||
|
val entries: List<HistoryEntry> get() = list
|
||||||
|
|
||||||
|
private var currentId: String? = null
|
||||||
|
private var current: HistoryEntry? = null
|
||||||
|
private var currentDurationS = 0.0
|
||||||
|
private var listenedS = 0.0
|
||||||
|
private var storedIndex = -1
|
||||||
|
/** Hoerdauer geaendert, aber noch nicht gespeichert */
|
||||||
|
private var dirty = false
|
||||||
|
private var lastTickMs: Long? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Neuer Stand aus der Seite. [videoId] = null oder [playing] = false: gerade laeuft nichts.
|
||||||
|
* Gibt true zurueck, wenn sich die gespeicherte Liste geaendert hat (dann speichern).
|
||||||
|
*/
|
||||||
|
fun observe(videoId: String?, info: NowPlaying, playing: Boolean, nowMs: Long, wallMs: Long): Boolean {
|
||||||
|
val step = lastTickMs?.let { ((nowMs - it).coerceAtLeast(0) / 1000.0).coerceAtMost(MAX_STEP_S) } ?: 0.0
|
||||||
|
lastTickMs = nowMs
|
||||||
|
if (videoId == null || !playing || !info.hasTrack) return finish()
|
||||||
|
|
||||||
|
if (videoId != currentId) {
|
||||||
|
val changed = finish()
|
||||||
|
currentId = videoId
|
||||||
|
current = HistoryEntry(videoId, info.title, info.artist, info.artworkUrl, wallMs, 0)
|
||||||
|
currentDurationS = info.durationMs / 1000.0
|
||||||
|
listenedS = 0.0
|
||||||
|
storedIndex = -1
|
||||||
|
return changed // der erste Takt eines neuen Songs zaehlt noch nicht
|
||||||
|
}
|
||||||
|
listenedS += step
|
||||||
|
if (info.durationMs > 0) currentDurationS = info.durationMs / 1000.0
|
||||||
|
val needed = if (currentDurationS > 0) minOf(COUNT_AFTER_S, currentDurationS / 2) else COUNT_AFTER_S
|
||||||
|
val entry = current ?: return false
|
||||||
|
if (storedIndex < 0 && listenedS >= needed) {
|
||||||
|
list += entry.copy(listened = listenedS.toInt())
|
||||||
|
while (list.size > MAX_ENTRIES) list.removeAt(0)
|
||||||
|
storedIndex = list.size - 1
|
||||||
|
dirty = false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (storedIndex in list.indices && list[storedIndex].listened != listenedS.toInt()) {
|
||||||
|
list[storedIndex] = list[storedIndex].copy(listened = listenedS.toInt())
|
||||||
|
dirty = true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Pause/Ende: gezaehlte Hoerdauer festhalten (true = speichern). */
|
||||||
|
private fun finish(): Boolean {
|
||||||
|
val save = dirty
|
||||||
|
dirty = false
|
||||||
|
return save
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Neueste zuerst, optional nach Titel/Interpret gefiltert. */
|
||||||
|
fun search(query: String, limit: Int = 300): List<HistoryEntry> {
|
||||||
|
val q = query.trim().lowercase()
|
||||||
|
return list.asReversed().asSequence()
|
||||||
|
.filter { q.isEmpty() || it.title.lowercase().contains(q) || it.artist.lowercase().contains(q) }
|
||||||
|
.take(limit)
|
||||||
|
.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
list.clear()
|
||||||
|
currentId = null
|
||||||
|
current = null
|
||||||
|
storedIndex = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toJson(): String {
|
||||||
|
val array = JSONArray()
|
||||||
|
for (e in list) {
|
||||||
|
array.put(JSONObject().apply {
|
||||||
|
put("videoId", e.videoId)
|
||||||
|
put("title", e.title)
|
||||||
|
put("artist", e.artist)
|
||||||
|
e.artwork?.let { put("artwork", it) }
|
||||||
|
put("playedAt", e.playedAt)
|
||||||
|
put("listened", e.listened)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return array.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val MAX_ENTRIES = 3000
|
||||||
|
private const val COUNT_AFTER_S = 30.0
|
||||||
|
private const val MAX_STEP_S = 10.0
|
||||||
|
|
||||||
|
fun fromJson(text: String?): PlayHistory {
|
||||||
|
if (text.isNullOrBlank()) return PlayHistory()
|
||||||
|
val array = runCatching { JSONArray(text) }.getOrNull() ?: return PlayHistory()
|
||||||
|
val entries = ArrayList<HistoryEntry>()
|
||||||
|
for (i in 0 until array.length()) {
|
||||||
|
val o = array.optJSONObject(i) ?: continue
|
||||||
|
val id = o.optString("videoId")
|
||||||
|
if (id.isBlank()) continue
|
||||||
|
entries += HistoryEntry(
|
||||||
|
videoId = id,
|
||||||
|
title = o.optString("title"),
|
||||||
|
artist = o.optString("artist"),
|
||||||
|
artwork = o.optString("artwork").takeIf { it.startsWith("https://") },
|
||||||
|
playedAt = o.optLong("playedAt"),
|
||||||
|
listened = o.optInt("listened"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return PlayHistory(entries)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** PC-Verlauf ("history"-Antwort der Fernsteuerung, playedAt in Sekunden). */
|
||||||
|
fun parsePcHistory(reply: JSONObject): List<HistoryEntry> {
|
||||||
|
val array = reply.optJSONArray("history") ?: return emptyList()
|
||||||
|
val entries = ArrayList<HistoryEntry>()
|
||||||
|
for (i in 0 until array.length()) {
|
||||||
|
val o = array.optJSONObject(i) ?: continue
|
||||||
|
val id = o.optString("videoId")
|
||||||
|
if (id.isBlank() || !id.all { it.isLetterOrDigit() || it == '_' || it == '-' }) continue
|
||||||
|
entries += HistoryEntry(
|
||||||
|
videoId = id,
|
||||||
|
title = o.optString("title").take(150),
|
||||||
|
artist = o.optString("artist").take(150),
|
||||||
|
artwork = o.optString("thumbnail").takeIf { it.startsWith("https://") },
|
||||||
|
playedAt = o.optLong("playedAt") * 1000,
|
||||||
|
listened = o.optInt("listened"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return entries
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ sealed class PlayerCommand {
|
|||||||
data object Pause : PlayerCommand()
|
data object Pause : PlayerCommand()
|
||||||
data object Next : PlayerCommand()
|
data object Next : PlayerCommand()
|
||||||
data object Previous : PlayerCommand()
|
data object Previous : PlayerCommand()
|
||||||
|
data object Like : PlayerCommand()
|
||||||
data class SeekTo(val positionMs: Long) : PlayerCommand()
|
data class SeekTo(val positionMs: Long) : PlayerCommand()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schlaf-Timer: nach X Minuten (mit sanftem Ausblenden in den letzten 15 s) oder am Ende des
|
||||||
|
* laufenden Songs pausieren. Reine Logik ohne Android - die Activity ruft [tick] regelmaessig auf.
|
||||||
|
* Gleiches Verhalten wie am PC (playtube-desktop/src/sleep.rs).
|
||||||
|
*/
|
||||||
|
class SleepTimer private constructor(
|
||||||
|
/** Zeitpunkt (elapsedRealtime) zum Pausieren; null = am Songende. */
|
||||||
|
private val deadlineMs: Long?,
|
||||||
|
/** Song, nach dem pausiert wird (nur bei Songende); null = noch nichts gemerkt. */
|
||||||
|
private var track: String?,
|
||||||
|
) {
|
||||||
|
sealed class Step {
|
||||||
|
data object Wait : Step()
|
||||||
|
/** Lautstaerke auf diesen Anteil (0..1) der urspruenglichen setzen. */
|
||||||
|
data class Fade(val factor: Double) : Step()
|
||||||
|
data object Stop : Step()
|
||||||
|
}
|
||||||
|
|
||||||
|
val endOfTrack: Boolean get() = deadlineMs == null
|
||||||
|
|
||||||
|
/** Restzeit in Sekunden; -1 = bis zum Songende. */
|
||||||
|
fun remainingSeconds(nowMs: Long): Long =
|
||||||
|
if (deadlineMs == null) -1 else ((deadlineMs - nowMs).coerceAtLeast(0) + 999) / 1000
|
||||||
|
|
||||||
|
fun tick(nowMs: Long, currentTrack: String?): Step {
|
||||||
|
if (deadlineMs == null) {
|
||||||
|
val remembered = track
|
||||||
|
return when {
|
||||||
|
currentTrack == null -> Step.Wait // kurze Ladepause zaehlt nicht
|
||||||
|
remembered == null -> {
|
||||||
|
track = currentTrack
|
||||||
|
Step.Wait
|
||||||
|
}
|
||||||
|
remembered != currentTrack -> Step.Stop
|
||||||
|
else -> Step.Wait
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val left = deadlineMs - nowMs
|
||||||
|
return when {
|
||||||
|
left <= 0 -> Step.Stop
|
||||||
|
left <= FADE_MS -> Step.Fade(left.toDouble() / FADE_MS)
|
||||||
|
else -> Step.Wait
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val FADE_MS = 15_000L
|
||||||
|
/** Auswahl im Dialog (Minuten). */
|
||||||
|
val CHOICES = listOf(15, 30, 45, 60, 90, 120)
|
||||||
|
const val MAX_MINUTES = 24 * 60
|
||||||
|
|
||||||
|
fun minutes(minutes: Int, nowMs: Long): SleepTimer =
|
||||||
|
SleepTimer(nowMs + minutes.coerceIn(1, MAX_MINUTES) * 60_000L, null)
|
||||||
|
|
||||||
|
fun endOfTrack(currentTrack: String?): SleepTimer = SleepTimer(null, currentTrack)
|
||||||
|
|
||||||
|
/** "12:34" bzw. "1:02:03". */
|
||||||
|
fun format(seconds: Long): String {
|
||||||
|
val s = seconds.coerceAtLeast(0)
|
||||||
|
val h = s / 3600
|
||||||
|
val m = (s % 3600) / 60
|
||||||
|
val sec = s % 60
|
||||||
|
return if (h > 0) "%d:%02d:%02d".format(h, m, sec) else "%d:%02d".format(m, sec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFFFF"
|
||||||
|
android:pathData="M12.34,2.02C6.59,1.82 2,6.42 2,12c0,5.52 4.48,10 10,10 3.71,0 6.93,-2.02 8.66,-5.02C13.15,16.73 8.57,8.55 12.34,2.02z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFFFF"
|
||||||
|
android:pathData="M13,3c-4.97,0 -9,4.03 -9,9L1,12l3.89,3.89 0.07,0.14L9,12L6,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.93,0 -3.68,-0.79 -4.94,-2.06l-1.42,1.42C8.27,19.99 10.51,21 13,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,8v5l4.28,2.54 0.72,-1.21 -3.5,-2.08L13.5,8L12,8z" />
|
||||||
|
</vector>
|
||||||
@@ -207,6 +207,15 @@
|
|||||||
android:textColor="@color/text_muted"
|
android:textColor="@color/text_muted"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
</LinearLayout>
|
</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>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|||||||
@@ -401,6 +401,48 @@
|
|||||||
android:textColor="@color/text"
|
android:textColor="@color/text"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/sleepButton"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_pill"
|
||||||
|
android:drawableStart="@drawable/ic_bedtime"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:drawableTint="@color/text"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:text="@string/pc_sleep"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/historyButton"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_pill"
|
||||||
|
android:drawableStart="@drawable/ic_history"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:drawableTint="@color/text"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:text="@string/pc_history"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Vollbild-Liste: Warteschlange oder Playlists -->
|
<!-- Vollbild-Liste: Warteschlange oder Playlists -->
|
||||||
|
|||||||
@@ -58,23 +58,23 @@
|
|||||||
<string name="pc_list_error">Das hat nicht geklappt: %1$s</string>
|
<string name="pc_list_error">Das hat nicht geklappt: %1$s</string>
|
||||||
<string name="pc_this_pc">Verbunden</string>
|
<string name="pc_this_pc">Verbunden</string>
|
||||||
|
|
||||||
<!-- Playtube Jam (JamActivity, JamHub) -->
|
<!-- Playtube Sync (JamActivity, JamHub) -->
|
||||||
<string name="jam_title">Jam</string>
|
<string name="jam_title">Sync</string>
|
||||||
<string name="jam_open">Playtube Jam: gemeinsam hören</string>
|
<string name="jam_open">Playtube Sync: gemeinsam hören</string>
|
||||||
<string name="jam_intro">Hört gemeinsam wie bei Spotify Jam: jeder auf seinem eigenen Gerät, synchron, und alle wünschen sich Songs. Freunde ohne Playtube machen über den Link im Browser mit.</string>
|
<string name="jam_intro">Hört gemeinsam wie bei Spotify Jam: jeder auf seinem eigenen Gerät, synchron, und alle wünschen sich Songs. Freunde ohne Playtube machen über den Link im Browser mit.</string>
|
||||||
<string name="jam_name_hint">Dein Name</string>
|
<string name="jam_name_hint">Dein Name</string>
|
||||||
<string name="jam_start">Jam starten</string>
|
<string name="jam_start">Sync starten</string>
|
||||||
<string name="jam_start_hint">Läuft gerade ein Song, wird er der erste im Jam.</string>
|
<string name="jam_start_hint">Läuft gerade ein Song, wird er der erste im Sync.</string>
|
||||||
<string name="jam_code_hint">Code oder Einladungslink</string>
|
<string name="jam_code_hint">Code oder Einladungslink</string>
|
||||||
<string name="jam_join">Beitreten</string>
|
<string name="jam_join">Beitreten</string>
|
||||||
<string name="jam_invite">Freunde einladen</string>
|
<string name="jam_invite">Freunde einladen</string>
|
||||||
<string name="jam_share">Link teilen</string>
|
<string name="jam_share">Link teilen</string>
|
||||||
<string name="jam_copy">Kopieren</string>
|
<string name="jam_copy">Kopieren</string>
|
||||||
<string name="jam_copied">Link kopiert.</string>
|
<string name="jam_copied">Link kopiert.</string>
|
||||||
<string name="jam_share_text">Hör mit mir in Playtube Jam: %1$s</string>
|
<string name="jam_share_text">Hör mit mir in Playtube Sync: %1$s</string>
|
||||||
<string name="jam_all_control">Alle dürfen steuern</string>
|
<string name="jam_all_control">Alle dürfen steuern</string>
|
||||||
<string name="jam_end">Jam beenden</string>
|
<string name="jam_end">Sync beenden</string>
|
||||||
<string name="jam_end_confirm">Jam für alle beenden?</string>
|
<string name="jam_end_confirm">Sync für alle beenden?</string>
|
||||||
<string name="jam_leave">Verlassen</string>
|
<string name="jam_leave">Verlassen</string>
|
||||||
<string name="jam_members">Dabei</string>
|
<string name="jam_members">Dabei</string>
|
||||||
<string name="jam_queue">Als Nächstes</string>
|
<string name="jam_queue">Als Nächstes</string>
|
||||||
@@ -95,33 +95,34 @@
|
|||||||
<string name="jam_client_android">Android</string>
|
<string name="jam_client_android">Android</string>
|
||||||
<string name="jam_client_web">Browser</string>
|
<string name="jam_client_web">Browser</string>
|
||||||
<string name="jam_kick">Entfernen</string>
|
<string name="jam_kick">Entfernen</string>
|
||||||
<string name="jam_kick_confirm">%1$s aus dem Jam entfernen?</string>
|
<string name="jam_kick_confirm">%1$s aus dem Sync entfernen?</string>
|
||||||
<string name="jam_make_host">Zum Host machen</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_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_error_offline">Diese Person ist gerade nicht verbunden.</string>
|
||||||
<string name="jam_play_now">Jetzt spielen</string>
|
<string name="jam_play_now">Jetzt spielen</string>
|
||||||
<string name="jam_remove">Entfernen</string>
|
<string name="jam_remove">Entfernen</string>
|
||||||
<string name="jam_added">Hinzugefügt: %1$s</string>
|
<string name="jam_added">Hinzugefügt: %1$s</string>
|
||||||
<string name="jam_added_shared">Zum Jam hinzugefügt.</string>
|
<string name="jam_added_shared">Zum Sync hinzugefügt.</string>
|
||||||
<string name="jam_playlist_adding">Playlist wird hinzugefügt …</string>
|
<string name="jam_playlist_adding">Playlist wird hinzugefügt …</string>
|
||||||
<string name="jam_error_playlist">Diese Playlist ist nicht öffentlich oder existiert nicht.</string>
|
<string name="jam_error_playlist">Diese Playlist ist nicht öffentlich oder existiert nicht.</string>
|
||||||
<string name="jam_share_no_jam">Du bist gerade in keinem Jam. Starte einen oder tritt einem bei.</string>
|
<string name="jam_share_no_jam">Du bist gerade in keinem Sync. Starte einen oder tritt einem bei.</string>
|
||||||
<string name="jam_play_hint">Die Musik läuft im Player von Playtube. Du kannst dort weiter in YouTube Music stöbern: Tippst du einen Song an, landet er wie bei Spotify im Jam. Mit Steuerrecht wirken Play/Pause und Weiter dort und in der Benachrichtigung für alle.</string>
|
<string name="jam_play_hint">Die Musik läuft im Player von Playtube. Du kannst dort weiter in YouTube Music stöbern: Tippst du einen Song an, landet er wie bei Spotify im Sync. Mit Steuerrecht wirken Play/Pause und Weiter dort und in der Benachrichtigung für alle.</string>
|
||||||
<string name="jam_status_creating">Jam wird gestartet …</string>
|
<string name="jam_status_creating">Sync wird gestartet …</string>
|
||||||
<string name="jam_status_joining">Verbinde …</string>
|
<string name="jam_status_joining">Verbinde …</string>
|
||||||
<string name="jam_status_connected">Verbunden.</string>
|
<string name="jam_status_connected">Verbunden.</string>
|
||||||
<string name="jam_status_reconnecting">Verbindung unterbrochen – verbinde neu …</string>
|
<string name="jam_status_reconnecting">Verbindung unterbrochen – verbinde neu …</string>
|
||||||
<string name="jam_status_bad_code">Das ist kein gültiger Code (6 Zeichen).</string>
|
<string name="jam_status_bad_code">Das ist kein gültiger Code (6 Zeichen).</string>
|
||||||
<string name="jam_status_not_found">Diesen Jam gibt es nicht (mehr).</string>
|
<string name="jam_status_not_found">Diesen Sync gibt es nicht (mehr).</string>
|
||||||
<string name="jam_status_failed">Keine Verbindung zum Jam-Server.</string>
|
<string name="jam_status_failed">Keine Verbindung zum Sync-Server.</string>
|
||||||
<string name="jam_status_need_name">Bitte gib zuerst deinen Namen ein.</string>
|
<string name="jam_status_need_name">Bitte gib zuerst deinen Namen ein.</string>
|
||||||
<string name="jam_status_in_other">Du bist schon in einem Jam – verlasse ihn zuerst.</string>
|
<string name="jam_status_in_other">Du bist schon in einem Sync – verlasse ihn zuerst.</string>
|
||||||
<string name="jam_ended_host">Der Host hat den Jam beendet.</string>
|
<string name="jam_ended_host">Der Host hat den Sync beendet.</string>
|
||||||
<string name="jam_ended_over">Der Jam ist zu Ende.</string>
|
<string name="jam_ended_over">Der Sync ist zu Ende.</string>
|
||||||
<string name="jam_ended_expired">Der Jam ist abgelaufen.</string>
|
<string name="jam_ended_expired">Der Sync ist abgelaufen.</string>
|
||||||
<string name="jam_ended_kicked">Du wurdest aus dem Jam entfernt.</string>
|
<string name="jam_ended_kicked">Du wurdest aus dem Sync entfernt.</string>
|
||||||
<string name="jam_ended_left">Du hast den Jam verlassen.</string>
|
<string name="jam_ended_left">Du hast den Sync verlassen.</string>
|
||||||
<string name="jam_ended_full">Der Jam ist voll.</string>
|
<string name="jam_ended_full">Der Sync ist voll.</string>
|
||||||
<string name="jam_error_not_allowed">Das darf nur der Host.</string>
|
<string name="jam_error_not_allowed">Das darf nur der Host.</string>
|
||||||
<string name="jam_error_queue_full">Die Warteschlange ist voll.</string>
|
<string name="jam_error_queue_full">Die Warteschlange ist voll.</string>
|
||||||
<string name="jam_error_bad_video">Das ist kein YouTube-Link.</string>
|
<string name="jam_error_bad_video">Das ist kein YouTube-Link.</string>
|
||||||
@@ -152,6 +153,29 @@
|
|||||||
<!-- Einstellungen / Diagnose -->
|
<!-- Einstellungen / Diagnose -->
|
||||||
<string name="settings_open">Einstellungen</string>
|
<string name="settings_open">Einstellungen</string>
|
||||||
<string name="settings_title">Playtube-Einstellungen</string>
|
<string name="settings_title">Playtube-Einstellungen</string>
|
||||||
|
|
||||||
|
<!-- Schlaf-Timer und Verlauf -->
|
||||||
|
<string name="menu_title">Playtube</string>
|
||||||
|
<string name="sleep_title">Schlaf-Timer</string>
|
||||||
|
<string name="sleep_title_active">Schlaf-Timer (%1$s)</string>
|
||||||
|
<string name="sleep_minutes">%1$d Minuten</string>
|
||||||
|
<string name="sleep_end">Ende des Songs</string>
|
||||||
|
<string name="sleep_end_short">Songende</string>
|
||||||
|
<string name="sleep_off">Aus</string>
|
||||||
|
<string name="sleep_set">Schlaf-Timer: %1$s</string>
|
||||||
|
<string name="sleep_cleared">Schlaf-Timer aus</string>
|
||||||
|
<string name="sleep_done">Schlaf-Timer abgelaufen – Wiedergabe pausiert</string>
|
||||||
|
<string name="history_title">Verlauf</string>
|
||||||
|
<string name="history_pc_title">Verlauf am PC</string>
|
||||||
|
<string name="history_search">Im Verlauf suchen …</string>
|
||||||
|
<string name="history_empty">Noch nichts gehört – Songs erscheinen hier nach 30 Sekunden.</string>
|
||||||
|
<string name="history_clear">Verlauf löschen</string>
|
||||||
|
<string name="history_clear_confirm">Den ganzen Verlauf auf diesem Handy löschen?</string>
|
||||||
|
<string name="history_close">Schließen</string>
|
||||||
|
<string name="history_today">Heute, %1$s</string>
|
||||||
|
<string name="pc_sleep">Schlaf-Timer</string>
|
||||||
|
<string name="pc_history">Verlauf</string>
|
||||||
|
<string name="pc_too_old">Dafür braucht Playtube am PC ein Update (ab 2.14.0).</string>
|
||||||
<string name="diag_enabled">Diagnosedaten senden (hilft, Fehler zu finden)</string>
|
<string name="diag_enabled">Diagnosedaten senden (hilft, Fehler zu finden)</string>
|
||||||
<string name="diag_hint">Gesendet werden Fehlermeldungen und Abstürze aus dem Playtube-Log, App- und Android-Version sowie das Gerätemodell mit einer zufälligen Kennung – keine Cookies, Anmeldedaten, Suchanfragen, Songtitel oder Video-IDs. Gespeichert 30 Tage. Details: playtube-ppp-eula.pages.dev/playtube/privacy/#diag</string>
|
<string name="diag_hint">Gesendet werden Fehlermeldungen und Abstürze aus dem Playtube-Log, App- und Android-Version sowie das Gerätemodell mit einer zufälligen Kennung – keine Cookies, Anmeldedaten, Suchanfragen, Songtitel oder Video-IDs. Gespeichert 30 Tage. Details: playtube-ppp-eula.pages.dev/playtube/privacy/#diag</string>
|
||||||
<string name="diag_install_id">Kennung dieser Installation: %1$s</string>
|
<string name="diag_install_id">Kennung dieser Installation: %1$s</string>
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class SleepAndHistoryTest {
|
||||||
|
private fun song(title: String, durationS: Long = 200) =
|
||||||
|
NowPlaying(title, "Band", "https://i.ytimg.com/x.jpg", playing = true, positionMs = 0, durationMs = durationS * 1000)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Schlaf-Timer wartet, blendet aus und stoppt`() {
|
||||||
|
val timer = SleepTimer.minutes(1, 0)
|
||||||
|
assertEquals(60L, timer.remainingSeconds(0))
|
||||||
|
assertEquals(SleepTimer.Step.Wait, timer.tick(10_000, null))
|
||||||
|
val fade = timer.tick(50_000, null) as SleepTimer.Step.Fade
|
||||||
|
assertEquals(10.0 / 15.0, fade.factor, 0.01)
|
||||||
|
assertEquals(SleepTimer.Step.Stop, timer.tick(60_000, null))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Schlaf-Timer am Songende stoppt beim naechsten Song`() {
|
||||||
|
val timer = SleepTimer.endOfTrack(null)
|
||||||
|
assertTrue(timer.endOfTrack)
|
||||||
|
assertEquals(-1L, timer.remainingSeconds(0))
|
||||||
|
assertEquals(SleepTimer.Step.Wait, timer.tick(0, "aaa"))
|
||||||
|
assertEquals(SleepTimer.Step.Wait, timer.tick(0, null))
|
||||||
|
assertEquals(SleepTimer.Step.Wait, timer.tick(0, "aaa"))
|
||||||
|
assertEquals(SleepTimer.Step.Stop, timer.tick(0, "bbb"))
|
||||||
|
assertEquals("1:05", SleepTimer.format(65))
|
||||||
|
assertEquals("1:02:03", SleepTimer.format(3723))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Verlauf zaehlt nach 30 Sekunden und haelt die Hoerdauer fest`() {
|
||||||
|
val history = PlayHistory()
|
||||||
|
val info = song("Lied")
|
||||||
|
assertFalse(history.observe("vid1", info, true, 0, 1000))
|
||||||
|
var changed = false
|
||||||
|
for (i in 1..14) changed = changed or history.observe("vid1", info, true, i * 2000L, 1000)
|
||||||
|
assertFalse(changed)
|
||||||
|
assertTrue(history.observe("vid1", info, true, 30_000, 1000))
|
||||||
|
assertEquals(1, history.entries.size)
|
||||||
|
history.observe("vid1", info, true, 40_000, 1000)
|
||||||
|
assertTrue(history.observe(null, info, false, 41_000, 1000))
|
||||||
|
assertEquals(40, history.entries[0].listened)
|
||||||
|
assertFalse("schon gespeichert", history.observe(null, info, false, 42_000, 1000))
|
||||||
|
assertEquals(1000L, history.entries[0].playedAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Uebersprungene Songs zaehlen nicht, kurze nach der Haelfte`() {
|
||||||
|
val history = PlayHistory()
|
||||||
|
history.observe("skip", song("Weg"), true, 0, 0)
|
||||||
|
history.observe("skip", song("Weg"), true, 5_000, 0)
|
||||||
|
history.observe("short", song("Kurz", 40), true, 6_000, 0)
|
||||||
|
history.observe("short", song("Kurz", 40), true, 16_000, 0)
|
||||||
|
history.observe("short", song("Kurz", 40), true, 26_000, 0)
|
||||||
|
assertEquals(listOf("Kurz"), history.entries.map { it.title })
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Speichern, Laden und Suchen`() {
|
||||||
|
val history = PlayHistory(listOf(
|
||||||
|
HistoryEntry("a1", "Alpha", "X", null, 1, 40),
|
||||||
|
HistoryEntry("b2", "Beta", "alphaband", "https://i.ytimg.com/b.jpg", 2, 50),
|
||||||
|
))
|
||||||
|
val loaded = PlayHistory.fromJson(history.toJson())
|
||||||
|
assertEquals(history.entries, loaded.entries)
|
||||||
|
assertEquals(listOf("Beta", "Alpha"), loaded.search("").map { it.title })
|
||||||
|
assertEquals(listOf("Beta", "Alpha"), loaded.search("ALPHA").map { it.title })
|
||||||
|
assertEquals(listOf("Alpha"), loaded.search("x").map { it.title })
|
||||||
|
assertTrue(PlayHistory.fromJson("kaputt").entries.isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `PC-Verlauf wird gelesen und geprueft`() {
|
||||||
|
val reply = JSONObject("""{"ok":true,"history":[
|
||||||
|
{"videoId":"dQw4w9WgXcQ","title":"Lied","artist":"Band","thumbnail":"https://i.ytimg.com/a.jpg","playedAt":100,"listened":60},
|
||||||
|
{"videoId":"bad id!","title":"X"},
|
||||||
|
{"videoId":"ok_id-1","title":"Y","thumbnail":"javascript:x"}]}""")
|
||||||
|
val list = PlayHistory.parsePcHistory(reply)
|
||||||
|
assertEquals(listOf("dQw4w9WgXcQ", "ok_id-1"), list.map { it.videoId })
|
||||||
|
assertEquals(100_000L, list[0].playedAt)
|
||||||
|
assertEquals(null, list[1].artwork)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,15 @@
|
|||||||
## Playtube für Android 1.7.0
|
## Playtube für Android 1.10.0
|
||||||
|
|
||||||
- **Host abgeben:** Als Host kannst du die Rolle im Jam an jemand anderen übergeben – in der Liste „Dabei“ auf die
|
- **„Jam" heißt jetzt „Sync".** Die gemeinsame Hör-Funktion wurde umbenannt – überall in der App. An der Bedienung
|
||||||
Krone neben dem Namen tippen und bestätigen.
|
ändert sich nichts, bestehende Einladungslinks funktionieren weiter.
|
||||||
- **„Freunde einladen“:** Code und Link stehen jetzt mittig.
|
|
||||||
|
|
||||||
Alles Weitere wie in 1.6.1. Voraussetzung: Android 8.0 oder neuer.
|
Alles Weitere wie in 1.9.0. Voraussetzung: Android 8.0 oder neuer.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Playtube for Android 1.7.0
|
## Playtube for Android 1.10.0
|
||||||
|
|
||||||
- **Hand over host:** as host you can pass the role in a jam to someone else – tap the crown next to their name in
|
- **"Jam" is now called "Sync".** The listen-together feature was renamed – everywhere in the app. Nothing changes
|
||||||
the "Listening" list and confirm.
|
about how it works, and existing invite links keep working.
|
||||||
- **"Invite friends":** the code and link are now centered.
|
|
||||||
|
|
||||||
Everything else as in 1.6.1. Requires Android 8.0 or newer.
|
Everything else as in 1.9.0. Requires Android 8.0 or newer.
|
||||||
|
|||||||
Reference in New Issue
Block a user