Skip to content

Commit 873b2be

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 4ef4ed1 commit 873b2be

3 files changed

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

0 commit comments

Comments
 (0)