Skip to content

Commit 500c681

Browse files
author
Yevhen Babiichuk (DustDFG)
committed
Convert newpipe/util/text/TimestampLongPressClickableSpan.java to kotlin
Also convert one class used by it into java record
1 parent 1418264 commit 500c681

3 files changed

Lines changed: 66 additions & 103 deletions

File tree

app/src/main/java/org/schabi/newpipe/util/text/TimestampExtractor.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,6 @@ public static TimestampMatchDTO getTimestampFromMatcher(
5454
return new TimestampMatchDTO(timestampStart, timestampEnd, seconds);
5555
}
5656

57-
public static class TimestampMatchDTO {
58-
private final int timestampStart;
59-
private final int timestampEnd;
60-
private final int seconds;
61-
62-
public TimestampMatchDTO(
63-
final int timestampStart,
64-
final int timestampEnd,
65-
final int seconds) {
66-
this.timestampStart = timestampStart;
67-
this.timestampEnd = timestampEnd;
68-
this.seconds = seconds;
69-
}
70-
71-
public int timestampStart() {
72-
return timestampStart;
73-
}
74-
75-
public int timestampEnd() {
76-
return timestampEnd;
77-
}
78-
79-
public int seconds() {
80-
return seconds;
81-
}
57+
public record TimestampMatchDTO(int timestampStart, int timestampEnd, int seconds) {
8258
}
8359
}

app/src/main/java/org/schabi/newpipe/util/text/TimestampLongPressClickableSpan.java

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2018-2025 NewPipe contributors <https://newpipe.net>
3+
* SPDX-FileCopyrightText: 2025 NewPipe e.V. <https://newpipe-ev.de>
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package org.schabi.newpipe.util.text
8+
9+
import android.content.Context
10+
import android.view.View
11+
import io.reactivex.rxjava3.disposables.CompositeDisposable
12+
import org.schabi.newpipe.extractor.ServiceList
13+
import org.schabi.newpipe.extractor.StreamingService
14+
import org.schabi.newpipe.util.external_communication.ShareUtils
15+
import org.schabi.newpipe.util.text.TimestampExtractor.TimestampMatchDTO
16+
17+
class TimestampLongPressClickableSpan(
18+
private val context: Context,
19+
private val descriptionText: String,
20+
private val disposables: CompositeDisposable,
21+
private val relatedInfoService: StreamingService,
22+
private val relatedStreamUrl: String,
23+
private val timestampMatchDTO: TimestampMatchDTO
24+
) : LongPressClickableSpan() {
25+
override fun onClick(view: View) {
26+
InternalUrlsHandler.playOnPopup(
27+
context, relatedStreamUrl, relatedInfoService,
28+
timestampMatchDTO.seconds()
29+
)
30+
}
31+
32+
override fun onLongClick(view: View) {
33+
ShareUtils.copyToClipboard(
34+
context,
35+
getTimestampTextToCopy(
36+
relatedInfoService, relatedStreamUrl, descriptionText, timestampMatchDTO
37+
)
38+
)
39+
}
40+
41+
companion object {
42+
private fun getTimestampTextToCopy(
43+
relatedInfoService: StreamingService,
44+
relatedStreamUrl: String,
45+
descriptionText: String,
46+
timestampMatchDTO: TimestampMatchDTO
47+
): String {
48+
// TODO: use extractor methods to get timestamps when this feature will be implemented in it
49+
when (relatedInfoService) {
50+
ServiceList.YouTube ->
51+
return relatedStreamUrl + "&t=" + timestampMatchDTO.seconds()
52+
ServiceList.SoundCloud, ServiceList.MediaCCC ->
53+
return relatedStreamUrl + "#t=" + timestampMatchDTO.seconds()
54+
ServiceList.PeerTube ->
55+
return relatedStreamUrl + "?start=" + timestampMatchDTO.seconds()
56+
}
57+
58+
// Return timestamp text for other services
59+
return descriptionText.subSequence(
60+
timestampMatchDTO.timestampStart(),
61+
timestampMatchDTO.timestampEnd()
62+
).toString()
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)