-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Convert newpipe/util/text/TimestampLongPressClickableSpan.java to kotlin #12951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| 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.subSequence( | ||
| timestampMatchDTO.timestampStart(), | ||
| timestampMatchDTO.timestampEnd() | ||
| ).toString() | ||
|
Comment on lines
+43
to
+56
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be possible to concat string and also lift the return statement out of the when block with an else logic.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am dumb. Could you explain (about else)? And thanks for reviews |
||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put all on single line or separate if its over 100 char.