mirror of https://github.com/NekoX-Dev/NekoX.git
fix links BottomSheet
This commit is contained in:
parent
31abbbbddd
commit
946f24c45b
|
@ -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) {
|
private void openClickableLink(CharacterStyle url, String str, boolean longPress, final ChatMessageCell cell, final MessageObject messageObject) {
|
||||||
if (longPress) {
|
if (longPress) {
|
||||||
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false, themeDelegate);
|
BottomBuilder builder = new BottomBuilder(getParentActivity(), false);
|
||||||
int timestamp = -1;
|
int timestamp = -1;
|
||||||
if (str.startsWith("video?")) {
|
if (str.startsWith("video?")) {
|
||||||
timestamp = Utilities.parseInt(str);
|
timestamp = Utilities.parseInt(str);
|
||||||
}
|
}
|
||||||
if (timestamp >= 0) {
|
if (timestamp >= 0) {
|
||||||
builder.setTitle(AndroidUtilities.formatDuration(timestamp, false));
|
builder.addTitle(AndroidUtilities.formatDuration(timestamp, false));
|
||||||
} else {
|
} else {
|
||||||
String formattedUrl = str;
|
String formattedUrl = str;
|
||||||
try {
|
try {
|
||||||
formattedUrl = URLDecoder.decode(str.replaceAll("\\+", "%2b"), "UTF-8");
|
formattedUrl = URLDecoder.decode(str.replaceAll("\\+", "%2b"), "UTF-8");
|
||||||
} catch (Exception ignore) {}
|
} catch (Exception ignore) {}
|
||||||
builder.setTitle(formattedUrl);
|
builder.addTitle(formattedUrl);
|
||||||
builder.setTitleMultipleLines(true);
|
// builder.setTitleMultipleLines(true);
|
||||||
}
|
}
|
||||||
final int finalTimestamp = timestamp;
|
final int finalTimestamp = timestamp;
|
||||||
boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || (messageObject != null && messageObject.messageOwner != null && messageObject.messageOwner.noforwards);
|
// 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) -> {
|
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 (which == 0) {
|
||||||
if (str.startsWith("video?")) {
|
if (str.startsWith("video?")) {
|
||||||
didPressMessageUrl(url, false, messageObject, cell);
|
didPressMessageUrl(url, false, messageObject, cell);
|
||||||
|
@ -25305,7 +25309,7 @@ ChatActivity extends BaseFragment implements NotificationCenter.NotificationCent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (link == null) {
|
if (link == null) {
|
||||||
return;
|
return Unit.INSTANCE;
|
||||||
}
|
}
|
||||||
AndroidUtilities.addToClipboard(link);
|
AndroidUtilities.addToClipboard(link);
|
||||||
} else {
|
} else {
|
||||||
|
@ -25320,6 +25324,7 @@ ChatActivity extends BaseFragment implements NotificationCenter.NotificationCent
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return Unit.INSTANCE;
|
||||||
});
|
});
|
||||||
builder.setOnPreDismissListener(di -> {
|
builder.setOnPreDismissListener(di -> {
|
||||||
if (cell != null) {
|
if (cell != null) {
|
||||||
|
|
|
@ -18,8 +18,11 @@ import org.telegram.ui.Cells.TextCheckCell
|
||||||
import org.telegram.ui.Components.LayoutHelper
|
import org.telegram.ui.Components.LayoutHelper
|
||||||
import java.util.*
|
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 {
|
private val rootView = LinearLayout(ctx).apply {
|
||||||
orientation = LinearLayout.VERTICAL
|
orientation = LinearLayout.VERTICAL
|
||||||
|
@ -68,39 +71,25 @@ class BottomBuilder(val ctx: Context) {
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun addTitle(title: CharSequence, bigTitle: Boolean = false): HeaderCell {
|
fun addTitle(title: CharSequence, bigTitle: Boolean = false): HeaderCell {
|
||||||
|
|
||||||
return addTitle(title, bigTitle, null)
|
return addTitle(title, bigTitle, null)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addTitle(title: CharSequence, subTitle: CharSequence): HeaderCell {
|
fun addTitle(title: CharSequence, subTitle: CharSequence): HeaderCell {
|
||||||
|
|
||||||
return addTitle(title, true, subTitle)
|
return addTitle(title, true, subTitle)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addTitle(title: CharSequence, bigTitle: Boolean, subTitle: CharSequence?): HeaderCell {
|
fun addTitle(title: CharSequence, bigTitle: Boolean, subTitle: CharSequence?): HeaderCell {
|
||||||
|
|
||||||
val headerCell = HeaderCell(ctx, Theme.key_dialogTextBlue2, 23, 15, false)
|
val headerCell = HeaderCell(ctx, Theme.key_dialogTextBlue2, 23, 15, false)
|
||||||
|
|
||||||
headerCell.setBigTitle(bigTitle)
|
headerCell.setBigTitle(bigTitle)
|
||||||
|
|
||||||
headerCell.setText(if (title is String) AndroidUtilities.replaceTags(title) else title)
|
headerCell.setText(if (title is String) AndroidUtilities.replaceTags(title) else title)
|
||||||
|
|
||||||
subTitle?.also {
|
subTitle?.also {
|
||||||
|
|
||||||
headerCell.setText2(it)
|
headerCell.setText2(it)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rootView.addView(headerCell, LayoutHelper.createLinear(-1, -2).apply {
|
rootView.addView(headerCell, LayoutHelper.createLinear(-1, -2).apply {
|
||||||
|
|
||||||
bottomMargin = AndroidUtilities.dp(8F)
|
bottomMargin = AndroidUtilities.dp(8F)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return headerCell
|
return headerCell
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
|
@ -135,39 +124,26 @@ class BottomBuilder(val ctx: Context) {
|
||||||
|
|
||||||
@JvmOverloads
|
@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> {
|
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>()
|
val list = mutableListOf<TextCheckCell>()
|
||||||
|
|
||||||
text.forEachIndexed { index, textI ->
|
text.forEachIndexed { index, textI ->
|
||||||
list.add(addCheckItem(textI, value(index), switch, valueText?.invoke(index)) { cell, isChecked ->
|
list.add(addCheckItem(textI, value(index), switch, valueText?.invoke(index)) { cell, isChecked ->
|
||||||
listener(index, textI, cell, isChecked)
|
listener(index, textI, cell, isChecked)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return list
|
return list
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val radioButtonGroup by lazy { LinkedList<RadioButtonCell>() }
|
private val radioButtonGroup by lazy { LinkedList<RadioButtonCell>() }
|
||||||
|
|
||||||
fun doRadioCheck(cell: RadioButtonCell) {
|
fun doRadioCheck(cell: RadioButtonCell) {
|
||||||
|
|
||||||
if (!cell.isChecked) {
|
if (!cell.isChecked) {
|
||||||
|
|
||||||
radioButtonGroup.forEach {
|
radioButtonGroup.forEach {
|
||||||
|
|
||||||
if (it.isChecked) {
|
if (it.isChecked) {
|
||||||
|
|
||||||
it.setChecked(false, true)
|
it.setChecked(false, true)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cell.setChecked(true, true)
|
cell.setChecked(true, true)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
|
@ -179,65 +155,42 @@ class BottomBuilder(val ctx: Context) {
|
||||||
rootView.addView(checkBoxCell, LayoutHelper.createLinear(-1, -2))
|
rootView.addView(checkBoxCell, LayoutHelper.createLinear(-1, -2))
|
||||||
|
|
||||||
if (valueText == null) {
|
if (valueText == null) {
|
||||||
|
|
||||||
checkBoxCell.setTextAndValue(text, true, value)
|
checkBoxCell.setTextAndValue(text, true, value)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
checkBoxCell.setTextAndValueAndCheck(text, valueText, true, value)
|
checkBoxCell.setTextAndValueAndCheck(text, valueText, true, value)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
radioButtonGroup.add(checkBoxCell)
|
radioButtonGroup.add(checkBoxCell)
|
||||||
|
|
||||||
checkBoxCell.setOnClickListener {
|
checkBoxCell.setOnClickListener {
|
||||||
|
|
||||||
listener(checkBoxCell)
|
listener(checkBoxCell)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkBoxCell
|
return checkBoxCell
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
@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> {
|
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>()
|
val list = mutableListOf<RadioButtonCell>()
|
||||||
|
|
||||||
text.forEachIndexed { index, textI ->
|
text.forEachIndexed { index, textI ->
|
||||||
|
|
||||||
list.add(addRadioItem(textI, value(index, textI), valueText?.invoke(index, textI)) { cell ->
|
list.add(addRadioItem(textI, value(index, textI), valueText?.invoke(index, textI)) { cell ->
|
||||||
|
|
||||||
listener(index, textI, cell)
|
listener(index, textI, cell)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list
|
return list
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addCancelItem() {
|
fun addCancelItem() {
|
||||||
|
|
||||||
addItem(LocaleController.getString("Cancel", R.string.Cancel), R.drawable.baseline_cancel_24) {}
|
addItem(LocaleController.getString("Cancel", R.string.Cancel), R.drawable.baseline_cancel_24) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun addCancelButton(left: Boolean = true) {
|
fun addCancelButton(left: Boolean = true) {
|
||||||
|
|
||||||
addButton(LocaleController.getString("Cancel", R.string.Cancel), left = left) {}
|
addButton(LocaleController.getString("Cancel", R.string.Cancel), left = left) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun addOkButton(listener: ((TextView) -> Unit), noAutoDismiss: Boolean = false) {
|
fun addOkButton(listener: ((TextView) -> Unit), noAutoDismiss: Boolean = false) {
|
||||||
|
|
||||||
addButton(LocaleController.getString("OK", R.string.OK), noAutoDismiss) { listener(it); }
|
addButton(LocaleController.getString("OK", R.string.OK), noAutoDismiss) { listener(it); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
|
@ -263,50 +216,33 @@ class BottomBuilder(val ctx: Context) {
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun addItem(text: String, icon: Int = 0, red: Boolean = false, listener: ((cell: TextCell) -> Unit)?): TextCell {
|
fun addItem(text: String, icon: Int = 0, red: Boolean = false, listener: ((cell: TextCell) -> Unit)?): TextCell {
|
||||||
|
|
||||||
return TextCell(ctx).apply {
|
return TextCell(ctx).apply {
|
||||||
|
|
||||||
background = Theme.getSelectorDrawable(false)
|
background = Theme.getSelectorDrawable(false)
|
||||||
setTextAndIcon(text, icon, false)
|
setTextAndIcon(text, icon, false)
|
||||||
|
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
dismiss()
|
dismiss()
|
||||||
listener?.invoke(this)
|
listener?.invoke(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (red) {
|
if (red) {
|
||||||
setColors("key_dialogTextRed2", "key_dialogTextRed2")
|
setColors("key_dialogTextRed2", "key_dialogTextRed2")
|
||||||
}
|
}
|
||||||
|
|
||||||
this@BottomBuilder.rootView.addView(this, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48, rtl))
|
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> {
|
fun addItems(text: Array<String?>, icon: IntArray?, listener: (index: Int, text: String, cell: TextCell) -> Unit): List<TextCell> {
|
||||||
|
|
||||||
val list = mutableListOf<TextCell>()
|
val list = mutableListOf<TextCell>()
|
||||||
|
|
||||||
text.forEachIndexed { index, textI ->
|
text.forEachIndexed { index, textI ->
|
||||||
|
|
||||||
list.add(addItem(textI ?: return@forEachIndexed, icon?.get(index) ?: 0) { cell ->
|
list.add(addItem(textI ?: return@forEachIndexed, icon?.get(index) ?: 0) { cell ->
|
||||||
|
|
||||||
listener(index, textI, cell)
|
listener(index, textI, cell)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list
|
return list
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun addEditText(hintText: String? = null): EditText {
|
fun addEditText(hintText: String? = null): EditText {
|
||||||
|
|
||||||
return EditText(ctx).apply {
|
return EditText(ctx).apply {
|
||||||
|
|
||||||
setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14f)
|
setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14f)
|
||||||
setTextColor(Theme.getColor(Theme.key_dialogTextBlack))
|
setTextColor(Theme.getColor(Theme.key_dialogTextBlack))
|
||||||
setHintTextColor(Theme.getColor(Theme.key_dialogTextBlue4))
|
setHintTextColor(Theme.getColor(Theme.key_dialogTextBlue4))
|
||||||
|
@ -316,9 +252,7 @@ class BottomBuilder(val ctx: Context) {
|
||||||
setBackgroundDrawable(null)
|
setBackgroundDrawable(null)
|
||||||
|
|
||||||
this@BottomBuilder.rootView.addView(this, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, -2, rtl, AndroidUtilities.dp(6F), 0, 0, 0))
|
this@BottomBuilder.rootView.addView(this, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, -2, rtl, AndroidUtilities.dp(6F), 0, 0, 0))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun create() = builder.create()
|
fun create() = builder.create()
|
||||||
|
|
Loading…
Reference in New Issue