mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 23:07:26 -04:00
Hide content uri in external link popup.
* It is unnecessary to show the epub and pdf URIs in the popup, as they are not URLs. If the user copies and pastes these links into an external browser, they will not open. Hence, displaying these links in the popup for epub and pdf files is not ideal. * Both URIs start with `content://` prefix so we have placed a check for these type of uris in our `AlertDialogShower.kt` file if the uri is content type then it will not display this uri as link to the user.
This commit is contained in:
parent
0834cdc248
commit
bb5e4d34c1
@ -72,36 +72,47 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) :
|
||||
}
|
||||
}
|
||||
uri?.let {
|
||||
val frameLayout = FrameLayout(activity.baseContext)
|
||||
|
||||
val textView = TextView(activity.baseContext).apply {
|
||||
layoutParams = getFrameLayoutParams()
|
||||
gravity = Gravity.CENTER
|
||||
setLinkTextColor(activity.getAttribute(R.attr.colorPrimary))
|
||||
setOnLongClickListener {
|
||||
val clipboard =
|
||||
ContextCompat.getSystemService(activity.baseContext, ClipboardManager::class.java)
|
||||
val clip = ClipData.newPlainText("External Url", "$uri")
|
||||
clipboard?.setPrimaryClip(clip)
|
||||
Toast.makeText(
|
||||
activity.baseContext,
|
||||
R.string.external_link_copied_message,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
true
|
||||
}
|
||||
@SuppressLint("SetTextI18n")
|
||||
text = "</br><a href=$uri> <b>$uri</b>".fromHtml()
|
||||
/*
|
||||
Check if it is valid url then show it to the user
|
||||
otherwise don't show uri to the user as they are not directly openable in the external app.
|
||||
We place this condition to improve the user experience see https://github.com/kiwix/kiwix-android/pull/3455
|
||||
*/
|
||||
if (!"$it".startsWith("content://")) {
|
||||
showUrlInDialog(this, it)
|
||||
}
|
||||
frameLayout.addView(textView)
|
||||
setView(frameLayout)
|
||||
dialog.getView?.let { setView(it()) }
|
||||
setCancelable(dialog.cancelable)
|
||||
}
|
||||
dialog.getView?.let { setView(it()) }
|
||||
setCancelable(dialog.cancelable)
|
||||
}
|
||||
.create()
|
||||
}
|
||||
|
||||
private fun showUrlInDialog(builder: AlertDialog.Builder, uri: Uri) {
|
||||
val frameLayout = FrameLayout(activity.baseContext)
|
||||
|
||||
val textView = TextView(activity.baseContext).apply {
|
||||
layoutParams = getFrameLayoutParams()
|
||||
gravity = Gravity.CENTER
|
||||
setLinkTextColor(activity.getAttribute(R.attr.colorPrimary))
|
||||
setOnLongClickListener {
|
||||
val clipboard =
|
||||
ContextCompat.getSystemService(activity.baseContext, ClipboardManager::class.java)
|
||||
val clip = ClipData.newPlainText("External Url", "$uri")
|
||||
clipboard?.setPrimaryClip(clip)
|
||||
Toast.makeText(
|
||||
activity.baseContext,
|
||||
R.string.external_link_copied_message,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
true
|
||||
}
|
||||
@SuppressLint("SetTextI18n")
|
||||
text = "</br><a href=$uri> <b>$uri</b>".fromHtml()
|
||||
}
|
||||
frameLayout.addView(textView)
|
||||
builder.setView(frameLayout)
|
||||
}
|
||||
|
||||
private fun getFrameLayoutParams() = FrameLayout.LayoutParams(
|
||||
LayoutParams.MATCH_PARENT,
|
||||
LayoutParams.WRAP_CONTENT
|
||||
|
Loading…
x
Reference in New Issue
Block a user