From 802cf19598e83709303199a1d361416a557daac2 Mon Sep 17 00:00:00 2001 From: Al Lansley Date: Mon, 12 Aug 2024 16:42:15 +1000 Subject: [PATCH] Open or copy URL WIP --- .../securesms/SessionDialogBuilder.kt | 49 ++++++++++++++++--- .../v2/messages/LinkPreviewView.kt | 16 +++++- .../fragment_modal_url_bottom_sheet.xml | 1 + 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt b/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt index e27ced3b3c..15b19956f9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms import android.content.Context import android.content.Intent import android.net.Uri +import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup.LayoutParams.MATCH_PARENT @@ -10,6 +11,7 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.Button import android.widget.LinearLayout import android.widget.LinearLayout.VERTICAL +import android.widget.ScrollView import android.widget.Space import android.widget.TextView import androidx.annotation.AttrRes @@ -21,6 +23,7 @@ import androidx.core.text.HtmlCompat import androidx.core.view.updateMargins import androidx.fragment.app.Fragment import network.loki.messenger.R +import org.thoughtcrime.securesms.conversation.v2.Util.writeTextToClipboard import org.thoughtcrime.securesms.util.toPx @DslMarker @@ -66,6 +69,26 @@ class SessionDialogBuilder(val context: Context) { layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT) .apply { updateMargins(dp40, 0, dp40, 0) } } + } + + fun textWithMaxOfFiveLines(text: CharSequence?, @StyleRes style: Int = 0) { + + ScrollView(context, null, 0).apply { + layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT) + + // fix this so it adds and shows a scrollbar if it exceeds 5 lines + here! + text(text, style) { + maxLines = 5 + layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT) + .apply { updateMargins(dp40, 0, dp40, 0) } + }.apply { refreshDrawableState() } + + } + + + + } private fun text(text: CharSequence?, @StyleRes style: Int, modify: TextView.() -> Unit) { @@ -127,6 +150,9 @@ class SessionDialogBuilder(val context: Context) { fun okButton(listener: (() -> Unit) = {}) = button(android.R.string.ok) { listener() } fun cancelButton(listener: (() -> Unit) = {}) = button(android.R.string.cancel, R.string.AccessibilityId_cancel) { listener() } + fun copyUrlButton(listener: (() -> Unit) = {}) = button(android.R.string.copyUrl, R.string.AccessibilityId_copy) { listener() } + + fun button( @StringRes text: Int, @StringRes contentDescriptionRes: Int = text, @@ -149,18 +175,29 @@ class SessionDialogBuilder(val context: Context) { fun Context.showSessionDialog(build: SessionDialogBuilder.() -> Unit): AlertDialog = SessionDialogBuilder(this).apply { build() }.show() -fun Context.showOpenUrlDialog(build: SessionDialogBuilder.() -> Unit): AlertDialog = + +private fun Context.showOpenUrlDialogInner(build: SessionDialogBuilder.() -> Unit): AlertDialog = SessionDialogBuilder(this).apply { title(R.string.urlOpen) text(R.string.urlOpenBrowser) build() }.show() -fun Context.showOpenUrlDialog(url: String): AlertDialog = - showOpenUrlDialog { - okButton { openUrl(url) } - cancelButton() - } +fun Context.showOpenUrlDialogPublicFacing(url: String): AlertDialog { + return SessionDialogBuilder(this).apply { + title(R.string.urlOpen) + val txt = getString(R.string.urlOpenBrowser) + "\n\n" + "https://github.com/oxen-io/session-android/theworldslongrsturlisverylongindeedandshouldgoover5linesbecausethatswhatIneedtotestbecausemaryhadalittlelamb" //url + textWithMaxOfFiveLines(txt) + dangerButton(R.string.open) { openUrl(url) } + copyUrlButton { writeTextToClipboard(context, url) } + }.show() + + +} +// showOpenUrlDialogInner { +// okButton { openUrl(url) } +// cancelButton() +// } fun Context.openUrl(url: String) = Intent(Intent.ACTION_VIEW, Uri.parse(url)).let(::startActivity) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt index 8cf80dc090..3993b61a71 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt @@ -16,8 +16,13 @@ import org.thoughtcrime.securesms.conversation.v2.ModalUrlBottomSheet import org.thoughtcrime.securesms.conversation.v2.utilities.MessageBubbleUtilities import org.thoughtcrime.securesms.database.model.MmsMessageRecord import com.bumptech.glide.RequestManager +import org.session.libsignal.utilities.Log +import org.thoughtcrime.securesms.SessionDialogBuilder import org.thoughtcrime.securesms.mms.ImageSlide +import org.thoughtcrime.securesms.showOpenUrlDialogPublicFacing + + class LinkPreviewView : LinearLayout { private val binding: ViewLinkPreviewBinding by lazy { ViewLinkPreviewBinding.bind(this) } private val cornerMask by lazy { CornerMask(this) } @@ -85,9 +90,16 @@ class LinkPreviewView : LinearLayout { } fun openURL() { - val url = this.url ?: return + val url = this.url ?: return Log.w("LinkPreviewView", "Cannot open a null URL") val activity = context as AppCompatActivity - ModalUrlBottomSheet(url).show(activity.supportFragmentManager, "Open URL Dialog") + + // OLDE! + //ModalUrlBottomSheet(url).show(activity.supportFragmentManager, "Open URL Dialog") + + activity.showOpenUrlDialogPublicFacing(url) + + + } // endregion } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_modal_url_bottom_sheet.xml b/app/src/main/res/layout/fragment_modal_url_bottom_sheet.xml index fb3876b28a..d41e510554 100644 --- a/app/src/main/res/layout/fragment_modal_url_bottom_sheet.xml +++ b/app/src/main/res/layout/fragment_modal_url_bottom_sheet.xml @@ -27,6 +27,7 @@ android:textColor="?android:textColorPrimary" android:textSize="@dimen/small_font_size" android:layout_margin="@dimen/large_spacing" + android:maxLines="5" android:textAlignment="center" />