Skip to content
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

refactor: add clipboard helper and improve repo url copy #946

Merged
merged 9 commits into from
Mar 13, 2024

Conversation

IndusAryan
Copy link
Contributor

@IndusAryan IndusAryan commented Feb 20, 2024

improve repository copying
add clipboard util to ease copying
close #970

# Conflicts:
#	app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt
@IndusAryan IndusAryan changed the title feat(ui): make description copyable , add clipboard helper refactor: add clipboard helper Feb 21, 2024
@IndusAryan IndusAryan changed the title refactor: add clipboard helper refactor: add clipboard helper and improve repo url copy Feb 21, 2024
val clip = ClipData.newPlainText(link.name, link.url)
serviceClipboard.setPrimaryClip(clip)
showToast(R.string.copy_link_toast, Toast.LENGTH_SHORT)
val linkCopyLabel = UiText.DynamicString(link.name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

txt

?: return@setOnClickListener
val clip = ClipData.newPlainText("logcat", text)
serviceClipboard.setPrimaryClip(clip)
val logcat = UiText.DynamicString("Logcat")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

txt

}
} catch (t: Throwable) {
Log.e("ClipboardService", "$t")
showToast(R.string.clipboard_too_large)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true, it can crash on multiple things like context!! or getSystemService!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better handling now

@@ -123,6 +129,20 @@ object UIHelper {
)
}

fun clipboardHelper(label: UiText, text: CharSequence) {
try {
val clip = ClipData.newPlainText(label.asString(context!!), text)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont. do smth like

context?.let { ctx ->

}
or let ctx = context ?: return

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never want to do !!

ctx.getSystemService<ClipboardManager>()?.setPrimaryClip(clip)

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
showToast("$label $labelSuffix")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this is wrong, you cant use string like this on a UIText

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot_20240308_015219

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for undersight, the asString(ctx) is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@Luna712
Copy link
Contributor

Luna712 commented Mar 8, 2024

Thanks for the version + commit addition, that's nice!

Copy link
Collaborator

@fire-light42 fire-light42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine, will merge after testing

Copy link
Contributor

@Luna712 Luna712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works nice for me thanks, I don't know if I necessarily like the format of copying repos like Repo Name : https://codeberg.org/repo/raw/branch/builds/repo.json, there is a bit extra whitespace and when it auto fills in when you go to paste the repo who have to manually remove the name now, but for most cases including the name is actually probably nice. Overall this does improve copying functionality.

@IndusAryan
Copy link
Contributor Author

the use case is for sharing , and after that it's not a problem ,because the shared platform link can be copied easily.

Screenshot_20240310-105533_Discord.png

@fire-light42 fire-light42 merged commit 040ac77 into recloudstream:master Mar 13, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow copying version and commit to clipboard by long clicking
3 participants