Skip to content

Commit cd36744

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 20637d0 commit cd36744

3 files changed

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

0 commit comments

Comments
 (0)