mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-01-18 17:10:27 +00:00
Convert newpipe/util/text/TimestampLongPressClickableSpan.java to kotlin
Also convert one class used by it into java record
This commit is contained in:
@@ -54,30 +54,6 @@ public final class TimestampExtractor {
|
||||
return new TimestampMatchDTO(timestampStart, timestampEnd, seconds);
|
||||
}
|
||||
|
||||
public static class TimestampMatchDTO {
|
||||
private final int timestampStart;
|
||||
private final int timestampEnd;
|
||||
private final int seconds;
|
||||
|
||||
public TimestampMatchDTO(
|
||||
final int timestampStart,
|
||||
final int timestampEnd,
|
||||
final int seconds) {
|
||||
this.timestampStart = timestampStart;
|
||||
this.timestampEnd = timestampEnd;
|
||||
this.seconds = seconds;
|
||||
}
|
||||
|
||||
public int timestampStart() {
|
||||
return timestampStart;
|
||||
}
|
||||
|
||||
public int timestampEnd() {
|
||||
return timestampEnd;
|
||||
}
|
||||
|
||||
public int seconds() {
|
||||
return seconds;
|
||||
}
|
||||
public record TimestampMatchDTO(int timestampStart, int timestampEnd, int seconds) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
package org.schabi.newpipe.util.text;
|
||||
|
||||
import static org.schabi.newpipe.util.text.InternalUrlsHandler.playOnPopup;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.schabi.newpipe.extractor.ServiceList;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||
|
||||
final class TimestampLongPressClickableSpan extends LongPressClickableSpan {
|
||||
|
||||
@NonNull
|
||||
private final Context context;
|
||||
@NonNull
|
||||
private final String descriptionText;
|
||||
@NonNull
|
||||
private final CompositeDisposable disposables;
|
||||
@NonNull
|
||||
private final StreamingService relatedInfoService;
|
||||
@NonNull
|
||||
private final String relatedStreamUrl;
|
||||
@NonNull
|
||||
private final TimestampExtractor.TimestampMatchDTO timestampMatchDTO;
|
||||
|
||||
TimestampLongPressClickableSpan(
|
||||
@NonNull final Context context,
|
||||
@NonNull final String descriptionText,
|
||||
@NonNull final CompositeDisposable disposables,
|
||||
@NonNull final StreamingService relatedInfoService,
|
||||
@NonNull final String relatedStreamUrl,
|
||||
@NonNull final TimestampExtractor.TimestampMatchDTO timestampMatchDTO) {
|
||||
this.context = context;
|
||||
this.descriptionText = descriptionText;
|
||||
this.disposables = disposables;
|
||||
this.relatedInfoService = relatedInfoService;
|
||||
this.relatedStreamUrl = relatedStreamUrl;
|
||||
this.timestampMatchDTO = timestampMatchDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(@NonNull final View view) {
|
||||
playOnPopup(context, relatedStreamUrl, relatedInfoService,
|
||||
timestampMatchDTO.seconds());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongClick(@NonNull final View view) {
|
||||
ShareUtils.copyToClipboard(context, getTimestampTextToCopy(
|
||||
relatedInfoService, relatedStreamUrl, descriptionText, timestampMatchDTO));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static String getTimestampTextToCopy(
|
||||
@NonNull final StreamingService relatedInfoService,
|
||||
@NonNull final String relatedStreamUrl,
|
||||
@NonNull final String descriptionText,
|
||||
@NonNull final TimestampExtractor.TimestampMatchDTO timestampMatchDTO) {
|
||||
// TODO: use extractor methods to get timestamps when this feature will be implemented in it
|
||||
if (relatedInfoService == ServiceList.YouTube) {
|
||||
return relatedStreamUrl + "&t=" + timestampMatchDTO.seconds();
|
||||
} else if (relatedInfoService == ServiceList.SoundCloud
|
||||
|| relatedInfoService == ServiceList.MediaCCC) {
|
||||
return relatedStreamUrl + "#t=" + timestampMatchDTO.seconds();
|
||||
} else if (relatedInfoService == ServiceList.PeerTube) {
|
||||
return relatedStreamUrl + "?start=" + timestampMatchDTO.seconds();
|
||||
}
|
||||
|
||||
// Return timestamp text for other services
|
||||
return descriptionText.subSequence(timestampMatchDTO.timestampStart(),
|
||||
timestampMatchDTO.timestampEnd()).toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2025 NewPipe contributors <https://newpipe.net>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package org.schabi.newpipe.util.text
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import org.schabi.newpipe.extractor.ServiceList
|
||||
import org.schabi.newpipe.extractor.StreamingService
|
||||
import org.schabi.newpipe.util.external_communication.ShareUtils
|
||||
import org.schabi.newpipe.util.text.TimestampExtractor.TimestampMatchDTO
|
||||
|
||||
class TimestampLongPressClickableSpan(
|
||||
private val context: Context,
|
||||
private val descriptionText: String,
|
||||
private val disposables: CompositeDisposable,
|
||||
private val relatedInfoService: StreamingService,
|
||||
private val relatedStreamUrl: String,
|
||||
private val timestampMatchDTO: TimestampMatchDTO
|
||||
) : LongPressClickableSpan() {
|
||||
override fun onClick(view: View) {
|
||||
InternalUrlsHandler.playOnPopup(
|
||||
context,
|
||||
relatedStreamUrl,
|
||||
relatedInfoService,
|
||||
timestampMatchDTO.seconds()
|
||||
)
|
||||
}
|
||||
|
||||
override fun onLongClick(view: View) {
|
||||
ShareUtils.copyToClipboard(
|
||||
context,
|
||||
getTimestampTextToCopy(
|
||||
relatedInfoService,
|
||||
relatedStreamUrl,
|
||||
descriptionText,
|
||||
timestampMatchDTO
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun getTimestampTextToCopy(
|
||||
relatedInfoService: StreamingService,
|
||||
relatedStreamUrl: String,
|
||||
descriptionText: String,
|
||||
timestampMatchDTO: TimestampMatchDTO
|
||||
): String {
|
||||
// TODO: use extractor methods to get timestamps when this feature will be implemented in it
|
||||
when (relatedInfoService) {
|
||||
ServiceList.YouTube ->
|
||||
return relatedStreamUrl + "&t=" + timestampMatchDTO.seconds()
|
||||
ServiceList.SoundCloud, ServiceList.MediaCCC ->
|
||||
return relatedStreamUrl + "#t=" + timestampMatchDTO.seconds()
|
||||
ServiceList.PeerTube ->
|
||||
return relatedStreamUrl + "?start=" + timestampMatchDTO.seconds()
|
||||
}
|
||||
|
||||
// Return timestamp text for other services
|
||||
return descriptionText.substring(
|
||||
timestampMatchDTO.timestampStart(),
|
||||
timestampMatchDTO.timestampEnd()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user