NekoX/TMessagesProj/src/main/java/org/telegram/ui/Components/BulletinFactory.java

656 lines
32 KiB
Java
Raw Normal View History

2020-09-30 15:48:47 +02:00
package org.telegram.ui.Components;
2022-06-21 04:51:00 +02:00
import android.app.DownloadManager;
2020-10-30 11:26:29 +01:00
import android.content.Context;
2022-06-21 04:51:00 +02:00
import android.content.Intent;
2022-08-12 17:23:51 +02:00
import android.graphics.drawable.Drawable;
2022-06-21 04:51:00 +02:00
import android.net.Uri;
import android.os.Environment;
2022-08-12 17:23:51 +02:00
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.util.TypedValue;
2022-06-21 04:51:00 +02:00
import android.view.HapticFeedbackConstants;
2022-08-12 17:23:51 +02:00
import android.view.View;
2020-09-30 15:48:47 +02:00
import android.widget.FrameLayout;
2020-12-23 08:48:30 +01:00
import androidx.annotation.CheckResult;
2022-08-12 17:23:51 +02:00
import androidx.annotation.NonNull;
2022-06-21 04:51:00 +02:00
import androidx.core.content.FileProvider;
2020-09-30 15:48:47 +02:00
2020-10-30 11:26:29 +01:00
import org.telegram.messenger.AndroidUtilities;
2022-06-21 04:51:00 +02:00
import org.telegram.messenger.BuildConfig;
import org.telegram.messenger.DialogObject;
2020-09-30 15:48:47 +02:00
import org.telegram.messenger.LocaleController;
2022-08-12 17:23:51 +02:00
import org.telegram.messenger.MediaDataController;
2022-06-21 04:51:00 +02:00
import org.telegram.messenger.MessagesController;
2020-09-30 15:48:47 +02:00
import org.telegram.messenger.NotificationsController;
import org.telegram.messenger.R;
2022-06-21 04:51:00 +02:00
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.UserObject;
2021-02-23 12:53:38 +01:00
import org.telegram.tgnet.TLRPC;
2020-09-30 15:48:47 +02:00
import org.telegram.ui.ActionBar.BaseFragment;
2021-09-20 07:54:41 +02:00
import org.telegram.ui.ActionBar.Theme;
2022-08-12 17:23:51 +02:00
import org.telegram.ui.PremiumPreviewFragment;
2020-09-30 15:48:47 +02:00
2022-06-21 04:51:00 +02:00
import java.io.File;
2020-09-30 15:48:47 +02:00
public final class BulletinFactory {
2020-10-30 11:26:29 +01:00
public static BulletinFactory of(BaseFragment fragment) {
return new BulletinFactory(fragment);
}
2021-09-20 07:54:41 +02:00
public static BulletinFactory of(FrameLayout containerLayout, Theme.ResourcesProvider resourcesProvider) {
return new BulletinFactory(containerLayout, resourcesProvider);
2020-09-30 15:48:47 +02:00
}
public static boolean canShowBulletin(BaseFragment fragment) {
2020-10-30 11:26:29 +01:00
return fragment != null && fragment.getParentActivity() != null && fragment.getLayoutContainer() != null;
}
2021-02-23 12:53:38 +01:00
public static final int ICON_TYPE_NOT_FOUND = 0;
public static final int ICON_TYPE_WARNING = 1;
2020-10-30 11:26:29 +01:00
public enum FileType {
2020-12-23 08:48:30 +01:00
PHOTO("PhotoSavedHint", R.string.PhotoSavedHint, Icon.SAVED_TO_GALLERY),
PHOTOS("PhotosSavedHint", Icon.SAVED_TO_GALLERY),
2020-10-30 11:26:29 +01:00
2020-12-23 08:48:30 +01:00
VIDEO("VideoSavedHint", R.string.VideoSavedHint, Icon.SAVED_TO_GALLERY),
VIDEOS("VideosSavedHint", Icon.SAVED_TO_GALLERY),
2020-10-30 11:26:29 +01:00
2020-12-23 08:48:30 +01:00
MEDIA("MediaSavedHint", Icon.SAVED_TO_GALLERY),
2021-01-01 05:38:45 +01:00
PHOTO_TO_DOWNLOADS("PhotoSavedToDownloadsHint", R.string.PhotoSavedToDownloadsHint, Icon.SAVED_TO_DOWNLOADS),
2020-12-23 08:48:30 +01:00
VIDEO_TO_DOWNLOADS("VideoSavedToDownloadsHint", R.string.VideoSavedToDownloadsHint, Icon.SAVED_TO_DOWNLOADS),
2022-02-12 06:22:45 +01:00
GIF("GifSavedHint", R.string.GifSavedHint, Icon.SAVED_TO_GIFS),
GIF_TO_DOWNLOADS("GifSavedToDownloadsHint", R.string.GifSavedToDownloadsHint, Icon.SAVED_TO_DOWNLOADS),
2020-12-23 08:48:30 +01:00
2021-01-01 05:38:45 +01:00
AUDIO("AudioSavedHint", R.string.AudioSavedHint, Icon.SAVED_TO_MUSIC),
2020-12-23 08:48:30 +01:00
AUDIOS("AudiosSavedHint", Icon.SAVED_TO_MUSIC),
2021-01-01 05:38:45 +01:00
UNKNOWN("FileSavedHint", R.string.FileSavedHint, Icon.SAVED_TO_DOWNLOADS),
2020-12-23 08:48:30 +01:00
UNKNOWNS("FilesSavedHint", Icon.SAVED_TO_DOWNLOADS);
2020-10-30 11:26:29 +01:00
private final String localeKey;
private final int localeRes;
private final boolean plural;
2020-12-23 08:48:30 +01:00
private final Icon icon;
2020-10-30 11:26:29 +01:00
2020-12-23 08:48:30 +01:00
FileType(String localeKey, int localeRes, Icon icon) {
2020-10-30 11:26:29 +01:00
this.localeKey = localeKey;
this.localeRes = localeRes;
2020-12-23 08:48:30 +01:00
this.icon = icon;
2020-10-30 11:26:29 +01:00
this.plural = false;
}
2020-12-23 08:48:30 +01:00
FileType(String localeKey, Icon icon) {
2020-10-30 11:26:29 +01:00
this.localeKey = localeKey;
2020-12-23 08:48:30 +01:00
this.icon = icon;
2020-10-30 11:26:29 +01:00
this.localeRes = 0;
this.plural = true;
}
private String getText() {
return getText(1);
}
private String getText(int amount) {
if (plural) {
return LocaleController.formatPluralString(localeKey, amount);
} else {
return LocaleController.getString(localeKey, localeRes);
}
}
2020-12-23 08:48:30 +01:00
private enum Icon {
SAVED_TO_DOWNLOADS(R.raw.ic_download, 2, "Box", "Arrow"),
SAVED_TO_GALLERY(R.raw.ic_save_to_gallery, 0, "Box", "Arrow", "Mask", "Arrow 2", "Splash"),
2022-02-12 06:22:45 +01:00
SAVED_TO_MUSIC(R.raw.ic_save_to_music, 2, "Box", "Arrow"),
SAVED_TO_GIFS(R.raw.ic_save_to_gifs, 0, "gif");
2020-12-23 08:48:30 +01:00
private final int resId;
private final String[] layers;
private final int paddingBottom;
Icon(int resId, int paddingBottom, String... layers) {
this.resId = resId;
this.paddingBottom = paddingBottom;
this.layers = layers;
}
}
2020-10-30 11:26:29 +01:00
}
private final BaseFragment fragment;
private final FrameLayout containerLayout;
2021-09-20 07:54:41 +02:00
private final Theme.ResourcesProvider resourcesProvider;
2020-10-30 11:26:29 +01:00
private BulletinFactory(BaseFragment fragment) {
this.fragment = fragment;
this.containerLayout = null;
2021-09-20 07:54:41 +02:00
this.resourcesProvider = fragment == null ? null : fragment.getResourceProvider();
2020-10-30 11:26:29 +01:00
}
2021-09-20 07:54:41 +02:00
private BulletinFactory(FrameLayout containerLayout, Theme.ResourcesProvider resourcesProvider) {
2020-10-30 11:26:29 +01:00
this.containerLayout = containerLayout;
this.fragment = null;
2021-09-20 07:54:41 +02:00
this.resourcesProvider = resourcesProvider;
2020-10-30 11:26:29 +01:00
}
2021-02-23 12:53:38 +01:00
public Bulletin createSimpleBulletin(int iconRawId, String text) {
2021-09-20 07:54:41 +02:00
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(getContext(), resourcesProvider);
2021-02-23 12:53:38 +01:00
layout.setAnimation(iconRawId, 36, 36);
layout.textView.setText(text);
2021-04-14 03:44:46 +02:00
layout.textView.setSingleLine(false);
layout.textView.setMaxLines(2);
2021-02-23 12:53:38 +01:00
return create(layout, Bulletin.DURATION_SHORT);
}
2022-04-16 16:43:17 +02:00
public Bulletin createSimpleBulletin(int iconRawId, CharSequence text, CharSequence subtext) {
final Bulletin.TwoLineLottieLayout layout = new Bulletin.TwoLineLottieLayout(getContext(), resourcesProvider);
layout.setAnimation(iconRawId, 36, 36);
layout.titleTextView.setText(text);
layout.subtitleTextView.setText(subtext);
return create(layout, Bulletin.DURATION_SHORT);
}
2022-08-12 17:23:51 +02:00
public Bulletin createSimpleBulletin(int iconRawId, CharSequence text, CharSequence button, Runnable onButtonClick) {
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(getContext(), resourcesProvider);
layout.setAnimation(iconRawId, 36, 36);
layout.textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
layout.textView.setSingleLine(false);
layout.textView.setMaxLines(3);
layout.textView.setText(text);
layout.setButton(new Bulletin.UndoButton(getContext(), true, resourcesProvider).setText(button).setUndoAction(onButtonClick));
return create(layout, Bulletin.DURATION_SHORT);
}
public Bulletin createSimpleBulletin(Drawable drawable, CharSequence text, String button, Runnable onButtonClick) {
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(getContext(), resourcesProvider);
layout.imageView.setImageDrawable(drawable);
layout.textView.setText(text);
layout.textView.setSingleLine(false);
layout.textView.setMaxLines(2);
layout.setButton(new Bulletin.UndoButton(getContext(), true, resourcesProvider).setText(button).setUndoAction(onButtonClick));
return create(layout, Bulletin.DURATION_LONG);
}
public Bulletin createEmojiBulletin(String emoji, String text) {
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(getContext(), resourcesProvider);
layout.setAnimation(MediaDataController.getInstance(UserConfig.selectedAccount).getEmojiAnimatedSticker(emoji), 36, 36);
layout.textView.setText(text);
layout.textView.setSingleLine(false);
layout.textView.setMaxLines(2);
return create(layout, Bulletin.DURATION_LONG);
}
public Bulletin createEmojiBulletin(String emoji, String text, String button, Runnable onButtonClick) {
return createEmojiBulletin(MediaDataController.getInstance(UserConfig.selectedAccount).getEmojiAnimatedSticker(emoji), text, button, onButtonClick);
}
public Bulletin createEmojiBulletin(TLRPC.Document document, CharSequence text, CharSequence button, Runnable onButtonClick) {
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(getContext(), resourcesProvider);
layout.setAnimation(document, 36, 36);
layout.textView.setText(text);
layout.textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
layout.textView.setSingleLine(false);
layout.textView.setMaxLines(3);
layout.setButton(new Bulletin.UndoButton(getContext(), true, resourcesProvider).setText(button).setUndoAction(onButtonClick));
return create(layout, Bulletin.DURATION_LONG);
}
2020-12-23 08:48:30 +01:00
@CheckResult
2020-10-30 11:26:29 +01:00
public Bulletin createDownloadBulletin(FileType fileType) {
2021-09-20 07:54:41 +02:00
return createDownloadBulletin(fileType, resourcesProvider);
2020-10-30 11:26:29 +01:00
}
2020-12-23 08:48:30 +01:00
@CheckResult
2021-09-20 07:54:41 +02:00
public Bulletin createDownloadBulletin(FileType fileType, Theme.ResourcesProvider resourcesProvider) {
return createDownloadBulletin(fileType, 1, resourcesProvider);
2020-10-30 11:26:29 +01:00
}
2021-09-20 07:54:41 +02:00
@CheckResult
public Bulletin createDownloadBulletin(FileType fileType, int filesAmount, Theme.ResourcesProvider resourcesProvider) {
return createDownloadBulletin(fileType, filesAmount, 0, 0, resourcesProvider);
}
public Bulletin createReportSent(Theme.ResourcesProvider resourcesProvider) {
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(getContext(), resourcesProvider);
2021-02-23 12:53:38 +01:00
layout.setAnimation(R.raw.chats_infotip);
layout.textView.setText(LocaleController.getString("ReportChatSent", R.string.ReportChatSent));
return create(layout, Bulletin.DURATION_SHORT);
}
2020-12-23 08:48:30 +01:00
@CheckResult
2020-10-30 11:26:29 +01:00
public Bulletin createDownloadBulletin(FileType fileType, int filesAmount, int backgroundColor, int textColor) {
2021-09-20 07:54:41 +02:00
return createDownloadBulletin(fileType, filesAmount, backgroundColor, textColor, null);
}
@CheckResult
public Bulletin createDownloadBulletin(FileType fileType, int filesAmount, int backgroundColor, int textColor, Theme.ResourcesProvider resourcesProvider) {
2020-10-30 11:26:29 +01:00
final Bulletin.LottieLayout layout;
if (backgroundColor != 0 && textColor != 0) {
2021-09-20 07:54:41 +02:00
layout = new Bulletin.LottieLayout(getContext(), resourcesProvider, backgroundColor, textColor);
2020-10-30 11:26:29 +01:00
} else {
2021-09-20 07:54:41 +02:00
layout = new Bulletin.LottieLayout(getContext(), resourcesProvider);
2020-10-30 11:26:29 +01:00
}
2020-12-23 08:48:30 +01:00
layout.setAnimation(fileType.icon.resId, fileType.icon.layers);
2020-10-30 11:26:29 +01:00
layout.textView.setText(fileType.getText(filesAmount));
2020-12-23 08:48:30 +01:00
if (fileType.icon.paddingBottom != 0) {
layout.setIconPaddingBottom(fileType.icon.paddingBottom);
}
2020-10-30 11:26:29 +01:00
return create(layout, Bulletin.DURATION_SHORT);
}
2021-09-20 07:54:41 +02:00
public Bulletin createErrorBulletin(CharSequence errorMessage) {
return createErrorBulletin(errorMessage, null);
}
2021-02-23 12:53:38 +01:00
2021-09-20 07:54:41 +02:00
public Bulletin createErrorBulletin(CharSequence errorMessage, Theme.ResourcesProvider resourcesProvider) {
Bulletin.LottieLayout layout = new Bulletin.LottieLayout(getContext(), resourcesProvider);
2021-02-23 12:53:38 +01:00
layout.setAnimation(R.raw.chats_infotip);
layout.textView.setText(errorMessage);
layout.textView.setSingleLine(false);
layout.textView.setMaxLines(2);
return create(layout, Bulletin.DURATION_SHORT);
}
2022-08-12 17:23:51 +02:00
public Bulletin createRestrictVoiceMessagesPremiumBulletin() {
Bulletin.LottieLayout layout = new Bulletin.LottieLayout(getContext(), null);
layout.setAnimation(R.raw.voip_muted);
String str = LocaleController.getString(R.string.PrivacyVoiceMessagesPremiumOnly);
SpannableStringBuilder spannable = new SpannableStringBuilder(str);
int indexStart = str.indexOf('*'), indexEnd = str.lastIndexOf('*');
spannable.replace(indexStart, indexEnd + 1, str.substring(indexStart + 1, indexEnd));
spannable.setSpan(new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
fragment.presentFragment(new PremiumPreviewFragment("settings"));
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}, indexStart, indexEnd - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
layout.textView.setText(spannable);
layout.textView.setSingleLine(false);
layout.textView.setMaxLines(2);
return create(layout, Bulletin.DURATION_LONG);
}
2022-04-16 16:43:17 +02:00
public Bulletin createErrorBulletinSubtitle(CharSequence errorMessage, CharSequence errorDescription, Theme.ResourcesProvider resourcesProvider) {
Bulletin.TwoLineLottieLayout layout = new Bulletin.TwoLineLottieLayout(getContext(), resourcesProvider);
layout.setAnimation(R.raw.chats_infotip);
layout.titleTextView.setText(errorMessage);
layout.subtitleTextView.setText(errorDescription);
return create(layout, Bulletin.DURATION_SHORT);
}
2020-12-23 08:48:30 +01:00
@CheckResult
public Bulletin createCopyLinkBulletin() {
2021-09-20 07:54:41 +02:00
return createCopyLinkBulletin(false, resourcesProvider);
2020-12-23 08:48:30 +01:00
}
2021-02-23 12:53:38 +01:00
@CheckResult
public Bulletin createCopyBulletin(String message) {
2022-06-21 04:51:00 +02:00
return createCopyBulletin(message, null);
}
@CheckResult
public Bulletin createCopyBulletin(String message, Theme.ResourcesProvider resourcesProvider) {
2022-04-16 16:43:17 +02:00
if (!AndroidUtilities.shouldShowClipboardToast()) {
2022-02-01 14:00:45 +01:00
return new Bulletin.EmptyBulletin();
}
2021-09-20 07:54:41 +02:00
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(getContext(), null);
2021-02-23 12:53:38 +01:00
layout.setAnimation(R.raw.copy, 36, 36, "NULL ROTATION", "Back", "Front");
layout.textView.setText(message);
return create(layout, Bulletin.DURATION_SHORT);
}
2020-12-23 08:48:30 +01:00
@CheckResult
2021-09-20 07:54:41 +02:00
public Bulletin createCopyLinkBulletin(boolean isPrivate, Theme.ResourcesProvider resourcesProvider) {
2022-04-16 16:43:17 +02:00
if (!AndroidUtilities.shouldShowClipboardToast()) {
2022-01-18 21:51:58 +01:00
return new Bulletin.EmptyBulletin();
}
2020-12-23 08:48:30 +01:00
if (isPrivate) {
2021-09-20 07:54:41 +02:00
final Bulletin.TwoLineLottieLayout layout = new Bulletin.TwoLineLottieLayout(getContext(), resourcesProvider);
2020-12-23 08:48:30 +01:00
layout.setAnimation(R.raw.voip_invite, 36, 36, "Wibe", "Circle");
layout.titleTextView.setText(LocaleController.getString("LinkCopied", R.string.LinkCopied));
layout.subtitleTextView.setText(LocaleController.getString("LinkCopiedPrivateInfo", R.string.LinkCopiedPrivateInfo));
return create(layout, Bulletin.DURATION_LONG);
} else {
2021-09-20 07:54:41 +02:00
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(getContext(), resourcesProvider);
2020-12-23 08:48:30 +01:00
layout.setAnimation(R.raw.voip_invite, 36, 36, "Wibe", "Circle");
layout.textView.setText(LocaleController.getString("LinkCopied", R.string.LinkCopied));
return create(layout, Bulletin.DURATION_SHORT);
}
}
2022-06-21 04:51:00 +02:00
@CheckResult
public Bulletin createCopyLinkBulletin(String text, Theme.ResourcesProvider resourcesProvider) {
if (!AndroidUtilities.shouldShowClipboardToast()) {
return new Bulletin.EmptyBulletin();
}
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(getContext(), resourcesProvider);
layout.setAnimation(R.raw.voip_invite, 36, 36, "Wibe", "Circle");
layout.textView.setText(text);
return create(layout, Bulletin.DURATION_SHORT);
}
2020-10-30 11:26:29 +01:00
private Bulletin create(Bulletin.Layout layout, int duration) {
if (fragment != null) {
return Bulletin.make(fragment, layout, duration);
} else {
return Bulletin.make(containerLayout, layout, duration);
}
}
private Context getContext() {
return fragment != null ? fragment.getParentActivity() : containerLayout.getContext();
2020-09-30 15:48:47 +02:00
}
2020-10-30 11:26:29 +01:00
//region Static Factory
2020-12-23 08:48:30 +01:00
@CheckResult
2020-09-30 15:48:47 +02:00
public static Bulletin createMuteBulletin(BaseFragment fragment, int setting) {
2022-04-16 16:43:17 +02:00
return createMuteBulletin(fragment, setting, 0, null);
2021-09-20 07:54:41 +02:00
}
@CheckResult
2022-04-16 16:43:17 +02:00
public static Bulletin createMuteBulletin(BaseFragment fragment, int setting, int timeInSeconds, Theme.ResourcesProvider resourcesProvider) {
2021-09-20 07:54:41 +02:00
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(fragment.getParentActivity(), resourcesProvider);
2020-09-30 15:48:47 +02:00
final String text;
final boolean mute;
2022-04-16 16:43:17 +02:00
boolean muteFor = false;
2020-09-30 15:48:47 +02:00
switch (setting) {
2022-04-16 16:43:17 +02:00
case NotificationsController.SETTING_MUTE_CUSTOM:
text = LocaleController.formatString("NotificationsMutedForHint", R.string.NotificationsMutedForHint, LocaleController.formatTTLString(timeInSeconds));
mute = true;
muteFor = true;
break;
2020-09-30 15:48:47 +02:00
case NotificationsController.SETTING_MUTE_HOUR:
text = LocaleController.formatString("NotificationsMutedForHint", R.string.NotificationsMutedForHint, LocaleController.formatPluralString("Hours", 1));
mute = true;
break;
case NotificationsController.SETTING_MUTE_8_HOURS:
text = LocaleController.formatString("NotificationsMutedForHint", R.string.NotificationsMutedForHint, LocaleController.formatPluralString("Hours", 8));
mute = true;
break;
case NotificationsController.SETTING_MUTE_2_DAYS:
text = LocaleController.formatString("NotificationsMutedForHint", R.string.NotificationsMutedForHint, LocaleController.formatPluralString("Days", 2));
mute = true;
break;
case NotificationsController.SETTING_MUTE_FOREVER:
text = LocaleController.getString("NotificationsMutedHint", R.string.NotificationsMutedHint);
mute = true;
break;
case NotificationsController.SETTING_MUTE_UNMUTE:
text = LocaleController.getString("NotificationsUnmutedHint", R.string.NotificationsUnmutedHint);
mute = false;
break;
default:
throw new IllegalArgumentException();
}
2022-04-16 16:43:17 +02:00
if (muteFor) {
layout.setAnimation(R.raw.mute_for);
} else if (mute) {
2020-09-30 15:48:47 +02:00
layout.setAnimation(R.raw.ic_mute, "Body Main", "Body Top", "Line", "Curve Big", "Curve Small");
} else {
layout.setAnimation(R.raw.ic_unmute, "BODY", "Wibe Big", "Wibe Big 3", "Wibe Small");
}
layout.textView.setText(text);
return Bulletin.make(fragment, layout, Bulletin.DURATION_SHORT);
}
2020-12-23 08:48:30 +01:00
@CheckResult
2021-09-20 07:54:41 +02:00
public static Bulletin createMuteBulletin(BaseFragment fragment, boolean muted, Theme.ResourcesProvider resourcesProvider) {
2022-04-16 16:43:17 +02:00
return createMuteBulletin(fragment, muted ? NotificationsController.SETTING_MUTE_FOREVER : NotificationsController.SETTING_MUTE_UNMUTE, 0, resourcesProvider);
2020-09-30 15:48:47 +02:00
}
2020-12-23 08:48:30 +01:00
@CheckResult
2021-09-20 07:54:41 +02:00
public static Bulletin createDeleteMessagesBulletin(BaseFragment fragment, int count, Theme.ResourcesProvider resourcesProvider) {
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(fragment.getParentActivity(), resourcesProvider);
2020-09-30 15:48:47 +02:00
layout.setAnimation(R.raw.ic_delete, "Envelope", "Cover", "Bucket");
layout.textView.setText(LocaleController.formatPluralString("MessagesDeletedHint", count));
return Bulletin.make(fragment, layout, Bulletin.DURATION_SHORT);
}
2020-12-23 08:48:30 +01:00
@CheckResult
2021-09-20 07:54:41 +02:00
public static Bulletin createUnpinAllMessagesBulletin(BaseFragment fragment, int count, boolean hide, Runnable undoAction, Runnable delayedAction, Theme.ResourcesProvider resourcesProvider) {
2021-01-30 07:18:23 +01:00
if (fragment.getParentActivity() == null) {
if (delayedAction != null) {
delayedAction.run();
}
return null;
}
2020-10-30 11:26:29 +01:00
Bulletin.ButtonLayout buttonLayout;
if (hide) {
2021-09-20 07:54:41 +02:00
final Bulletin.TwoLineLottieLayout layout = new Bulletin.TwoLineLottieLayout(fragment.getParentActivity(), resourcesProvider);
2020-12-23 08:48:30 +01:00
layout.setAnimation(R.raw.ic_unpin, 28, 28, "Pin", "Line");
2020-10-30 11:26:29 +01:00
layout.titleTextView.setText(LocaleController.getString("PinnedMessagesHidden", R.string.PinnedMessagesHidden));
layout.subtitleTextView.setText(LocaleController.getString("PinnedMessagesHiddenInfo", R.string.PinnedMessagesHiddenInfo));
buttonLayout = layout;
2020-09-30 15:48:47 +02:00
} else {
2021-09-20 07:54:41 +02:00
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(fragment.getParentActivity(), resourcesProvider);
2020-12-23 08:48:30 +01:00
layout.setAnimation(R.raw.ic_unpin, 28, 28, "Pin", "Line");
2020-10-30 11:26:29 +01:00
layout.textView.setText(LocaleController.formatPluralString("MessagesUnpinned", count));
buttonLayout = layout;
}
2021-09-20 07:54:41 +02:00
buttonLayout.setButton(new Bulletin.UndoButton(fragment.getParentActivity(), true, resourcesProvider).setUndoAction(undoAction).setDelayedAction(delayedAction));
2020-10-30 11:26:29 +01:00
return Bulletin.make(fragment, buttonLayout, 5000);
}
2020-12-23 08:48:30 +01:00
@CheckResult
2021-09-20 07:54:41 +02:00
public static Bulletin createSaveToGalleryBulletin(BaseFragment fragment, boolean video, Theme.ResourcesProvider resourcesProvider) {
return of(fragment).createDownloadBulletin(video ? FileType.VIDEO : FileType.PHOTO, resourcesProvider);
2020-10-30 11:26:29 +01:00
}
2020-12-23 08:48:30 +01:00
@CheckResult
2020-10-30 11:26:29 +01:00
public static Bulletin createSaveToGalleryBulletin(FrameLayout containerLayout, boolean video, int backgroundColor, int textColor) {
2021-09-20 07:54:41 +02:00
return of(containerLayout, null).createDownloadBulletin(video ? FileType.VIDEO : FileType.PHOTO, 1, backgroundColor, textColor);
2020-10-30 11:26:29 +01:00
}
2020-12-23 08:48:30 +01:00
@CheckResult
2020-10-30 11:26:29 +01:00
public static Bulletin createPromoteToAdminBulletin(BaseFragment fragment, String userFirstName) {
2022-06-21 04:51:00 +02:00
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(fragment.getParentActivity(), fragment.getResourceProvider());
2020-10-30 11:26:29 +01:00
layout.setAnimation(R.raw.ic_admin, "Shield");
layout.textView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("UserSetAsAdminHint", R.string.UserSetAsAdminHint, userFirstName)));
return Bulletin.make(fragment, layout, Bulletin.DURATION_SHORT);
}
2022-04-16 16:43:17 +02:00
@CheckResult
public static Bulletin createAddedAsAdminBulletin(BaseFragment fragment, String userFirstName) {
2022-06-21 04:51:00 +02:00
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(fragment.getParentActivity(), fragment.getResourceProvider());
2022-04-16 16:43:17 +02:00
layout.setAnimation(R.raw.ic_admin, "Shield");
layout.textView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("UserAddedAsAdminHint", R.string.UserAddedAsAdminHint, userFirstName)));
return Bulletin.make(fragment, layout, Bulletin.DURATION_SHORT);
}
2022-08-12 17:23:51 +02:00
@CheckResult
public static Bulletin createInviteSentBulletin(Context context, FrameLayout containerLayout, int dialogsCount, long did, int messagesCount, int backgroundColor, int textColor) {
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(context, null, backgroundColor, textColor);
CharSequence text;
int hapticDelay = -1;
if (dialogsCount <= 1) {
if (did == UserConfig.getInstance(UserConfig.selectedAccount).clientUserId) {
text = AndroidUtilities.replaceTags(LocaleController.getString("InvLinkToSavedMessages", R.string.InvLinkToSavedMessages));
layout.setAnimation(R.raw.saved_messages, 30, 30);
} else {
if (DialogObject.isChatDialog(did)) {
TLRPC.Chat chat = MessagesController.getInstance(UserConfig.selectedAccount).getChat(-did);
text = AndroidUtilities.replaceTags(LocaleController.formatString("InvLinkToGroup", R.string.InvLinkToGroup, chat.title));
} else {
TLRPC.User user = MessagesController.getInstance(UserConfig.selectedAccount).getUser(did);
text = AndroidUtilities.replaceTags(LocaleController.formatString("InvLinkToUser", R.string.InvLinkToUser, UserObject.getFirstName(user)));
}
layout.setAnimation(R.raw.forward, 30, 30);
hapticDelay = 300;
}
} else {
text = AndroidUtilities.replaceTags(LocaleController.formatString("InvLinkToChats", R.string.InvLinkToChats, LocaleController.formatPluralString("Chats", dialogsCount)));
layout.setAnimation(R.raw.forward, 30, 30);
hapticDelay = 300;
}
layout.textView.setText(text);
if (hapticDelay > 0) {
layout.postDelayed(() -> {
layout.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}, hapticDelay);
}
return Bulletin.make(containerLayout, layout, Bulletin.DURATION_SHORT);
}
2022-06-21 04:51:00 +02:00
@CheckResult
public static Bulletin createForwardedBulletin(Context context, FrameLayout containerLayout, int dialogsCount, long did, int messagesCount, int backgroundColor, int textColor) {
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(context, null, backgroundColor, textColor);
CharSequence text;
int hapticDelay = -1;
if (dialogsCount <= 1) {
if (did == UserConfig.getInstance(UserConfig.selectedAccount).clientUserId) {
if (messagesCount <= 1) {
text = AndroidUtilities.replaceTags(LocaleController.getString("FwdMessageToSavedMessages", R.string.FwdMessageToSavedMessages));
} else {
text = AndroidUtilities.replaceTags(LocaleController.getString("FwdMessagesToSavedMessages", R.string.FwdMessagesToSavedMessages));
}
layout.setAnimation(R.raw.saved_messages, 30, 30);
} else {
if (DialogObject.isChatDialog(did)) {
TLRPC.Chat chat = MessagesController.getInstance(UserConfig.selectedAccount).getChat(-did);
if (messagesCount <= 1) {
text = AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessageToGroup", R.string.FwdMessageToGroup, chat.title));
} else {
text = AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessagesToGroup", R.string.FwdMessagesToGroup, chat.title));
}
} else {
TLRPC.User user = MessagesController.getInstance(UserConfig.selectedAccount).getUser(did);
if (messagesCount <= 1) {
text = AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessageToUser", R.string.FwdMessageToUser, UserObject.getFirstName(user)));
} else {
text = AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessagesToUser", R.string.FwdMessagesToUser, UserObject.getFirstName(user)));
}
}
layout.setAnimation(R.raw.forward, 30, 30);
hapticDelay = 300;
}
} else {
if (messagesCount <= 1) {
text = AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessageToChats", R.string.FwdMessageToChats, LocaleController.formatPluralString("Chats", dialogsCount)));
} else {
text = AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessagesToChats", R.string.FwdMessagesToChats, LocaleController.formatPluralString("Chats", dialogsCount)));
}
layout.setAnimation(R.raw.forward, 30, 30);
hapticDelay = 300;
}
layout.textView.setText(text);
if (hapticDelay > 0) {
layout.postDelayed(() -> {
layout.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}, hapticDelay);
}
return Bulletin.make(containerLayout, layout, Bulletin.DURATION_SHORT);
}
2020-12-23 08:48:30 +01:00
@CheckResult
2021-02-23 12:53:38 +01:00
public static Bulletin createRemoveFromChatBulletin(BaseFragment fragment, TLRPC.User user, String chatName) {
2022-06-21 04:51:00 +02:00
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(fragment.getParentActivity(), fragment.getResourceProvider());
2020-12-23 08:48:30 +01:00
layout.setAnimation(R.raw.ic_ban, "Hand");
2021-02-23 12:53:38 +01:00
String name;
if (user.deleted) {
name = LocaleController.formatString("HiddenName", R.string.HiddenName);
} else {
name = user.first_name;
}
layout.textView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("UserRemovedFromChatHint", R.string.UserRemovedFromChatHint, name, chatName)));
2020-12-23 08:48:30 +01:00
return Bulletin.make(fragment, layout, Bulletin.DURATION_SHORT);
}
@CheckResult
public static Bulletin createBanBulletin(BaseFragment fragment, boolean banned) {
2022-06-21 04:51:00 +02:00
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(fragment.getParentActivity(), fragment.getResourceProvider());
2020-12-23 08:48:30 +01:00
final String text;
if (banned) {
layout.setAnimation(R.raw.ic_ban, "Hand");
text = LocaleController.getString("UserBlocked", R.string.UserBlocked);
} else {
layout.setAnimation(R.raw.ic_unban, "Main", "Finger 1", "Finger 2", "Finger 3", "Finger 4");
text = LocaleController.getString("UserUnblocked", R.string.UserUnblocked);
}
layout.textView.setText(AndroidUtilities.replaceTags(text));
return Bulletin.make(fragment, layout, Bulletin.DURATION_SHORT);
}
@CheckResult
public static Bulletin createCopyLinkBulletin(BaseFragment fragment) {
return of(fragment).createCopyLinkBulletin();
}
2021-01-28 15:15:51 +01:00
@CheckResult
public static Bulletin createCopyLinkBulletin(FrameLayout containerView) {
2021-09-20 07:54:41 +02:00
return of(containerView, null).createCopyLinkBulletin();
2021-01-28 15:15:51 +01:00
}
2020-12-23 08:48:30 +01:00
@CheckResult
2021-09-20 07:54:41 +02:00
public static Bulletin createPinMessageBulletin(BaseFragment fragment, Theme.ResourcesProvider resourcesProvider) {
return createPinMessageBulletin(fragment, true, null, null, resourcesProvider);
2020-10-30 11:26:29 +01:00
}
2020-12-23 08:48:30 +01:00
@CheckResult
2021-09-20 07:54:41 +02:00
public static Bulletin createUnpinMessageBulletin(BaseFragment fragment, Runnable undoAction, Runnable delayedAction, Theme.ResourcesProvider resourcesProvider) {
return createPinMessageBulletin(fragment, false, undoAction, delayedAction, resourcesProvider);
2020-10-30 11:26:29 +01:00
}
2020-12-23 08:48:30 +01:00
@CheckResult
2021-09-20 07:54:41 +02:00
private static Bulletin createPinMessageBulletin(BaseFragment fragment, boolean pinned, Runnable undoAction, Runnable delayedAction, Theme.ResourcesProvider resourcesProvider) {
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(fragment.getParentActivity(), resourcesProvider);
2020-12-23 08:48:30 +01:00
layout.setAnimation(pinned ? R.raw.ic_pin : R.raw.ic_unpin, 28, 28, "Pin", "Line");
2020-10-30 11:26:29 +01:00
layout.textView.setText(LocaleController.getString(pinned ? "MessagePinnedHint" : "MessageUnpinnedHint", pinned ? R.string.MessagePinnedHint : R.string.MessageUnpinnedHint));
if (!pinned) {
2021-09-20 07:54:41 +02:00
layout.setButton(new Bulletin.UndoButton(fragment.getParentActivity(), true, resourcesProvider).setUndoAction(undoAction).setDelayedAction(delayedAction));
2020-09-30 15:48:47 +02:00
}
2020-10-30 11:26:29 +01:00
return Bulletin.make(fragment, layout, pinned ? Bulletin.DURATION_SHORT : 5000);
2020-09-30 15:48:47 +02:00
}
2022-04-16 16:43:17 +02:00
@CheckResult
public static Bulletin createSoundEnabledBulletin(BaseFragment fragment, int setting, Theme.ResourcesProvider resourcesProvider) {
final Bulletin.LottieLayout layout = new Bulletin.LottieLayout(fragment.getParentActivity(), resourcesProvider);
final String text;
final boolean soundOn;
switch (setting) {
case NotificationsController.SETTING_SOUND_ON:
text = LocaleController.getString("SoundOnHint", R.string.SoundOnHint);
soundOn = true;
break;
case NotificationsController.SETTING_SOUND_OFF:
text = LocaleController.getString("SoundOffHint", R.string.SoundOffHint);
soundOn = false;
break;
default:
throw new IllegalArgumentException();
}
if (soundOn) {
layout.setAnimation(R.raw.sound_on);
} else {
layout.setAnimation(R.raw.sound_off);
}
layout.textView.setText(text);
return Bulletin.make(fragment, layout, Bulletin.DURATION_SHORT);
}
2020-10-30 11:26:29 +01:00
//endregion
2020-09-30 15:48:47 +02:00
}