2021-01-28 15:15:51 +01:00
|
|
|
package org.telegram.ui.Components;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import androidx.core.graphics.ColorUtils;
|
|
|
|
import androidx.core.widget.NestedScrollView;
|
|
|
|
|
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.R;
|
2021-02-23 12:53:38 +01:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2021-01-28 15:15:51 +01:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
2021-02-23 12:53:38 +01:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2021-01-28 15:15:51 +01:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
|
|
|
import org.telegram.ui.ActionBar.BottomSheet;
|
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.ActionBar.ThemeDescription;
|
|
|
|
import org.telegram.ui.ManageLinksActivity;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class PermanentLinkBottomSheet extends BottomSheet {
|
|
|
|
|
|
|
|
TLRPC.ChatFull info;
|
|
|
|
RLottieDrawable linkIcon;
|
|
|
|
private final TextView titleView;
|
|
|
|
private final TextView subtitle;
|
2021-02-23 12:53:38 +01:00
|
|
|
private final TextView manage;
|
2021-01-28 15:15:51 +01:00
|
|
|
private final RLottieImageView imageView;
|
|
|
|
private final LinkActionView linkActionView;
|
2021-09-20 00:10:42 +02:00
|
|
|
private long chatId;
|
2021-02-23 12:53:38 +01:00
|
|
|
private BaseFragment fragment;
|
|
|
|
private boolean isChannel;
|
2021-01-28 15:15:51 +01:00
|
|
|
|
2021-09-20 00:10:42 +02:00
|
|
|
public PermanentLinkBottomSheet(Context context, boolean needFocus, BaseFragment fragment, TLRPC.ChatFull info, long chatId, boolean isChannel) {
|
2021-01-28 15:15:51 +01:00
|
|
|
super(context, needFocus);
|
|
|
|
this.info = info;
|
|
|
|
this.chatId = chatId;
|
2021-02-23 12:53:38 +01:00
|
|
|
this.isChannel = isChannel;
|
2021-01-28 15:15:51 +01:00
|
|
|
|
|
|
|
setAllowNestedScroll(true);
|
|
|
|
setApplyBottomPadding(false);
|
|
|
|
|
2021-02-23 12:53:38 +01:00
|
|
|
linkActionView = new LinkActionView(context, fragment, this, chatId, true, isChannel);
|
2021-01-28 15:15:51 +01:00
|
|
|
linkActionView.setPermanent(true);
|
|
|
|
imageView = new RLottieImageView(context);
|
|
|
|
linkIcon = new RLottieDrawable(R.raw.shared_link_enter, "" + R.raw.shared_link_enter, AndroidUtilities.dp(90), AndroidUtilities.dp(90), false, null);
|
|
|
|
linkIcon.setCustomEndFrame(42);
|
|
|
|
imageView.setAnimation(linkIcon);
|
|
|
|
linkActionView.setUsers(0, null);
|
2021-02-25 17:58:14 +01:00
|
|
|
linkActionView.hideRevokeOption(true);
|
2021-02-23 12:53:38 +01:00
|
|
|
linkActionView.setDelegate(() -> generateLink(true));
|
2021-01-28 15:15:51 +01:00
|
|
|
|
|
|
|
titleView = new TextView(context);
|
|
|
|
titleView.setText(LocaleController.getString("InviteLink", R.string.InviteLink));
|
|
|
|
titleView.setTextSize(24);
|
|
|
|
titleView.setGravity(Gravity.CENTER_HORIZONTAL);
|
|
|
|
titleView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
|
|
|
|
subtitle = new TextView(context);
|
2021-02-23 12:53:38 +01:00
|
|
|
subtitle.setText(isChannel ? LocaleController.getString("LinkInfoChannel", R.string.LinkInfoChannel) : LocaleController.getString("LinkInfo", R.string.LinkInfo));
|
2021-01-28 15:15:51 +01:00
|
|
|
subtitle.setTextSize(14);
|
|
|
|
subtitle.setGravity(Gravity.CENTER_HORIZONTAL);
|
|
|
|
subtitle.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText));
|
|
|
|
|
|
|
|
manage = new TextView(context);
|
|
|
|
manage.setText(LocaleController.getString("ManageInviteLinks", R.string.ManageInviteLinks));
|
|
|
|
manage.setTextSize(14);
|
|
|
|
manage.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText));
|
|
|
|
manage.setBackground(Theme.createRadSelectorDrawable(ColorUtils.setAlphaComponent(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText), (int) (255 * 0.3f)), AndroidUtilities.dp(4), AndroidUtilities.dp(4)));
|
|
|
|
manage.setPadding(AndroidUtilities.dp(12), AndroidUtilities.dp(4), AndroidUtilities.dp(12), AndroidUtilities.dp(4));
|
|
|
|
|
2021-02-23 12:53:38 +01:00
|
|
|
manage.setOnClickListener(view -> {
|
|
|
|
ManageLinksActivity manageFragment = new ManageLinksActivity(info.id, 0, 0);
|
2021-01-28 15:15:51 +01:00
|
|
|
manageFragment.setInfo(info, info.exported_invite);
|
|
|
|
fragment.presentFragment(manageFragment);
|
|
|
|
dismiss();
|
|
|
|
});
|
2021-02-23 12:53:38 +01:00
|
|
|
|
2021-01-28 15:15:51 +01:00
|
|
|
LinearLayout linearLayout = new LinearLayout(context);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
linearLayout.addView(imageView, LayoutHelper.createLinear(90, 90, Gravity.CENTER_HORIZONTAL, 0, 24, 0, 0));
|
|
|
|
linearLayout.addView(titleView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 60, 16, 60, 0));
|
|
|
|
linearLayout.addView(subtitle, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 60, 16, 60, 0));
|
|
|
|
linearLayout.addView(linkActionView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
2021-02-23 12:53:38 +01:00
|
|
|
linearLayout.addView(manage, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 60, 26, 60, 26));
|
2021-01-28 15:15:51 +01:00
|
|
|
|
|
|
|
NestedScrollView scrollView = new NestedScrollView(context);
|
|
|
|
scrollView.setVerticalScrollBarEnabled(false);
|
|
|
|
scrollView.addView(linearLayout);
|
|
|
|
|
|
|
|
setCustomView(scrollView);
|
|
|
|
|
2021-02-23 12:53:38 +01:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance(UserConfig.selectedAccount).getChat(chatId);
|
|
|
|
if (chat != null && chat.username != null) {
|
|
|
|
linkActionView.setLink("https://t.me/" + chat.username);
|
|
|
|
manage.setVisibility(View.GONE);
|
|
|
|
} else if (info != null && info.exported_invite != null) {
|
2021-01-28 15:15:51 +01:00
|
|
|
linkActionView.setLink(info.exported_invite.link);
|
|
|
|
} else {
|
2021-02-23 12:53:38 +01:00
|
|
|
generateLink(false);
|
2021-01-28 15:15:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateColors();
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean linkGenerating;
|
|
|
|
TLRPC.TL_chatInviteExported invite;
|
|
|
|
|
2021-02-23 12:53:38 +01:00
|
|
|
private void generateLink(boolean showDialog) {
|
2021-01-28 15:15:51 +01:00
|
|
|
if (linkGenerating) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
linkGenerating = true;
|
|
|
|
TLRPC.TL_messages_exportChatInvite req = new TLRPC.TL_messages_exportChatInvite();
|
2021-02-23 12:53:38 +01:00
|
|
|
req.legacy_revoke_permanent = true;
|
2021-01-28 15:15:51 +01:00
|
|
|
req.peer = MessagesController.getInstance(currentAccount).getInputPeer(-chatId);
|
|
|
|
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (error == null) {
|
|
|
|
invite = (TLRPC.TL_chatInviteExported) response;
|
|
|
|
|
|
|
|
TLRPC.ChatFull chatInfo = MessagesController.getInstance(currentAccount).getChatFull(chatId);
|
|
|
|
if (chatInfo != null) {
|
|
|
|
chatInfo.exported_invite = invite;
|
|
|
|
}
|
|
|
|
|
|
|
|
linkActionView.setLink(invite.link);
|
2021-02-23 12:53:38 +01:00
|
|
|
|
|
|
|
if (showDialog && fragment != null) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
|
|
|
builder.setMessage(LocaleController.getString("RevokeAlertNewLink", R.string.RevokeAlertNewLink));
|
|
|
|
builder.setTitle(LocaleController.getString("RevokeLink", R.string.RevokeLink));
|
|
|
|
builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
fragment.showDialog(builder.create());
|
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
}
|
|
|
|
linkGenerating = false;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void show() {
|
|
|
|
super.show();
|
2021-09-20 00:10:42 +02:00
|
|
|
AndroidUtilities.runOnUIThread(() -> linkIcon.start(), 50);
|
2021-01-28 15:15:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList<ThemeDescription> getThemeDescriptions() {
|
|
|
|
ArrayList<ThemeDescription> arrayList = new ArrayList<>();
|
2021-09-20 00:10:42 +02:00
|
|
|
ThemeDescription.ThemeDescriptionDelegate descriptionDelegate = this::updateColors;
|
2021-01-28 15:15:51 +01:00
|
|
|
arrayList.add(new ThemeDescription(titleView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
arrayList.add(new ThemeDescription(subtitle, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText));
|
2021-02-23 12:53:38 +01:00
|
|
|
arrayList.add(new ThemeDescription(manage, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueText));
|
2021-01-28 15:15:51 +01:00
|
|
|
arrayList.add(new ThemeDescription(null, 0, null, null, null, descriptionDelegate, Theme.key_featuredStickers_addButton));
|
|
|
|
arrayList.add(new ThemeDescription(null, 0, null, null, null, descriptionDelegate, Theme.key_featuredStickers_buttonText));
|
|
|
|
arrayList.add(new ThemeDescription(null, 0, null, null, null, descriptionDelegate, Theme.key_windowBackgroundWhiteBlueText));
|
|
|
|
return arrayList;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateColors() {
|
|
|
|
imageView.setBackground(Theme.createCircleDrawable(AndroidUtilities.dp(90), Theme.getColor(Theme.key_featuredStickers_addButton)));
|
2021-02-23 12:53:38 +01:00
|
|
|
manage.setBackground(Theme.createRadSelectorDrawable(ColorUtils.setAlphaComponent(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText), (int) (255 * 0.3f)), AndroidUtilities.dp(4), AndroidUtilities.dp(4)));
|
2021-01-28 15:15:51 +01:00
|
|
|
int color = Theme.getColor(Theme.key_featuredStickers_buttonText);
|
|
|
|
linkIcon.setLayerColor("Top.**", color);
|
|
|
|
linkIcon.setLayerColor("Bottom.**", color);
|
|
|
|
linkIcon.setLayerColor("Center.**", color);
|
|
|
|
linkActionView.updateColors();
|
|
|
|
setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
|
|
|
|
}
|
2021-02-23 12:53:38 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dismissInternal() {
|
|
|
|
super.dismissInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dismiss() {
|
|
|
|
super.dismiss();
|
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
}
|