fix links BottomSheet

This commit is contained in:
luvletter2333 2022-07-12 22:29:42 +08:00
parent 31abbbbddd
commit 946f24c45b
No known key found for this signature in database
GPG Key ID: A26A8880836E1978
2 changed files with 17 additions and 78 deletions

View File

@ -25248,24 +25248,28 @@ ChatActivity extends BaseFragment implements NotificationCenter.NotificationCent
private void openClickableLink(CharacterStyle url, String str, boolean longPress, final ChatMessageCell cell, final MessageObject messageObject) {
if (longPress) {
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false, themeDelegate);
BottomBuilder builder = new BottomBuilder(getParentActivity(), false);
int timestamp = -1;
if (str.startsWith("video?")) {
timestamp = Utilities.parseInt(str);
}
if (timestamp >= 0) {
builder.setTitle(AndroidUtilities.formatDuration(timestamp, false));
builder.addTitle(AndroidUtilities.formatDuration(timestamp, false));
} else {
String formattedUrl = str;
try {
formattedUrl = URLDecoder.decode(str.replaceAll("\\+", "%2b"), "UTF-8");
} catch (Exception ignore) {}
builder.setTitle(formattedUrl);
builder.setTitleMultipleLines(true);
builder.addTitle(formattedUrl);
// builder.setTitleMultipleLines(true);
}
final int finalTimestamp = timestamp;
boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || (messageObject != null && messageObject.messageOwner != null && messageObject.messageOwner.noforwards);
builder.setItems(noforwards ? new CharSequence[] {LocaleController.getString("Open", R.string.Open)} : new CharSequence[]{LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy)}, (dialog, which) -> {
// boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || (messageObject != null && messageObject.messageOwner != null && messageObject.messageOwner.noforwards);
builder.addItems(new String[]{LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy)},
new int[]{
R.drawable.baseline_open_in_browser_24,
R.drawable.baseline_content_copy_24,
}, (which, _text, ign) -> {
if (which == 0) {
if (str.startsWith("video?")) {
didPressMessageUrl(url, false, messageObject, cell);
@ -25305,7 +25309,7 @@ ChatActivity extends BaseFragment implements NotificationCenter.NotificationCent
}
}
if (link == null) {
return;
return Unit.INSTANCE;
}
AndroidUtilities.addToClipboard(link);
} else {
@ -25320,6 +25324,7 @@ ChatActivity extends BaseFragment implements NotificationCenter.NotificationCent
}
}
return Unit.INSTANCE;
});
builder.setOnPreDismissListener(di -> {
if (cell != null) {

View File

@ -18,8 +18,11 @@ import org.telegram.ui.Cells.TextCheckCell
import org.telegram.ui.Components.LayoutHelper
import java.util.*
class BottomBuilder(val ctx: Context) {
val builder = BottomSheet.Builder(ctx, true)
class BottomBuilder(val ctx: Context, val needFocus: Boolean = true) {
constructor(ctx: Context) : this(ctx, true) {}
val builder = BottomSheet.Builder(ctx, needFocus)
private val rootView = LinearLayout(ctx).apply {
orientation = LinearLayout.VERTICAL
@ -68,39 +71,25 @@ class BottomBuilder(val ctx: Context) {
@JvmOverloads
fun addTitle(title: CharSequence, bigTitle: Boolean = false): HeaderCell {
return addTitle(title, bigTitle, null)
}
fun addTitle(title: CharSequence, subTitle: CharSequence): HeaderCell {
return addTitle(title, true, subTitle)
}
fun addTitle(title: CharSequence, bigTitle: Boolean, subTitle: CharSequence?): HeaderCell {
val headerCell = HeaderCell(ctx, Theme.key_dialogTextBlue2, 23, 15, false)
headerCell.setBigTitle(bigTitle)
headerCell.setText(if (title is String) AndroidUtilities.replaceTags(title) else title)
subTitle?.also {
headerCell.setText2(it)
}
rootView.addView(headerCell, LayoutHelper.createLinear(-1, -2).apply {
bottomMargin = AndroidUtilities.dp(8F)
})
return headerCell
}
@JvmOverloads
@ -135,39 +124,26 @@ class BottomBuilder(val ctx: Context) {
@JvmOverloads
fun addCheckItems(text: Array<String>, value: (Int) -> Boolean, switch: Boolean = false, valueText: ((Int) -> String)? = null, listener: (index: Int, text: String, cell: TextCheckCell, isChecked: Boolean) -> Unit): List<TextCheckCell> {
val list = mutableListOf<TextCheckCell>()
text.forEachIndexed { index, textI ->
list.add(addCheckItem(textI, value(index), switch, valueText?.invoke(index)) { cell, isChecked ->
listener(index, textI, cell, isChecked)
})
}
return list
}
private val radioButtonGroup by lazy { LinkedList<RadioButtonCell>() }
fun doRadioCheck(cell: RadioButtonCell) {
if (!cell.isChecked) {
radioButtonGroup.forEach {
if (it.isChecked) {
it.setChecked(false, true)
}
}
cell.setChecked(true, true)
}
}
@JvmOverloads
@ -179,65 +155,42 @@ class BottomBuilder(val ctx: Context) {
rootView.addView(checkBoxCell, LayoutHelper.createLinear(-1, -2))
if (valueText == null) {
checkBoxCell.setTextAndValue(text, true, value)
} else {
checkBoxCell.setTextAndValueAndCheck(text, valueText, true, value)
}
radioButtonGroup.add(checkBoxCell)
checkBoxCell.setOnClickListener {
listener(checkBoxCell)
}
return checkBoxCell
}
@JvmOverloads
fun addRadioItems(text: Array<String>, value: (Int, String) -> Boolean, valueText: ((Int, String) -> String)? = null, listener: (index: Int, text: String, cell: RadioButtonCell) -> Unit): List<RadioButtonCell> {
val list = mutableListOf<RadioButtonCell>()
text.forEachIndexed { index, textI ->
list.add(addRadioItem(textI, value(index, textI), valueText?.invoke(index, textI)) { cell ->
listener(index, textI, cell)
})
}
return list
}
fun addCancelItem() {
addItem(LocaleController.getString("Cancel", R.string.Cancel), R.drawable.baseline_cancel_24) {}
}
@JvmOverloads
fun addCancelButton(left: Boolean = true) {
addButton(LocaleController.getString("Cancel", R.string.Cancel), left = left) {}
}
@JvmOverloads
fun addOkButton(listener: ((TextView) -> Unit), noAutoDismiss: Boolean = false) {
addButton(LocaleController.getString("OK", R.string.OK), noAutoDismiss) { listener(it); }
}
@JvmOverloads
@ -263,50 +216,33 @@ class BottomBuilder(val ctx: Context) {
@JvmOverloads
fun addItem(text: String, icon: Int = 0, red: Boolean = false, listener: ((cell: TextCell) -> Unit)?): TextCell {
return TextCell(ctx).apply {
background = Theme.getSelectorDrawable(false)
setTextAndIcon(text, icon, false)
setOnClickListener {
dismiss()
listener?.invoke(this)
}
if (red) {
setColors("key_dialogTextRed2", "key_dialogTextRed2")
}
this@BottomBuilder.rootView.addView(this, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48, rtl))
}
}
fun addItems(text: Array<String?>, icon: IntArray?, listener: (index: Int, text: String, cell: TextCell) -> Unit): List<TextCell> {
val list = mutableListOf<TextCell>()
text.forEachIndexed { index, textI ->
list.add(addItem(textI ?: return@forEachIndexed, icon?.get(index) ?: 0) { cell ->
listener(index, textI, cell)
})
}
return list
}
@JvmOverloads
fun addEditText(hintText: String? = null): EditText {
return EditText(ctx).apply {
setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14f)
setTextColor(Theme.getColor(Theme.key_dialogTextBlack))
setHintTextColor(Theme.getColor(Theme.key_dialogTextBlue4))
@ -316,9 +252,7 @@ class BottomBuilder(val ctx: Context) {
setBackgroundDrawable(null)
this@BottomBuilder.rootView.addView(this, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, -2, rtl, AndroidUtilities.dp(6F), 0, 0, 0))
}
}
fun create() = builder.create()