fix: bottom sheet when long press link in profile
This commit is contained in:
parent
56d7e56491
commit
6b6ffaf2a2
@ -27,7 +27,6 @@ import android.text.StaticLayout;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.text.style.URLSpan;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
@ -50,11 +49,10 @@ import org.telegram.messenger.MessageObject;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.browser.Browser;
|
||||
import org.telegram.ui.ActionBar.BaseFragment;
|
||||
import org.telegram.ui.ActionBar.BottomSheet;
|
||||
import org.telegram.ui.ActionBar.Theme;
|
||||
import org.telegram.ui.Components.AlertsCreator;
|
||||
import org.telegram.ui.Components.EmojiTextView;
|
||||
import org.telegram.ui.Components.BulletinFactory;
|
||||
import org.telegram.ui.Components.EmojiTextView;
|
||||
import org.telegram.ui.Components.LayoutHelper;
|
||||
import org.telegram.ui.Components.LinkPath;
|
||||
import org.telegram.ui.Components.LinkSpanDrawable;
|
||||
@ -63,6 +61,9 @@ import org.telegram.ui.Components.URLSpanNoUnderline;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import kotlin.Unit;
|
||||
import tw.nekomimi.nekogram.ui.BottomBuilder;
|
||||
|
||||
public class AboutLinkCell extends FrameLayout {
|
||||
|
||||
private StaticLayout textLayout;
|
||||
@ -400,24 +401,30 @@ public class AboutLinkCell extends FrameLayout {
|
||||
} catch (Exception ignore) {}
|
||||
|
||||
ClickableSpan pressedLinkFinal = (ClickableSpan) pressedLink.getSpan();
|
||||
BottomSheet.Builder builder = new BottomSheet.Builder(parentFragment.getParentActivity());
|
||||
builder.setTitle(url);
|
||||
builder.setItems(new CharSequence[]{LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy)}, (dialog, which) -> {
|
||||
if (which == 0) {
|
||||
onLinkClick(pressedLinkFinal);
|
||||
} else if (which == 1) {
|
||||
AndroidUtilities.addToClipboard(url);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
||||
if (url.startsWith("@")) {
|
||||
BulletinFactory.of(parentFragment).createSimpleBulletin(R.raw.copy, LocaleController.getString("UsernameCopied", R.string.UsernameCopied)).show();
|
||||
} else if (url.startsWith("#") || url.startsWith("$")) {
|
||||
BulletinFactory.of(parentFragment).createSimpleBulletin(R.raw.copy, LocaleController.getString("HashtagCopied", R.string.HashtagCopied)).show();
|
||||
} else {
|
||||
BulletinFactory.of(parentFragment).createSimpleBulletin(R.raw.copy, LocaleController.getString("LinkCopied", R.string.LinkCopied)).show();
|
||||
BottomBuilder builder = new BottomBuilder(parentFragment.getParentActivity());
|
||||
builder.addTitle(url);
|
||||
builder.addItems(new String[]{LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy)},
|
||||
new int[]{R.drawable.msg_openin, R.drawable.msg_copy},
|
||||
(which, __, ___) -> {
|
||||
if (which == 0) {
|
||||
onLinkClick(pressedLinkFinal);
|
||||
} else if (which == 1) {
|
||||
AndroidUtilities.addToClipboard(url);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
||||
if (url.startsWith("@")) {
|
||||
BulletinFactory.of(parentFragment).createSimpleBulletin(R.raw.copy,
|
||||
LocaleController.getString("UsernameCopied", R.string.UsernameCopied)).show();
|
||||
} else if (url.startsWith("#") || url.startsWith("$")) {
|
||||
BulletinFactory.of(parentFragment).createSimpleBulletin(R.raw.copy,
|
||||
LocaleController.getString("HashtagCopied", R.string.HashtagCopied)).show();
|
||||
} else {
|
||||
BulletinFactory.of(parentFragment).createSimpleBulletin(R.raw.copy,
|
||||
LocaleController.getString("LinkCopied", R.string.LinkCopied)).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
builder.setOnPreDismissListener(di -> resetPressedLink());
|
||||
builder.show();
|
||||
|
||||
|
@ -68,7 +68,6 @@ import android.transition.TransitionManager;
|
||||
import android.transition.TransitionSet;
|
||||
import android.transition.TransitionValues;
|
||||
import android.util.FloatProperty;
|
||||
import android.util.Log;
|
||||
import android.util.Property;
|
||||
import android.util.Range;
|
||||
import android.util.SparseArray;
|
||||
@ -257,6 +256,7 @@ import tw.nekomimi.nekogram.NekoXConfig;
|
||||
import tw.nekomimi.nekogram.transtale.TranslateDb;
|
||||
import tw.nekomimi.nekogram.transtale.Translator;
|
||||
import tw.nekomimi.nekogram.transtale.TranslatorKt;
|
||||
import tw.nekomimi.nekogram.ui.BottomBuilder;
|
||||
import tw.nekomimi.nekogram.utils.AlertUtil;
|
||||
import tw.nekomimi.nekogram.utils.ProxyUtil;
|
||||
import xyz.nextalone.nagram.NaConfig;
|
||||
@ -654,7 +654,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
||||
|
||||
private void onLinkLongPress(URLSpan link, TextView widget, Runnable onDismiss) {
|
||||
int timestamp = -1;
|
||||
BottomSheet.Builder builder = new BottomSheet.Builder(parentActivity, false, resourcesProvider, 0xff1C2229);
|
||||
BottomBuilder builder = new BottomBuilder(parentActivity, false, 0xff1C2229);
|
||||
if (link.getURL().startsWith("video?")) {
|
||||
try {
|
||||
String timestampStr = link.getURL().substring(link.getURL().indexOf('?') + 1);
|
||||
@ -664,12 +664,13 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
||||
}
|
||||
}
|
||||
if (timestamp >= 0) {
|
||||
builder.setTitle(AndroidUtilities.formatDuration(timestamp, false));
|
||||
builder.addTitle(AndroidUtilities.formatDuration(timestamp, false));
|
||||
} else {
|
||||
builder.setTitle(link.getURL());
|
||||
builder.addTitle(link.getURL());
|
||||
}
|
||||
final int finalTimestamp = timestamp;
|
||||
builder.setItems(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.msg_openin, R.drawable.msg_copy}, (which,__,___ ) -> {
|
||||
if (which == 0) {
|
||||
onLinkClick(link, widget);
|
||||
} else if (which == 1) {
|
||||
@ -728,6 +729,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
||||
BulletinFactory.of(containerView, resourcesProvider).createSimpleBulletin(R.raw.voip_invite, bulletinMessage).show();
|
||||
}
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
builder.setOnPreDismissListener(di -> onDismiss.run());
|
||||
BottomSheet bottomSheet = builder.create();
|
||||
|
@ -19,9 +19,9 @@ import org.telegram.ui.Components.LayoutHelper
|
||||
import java.util.*
|
||||
|
||||
|
||||
class BottomBuilder(val ctx: Context, val needFocus: Boolean = true) {
|
||||
class BottomBuilder(val ctx: Context, val needFocus: Boolean = true, val bgColor: Int = Theme.getColor(Theme.key_dialogBackground)) {
|
||||
constructor(ctx: Context) : this(ctx, true) {}
|
||||
|
||||
constructor(ctx: Context, needFocus: Boolean) : this(ctx, needFocus, Theme.getColor(Theme.key_dialogBackground)) {}
|
||||
val builder = BottomSheet.Builder(ctx, needFocus)
|
||||
|
||||
private val rootView = LinearLayout(ctx).apply {
|
||||
@ -48,7 +48,7 @@ class BottomBuilder(val ctx: Context, val needFocus: Boolean = true) {
|
||||
|
||||
FrameLayout(ctx).apply {
|
||||
|
||||
setBackgroundColor(Theme.getColor(Theme.key_dialogBackground))
|
||||
setBackgroundColor(bgColor)
|
||||
|
||||
this@BottomBuilder.rootView.addView(this, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50, Gravity.LEFT or Gravity.BOTTOM))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user