|
| 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