2015-06-29 19:12:11 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2015-06-29 19:12:11 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2015-06-29 19:12:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Components;
|
|
|
|
|
2020-10-30 11:26:29 +01:00
|
|
|
import android.Manifest;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.SharedPreferences;
|
2020-10-30 11:26:29 +01:00
|
|
|
import android.content.pm.PackageManager;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.graphics.Color;
|
2020-10-30 11:26:29 +01:00
|
|
|
import android.graphics.Outline;
|
2018-08-27 10:33:11 +02:00
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2020-06-04 18:47:15 +02:00
|
|
|
import android.net.Uri;
|
2020-10-30 11:26:29 +01:00
|
|
|
import android.os.Build;
|
2016-03-16 13:26:32 +01:00
|
|
|
import android.os.Bundle;
|
2019-03-03 21:40:48 +01:00
|
|
|
import android.text.Html;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.text.InputType;
|
2019-01-23 18:03:33 +01:00
|
|
|
import android.text.Spannable;
|
2019-03-03 21:40:48 +01:00
|
|
|
import android.text.SpannableString;
|
2019-01-23 18:03:33 +01:00
|
|
|
import android.text.SpannableStringBuilder;
|
|
|
|
import android.text.TextUtils;
|
2019-03-03 21:40:48 +01:00
|
|
|
import android.text.style.URLSpan;
|
|
|
|
import android.util.Base64;
|
2019-05-14 14:08:05 +02:00
|
|
|
import android.util.SparseArray;
|
2017-12-08 18:35:59 +01:00
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.Gravity;
|
2020-09-30 15:48:47 +02:00
|
|
|
import android.view.HapticFeedbackConstants;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.view.View;
|
2020-10-30 11:26:29 +01:00
|
|
|
import android.view.ViewOutlineProvider;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2020-07-26 10:03:38 +02:00
|
|
|
import android.widget.Button;
|
2019-01-23 18:03:33 +01:00
|
|
|
import android.widget.FrameLayout;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.widget.LinearLayout;
|
2017-12-08 18:35:59 +01:00
|
|
|
import android.widget.TextView;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.widget.Toast;
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
import org.telegram.messenger.AccountInstance;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2019-01-23 18:03:33 +01:00
|
|
|
import org.telegram.messenger.ChatObject;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.messenger.ContactsController;
|
2019-03-03 21:40:48 +01:00
|
|
|
import org.telegram.messenger.FileLog;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.messenger.ImageLocation;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.messenger.MessageObject;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.MessagesStorage;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.NotificationsController;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.messenger.R;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.messenger.SecretChatHelper;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.SharedConfig;
|
|
|
|
import org.telegram.messenger.UserConfig;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.messenger.UserObject;
|
2016-03-16 13:26:32 +01:00
|
|
|
import org.telegram.messenger.Utilities;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.browser.Browser;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
2019-03-03 21:40:48 +01:00
|
|
|
import org.telegram.tgnet.SerializedData;
|
2016-03-16 13:26:32 +01:00
|
|
|
import org.telegram.tgnet.TLObject;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.ui.ActionBar.BottomSheet;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.CacheControlActivity;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.ui.Cells.AccountSelectCell;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.ui.Cells.CheckBoxCell;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Cells.RadioColorCell;
|
|
|
|
import org.telegram.ui.Cells.TextColorCell;
|
2019-03-03 21:40:48 +01:00
|
|
|
import org.telegram.ui.ChatActivity;
|
2020-09-30 15:48:47 +02:00
|
|
|
import org.telegram.ui.Components.voip.VoIPHelper;
|
2019-01-23 18:03:33 +01:00
|
|
|
import org.telegram.ui.LanguageSelectActivity;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.LaunchActivity;
|
2019-01-23 18:03:33 +01:00
|
|
|
import org.telegram.ui.NotificationsCustomSettingsActivity;
|
|
|
|
import org.telegram.ui.NotificationsSettingsActivity;
|
2018-08-27 10:33:11 +02:00
|
|
|
import org.telegram.ui.ProfileNotificationsActivity;
|
2016-03-16 13:26:32 +01:00
|
|
|
import org.telegram.ui.ReportOtherActivity;
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.ui.ThemePreviewActivity;
|
|
|
|
import org.telegram.ui.TooManyCommunitiesActivity;
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
import java.net.IDN;
|
2018-07-30 04:07:02 +02:00
|
|
|
import java.util.ArrayList;
|
2019-12-31 14:08:08 +01:00
|
|
|
import java.util.Arrays;
|
2018-07-30 04:07:02 +02:00
|
|
|
import java.util.Calendar;
|
2019-12-31 14:08:08 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2018-07-30 04:07:02 +02:00
|
|
|
import java.util.Locale;
|
2019-08-22 01:53:26 +02:00
|
|
|
import java.util.concurrent.CountDownLatch;
|
2018-07-30 04:07:02 +02:00
|
|
|
|
2020-06-25 17:28:24 +02:00
|
|
|
import kotlin.Unit;
|
|
|
|
import tw.nekomimi.nekogram.BottomBuilder;
|
2020-07-19 02:22:26 +02:00
|
|
|
import tw.nekomimi.nekogram.JalaliCalendar;
|
2020-07-26 18:07:20 +02:00
|
|
|
import tw.nekomimi.nekogram.utils.VibrateUtil;
|
2020-06-25 17:28:24 +02:00
|
|
|
|
2020-10-30 11:26:29 +01:00
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public class AlertsCreator {
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static Dialog processError(int currentAccount, TLRPC.TL_error error, BaseFragment fragment, TLObject request, Object... args) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (error.code == 406 || error.text == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (request instanceof TLRPC.TL_account_saveSecureValue || request instanceof TLRPC.TL_account_getAuthorizationForm) {
|
|
|
|
if (error.text.contains("PHONE_NUMBER_INVALID")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber));
|
|
|
|
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("FloodWait", R.string.FloodWait));
|
2018-08-27 10:33:11 +02:00
|
|
|
} else if ("APP_VERSION_OUTDATED".equals(error.text)) {
|
|
|
|
showUpdateAppAlert(fragment.getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text);
|
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_channels_joinChannel ||
|
2017-03-31 01:58:05 +02:00
|
|
|
request instanceof TLRPC.TL_channels_editAdmin ||
|
|
|
|
request instanceof TLRPC.TL_channels_inviteToChannel ||
|
|
|
|
request instanceof TLRPC.TL_messages_addChatUser ||
|
2017-07-08 18:32:04 +02:00
|
|
|
request instanceof TLRPC.TL_messages_startBot ||
|
2019-01-23 18:03:33 +01:00
|
|
|
request instanceof TLRPC.TL_channels_editBanned ||
|
2019-08-22 01:53:26 +02:00
|
|
|
request instanceof TLRPC.TL_messages_editChatDefaultBannedRights ||
|
|
|
|
request instanceof TLRPC.TL_messages_editChatAdmin ||
|
|
|
|
request instanceof TLRPC.TL_messages_migrateChat) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (fragment != null && error.text.equals("CHANNELS_TOO_MUCH")) {
|
|
|
|
if (request instanceof TLRPC.TL_channels_joinChannel || request instanceof TLRPC.TL_channels_inviteToChannel) {
|
|
|
|
fragment.presentFragment(new TooManyCommunitiesActivity(TooManyCommunitiesActivity.TYPE_JOIN));
|
|
|
|
} else {
|
|
|
|
fragment.presentFragment(new TooManyCommunitiesActivity(TooManyCommunitiesActivity.TYPE_EDIT));
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
} else if (fragment != null) {
|
2019-09-10 12:56:11 +02:00
|
|
|
AlertsCreator.showAddUserAlert(error.text, fragment, args != null && args.length > 0 ? (Boolean) args[0] : false, request);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
|
|
|
if (error.text.equals("PEER_FLOOD")) {
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.needShowAlert, 1);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_messages_createChat) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (error.text.equals("CHANNELS_TOO_MUCH")) {
|
|
|
|
fragment.presentFragment(new TooManyCommunitiesActivity(TooManyCommunitiesActivity.TYPE_CREATE));
|
|
|
|
return null;
|
|
|
|
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
2017-03-31 01:58:05 +02:00
|
|
|
AlertsCreator.showFloodWaitAlert(error.text, fragment);
|
|
|
|
} else {
|
2019-09-10 12:56:11 +02:00
|
|
|
AlertsCreator.showAddUserAlert(error.text, fragment, false, request);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_channels_createChannel) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (error.text.equals("CHANNELS_TOO_MUCH")) {
|
|
|
|
fragment.presentFragment(new TooManyCommunitiesActivity(TooManyCommunitiesActivity.TYPE_CREATE));
|
|
|
|
return null;
|
|
|
|
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
2017-03-31 01:58:05 +02:00
|
|
|
AlertsCreator.showFloodWaitAlert(error.text, fragment);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
2019-09-10 12:56:11 +02:00
|
|
|
AlertsCreator.showAddUserAlert(error.text, fragment, false, request);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_messages_editMessage) {
|
|
|
|
if (!error.text.equals("MESSAGE_NOT_MODIFIED")) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (fragment != null) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("EditMessageError", R.string.EditMessageError));
|
|
|
|
} else {
|
2020-10-30 11:26:29 +01:00
|
|
|
showSimpleToast(null, LocaleController.getString("EditMessageError", R.string.EditMessageError));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_messages_sendMessage ||
|
|
|
|
request instanceof TLRPC.TL_messages_sendMedia ||
|
|
|
|
request instanceof TLRPC.TL_messages_sendInlineBotResult ||
|
2019-01-23 18:03:33 +01:00
|
|
|
request instanceof TLRPC.TL_messages_forwardMessages ||
|
2019-09-10 12:56:11 +02:00
|
|
|
request instanceof TLRPC.TL_messages_sendMultiMedia ||
|
|
|
|
request instanceof TLRPC.TL_messages_sendScheduledMessages) {
|
|
|
|
switch (error.text) {
|
|
|
|
case "PEER_FLOOD":
|
|
|
|
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.needShowAlert, 0);
|
|
|
|
break;
|
|
|
|
case "USER_BANNED_IN_CHANNEL":
|
|
|
|
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.needShowAlert, 5);
|
|
|
|
break;
|
|
|
|
case "SCHEDULE_TOO_MUCH":
|
|
|
|
showSimpleToast(fragment, LocaleController.getString("MessageScheduledLimitReached", R.string.MessageScheduledLimitReached));
|
|
|
|
break;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_messages_importChatInvite) {
|
|
|
|
if (error.text.startsWith("FLOOD_WAIT")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("FloodWait", R.string.FloodWait));
|
|
|
|
} else if (error.text.equals("USERS_TOO_MUCH")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("JoinToGroupErrorFull", R.string.JoinToGroupErrorFull));
|
2019-12-31 14:08:08 +01:00
|
|
|
} else if (error.text.equals("CHANNELS_TOO_MUCH")) {
|
|
|
|
fragment.presentFragment(new TooManyCommunitiesActivity(TooManyCommunitiesActivity.TYPE_JOIN));
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist));
|
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_messages_getAttachedStickers) {
|
|
|
|
if (fragment != null && fragment.getParentActivity() != null) {
|
|
|
|
Toast.makeText(fragment.getParentActivity(), LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (request instanceof TLRPC.TL_account_confirmPhone || request instanceof TLRPC.TL_account_verifyPhone || request instanceof TLRPC.TL_account_verifyEmail) {
|
|
|
|
if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID") || error.text.contains("CODE_INVALID") || error.text.contains("CODE_EMPTY")) {
|
|
|
|
return showSimpleAlert(fragment, LocaleController.getString("InvalidCode", R.string.InvalidCode));
|
|
|
|
} else if (error.text.contains("PHONE_CODE_EXPIRED") || error.text.contains("EMAIL_VERIFY_EXPIRED")) {
|
|
|
|
return showSimpleAlert(fragment, LocaleController.getString("CodeExpired", R.string.CodeExpired));
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return showSimpleAlert(fragment, LocaleController.getString("FloodWait", R.string.FloodWait));
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
return showSimpleAlert(fragment, error.text);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_auth_resendCode) {
|
|
|
|
if (error.text.contains("PHONE_NUMBER_INVALID")) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return showSimpleAlert(fragment, LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber));
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return showSimpleAlert(fragment, LocaleController.getString("InvalidCode", R.string.InvalidCode));
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return showSimpleAlert(fragment, LocaleController.getString("CodeExpired", R.string.CodeExpired));
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return showSimpleAlert(fragment, LocaleController.getString("FloodWait", R.string.FloodWait));
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (error.code != -1000) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return showSimpleAlert(fragment, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_account_sendConfirmPhoneCode) {
|
|
|
|
if (error.code == 400) {
|
|
|
|
return showSimpleAlert(fragment, LocaleController.getString("CancelLinkExpired", R.string.CancelLinkExpired));
|
2020-10-30 11:26:29 +01:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (error.text.startsWith("FLOOD_WAIT")) {
|
|
|
|
return showSimpleAlert(fragment, LocaleController.getString("FloodWait", R.string.FloodWait));
|
|
|
|
} else {
|
|
|
|
return showSimpleAlert(fragment, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_account_changePhone) {
|
|
|
|
if (error.text.contains("PHONE_NUMBER_INVALID")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber));
|
|
|
|
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("InvalidCode", R.string.InvalidCode));
|
|
|
|
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("CodeExpired", R.string.CodeExpired));
|
|
|
|
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("FloodWait", R.string.FloodWait));
|
|
|
|
} else {
|
|
|
|
showSimpleAlert(fragment, error.text);
|
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_account_sendChangePhoneCode) {
|
|
|
|
if (error.text.contains("PHONE_NUMBER_INVALID")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber));
|
|
|
|
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("InvalidCode", R.string.InvalidCode));
|
|
|
|
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("CodeExpired", R.string.CodeExpired));
|
|
|
|
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("FloodWait", R.string.FloodWait));
|
|
|
|
} else if (error.text.startsWith("PHONE_NUMBER_OCCUPIED")) {
|
2020-03-30 14:00:09 +02:00
|
|
|
showSimpleAlert(fragment, LocaleController.formatString("ChangePhoneNumberOccupied", R.string.ChangePhoneNumberOccupied, args[0]));
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
|
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_updateUserName) {
|
|
|
|
switch (error.text) {
|
|
|
|
case "USERNAME_INVALID":
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("UsernameInvalid", R.string.UsernameInvalid));
|
|
|
|
break;
|
|
|
|
case "USERNAME_OCCUPIED":
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("UsernameInUse", R.string.UsernameInUse));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_contacts_importContacts) {
|
2020-10-30 11:26:29 +01:00
|
|
|
if (error.text.startsWith("FLOOD_WAIT")) {
|
2017-03-31 01:58:05 +02:00
|
|
|
showSimpleAlert(fragment, LocaleController.getString("FloodWait", R.string.FloodWait));
|
|
|
|
} else {
|
|
|
|
showSimpleAlert(fragment, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text);
|
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_account_getPassword || request instanceof TLRPC.TL_account_getTmpPassword) {
|
|
|
|
if (error.text.startsWith("FLOOD_WAIT")) {
|
|
|
|
showSimpleToast(fragment, getFloodWaitString(error.text));
|
|
|
|
} else {
|
|
|
|
showSimpleToast(fragment, error.text);
|
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_payments_sendPaymentForm) {
|
|
|
|
switch (error.text) {
|
|
|
|
case "BOT_PRECHECKOUT_FAILED":
|
|
|
|
showSimpleToast(fragment, LocaleController.getString("PaymentPrecheckoutFailed", R.string.PaymentPrecheckoutFailed));
|
|
|
|
break;
|
|
|
|
case "PAYMENT_FAILED":
|
|
|
|
showSimpleToast(fragment, LocaleController.getString("PaymentFailed", R.string.PaymentFailed));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
showSimpleToast(fragment, error.text);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (request instanceof TLRPC.TL_payments_validateRequestedInfo) {
|
|
|
|
switch (error.text) {
|
|
|
|
case "SHIPPING_NOT_AVAILABLE":
|
|
|
|
showSimpleToast(fragment, LocaleController.getString("PaymentNoShippingMethod", R.string.PaymentNoShippingMethod));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
showSimpleToast(fragment, error.text);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Toast showSimpleToast(BaseFragment baseFragment, final String text) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (text == null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
return null;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
Context context;
|
|
|
|
if (baseFragment != null && baseFragment.getParentActivity() != null) {
|
|
|
|
context = baseFragment.getParentActivity();
|
|
|
|
} else {
|
|
|
|
context = ApplicationLoader.applicationContext;
|
|
|
|
}
|
|
|
|
Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
|
2017-03-31 01:58:05 +02:00
|
|
|
toast.show();
|
|
|
|
return toast;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static AlertDialog showUpdateAppAlert(final Context context, final String text, boolean updateApp) {
|
|
|
|
if (context == null || text == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(text);
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
return builder.show();
|
|
|
|
}
|
|
|
|
|
2020-06-25 17:28:24 +02:00
|
|
|
private static SpannableStringBuilder mkTransSpan(String str, TLRPC.TL_langPackLanguage language, BottomBuilder builder) {
|
|
|
|
SpannableStringBuilder spanned = new SpannableStringBuilder(AndroidUtilities.replaceTags(str));
|
|
|
|
|
|
|
|
int start = TextUtils.indexOf(spanned, '[');
|
|
|
|
int end;
|
|
|
|
if (start != -1) {
|
|
|
|
end = TextUtils.indexOf(spanned, ']', start + 1);
|
|
|
|
if (start != -1 && end != -1) {
|
|
|
|
spanned.delete(end, end + 1);
|
|
|
|
spanned.delete(start, start + 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
end = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start != -1 && end != -1) {
|
|
|
|
spanned.setSpan(new URLSpanNoUnderline(language.translations_url) {
|
|
|
|
@Override
|
|
|
|
public void onClick(View widget) {
|
|
|
|
builder.dismiss();
|
|
|
|
super.onClick(widget);
|
|
|
|
}
|
|
|
|
}, start, end - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return spanned;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BottomSheet createLanguageAlert(LaunchActivity activity, final TLRPC.TL_langPackLanguage language) {
|
|
|
|
return createLanguageAlert(activity, language, null).create();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BottomBuilder createLanguageAlert(LaunchActivity activity, final TLRPC.TL_langPackLanguage language, Runnable callback) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (language == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
language.lang_code = language.lang_code.replace('-', '_').toLowerCase();
|
|
|
|
language.plural_code = language.plural_code.replace('-', '_').toLowerCase();
|
|
|
|
if (language.base_lang_code != null) {
|
|
|
|
language.base_lang_code = language.base_lang_code.replace('-', '_').toLowerCase();
|
|
|
|
}
|
|
|
|
|
2020-06-25 17:28:24 +02:00
|
|
|
BottomBuilder builder = new BottomBuilder(activity);
|
2019-01-23 18:03:33 +01:00
|
|
|
LocaleController.LocaleInfo currentInfo = LocaleController.getInstance().getCurrentLocaleInfo();
|
|
|
|
if (currentInfo.shortName.equals(language.lang_code)) {
|
2020-06-25 17:28:24 +02:00
|
|
|
String str = LocaleController.formatString("LanguageSame", R.string.LanguageSame, language.name);
|
|
|
|
builder.addTitle(LocaleController.getString("Language", R.string.Language), mkTransSpan(str, language, builder));
|
|
|
|
builder.addCancelButton();
|
|
|
|
builder.addButton(LocaleController.getString("SETTINGS", R.string.SETTINGS), (__) -> {
|
|
|
|
activity.presentFragment(new LanguageSelectActivity());
|
|
|
|
return Unit.INSTANCE;
|
|
|
|
});
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
|
|
|
if (language.strings_count == 0) {
|
2020-06-25 17:28:24 +02:00
|
|
|
String str = LocaleController.formatString("LanguageUnknownCustomAlert", R.string.LanguageUnknownCustomAlert, language.name);
|
|
|
|
builder.addTitle(LocaleController.getString("LanguageUnknownTitle", R.string.LanguageUnknownTitle), mkTransSpan(str, language, builder));
|
|
|
|
builder.addCancelButton();
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
2020-06-25 17:28:24 +02:00
|
|
|
String str;
|
2019-01-23 18:03:33 +01:00
|
|
|
if (language.official) {
|
|
|
|
str = LocaleController.formatString("LanguageAlert", R.string.LanguageAlert, language.name, (int) Math.ceil(language.translated_count / (float) language.strings_count * 100));
|
|
|
|
} else {
|
|
|
|
str = LocaleController.formatString("LanguageCustomAlert", R.string.LanguageCustomAlert, language.name, (int) Math.ceil(language.translated_count / (float) language.strings_count * 100));
|
|
|
|
}
|
2020-06-25 17:28:24 +02:00
|
|
|
builder.addTitle(LocaleController.getString("LanguageTitle", R.string.LanguageTitle), mkTransSpan(str, language, builder));
|
|
|
|
builder.addButton(LocaleController.getString("Change", R.string.Change), (it) -> {
|
2019-01-23 18:03:33 +01:00
|
|
|
String key;
|
|
|
|
if (language.official) {
|
|
|
|
key = "remote_" + language.lang_code;
|
|
|
|
} else {
|
|
|
|
key = "unofficial_" + language.lang_code;
|
|
|
|
}
|
|
|
|
LocaleController.LocaleInfo localeInfo = LocaleController.getInstance().getLanguageFromDict(key);
|
|
|
|
if (localeInfo == null) {
|
|
|
|
localeInfo = new LocaleController.LocaleInfo();
|
|
|
|
localeInfo.name = language.native_name;
|
|
|
|
localeInfo.nameEnglish = language.name;
|
|
|
|
localeInfo.shortName = language.lang_code;
|
|
|
|
localeInfo.baseLangCode = language.base_lang_code;
|
|
|
|
localeInfo.pluralLangCode = language.plural_code;
|
|
|
|
localeInfo.isRtl = language.rtl;
|
|
|
|
if (language.official) {
|
|
|
|
localeInfo.pathToFile = "remote";
|
|
|
|
} else {
|
|
|
|
localeInfo.pathToFile = "unofficial";
|
|
|
|
}
|
|
|
|
}
|
2020-06-25 17:28:24 +02:00
|
|
|
if (callback != null) {
|
|
|
|
callback.run();
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
LocaleController.getInstance().applyLanguage(localeInfo, true, false, false, true, UserConfig.selectedAccount);
|
|
|
|
activity.rebuildAllFragments(true);
|
2020-06-25 17:28:24 +02:00
|
|
|
return Unit.INSTANCE;
|
2019-01-23 18:03:33 +01:00
|
|
|
});
|
2020-06-25 17:28:24 +02:00
|
|
|
builder.addCancelButton();
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
public static boolean checkSlowMode(Context context, int currentAccount, long did, boolean few) {
|
|
|
|
int lowerId = (int) did;
|
|
|
|
if (lowerId < 0) {
|
|
|
|
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lowerId);
|
|
|
|
if (chat != null && chat.slowmode_enabled && !ChatObject.hasAdminRights(chat)) {
|
|
|
|
if (!few) {
|
|
|
|
TLRPC.ChatFull chatFull = MessagesController.getInstance(currentAccount).getChatFull(chat.id);
|
|
|
|
if (chatFull == null) {
|
2020-10-30 11:26:29 +01:00
|
|
|
chatFull = MessagesStorage.getInstance(currentAccount).loadChatInfo(chat.id, ChatObject.isChannel(chat), new CountDownLatch(1), false, false);
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
|
|
|
if (chatFull != null && chatFull.slowmode_next_send_date >= ConnectionsManager.getInstance(currentAccount).getCurrentTime()) {
|
|
|
|
few = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (few) {
|
|
|
|
AlertsCreator.createSimpleAlert(context, chat.title, LocaleController.getString("SlowmodeSendError", R.string.SlowmodeSendError)).show();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static AlertDialog.Builder createSimpleAlert(Context context, final String text) {
|
2019-08-22 01:53:26 +02:00
|
|
|
return createSimpleAlert(context, null, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AlertDialog.Builder createSimpleAlert(Context context, final String title, final String text) {
|
2020-06-04 18:47:15 +02:00
|
|
|
if (context == null || text == null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
return null;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
2020-06-21 06:37:07 +02:00
|
|
|
builder.setTitle(title == null ? LocaleController.getString("AppName", R.string.AppName) : title);
|
2017-03-31 01:58:05 +02:00
|
|
|
builder.setMessage(text);
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2018-07-30 04:07:02 +02:00
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Dialog showSimpleAlert(BaseFragment baseFragment, final String text) {
|
2019-08-22 01:53:26 +02:00
|
|
|
return showSimpleAlert(baseFragment, null, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Dialog showSimpleAlert(BaseFragment baseFragment, final String title, final String text) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (text == null || baseFragment == null || baseFragment.getParentActivity() == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
AlertDialog.Builder builder = createSimpleAlert(baseFragment.getParentActivity(), title, text);
|
2017-03-31 01:58:05 +02:00
|
|
|
Dialog dialog = builder.create();
|
|
|
|
baseFragment.showDialog(dialog);
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
public static void showBlockReportSpamReplyAlert(ChatActivity fragment, MessageObject messageObject, int peerId) {
|
|
|
|
if (fragment == null || fragment.getParentActivity() == null || messageObject == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountInstance accountInstance = fragment.getAccountInstance();
|
|
|
|
TLRPC.User user = peerId > 0 ? accountInstance.getMessagesController().getUser(peerId) : null;
|
|
|
|
TLRPC.Chat chat = peerId < 0 ? accountInstance.getMessagesController().getChat(-peerId) : null;
|
|
|
|
if (user == null && chat == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
|
|
|
|
|
|
|
|
builder.setTitle(LocaleController.getString("BlockUser", R.string.BlockUser));
|
|
|
|
if (user != null) {
|
|
|
|
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserReplyAlert", R.string.BlockUserReplyAlert, UserObject.getFirstName(user))));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserReplyAlert", R.string.BlockUserReplyAlert, chat.title)));
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckBoxCell[] cells = new CheckBoxCell[1];
|
|
|
|
LinearLayout linearLayout = new LinearLayout(fragment.getParentActivity());
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
|
|
|
cells[0] = new CheckBoxCell(fragment.getParentActivity(), 1);
|
|
|
|
cells[0].setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
|
|
|
cells[0].setTag(0);
|
|
|
|
cells[0].setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", true, false);
|
|
|
|
|
|
|
|
cells[0].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
|
|
|
|
linearLayout.addView(cells[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
cells[0].setOnClickListener(v -> {
|
|
|
|
Integer num = (Integer) v.getTag();
|
|
|
|
cells[num].setChecked(!cells[num].isChecked(), true);
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.setCustomViewOffset(12);
|
|
|
|
builder.setView(linearLayout);
|
|
|
|
|
|
|
|
builder.setPositiveButton(LocaleController.getString("BlockAndDeleteReplies", R.string.BlockAndDeleteReplies), (dialogInterface, i) -> {
|
|
|
|
if (user != null) {
|
|
|
|
accountInstance.getMessagesStorage().deleteUserChatHistory(fragment.getDialogId(), 0, user.id);
|
|
|
|
} else {
|
|
|
|
accountInstance.getMessagesStorage().deleteUserChatHistory(fragment.getDialogId(), 0, -chat.id);
|
|
|
|
}
|
|
|
|
TLRPC.TL_contacts_blockFromReplies request = new TLRPC.TL_contacts_blockFromReplies();
|
|
|
|
request.msg_id = messageObject.getId();
|
|
|
|
request.delete_message = true;
|
|
|
|
request.delete_history = true;
|
|
|
|
if (cells[0].isChecked()) {
|
|
|
|
request.report_spam = true;
|
|
|
|
if (fragment.getParentActivity() != null) {
|
|
|
|
Toast.makeText(fragment.getParentActivity(), LocaleController.getString("ReportChatSent", R.string.ReportChatSent), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
accountInstance.getConnectionsManager().sendRequest(request, (response, error) -> {
|
|
|
|
if (response instanceof TLRPC.Updates) {
|
|
|
|
accountInstance.getMessagesController().processUpdates((TLRPC.Updates) response, false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
fragment.showDialog(dialog);
|
|
|
|
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
|
|
|
if (button != null) {
|
|
|
|
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
public static void showBlockReportSpamAlert(BaseFragment fragment, long dialog_id, TLRPC.User currentUser, TLRPC.Chat currentChat, TLRPC.EncryptedChat encryptedChat, boolean isLocation, TLRPC.ChatFull chatInfo, MessagesStorage.IntCallback callback) {
|
|
|
|
if (fragment == null || fragment.getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AccountInstance accountInstance = fragment.getAccountInstance();
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
|
|
|
|
CharSequence reportText;
|
|
|
|
CheckBoxCell[] cells;
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(fragment.getCurrentAccount());
|
2019-12-31 14:08:08 +01:00
|
|
|
boolean showReport = encryptedChat != null || preferences.getBoolean("dialog_bar_report" + dialog_id, false);
|
2019-07-18 15:01:39 +02:00
|
|
|
if (currentUser != null) {
|
|
|
|
builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, UserObject.getFirstName(currentUser)));
|
|
|
|
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserAlert", R.string.BlockUserAlert, UserObject.getFirstName(currentUser))));
|
|
|
|
reportText = LocaleController.getString("BlockContact", R.string.BlockContact);
|
|
|
|
|
|
|
|
cells = new CheckBoxCell[2];
|
|
|
|
LinearLayout linearLayout = new LinearLayout(fragment.getParentActivity());
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
if (a == 0 && !showReport) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cells[a] = new CheckBoxCell(fragment.getParentActivity(), 1);
|
|
|
|
cells[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
|
|
|
cells[a].setTag(a);
|
|
|
|
if (a == 0) {
|
|
|
|
cells[a].setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", true, false);
|
2020-10-30 11:26:29 +01:00
|
|
|
} else {
|
2019-07-18 15:01:39 +02:00
|
|
|
cells[a].setText(LocaleController.formatString("DeleteThisChat", R.string.DeleteThisChat), "", true, false);
|
|
|
|
}
|
|
|
|
cells[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
|
|
|
|
linearLayout.addView(cells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
cells[a].setOnClickListener(v -> {
|
|
|
|
Integer num = (Integer) v.getTag();
|
|
|
|
cells[num].setChecked(!cells[num].isChecked(), true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
builder.setCustomViewOffset(12);
|
|
|
|
builder.setView(linearLayout);
|
|
|
|
} else {
|
|
|
|
cells = null;
|
|
|
|
if (currentChat != null && isLocation) {
|
|
|
|
builder.setTitle(LocaleController.getString("ReportUnrelatedGroup", R.string.ReportUnrelatedGroup));
|
|
|
|
if (chatInfo != null && chatInfo.location instanceof TLRPC.TL_channelLocation) {
|
|
|
|
TLRPC.TL_channelLocation location = (TLRPC.TL_channelLocation) chatInfo.location;
|
|
|
|
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("ReportUnrelatedGroupText", R.string.ReportUnrelatedGroupText, location.address)));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("ReportUnrelatedGroupTextNoAddress", R.string.ReportUnrelatedGroupTextNoAddress));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
builder.setTitle(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle));
|
|
|
|
if (ChatObject.isChannel(currentChat) && !currentChat.megagroup) {
|
|
|
|
builder.setMessage(LocaleController.getString("ReportSpamAlertChannel", R.string.ReportSpamAlertChannel));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("ReportSpamAlertGroup", R.string.ReportSpamAlertGroup));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reportText = LocaleController.getString("ReportChat", R.string.ReportChat);
|
|
|
|
}
|
|
|
|
builder.setPositiveButton(reportText, (dialogInterface, i) -> {
|
|
|
|
if (currentUser != null) {
|
2020-09-30 15:48:47 +02:00
|
|
|
accountInstance.getMessagesController().blockPeer(currentUser.id);
|
2019-07-18 15:01:39 +02:00
|
|
|
}
|
|
|
|
if (cells == null || cells[0] != null && cells[0].isChecked()) {
|
|
|
|
accountInstance.getMessagesController().reportSpam(dialog_id, currentUser, currentChat, encryptedChat, currentChat != null && isLocation);
|
|
|
|
}
|
|
|
|
if (cells == null || cells[1].isChecked()) {
|
|
|
|
if (currentChat != null) {
|
|
|
|
if (ChatObject.isNotInChat(currentChat)) {
|
|
|
|
accountInstance.getMessagesController().deleteDialog(dialog_id, 0);
|
|
|
|
} else {
|
|
|
|
accountInstance.getMessagesController().deleteUserFromChat((int) -dialog_id, accountInstance.getMessagesController().getUser(accountInstance.getUserConfig().getClientUserId()), null);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
accountInstance.getMessagesController().deleteDialog(dialog_id, 0);
|
|
|
|
}
|
|
|
|
callback.run(1);
|
|
|
|
} else {
|
|
|
|
callback.run(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
fragment.showDialog(dialog);
|
|
|
|
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
|
|
|
if (button != null) {
|
|
|
|
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public static void showCustomNotificationsDialog(BaseFragment parentFragment, long did, int globalType, ArrayList<NotificationsSettingsActivity.NotificationException> exceptions, int currentAccount, MessagesStorage.IntCallback callback) {
|
|
|
|
showCustomNotificationsDialog(parentFragment, did, globalType, exceptions, currentAccount, callback, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void showCustomNotificationsDialog(BaseFragment parentFragment, long did, int globalType, ArrayList<NotificationsSettingsActivity.NotificationException> exceptions, int currentAccount, MessagesStorage.IntCallback callback, MessagesStorage.IntCallback resultCallback) {
|
2018-08-27 10:33:11 +02:00
|
|
|
if (parentFragment == null || parentFragment.getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean enabled;
|
2019-01-23 18:03:33 +01:00
|
|
|
boolean defaultEnabled = NotificationsController.getInstance(currentAccount).isGlobalNotificationsEnabled(did);
|
2018-08-27 10:33:11 +02:00
|
|
|
|
|
|
|
String[] descriptions = new String[]{
|
|
|
|
LocaleController.getString("NotificationsTurnOn", R.string.NotificationsTurnOn),
|
|
|
|
LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)),
|
|
|
|
LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)),
|
2019-01-23 18:03:33 +01:00
|
|
|
did == 0 && parentFragment instanceof NotificationsCustomSettingsActivity ? null : LocaleController.getString("NotificationsCustomize", R.string.NotificationsCustomize),
|
2018-08-27 10:33:11 +02:00
|
|
|
LocaleController.getString("NotificationsTurnOff", R.string.NotificationsTurnOff)
|
|
|
|
};
|
|
|
|
|
|
|
|
int[] icons = new int[]{
|
2020-06-25 17:28:24 +02:00
|
|
|
R.drawable.baseline_notifications_24,
|
|
|
|
R.drawable.deproko_baseline_clock_24,
|
|
|
|
R.drawable.deproko_baseline_clock_24,
|
|
|
|
R.drawable.baseline_settings_24,
|
|
|
|
R.drawable.baseline_notifications_off_24
|
2018-08-27 10:33:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
final LinearLayout linearLayout = new LinearLayout(parentFragment.getParentActivity());
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
2019-01-23 18:03:33 +01:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
|
2018-08-27 10:33:11 +02:00
|
|
|
|
|
|
|
for (int a = 0; a < descriptions.length; a++) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (descriptions[a] == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
TextView textView = new TextView(parentFragment.getParentActivity());
|
2019-01-23 18:03:33 +01:00
|
|
|
Drawable drawable = parentFragment.getParentActivity().getResources().getDrawable(icons[a]);
|
|
|
|
if (a == descriptions.length - 1) {
|
|
|
|
textView.setTextColor(Theme.getColor(Theme.key_dialogTextRed));
|
2020-06-25 17:28:24 +02:00
|
|
|
drawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogRedIcon), PorterDuff.Mode.SRC_IN));
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
|
|
|
textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
2020-06-25 17:28:24 +02:00
|
|
|
drawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogIcon), PorterDuff.Mode.SRC_IN));
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
textView.setLines(1);
|
|
|
|
textView.setMaxLines(1);
|
|
|
|
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
|
|
|
|
textView.setTag(a);
|
|
|
|
textView.setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
|
|
|
textView.setPadding(AndroidUtilities.dp(24), 0, AndroidUtilities.dp(24), 0);
|
|
|
|
textView.setSingleLine(true);
|
|
|
|
textView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
|
|
|
|
textView.setCompoundDrawablePadding(AndroidUtilities.dp(26));
|
|
|
|
textView.setText(descriptions[a]);
|
|
|
|
linearLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));
|
|
|
|
textView.setOnClickListener(v -> {
|
|
|
|
int i = (Integer) v.getTag();
|
2019-01-23 18:03:33 +01:00
|
|
|
if (i == 0) {
|
|
|
|
if (did != 0) {
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
if (defaultEnabled) {
|
|
|
|
editor.remove("notify2_" + did);
|
|
|
|
} else {
|
|
|
|
editor.putInt("notify2_" + did, 0);
|
|
|
|
}
|
|
|
|
MessagesStorage.getInstance(currentAccount).setDialogFlags(did, 0);
|
|
|
|
editor.commit();
|
2019-05-14 14:08:05 +02:00
|
|
|
TLRPC.Dialog dialog = MessagesController.getInstance(currentAccount).dialogs_dict.get(did);
|
2019-01-23 18:03:33 +01:00
|
|
|
if (dialog != null) {
|
|
|
|
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
|
|
|
|
}
|
|
|
|
NotificationsController.getInstance(currentAccount).updateServerNotificationsSettings(did);
|
|
|
|
if (resultCallback != null) {
|
|
|
|
if (defaultEnabled) {
|
|
|
|
resultCallback.run(0);
|
|
|
|
} else {
|
|
|
|
resultCallback.run(1);
|
|
|
|
}
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationsController.getInstance(currentAccount).setGlobalNotificationsEnabled(globalType, 0);
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (i == 3) {
|
|
|
|
if (did != 0) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("dialog_id", did);
|
|
|
|
parentFragment.presentFragment(new ProfileNotificationsActivity(args));
|
|
|
|
} else {
|
|
|
|
parentFragment.presentFragment(new NotificationsCustomSettingsActivity(globalType, exceptions));
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int untilTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
|
2019-01-23 18:03:33 +01:00
|
|
|
if (i == 1) {
|
2018-08-27 10:33:11 +02:00
|
|
|
untilTime += 60 * 60;
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (i == 2) {
|
2018-08-27 10:33:11 +02:00
|
|
|
untilTime += 60 * 60 * 48;
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (i == 4) {
|
2018-08-27 10:33:11 +02:00
|
|
|
untilTime = Integer.MAX_VALUE;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
|
|
|
|
if (did != 0) {
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
long flags;
|
|
|
|
if (i == 4) {
|
|
|
|
if (!defaultEnabled) {
|
|
|
|
editor.remove("notify2_" + did);
|
|
|
|
flags = 0;
|
|
|
|
} else {
|
|
|
|
editor.putInt("notify2_" + did, 2);
|
|
|
|
flags = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
editor.putInt("notify2_" + did, 3);
|
|
|
|
editor.putInt("notifyuntil_" + did, untilTime);
|
|
|
|
flags = ((long) untilTime << 32) | 1;
|
|
|
|
}
|
|
|
|
NotificationsController.getInstance(currentAccount).removeNotificationsForDialog(did);
|
|
|
|
MessagesStorage.getInstance(currentAccount).setDialogFlags(did, flags);
|
|
|
|
editor.commit();
|
2019-05-14 14:08:05 +02:00
|
|
|
TLRPC.Dialog dialog = MessagesController.getInstance(currentAccount).dialogs_dict.get(did);
|
2019-01-23 18:03:33 +01:00
|
|
|
if (dialog != null) {
|
|
|
|
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
|
|
|
|
if (i != 4 || defaultEnabled) {
|
|
|
|
dialog.notify_settings.mute_until = untilTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NotificationsController.getInstance(currentAccount).updateServerNotificationsSettings(did);
|
|
|
|
if (resultCallback != null) {
|
|
|
|
if (i == 4 && !defaultEnabled) {
|
|
|
|
resultCallback.run(0);
|
|
|
|
} else {
|
|
|
|
resultCallback.run(1);
|
|
|
|
}
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (i == 4) {
|
|
|
|
NotificationsController.getInstance(currentAccount).setGlobalNotificationsEnabled(globalType, Integer.MAX_VALUE);
|
|
|
|
} else {
|
|
|
|
NotificationsController.getInstance(currentAccount).setGlobalNotificationsEnabled(globalType, untilTime);
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (callback != null) {
|
|
|
|
callback.run(i);
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
builder.getDismissRunnable().run();
|
2018-08-27 10:33:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications));
|
|
|
|
builder.setView(linearLayout);
|
|
|
|
parentFragment.showDialog(builder.create());
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static AlertDialog showSecretLocationAlert(Context context, int currentAccount, final Runnable onSelectRunnable, boolean inChat) {
|
|
|
|
ArrayList<String> arrayList = new ArrayList<>();
|
2019-12-31 14:08:08 +01:00
|
|
|
ArrayList<Integer> types = new ArrayList<>();
|
2019-12-17 09:06:28 +01:00
|
|
|
int providers = 5; // MessagesController.getInstance(currentAccount).availableMapProviders;
|
2018-07-30 04:07:02 +02:00
|
|
|
if ((providers & 1) != 0) {
|
|
|
|
arrayList.add(LocaleController.getString("MapPreviewProviderTelegram", R.string.MapPreviewProviderTelegram));
|
2019-12-31 14:08:08 +01:00
|
|
|
types.add(0);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
if ((providers & 2) != 0) {
|
|
|
|
arrayList.add(LocaleController.getString("MapPreviewProviderGoogle", R.string.MapPreviewProviderGoogle));
|
2019-12-31 14:08:08 +01:00
|
|
|
types.add(1);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
if ((providers & 4) != 0) {
|
|
|
|
arrayList.add(LocaleController.getString("MapPreviewProviderYandex", R.string.MapPreviewProviderYandex));
|
2019-12-31 14:08:08 +01:00
|
|
|
types.add(3);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
arrayList.add(LocaleController.getString("MapPreviewProviderNobody", R.string.MapPreviewProviderNobody));
|
2019-12-31 14:08:08 +01:00
|
|
|
types.add(2);
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
builder.setTitle(LocaleController.getString("MapPreviewProviderTitle", R.string.MapPreviewProviderTitle));
|
|
|
|
final LinearLayout linearLayout = new LinearLayout(context);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
builder.setView(linearLayout);
|
|
|
|
|
|
|
|
for (int a = 0; a < arrayList.size(); a++) {
|
|
|
|
RadioColorCell cell = new RadioColorCell(context);
|
|
|
|
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
|
|
|
cell.setTag(a);
|
|
|
|
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
|
|
|
cell.setTextAndValue(arrayList.get(a), SharedConfig.mapPreviewType == types.get(a));
|
|
|
|
linearLayout.addView(cell);
|
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
Integer which = (Integer) v.getTag();
|
|
|
|
SharedConfig.setSecretMapPreviewType(types.get(which));
|
|
|
|
if (onSelectRunnable != null) {
|
|
|
|
onSelectRunnable.run();
|
|
|
|
}
|
|
|
|
builder.getDismissRunnable().run();
|
|
|
|
});
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!inChat) {
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
}
|
|
|
|
AlertDialog dialog = builder.show();
|
|
|
|
if (inChat) {
|
|
|
|
dialog.setCanceledOnTouchOutside(false);
|
|
|
|
}
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void updateDayPicker(NumberPicker dayPicker, NumberPicker monthPicker, NumberPicker yearPicker) {
|
2020-07-19 02:22:26 +02:00
|
|
|
Calendar calendar = JalaliCalendar.mInstance();
|
2018-07-30 04:07:02 +02:00
|
|
|
calendar.set(Calendar.MONTH, monthPicker.getValue());
|
|
|
|
calendar.set(Calendar.YEAR, yearPicker.getValue());
|
|
|
|
dayPicker.setMinValue(1);
|
|
|
|
dayPicker.setMaxValue(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void checkPickerDate(NumberPicker dayPicker, NumberPicker monthPicker, NumberPicker yearPicker) {
|
2020-07-19 02:22:26 +02:00
|
|
|
Calendar calendar = JalaliCalendar.mInstance();
|
2018-07-30 04:07:02 +02:00
|
|
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
|
|
|
|
|
int currentYear = calendar.get(Calendar.YEAR);
|
|
|
|
int currentMonth = calendar.get(Calendar.MONTH);
|
|
|
|
int currentDay = calendar.get(Calendar.DAY_OF_MONTH);
|
|
|
|
|
|
|
|
if (currentYear > yearPicker.getValue()) {
|
|
|
|
yearPicker.setValue(currentYear);
|
|
|
|
//yearPicker.finishScroll();
|
|
|
|
}
|
|
|
|
if (yearPicker.getValue() == currentYear) {
|
|
|
|
if (currentMonth > monthPicker.getValue()) {
|
|
|
|
monthPicker.setValue(currentMonth);
|
|
|
|
//monthPicker.finishScroll();
|
|
|
|
}
|
|
|
|
if (currentMonth == monthPicker.getValue()) {
|
|
|
|
if (currentDay > dayPicker.getValue()) {
|
|
|
|
dayPicker.setValue(currentDay);
|
|
|
|
//dayPicker.finishScroll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public static void showOpenUrlAlert(BaseFragment fragment, String url, boolean punycode, boolean ask) {
|
|
|
|
showOpenUrlAlert(fragment, url, punycode, true, ask);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void showOpenUrlAlert(BaseFragment fragment, String url, boolean punycode, boolean tryTelegraph, boolean ask) {
|
|
|
|
if (fragment == null || fragment.getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
long inlineReturn = (fragment instanceof ChatActivity) ? ((ChatActivity) fragment).getInlineReturn() : 0;
|
|
|
|
if (Browser.isInternalUrl(url, null) || !ask) {
|
|
|
|
Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph);
|
|
|
|
} else {
|
|
|
|
String urlFinal;
|
|
|
|
if (punycode) {
|
|
|
|
try {
|
|
|
|
Uri uri = Uri.parse(url);
|
|
|
|
String host = IDN.toASCII(uri.getHost(), IDN.ALLOW_UNASSIGNED);
|
|
|
|
urlFinal = uri.getScheme() + "://" + host + uri.getPath();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
urlFinal = url;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
urlFinal = url;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("OpenUrlTitle", R.string.OpenUrlTitle));
|
|
|
|
String format = LocaleController.getString("OpenUrlAlert2", R.string.OpenUrlAlert2);
|
|
|
|
int index = format.indexOf("%");
|
|
|
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format(format, urlFinal));
|
|
|
|
if (index >= 0) {
|
|
|
|
stringBuilder.setSpan(new URLSpan(urlFinal), index, index + urlFinal.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
}
|
|
|
|
builder.setMessage(stringBuilder);
|
|
|
|
builder.setMessageTextViewClickable(false);
|
|
|
|
builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), (dialogInterface, i) -> Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph));
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2020-06-21 06:37:07 +02:00
|
|
|
builder.setNeutralButton(LocaleController.getString("Copy", R.string.Copy), (dialogInterface, i) -> {
|
|
|
|
try {
|
|
|
|
AndroidUtilities.addToClipboard(url);
|
|
|
|
Toast.makeText(fragment.getParentActivity(), LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT).show();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
});
|
2020-06-04 18:47:15 +02:00
|
|
|
fragment.showDialog(builder.create());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public static AlertDialog createSupportAlert(BaseFragment fragment) {
|
|
|
|
if (fragment == null || fragment.getParentActivity() == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
final TextView message = new TextView(fragment.getParentActivity());
|
|
|
|
Spannable spanned = new SpannableString(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo).replace("\n", "<br>")));
|
|
|
|
URLSpan[] spans = spanned.getSpans(0, spanned.length(), URLSpan.class);
|
|
|
|
for (int i = 0; i < spans.length; i++) {
|
|
|
|
URLSpan span = spans[i];
|
|
|
|
int start = spanned.getSpanStart(span);
|
|
|
|
int end = spanned.getSpanEnd(span);
|
|
|
|
spanned.removeSpan(span);
|
|
|
|
span = new URLSpanNoUnderline(span.getURL()) {
|
|
|
|
@Override
|
|
|
|
public void onClick(View widget) {
|
2020-07-26 10:03:38 +02:00
|
|
|
fragment.dismissCurrentDialog();
|
2019-03-03 21:40:48 +01:00
|
|
|
super.onClick(widget);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
spanned.setSpan(span, start, end, 0);
|
|
|
|
}
|
|
|
|
message.setText(spanned);
|
|
|
|
message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
message.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
|
|
|
|
message.setHighlightColor(Theme.getColor(Theme.key_dialogLinkSelection));
|
|
|
|
message.setPadding(AndroidUtilities.dp(23), 0, AndroidUtilities.dp(23), 0);
|
|
|
|
message.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
|
|
|
|
message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
|
|
|
|
AlertDialog.Builder builder1 = new AlertDialog.Builder(fragment.getParentActivity());
|
|
|
|
builder1.setView(message);
|
|
|
|
builder1.setTitle(LocaleController.getString("AskAQuestion", R.string.AskAQuestion));
|
|
|
|
builder1.setPositiveButton(LocaleController.getString("AskButton", R.string.AskButton), (dialogInterface, i) -> performAskAQuestion(fragment));
|
|
|
|
builder1.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
return builder1.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void performAskAQuestion(BaseFragment fragment) {
|
|
|
|
int currentAccount = fragment.getCurrentAccount();
|
|
|
|
final SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
|
|
|
|
int uid = preferences.getInt("support_id", 0);
|
|
|
|
TLRPC.User supportUser = null;
|
|
|
|
if (uid != 0) {
|
|
|
|
supportUser = MessagesController.getInstance(currentAccount).getUser(uid);
|
|
|
|
if (supportUser == null) {
|
|
|
|
String userString = preferences.getString("support_user", null);
|
|
|
|
if (userString != null) {
|
|
|
|
try {
|
|
|
|
byte[] datacentersBytes = Base64.decode(userString, Base64.DEFAULT);
|
|
|
|
if (datacentersBytes != null) {
|
|
|
|
SerializedData data = new SerializedData(datacentersBytes);
|
|
|
|
supportUser = TLRPC.User.TLdeserialize(data, data.readInt32(false), false);
|
|
|
|
if (supportUser != null && supportUser.id == 333000) {
|
|
|
|
supportUser = null;
|
|
|
|
}
|
|
|
|
data.cleanup();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
supportUser = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (supportUser == null) {
|
|
|
|
final AlertDialog progressDialog = new AlertDialog(fragment.getParentActivity(), 3);
|
|
|
|
progressDialog.setCanCacnel(false);
|
|
|
|
progressDialog.show();
|
|
|
|
TLRPC.TL_help_getSupport req = new TLRPC.TL_help_getSupport();
|
|
|
|
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
|
|
|
|
if (error == null) {
|
|
|
|
final TLRPC.TL_help_support res = (TLRPC.TL_help_support) response;
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("support_id", res.user.id);
|
|
|
|
SerializedData data = new SerializedData();
|
|
|
|
res.user.serializeToStream(data);
|
|
|
|
editor.putString("support_user", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
|
|
|
|
editor.commit();
|
|
|
|
data.cleanup();
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
ArrayList<TLRPC.User> users = new ArrayList<>();
|
|
|
|
users.add(res.user);
|
|
|
|
MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, true, true);
|
|
|
|
MessagesController.getInstance(currentAccount).putUser(res.user, false);
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", res.user.id);
|
|
|
|
fragment.presentFragment(new ChatActivity(args));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
MessagesController.getInstance(currentAccount).putUser(supportUser, true);
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", supportUser.id);
|
|
|
|
fragment.presentFragment(new ChatActivity(args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public static void createClearOrDeleteDialogAlert(BaseFragment fragment, boolean clear, TLRPC.Chat chat, TLRPC.User user, boolean secret, MessagesStorage.BooleanCallback onProcessRunnable) {
|
2019-06-04 12:14:50 +02:00
|
|
|
createClearOrDeleteDialogAlert(fragment, clear, false, false, chat, user, secret, onProcessRunnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void createClearOrDeleteDialogAlert(BaseFragment fragment, boolean clear, boolean admin, boolean second, TLRPC.Chat chat, TLRPC.User user, boolean secret, MessagesStorage.BooleanCallback onProcessRunnable) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (fragment == null || fragment.getParentActivity() == null || chat == null && user == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
int account = fragment.getCurrentAccount();
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
Context context = fragment.getParentActivity();
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
2019-05-14 14:08:05 +02:00
|
|
|
int selfUserId = UserConfig.getInstance(account).getClientUserId();
|
|
|
|
|
|
|
|
CheckBoxCell[] cell = new CheckBoxCell[1];
|
|
|
|
|
|
|
|
TextView messageTextView = new TextView(context);
|
|
|
|
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
|
|
|
|
|
|
|
boolean clearingCache = ChatObject.isChannel(chat) && !TextUtils.isEmpty(chat.username);
|
2019-01-23 18:03:33 +01:00
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
FrameLayout frameLayout = new FrameLayout(context) {
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
if (cell[0] != null) {
|
|
|
|
setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight() + cell[0].getMeasuredHeight() + AndroidUtilities.dp(7));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-01-23 18:03:33 +01:00
|
|
|
builder.setView(frameLayout);
|
|
|
|
|
|
|
|
AvatarDrawable avatarDrawable = new AvatarDrawable();
|
|
|
|
avatarDrawable.setTextSize(AndroidUtilities.dp(12));
|
|
|
|
|
|
|
|
BackupImageView imageView = new BackupImageView(context);
|
|
|
|
imageView.setRoundRadius(AndroidUtilities.dp(20));
|
2019-05-14 14:08:05 +02:00
|
|
|
frameLayout.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));
|
2019-01-23 18:03:33 +01:00
|
|
|
|
|
|
|
TextView textView = new TextView(context);
|
|
|
|
textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
|
|
|
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
textView.setLines(1);
|
|
|
|
textView.setMaxLines(1);
|
|
|
|
textView.setSingleLine(true);
|
2019-05-14 14:08:05 +02:00
|
|
|
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
|
2019-01-23 18:03:33 +01:00
|
|
|
textView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
if (clear) {
|
2019-05-14 14:08:05 +02:00
|
|
|
if (clearingCache) {
|
|
|
|
textView.setText(LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache));
|
|
|
|
} else {
|
|
|
|
textView.setText(LocaleController.getString("ClearHistory", R.string.ClearHistory));
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (admin) {
|
|
|
|
if (ChatObject.isChannel(chat)) {
|
|
|
|
if (chat.megagroup) {
|
|
|
|
textView.setText(LocaleController.getString("DeleteMegaMenu", R.string.DeleteMegaMenu));
|
|
|
|
} else {
|
|
|
|
textView.setText(LocaleController.getString("ChannelDeleteMenu", R.string.ChannelDeleteMenu));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
textView.setText(LocaleController.getString("DeleteMegaMenu", R.string.DeleteMegaMenu));
|
|
|
|
}
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (chat != null) {
|
|
|
|
if (ChatObject.isChannel(chat)) {
|
|
|
|
if (chat.megagroup) {
|
|
|
|
textView.setText(LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu));
|
|
|
|
} else {
|
|
|
|
textView.setText(LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
textView.setText(LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
textView.setText(LocaleController.getString("DeleteChatUser", R.string.DeleteChatUser));
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
|
2019-01-23 18:03:33 +01:00
|
|
|
frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
boolean canRevokeInbox = user != null && !user.bot && user.id != selfUserId && MessagesController.getInstance(account).canRevokePmInbox;
|
|
|
|
int revokeTimeLimit;
|
|
|
|
if (user != null) {
|
|
|
|
revokeTimeLimit = MessagesController.getInstance(account).revokeTimePmLimit;
|
|
|
|
} else {
|
|
|
|
revokeTimeLimit = MessagesController.getInstance(account).revokeTimeLimit;
|
|
|
|
}
|
|
|
|
boolean canDeleteInbox = !secret && user != null && canRevokeInbox && revokeTimeLimit == 0x7fffffff;
|
2020-02-08 05:13:55 +01:00
|
|
|
final boolean[] deleteForAll = {true};
|
2019-05-14 14:08:05 +02:00
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
if (!second && canDeleteInbox) {
|
2019-05-14 14:08:05 +02:00
|
|
|
cell[0] = new CheckBoxCell(context, 1);
|
|
|
|
cell[0].setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
|
|
|
if (clear) {
|
2020-02-08 04:05:56 +01:00
|
|
|
cell[0].setText(LocaleController.formatString("ClearHistoryOptionAlso", R.string.ClearHistoryOptionAlso, UserObject.getFirstName(user)), "", true, false);
|
2019-05-14 14:08:05 +02:00
|
|
|
} else {
|
2020-02-08 04:05:56 +01:00
|
|
|
cell[0].setText(LocaleController.formatString("DeleteMessagesOptionAlso", R.string.DeleteMessagesOptionAlso, UserObject.getFirstName(user)), "", true, false);
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
|
|
|
cell[0].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
|
|
|
|
frameLayout.addView(cell[0], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 0));
|
|
|
|
cell[0].setOnClickListener(v -> {
|
|
|
|
CheckBoxCell cell1 = (CheckBoxCell) v;
|
|
|
|
deleteForAll[0] = !deleteForAll[0];
|
|
|
|
cell1.setChecked(deleteForAll[0], true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
if (user != null) {
|
2020-09-30 15:48:47 +02:00
|
|
|
if (UserObject.isReplyUser(user)) {
|
|
|
|
avatarDrawable.setSmallSize(true);
|
|
|
|
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_REPLIES);
|
|
|
|
imageView.setImage(null, null, avatarDrawable, user);
|
|
|
|
} else if (user.id == selfUserId) {
|
2020-03-30 14:00:09 +02:00
|
|
|
avatarDrawable.setSmallSize(true);
|
|
|
|
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
|
2019-05-14 14:08:05 +02:00
|
|
|
imageView.setImage(null, null, avatarDrawable, user);
|
|
|
|
} else {
|
2020-03-30 14:00:09 +02:00
|
|
|
avatarDrawable.setSmallSize(false);
|
2019-05-14 14:08:05 +02:00
|
|
|
avatarDrawable.setInfo(user);
|
|
|
|
imageView.setImage(ImageLocation.getForUser(user, false), "50_50", avatarDrawable, user);
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2020-10-30 11:26:29 +01:00
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
avatarDrawable.setInfo(chat);
|
2019-06-04 12:14:50 +02:00
|
|
|
imageView.setImage(ImageLocation.getForChat(chat, false), "50_50", avatarDrawable, chat);
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
if (second) {
|
2020-06-04 18:47:15 +02:00
|
|
|
if (UserObject.isUserSelf(user)) {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DeleteAllMessagesSavedAlert", R.string.DeleteAllMessagesSavedAlert)));
|
|
|
|
} else {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DeleteAllMessagesAlert", R.string.DeleteAllMessagesAlert)));
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
} else {
|
|
|
|
if (clear) {
|
|
|
|
if (user != null) {
|
|
|
|
if (secret) {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureClearHistoryWithSecretUser", R.string.AreYouSureClearHistoryWithSecretUser, UserObject.getUserName(user))));
|
2019-05-14 14:08:05 +02:00
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (user.id == selfUserId) {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("AreYouSureClearHistorySavedMessages", R.string.AreYouSureClearHistorySavedMessages)));
|
|
|
|
} else {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureClearHistoryWithUser", R.string.AreYouSureClearHistoryWithUser, UserObject.getUserName(user))));
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2020-10-30 11:26:29 +01:00
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (!ChatObject.isChannel(chat) || chat.megagroup && TextUtils.isEmpty(chat.username)) {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureClearHistoryWithChat", R.string.AreYouSureClearHistoryWithChat, chat.title)));
|
|
|
|
} else if (chat.megagroup) {
|
|
|
|
messageTextView.setText(LocaleController.getString("AreYouSureClearHistoryGroup", R.string.AreYouSureClearHistoryGroup));
|
2019-05-14 14:08:05 +02:00
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
messageTextView.setText(LocaleController.getString("AreYouSureClearHistoryChannel", R.string.AreYouSureClearHistoryChannel));
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
} else {
|
|
|
|
if (admin) {
|
|
|
|
if (ChatObject.isChannel(chat)) {
|
|
|
|
if (chat.megagroup) {
|
|
|
|
messageTextView.setText(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert));
|
|
|
|
} else {
|
|
|
|
messageTextView.setText(LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
messageTextView.setText(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (user != null) {
|
|
|
|
if (secret) {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteThisChatWithSecretUser", R.string.AreYouSureDeleteThisChatWithSecretUser, UserObject.getUserName(user))));
|
|
|
|
} else {
|
|
|
|
if (user.id == selfUserId) {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("AreYouSureDeleteThisChatSavedMessages", R.string.AreYouSureDeleteThisChatSavedMessages)));
|
|
|
|
} else {
|
2020-06-04 18:47:15 +02:00
|
|
|
if (user.bot && !user.support) {
|
2020-04-24 11:21:58 +02:00
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteThisChatWithBot", R.string.AreYouSureDeleteThisChatWithBot, UserObject.getUserName(user))));
|
|
|
|
} else {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteThisChatWithUser", R.string.AreYouSureDeleteThisChatWithUser, UserObject.getUserName(user))));
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (ChatObject.isChannel(chat)) {
|
|
|
|
if (chat.megagroup) {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("MegaLeaveAlertWithName", R.string.MegaLeaveAlertWithName, chat.title)));
|
|
|
|
} else {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ChannelLeaveAlertWithName", R.string.ChannelLeaveAlertWithName, chat.title)));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteAndExitName", R.string.AreYouSureDeleteAndExitName, chat.title)));
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
String actionText;
|
2019-06-04 12:14:50 +02:00
|
|
|
if (second) {
|
|
|
|
actionText = LocaleController.getString("DeleteAll", R.string.DeleteAll);
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (clear) {
|
|
|
|
if (clearingCache) {
|
|
|
|
actionText = LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache);
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
actionText = LocaleController.getString("ClearHistory", R.string.ClearHistory);
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (admin) {
|
|
|
|
if (ChatObject.isChannel(chat)) {
|
|
|
|
if (chat.megagroup) {
|
|
|
|
actionText = LocaleController.getString("DeleteMega", R.string.DeleteMega);
|
|
|
|
} else {
|
|
|
|
actionText = LocaleController.getString("ChannelDelete", R.string.ChannelDelete);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actionText = LocaleController.getString("DeleteMega", R.string.DeleteMega);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ChatObject.isChannel(chat)) {
|
|
|
|
if (chat.megagroup) {
|
|
|
|
actionText = LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu);
|
|
|
|
} else {
|
|
|
|
actionText = LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actionText = LocaleController.getString("DeleteChatUser", R.string.DeleteChatUser);
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
builder.setPositiveButton(actionText, (dialogInterface, i) -> {
|
2020-06-04 18:47:15 +02:00
|
|
|
if (!clearingCache && !second) {
|
|
|
|
if (UserObject.isUserSelf(user)) {
|
|
|
|
createClearOrDeleteDialogAlert(fragment, clear, admin, true, chat, user, secret, onProcessRunnable);
|
|
|
|
return;
|
|
|
|
} else if (user != null && deleteForAll[0]) {
|
|
|
|
MessagesStorage.getInstance(fragment.getCurrentAccount()).getMessagesCount(user.id, (count) -> {
|
|
|
|
if (count >= 50) {
|
|
|
|
createClearOrDeleteDialogAlert(fragment, clear, admin, true, chat, user, secret, onProcessRunnable);
|
|
|
|
} else {
|
|
|
|
if (onProcessRunnable != null) {
|
|
|
|
onProcessRunnable.run(deleteForAll[0]);
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (onProcessRunnable != null) {
|
2019-06-04 12:14:50 +02:00
|
|
|
onProcessRunnable.run(second || deleteForAll[0]);
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2020-02-13 19:26:53 +01:00
|
|
|
AlertDialog alertDialog = builder.create();
|
|
|
|
fragment.showDialog(alertDialog);
|
|
|
|
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
|
|
|
if (button != null) {
|
|
|
|
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
public static void createCallDialogAlert(BaseFragment fragment, TLRPC.User user, boolean videoCall) {
|
|
|
|
if (fragment == null || fragment.getParentActivity() == null || user == null || UserObject.isDeleted(user) || UserConfig.getInstance(fragment.getCurrentAccount()).getClientUserId() == user.id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final int account = fragment.getCurrentAccount();
|
|
|
|
final Context context = fragment.getParentActivity();
|
|
|
|
final FrameLayout frameLayout = new FrameLayout(context);
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
final String message;
|
|
|
|
if (videoCall) {
|
|
|
|
title = LocaleController.getString("VideoCallAlertTitle", R.string.VideoCallAlertTitle);
|
|
|
|
message = LocaleController.formatString("VideoCallAlert", R.string.VideoCallAlert, UserObject.getUserName(user));
|
|
|
|
} else {
|
|
|
|
title = LocaleController.getString("CallAlertTitle", R.string.CallAlertTitle);
|
|
|
|
message = LocaleController.formatString("CallAlert", R.string.CallAlert, UserObject.getUserName(user));
|
|
|
|
}
|
|
|
|
|
|
|
|
TextView messageTextView = new TextView(context);
|
|
|
|
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
|
|
|
messageTextView.setText(AndroidUtilities.replaceTags(message));
|
|
|
|
|
|
|
|
AvatarDrawable avatarDrawable = new AvatarDrawable();
|
|
|
|
avatarDrawable.setTextSize(AndroidUtilities.dp(12));
|
|
|
|
avatarDrawable.setSmallSize(false);
|
|
|
|
avatarDrawable.setInfo(user);
|
|
|
|
|
|
|
|
BackupImageView imageView = new BackupImageView(context);
|
|
|
|
imageView.setRoundRadius(AndroidUtilities.dp(20));
|
|
|
|
imageView.setImage(ImageLocation.getForUser(user, false), "50_50", avatarDrawable, user);
|
|
|
|
frameLayout.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));
|
|
|
|
|
|
|
|
TextView textView = new TextView(context);
|
|
|
|
textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
|
|
|
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
textView.setLines(1);
|
|
|
|
textView.setMaxLines(1);
|
|
|
|
textView.setSingleLine(true);
|
|
|
|
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
|
|
|
|
textView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
textView.setText(title);
|
|
|
|
frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
|
|
|
|
frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
|
|
|
|
|
|
|
|
AlertDialog dialog = new AlertDialog.Builder(context).setView(frameLayout)
|
|
|
|
.setPositiveButton(LocaleController.getString("Call", R.string.Call), (dialogInterface, i) -> {
|
|
|
|
final TLRPC.UserFull userFull = fragment.getMessagesController().getUserFull(user.id);
|
|
|
|
VoIPHelper.startCall(user, videoCall, userFull != null && userFull.video_calls_available, fragment.getParentActivity(), userFull);
|
|
|
|
})
|
|
|
|
.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null)
|
|
|
|
.create();
|
|
|
|
fragment.showDialog(dialog);
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
public interface BlockDialogCallback {
|
|
|
|
void run(boolean report, boolean delete);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void createBlockDialogAlert(BaseFragment fragment, int count, boolean reportSpam, TLRPC.User user, BlockDialogCallback onProcessRunnable) {
|
|
|
|
if (fragment == null || fragment.getParentActivity() == null || count == 1 && user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Context context = fragment.getParentActivity();
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
|
|
|
|
CheckBoxCell[] cell = new CheckBoxCell[2];
|
|
|
|
|
|
|
|
LinearLayout linearLayout = new LinearLayout(context);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
builder.setView(linearLayout);
|
|
|
|
|
|
|
|
String actionText;
|
|
|
|
if (count == 1) {
|
|
|
|
String name = ContactsController.formatName(user.first_name, user.last_name);
|
|
|
|
builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, name));
|
|
|
|
actionText = LocaleController.getString("BlockUser", R.string.BlockUser);
|
|
|
|
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserMessage", R.string.BlockUserMessage, name)));
|
|
|
|
} else {
|
|
|
|
builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, LocaleController.formatPluralString("UsersCountTitle", count)));
|
|
|
|
actionText = LocaleController.getString("BlockUsers", R.string.BlockUsers);
|
|
|
|
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUsersMessage", R.string.BlockUsersMessage, LocaleController.formatPluralString("UsersCount", count))));
|
|
|
|
}
|
|
|
|
|
|
|
|
final boolean[] checks = new boolean[]{true, true};
|
|
|
|
|
|
|
|
for (int a = 0; a < cell.length; a++) {
|
|
|
|
if (a == 0 && !reportSpam) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int num = a;
|
|
|
|
cell[a] = new CheckBoxCell(context, 1);
|
|
|
|
cell[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
|
|
|
if (a == 0) {
|
|
|
|
cell[a].setText(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle), "", true, false);
|
|
|
|
} else {
|
2020-04-24 11:21:58 +02:00
|
|
|
cell[a].setText(count == 1 ? LocaleController.getString("DeleteThisChatBothSides", R.string.DeleteThisChatBothSides) : LocaleController.getString("DeleteTheseChatsBothSides", R.string.DeleteTheseChatsBothSides), "", true, false);
|
2020-02-13 19:26:53 +01:00
|
|
|
}
|
|
|
|
cell[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
|
|
|
|
linearLayout.addView(cell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
|
|
|
|
cell[a].setOnClickListener(v -> {
|
|
|
|
CheckBoxCell cell1 = (CheckBoxCell) v;
|
|
|
|
checks[num] = !checks[num];
|
|
|
|
cell1.setChecked(checks[num], true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.setPositiveButton(actionText, (dialogInterface, i) -> onProcessRunnable.run(checks[0], checks[1]));
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2019-01-23 18:03:33 +01:00
|
|
|
AlertDialog alertDialog = builder.create();
|
|
|
|
fragment.showDialog(alertDialog);
|
|
|
|
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
2019-02-08 03:30:32 +01:00
|
|
|
if (button != null) {
|
|
|
|
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public interface DatePickerDelegate {
|
|
|
|
void didSelectDate(int year, int month, int dayOfMonth);
|
|
|
|
}
|
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
public static AlertDialog.Builder createDatePickerDialog(Context context, int minYear, int maxYear, int currentYearDiff, int selectedDay, int selectedMonth, int selectedYear, String title, final boolean checkMinDate, final DatePickerDelegate datePickerDelegate) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (context == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
LinearLayout linearLayout = new LinearLayout(context);
|
|
|
|
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
linearLayout.setWeightSum(1.0f);
|
|
|
|
|
|
|
|
final NumberPicker monthPicker = new NumberPicker(context);
|
|
|
|
final NumberPicker dayPicker = new NumberPicker(context);
|
|
|
|
final NumberPicker yearPicker = new NumberPicker(context);
|
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
linearLayout.addView(dayPicker, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 0.3f));
|
|
|
|
dayPicker.setOnScrollListener((view, scrollState) -> {
|
|
|
|
if (checkMinDate && scrollState == NumberPicker.OnScrollListener.SCROLL_STATE_IDLE) {
|
|
|
|
checkPickerDate(dayPicker, monthPicker, yearPicker);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
monthPicker.setMinValue(0);
|
|
|
|
monthPicker.setMaxValue(11);
|
|
|
|
linearLayout.addView(monthPicker, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 0.3f));
|
|
|
|
monthPicker.setFormatter(value -> {
|
2020-07-19 02:22:26 +02:00
|
|
|
Calendar calendar = JalaliCalendar.mInstance();
|
2018-08-27 10:33:11 +02:00
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
calendar.set(Calendar.MONTH, value);
|
|
|
|
return calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
|
|
|
|
});
|
|
|
|
monthPicker.setOnValueChangedListener((picker, oldVal, newVal) -> updateDayPicker(dayPicker, monthPicker, yearPicker));
|
|
|
|
monthPicker.setOnScrollListener((view, scrollState) -> {
|
|
|
|
if (checkMinDate && scrollState == NumberPicker.OnScrollListener.SCROLL_STATE_IDLE) {
|
|
|
|
checkPickerDate(dayPicker, monthPicker, yearPicker);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-19 02:22:26 +02:00
|
|
|
Calendar calendar = JalaliCalendar.mInstance();
|
2018-07-30 04:07:02 +02:00
|
|
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
|
final int currentYear = calendar.get(Calendar.YEAR);
|
|
|
|
yearPicker.setMinValue(currentYear + minYear);
|
|
|
|
yearPicker.setMaxValue(currentYear + maxYear);
|
2018-08-27 10:33:11 +02:00
|
|
|
yearPicker.setValue(currentYear + currentYearDiff);
|
2018-07-30 04:07:02 +02:00
|
|
|
linearLayout.addView(yearPicker, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 0.4f));
|
2018-08-27 10:33:11 +02:00
|
|
|
yearPicker.setOnValueChangedListener((picker, oldVal, newVal) -> updateDayPicker(dayPicker, monthPicker, yearPicker));
|
|
|
|
yearPicker.setOnScrollListener((view, scrollState) -> {
|
|
|
|
if (checkMinDate && scrollState == NumberPicker.OnScrollListener.SCROLL_STATE_IDLE) {
|
|
|
|
checkPickerDate(dayPicker, monthPicker, yearPicker);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
updateDayPicker(dayPicker, monthPicker, yearPicker);
|
|
|
|
if (checkMinDate) {
|
|
|
|
checkPickerDate(dayPicker, monthPicker, yearPicker);
|
|
|
|
}
|
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
if (selectedDay != -1) {
|
|
|
|
dayPicker.setValue(selectedDay);
|
|
|
|
monthPicker.setValue(selectedMonth);
|
|
|
|
yearPicker.setValue(selectedYear);
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
builder.setTitle(title);
|
|
|
|
|
|
|
|
builder.setView(linearLayout);
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), (dialog, which) -> {
|
|
|
|
if (checkMinDate) {
|
|
|
|
checkPickerDate(dayPicker, monthPicker, yearPicker);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
datePickerDelegate.didSelectDate(yearPicker.getValue(), monthPicker.getValue(), dayPicker.getValue());
|
2018-07-30 04:07:02 +02:00
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private static boolean checkScheduleDate(TextView button, boolean reminder, NumberPicker dayPicker, NumberPicker hourPicker, NumberPicker minutePicker) {
|
|
|
|
int day = dayPicker.getValue();
|
|
|
|
int hour = hourPicker.getValue();
|
|
|
|
int minute = minutePicker.getValue();
|
|
|
|
|
2020-07-19 02:22:26 +02:00
|
|
|
Calendar calendar = JalaliCalendar.mInstance();
|
2019-09-10 12:56:11 +02:00
|
|
|
long systemTime = System.currentTimeMillis();
|
|
|
|
calendar.setTimeInMillis(systemTime);
|
|
|
|
int currentYear = calendar.get(Calendar.YEAR);
|
|
|
|
int currentDay = calendar.get(Calendar.DAY_OF_YEAR);
|
|
|
|
|
|
|
|
calendar.setTimeInMillis(System.currentTimeMillis() + (long) day * 24 * 3600 * 1000);
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, hour);
|
|
|
|
calendar.set(Calendar.MINUTE, minute);
|
|
|
|
long currentTime = calendar.getTimeInMillis();
|
|
|
|
|
|
|
|
if (currentTime <= systemTime + 60000L) {
|
|
|
|
calendar.setTimeInMillis(systemTime + 60000L);
|
|
|
|
if (currentDay != calendar.get(Calendar.DAY_OF_YEAR)) {
|
|
|
|
dayPicker.setValue(day = 1);
|
|
|
|
}
|
|
|
|
hourPicker.setValue(hour = calendar.get(Calendar.HOUR_OF_DAY));
|
|
|
|
minutePicker.setValue(minute = calendar.get(Calendar.MINUTE));
|
|
|
|
}
|
|
|
|
int selectedYear = calendar.get(Calendar.YEAR);
|
|
|
|
|
|
|
|
calendar.setTimeInMillis(System.currentTimeMillis() + (long) day * 24 * 3600 * 1000);
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, hour);
|
|
|
|
calendar.set(Calendar.MINUTE, minute);
|
|
|
|
|
|
|
|
if (button != null) {
|
|
|
|
long time = calendar.getTimeInMillis();
|
|
|
|
int num;
|
|
|
|
if (day == 0) {
|
|
|
|
num = 0;
|
|
|
|
} else if (currentYear == selectedYear) {
|
|
|
|
num = 1;
|
|
|
|
} else {
|
|
|
|
num = 2;
|
|
|
|
}
|
|
|
|
if (reminder) {
|
|
|
|
num += 3;
|
|
|
|
}
|
|
|
|
button.setText(LocaleController.getInstance().formatterScheduleSend[num].format(time));
|
|
|
|
}
|
|
|
|
return currentTime - systemTime > 60000L;
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface ScheduleDatePickerDelegate {
|
|
|
|
void didSelectDate(boolean notify, int scheduleDate);
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
public static BottomSheet.Builder createScheduleDatePickerDialog(Context context, long dialogId, final ScheduleDatePickerDelegate datePickerDelegate) {
|
|
|
|
return createScheduleDatePickerDialog(context, dialogId, -1, datePickerDelegate, null);
|
2019-09-10 12:56:11 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
public static BottomSheet.Builder createScheduleDatePickerDialog(Context context, long dialogId, final ScheduleDatePickerDelegate datePickerDelegate, final Runnable cancelRunnable) {
|
|
|
|
return createScheduleDatePickerDialog(context, dialogId, -1, datePickerDelegate, cancelRunnable);
|
2019-09-10 12:56:11 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
public static BottomSheet.Builder createScheduleDatePickerDialog(Context context, long dialogId, long currentDate, final ScheduleDatePickerDelegate datePickerDelegate, final Runnable cancelRunnable) {
|
2019-09-10 12:56:11 +02:00
|
|
|
if (context == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
int selfUserId = UserConfig.getInstance(UserConfig.selectedAccount).getClientUserId();
|
|
|
|
|
|
|
|
BottomSheet.Builder builder = new BottomSheet.Builder(context, false);
|
2019-09-10 12:56:11 +02:00
|
|
|
builder.setApplyBottomPadding(false);
|
|
|
|
|
|
|
|
final NumberPicker dayPicker = new NumberPicker(context);
|
|
|
|
dayPicker.setTextOffset(AndroidUtilities.dp(10));
|
|
|
|
dayPicker.setItemCount(5);
|
2020-07-26 10:03:38 +02:00
|
|
|
final NumberPicker hourPicker = new NumberPicker(context) {
|
|
|
|
@Override
|
|
|
|
protected CharSequence getContentDescription(int value) {
|
|
|
|
return LocaleController.formatPluralString("Hours", value);
|
|
|
|
}
|
|
|
|
};
|
2019-09-10 12:56:11 +02:00
|
|
|
hourPicker.setItemCount(5);
|
|
|
|
hourPicker.setTextOffset(-AndroidUtilities.dp(10));
|
2020-07-26 10:03:38 +02:00
|
|
|
final NumberPicker minutePicker = new NumberPicker(context) {
|
|
|
|
@Override
|
|
|
|
protected CharSequence getContentDescription(int value) {
|
|
|
|
return LocaleController.formatPluralString("Minutes", value);
|
|
|
|
}
|
|
|
|
};
|
2019-09-10 12:56:11 +02:00
|
|
|
minutePicker.setItemCount(5);
|
|
|
|
minutePicker.setTextOffset(-AndroidUtilities.dp(34));
|
|
|
|
|
|
|
|
LinearLayout container = new LinearLayout(context) {
|
|
|
|
|
|
|
|
boolean ignoreLayout = false;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
ignoreLayout = true;
|
|
|
|
int count;
|
|
|
|
if (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
|
|
|
|
count = 3;
|
|
|
|
} else {
|
|
|
|
count = 5;
|
|
|
|
}
|
|
|
|
dayPicker.setItemCount(count);
|
|
|
|
hourPicker.setItemCount(count);
|
|
|
|
minutePicker.setItemCount(count);
|
|
|
|
dayPicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
|
|
|
|
hourPicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
|
|
|
|
minutePicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
|
|
|
|
ignoreLayout = false;
|
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void requestLayout() {
|
|
|
|
if (ignoreLayout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.requestLayout();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
container.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
FrameLayout titleLayout = new FrameLayout(context);
|
|
|
|
container.addView(titleLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 22, 0, 0, 4));
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
TextView titleView = new TextView(context);
|
2019-12-31 14:08:08 +01:00
|
|
|
if (dialogId == selfUserId) {
|
|
|
|
titleView.setText(LocaleController.getString("SetReminder", R.string.SetReminder));
|
|
|
|
} else {
|
|
|
|
titleView.setText(LocaleController.getString("ScheduleMessage", R.string.ScheduleMessage));
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
titleView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
|
|
|
titleView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
2019-12-31 14:08:08 +01:00
|
|
|
titleLayout.addView(titleView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 12, 0, 0));
|
2019-09-10 12:56:11 +02:00
|
|
|
titleView.setOnTouchListener((v, event) -> true);
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
if ((int) dialogId > 0 && dialogId != selfUserId) {
|
|
|
|
TLRPC.User user = MessagesController.getInstance(UserConfig.selectedAccount).getUser((int) dialogId);
|
|
|
|
if (user != null && !user.bot && user.status != null && user.status.expires > 0) {
|
|
|
|
String name = UserObject.getFirstName(user);
|
|
|
|
if (name.length() > 10) {
|
|
|
|
name = name.substring(0, 10) + "\u2026";
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionBarMenuItem optionsButton = new ActionBarMenuItem(context, null, 0, Theme.getColor(Theme.key_sheet_other));
|
|
|
|
optionsButton.setLongClickEnabled(false);
|
|
|
|
optionsButton.setSubMenuOpenSide(2);
|
|
|
|
optionsButton.setIcon(R.drawable.ic_ab_other);
|
|
|
|
optionsButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_player_actionBarSelector), 1));
|
|
|
|
titleLayout.addView(optionsButton, LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.RIGHT, 0, 8, 5, 0));
|
|
|
|
optionsButton.addSubItem(1, LocaleController.formatString("ScheduleWhenOnline", R.string.ScheduleWhenOnline, name));
|
|
|
|
optionsButton.setOnClickListener(v -> optionsButton.toggleSubMenu());
|
|
|
|
optionsButton.setDelegate(id -> {
|
|
|
|
if (id == 1) {
|
|
|
|
datePickerDelegate.didSelectDate(true, 0x7ffffffe);
|
|
|
|
builder.getDismissRunnable().run();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
optionsButton.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
LinearLayout linearLayout = new LinearLayout(context);
|
|
|
|
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
linearLayout.setWeightSum(1.0f);
|
|
|
|
container.addView(linearLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
|
|
|
|
long currentTime = System.currentTimeMillis();
|
2020-07-19 02:22:26 +02:00
|
|
|
Calendar calendar = JalaliCalendar.mInstance();
|
2019-09-10 12:56:11 +02:00
|
|
|
calendar.setTimeInMillis(currentTime);
|
|
|
|
int currentYear = calendar.get(Calendar.YEAR);
|
|
|
|
|
2020-07-26 10:03:38 +02:00
|
|
|
TextView buttonTextView = new TextView(context) {
|
|
|
|
@Override
|
|
|
|
public CharSequence getAccessibilityClassName() {
|
|
|
|
return Button.class.getName();
|
|
|
|
}
|
|
|
|
};
|
2019-09-10 12:56:11 +02:00
|
|
|
|
|
|
|
linearLayout.addView(dayPicker, LayoutHelper.createLinear(0, 54 * 5, 0.5f));
|
|
|
|
dayPicker.setMinValue(0);
|
|
|
|
dayPicker.setMaxValue(365);
|
|
|
|
dayPicker.setWrapSelectorWheel(false);
|
|
|
|
dayPicker.setFormatter(value -> {
|
|
|
|
if (value == 0) {
|
|
|
|
return LocaleController.getString("MessageScheduleToday", R.string.MessageScheduleToday);
|
|
|
|
} else {
|
|
|
|
long date = currentTime + (long) value * 86400000L;
|
|
|
|
calendar.setTimeInMillis(date);
|
|
|
|
int year = calendar.get(Calendar.YEAR);
|
|
|
|
if (year == currentYear) {
|
|
|
|
return LocaleController.getInstance().formatterScheduleDay.format(date);
|
|
|
|
} else {
|
|
|
|
return LocaleController.getInstance().formatterScheduleYear.format(date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-09-30 15:48:47 +02:00
|
|
|
final NumberPicker.OnValueChangeListener onValueChangeListener = (picker, oldVal, newVal) -> {
|
2020-10-01 03:59:32 +02:00
|
|
|
try {
|
|
|
|
container.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
checkScheduleDate(buttonTextView, selfUserId == dialogId, dayPicker, hourPicker, minutePicker);
|
|
|
|
};
|
2019-09-10 12:56:11 +02:00
|
|
|
dayPicker.setOnValueChangedListener(onValueChangeListener);
|
|
|
|
|
|
|
|
hourPicker.setMinValue(0);
|
|
|
|
hourPicker.setMaxValue(23);
|
|
|
|
linearLayout.addView(hourPicker, LayoutHelper.createLinear(0, 54 * 5, 0.2f));
|
|
|
|
hourPicker.setFormatter(value -> String.format("%02d", value));
|
|
|
|
hourPicker.setOnValueChangedListener(onValueChangeListener);
|
|
|
|
|
|
|
|
minutePicker.setMinValue(0);
|
|
|
|
minutePicker.setMaxValue(59);
|
|
|
|
minutePicker.setValue(0);
|
|
|
|
minutePicker.setFormatter(value -> String.format("%02d", value));
|
|
|
|
linearLayout.addView(minutePicker, LayoutHelper.createLinear(0, 54 * 5, 0.3f));
|
|
|
|
minutePicker.setOnValueChangedListener(onValueChangeListener);
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
if (currentDate > 0 && currentDate != 0x7FFFFFFE) {
|
2019-09-10 12:56:11 +02:00
|
|
|
currentDate *= 1000;
|
|
|
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
|
calendar.set(Calendar.MINUTE, 0);
|
2020-07-26 10:03:38 +02:00
|
|
|
calendar.set(Calendar.SECOND, 0);
|
|
|
|
calendar.set(Calendar.MILLISECOND, 0);
|
2019-09-10 12:56:11 +02:00
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
int days = (int) ((currentDate - calendar.getTimeInMillis()) / (24 * 60 * 60 * 1000));
|
|
|
|
calendar.setTimeInMillis(currentDate);
|
|
|
|
if (days >= 0) {
|
|
|
|
minutePicker.setValue(calendar.get(Calendar.MINUTE));
|
|
|
|
hourPicker.setValue(calendar.get(Calendar.HOUR_OF_DAY));
|
|
|
|
dayPicker.setValue(days);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final boolean[] canceled = {true};
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
checkScheduleDate(buttonTextView, selfUserId == dialogId, dayPicker, hourPicker, minutePicker);
|
2019-09-10 12:56:11 +02:00
|
|
|
|
|
|
|
buttonTextView.setPadding(AndroidUtilities.dp(34), 0, AndroidUtilities.dp(34), 0);
|
|
|
|
buttonTextView.setGravity(Gravity.CENTER);
|
|
|
|
buttonTextView.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
|
|
|
|
buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
buttonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
buttonTextView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
|
|
|
|
container.addView(buttonTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM, 16, 15, 16, 16));
|
|
|
|
buttonTextView.setOnClickListener(v -> {
|
|
|
|
canceled[0] = false;
|
2019-12-31 14:08:08 +01:00
|
|
|
boolean setSeconds = checkScheduleDate(null, selfUserId == dialogId, dayPicker, hourPicker, minutePicker);
|
2019-09-10 12:56:11 +02:00
|
|
|
calendar.setTimeInMillis(System.currentTimeMillis() + (long) dayPicker.getValue() * 24 * 3600 * 1000);
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, hourPicker.getValue());
|
|
|
|
calendar.set(Calendar.MINUTE, minutePicker.getValue());
|
|
|
|
if (setSeconds) {
|
|
|
|
calendar.set(Calendar.SECOND, 0);
|
|
|
|
}
|
|
|
|
datePickerDelegate.didSelectDate(true, (int) (calendar.getTimeInMillis() / 1000));
|
|
|
|
builder.getDismissRunnable().run();
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.setCustomView(container);
|
|
|
|
builder.show().setOnDismissListener(dialog -> {
|
|
|
|
if (cancelRunnable != null && canceled[0]) {
|
|
|
|
cancelRunnable.run();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
private static void checkCalendarDate(long minDate, NumberPicker dayPicker, NumberPicker monthPicker, NumberPicker yearPicker) {
|
|
|
|
int day = dayPicker.getValue();
|
|
|
|
int month = monthPicker.getValue();
|
|
|
|
int year = yearPicker.getValue();
|
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
calendar.setTimeInMillis(minDate);
|
|
|
|
int minYear = calendar.get(Calendar.YEAR);
|
|
|
|
int minMonth = calendar.get(Calendar.MONTH);
|
|
|
|
int minDay = calendar.get(Calendar.DAY_OF_MONTH);
|
|
|
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
|
int maxYear = calendar.get(Calendar.YEAR);
|
|
|
|
int maxMonth = calendar.get(Calendar.MONTH);
|
|
|
|
int maxDay = calendar.get(Calendar.DAY_OF_MONTH);
|
|
|
|
|
|
|
|
if (year > maxYear) {
|
|
|
|
yearPicker.setValue(year = maxYear);
|
|
|
|
}
|
|
|
|
if (year == maxYear) {
|
|
|
|
if (month > maxMonth) {
|
|
|
|
monthPicker.setValue(month = maxMonth);
|
|
|
|
}
|
|
|
|
if (month == maxMonth) {
|
|
|
|
if (day > maxDay) {
|
|
|
|
dayPicker.setValue(day = maxDay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (year < minYear) {
|
|
|
|
yearPicker.setValue(year = minYear);
|
|
|
|
}
|
|
|
|
if (year == minYear) {
|
|
|
|
if (month < minMonth) {
|
|
|
|
monthPicker.setValue(month = minMonth);
|
|
|
|
}
|
|
|
|
if (month == minMonth) {
|
|
|
|
if (day < minDay) {
|
|
|
|
dayPicker.setValue(day = minDay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
calendar.set(Calendar.YEAR, year);
|
|
|
|
calendar.set(Calendar.MONTH, month);
|
|
|
|
|
|
|
|
int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
|
|
|
|
dayPicker.setMaxValue(daysInMonth);
|
|
|
|
if (day > daysInMonth) {
|
|
|
|
day = daysInMonth;
|
|
|
|
dayPicker.setValue(day);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BottomSheet.Builder createCalendarPickerDialog(Context context, long minDate, final MessagesStorage.IntCallback callback) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (context == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
BottomSheet.Builder builder = new BottomSheet.Builder(context, false);
|
|
|
|
builder.setApplyBottomPadding(false);
|
|
|
|
|
|
|
|
final NumberPicker dayPicker = new NumberPicker(context);
|
|
|
|
dayPicker.setTextOffset(AndroidUtilities.dp(10));
|
|
|
|
dayPicker.setItemCount(5);
|
|
|
|
final NumberPicker monthPicker = new NumberPicker(context);
|
|
|
|
monthPicker.setItemCount(5);
|
|
|
|
monthPicker.setTextOffset(-AndroidUtilities.dp(10));
|
|
|
|
final NumberPicker yearPicker = new NumberPicker(context);
|
|
|
|
yearPicker.setItemCount(5);
|
|
|
|
yearPicker.setTextOffset(-AndroidUtilities.dp(24));
|
|
|
|
|
|
|
|
LinearLayout container = new LinearLayout(context) {
|
|
|
|
|
|
|
|
boolean ignoreLayout = false;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
ignoreLayout = true;
|
|
|
|
int count;
|
|
|
|
if (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
|
|
|
|
count = 3;
|
|
|
|
} else {
|
|
|
|
count = 5;
|
|
|
|
}
|
|
|
|
dayPicker.setItemCount(count);
|
|
|
|
monthPicker.setItemCount(count);
|
|
|
|
yearPicker.setItemCount(count);
|
|
|
|
dayPicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
|
|
|
|
monthPicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
|
|
|
|
yearPicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
|
|
|
|
ignoreLayout = false;
|
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void requestLayout() {
|
|
|
|
if (ignoreLayout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.requestLayout();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
container.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
|
|
|
FrameLayout titleLayout = new FrameLayout(context);
|
|
|
|
container.addView(titleLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 22, 0, 0, 4));
|
|
|
|
|
|
|
|
TextView titleView = new TextView(context);
|
|
|
|
titleView.setText(LocaleController.getString("ChooseDate", R.string.ChooseDate));
|
|
|
|
titleView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
|
|
|
titleView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
titleLayout.addView(titleView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 12, 0, 0));
|
|
|
|
titleView.setOnTouchListener((v, event) -> true);
|
|
|
|
|
|
|
|
LinearLayout linearLayout = new LinearLayout(context);
|
|
|
|
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
linearLayout.setWeightSum(1.0f);
|
|
|
|
container.addView(linearLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
|
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
TextView buttonTextView = new TextView(context) {
|
|
|
|
@Override
|
|
|
|
public CharSequence getAccessibilityClassName() {
|
|
|
|
return Button.class.getName();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
linearLayout.addView(dayPicker, LayoutHelper.createLinear(0, 54 * 5, 0.25f));
|
|
|
|
dayPicker.setMinValue(1);
|
|
|
|
dayPicker.setMaxValue(31);
|
|
|
|
dayPicker.setWrapSelectorWheel(false);
|
|
|
|
dayPicker.setFormatter(value -> "" + value);
|
|
|
|
final NumberPicker.OnValueChangeListener onValueChangeListener = (picker, oldVal, newVal) -> {
|
2020-10-01 03:59:32 +02:00
|
|
|
try {
|
|
|
|
container.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
checkCalendarDate(minDate, dayPicker, monthPicker, yearPicker);
|
|
|
|
};
|
|
|
|
dayPicker.setOnValueChangedListener(onValueChangeListener);
|
|
|
|
|
|
|
|
monthPicker.setMinValue(0);
|
|
|
|
monthPicker.setMaxValue(11);
|
|
|
|
monthPicker.setWrapSelectorWheel(false);
|
|
|
|
linearLayout.addView(monthPicker, LayoutHelper.createLinear(0, 54 * 5, 0.5f));
|
|
|
|
monthPicker.setFormatter(value -> {
|
|
|
|
switch (value) {
|
|
|
|
case 0: {
|
|
|
|
return LocaleController.getString("January", R.string.January);
|
|
|
|
}
|
|
|
|
case 1: {
|
|
|
|
return LocaleController.getString("February", R.string.February);
|
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
return LocaleController.getString("March", R.string.March);
|
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
return LocaleController.getString("April", R.string.April);
|
|
|
|
}
|
|
|
|
case 4: {
|
|
|
|
return LocaleController.getString("May", R.string.May);
|
|
|
|
}
|
|
|
|
case 5: {
|
|
|
|
return LocaleController.getString("June", R.string.June);
|
|
|
|
}
|
|
|
|
case 6: {
|
|
|
|
return LocaleController.getString("July", R.string.July);
|
|
|
|
}
|
|
|
|
case 7: {
|
|
|
|
return LocaleController.getString("August", R.string.August);
|
|
|
|
}
|
|
|
|
case 8: {
|
|
|
|
return LocaleController.getString("September", R.string.September);
|
|
|
|
}
|
|
|
|
case 9: {
|
|
|
|
return LocaleController.getString("October", R.string.October);
|
|
|
|
}
|
|
|
|
case 10: {
|
|
|
|
return LocaleController.getString("November", R.string.November);
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
default: {
|
|
|
|
return LocaleController.getString("December", R.string.December);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
monthPicker.setOnValueChangedListener(onValueChangeListener);
|
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
calendar.setTimeInMillis(minDate);
|
|
|
|
int minYear = calendar.get(Calendar.YEAR);
|
|
|
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
|
int maxYear = calendar.get(Calendar.YEAR);
|
|
|
|
|
|
|
|
yearPicker.setMinValue(minYear);
|
|
|
|
yearPicker.setMaxValue(maxYear);
|
|
|
|
yearPicker.setWrapSelectorWheel(false);
|
|
|
|
yearPicker.setFormatter(value -> String.format("%02d", value));
|
|
|
|
linearLayout.addView(yearPicker, LayoutHelper.createLinear(0, 54 * 5, 0.25f));
|
|
|
|
yearPicker.setOnValueChangedListener(onValueChangeListener);
|
|
|
|
|
|
|
|
dayPicker.setValue(31);
|
|
|
|
monthPicker.setValue(12);
|
|
|
|
yearPicker.setValue(maxYear);
|
|
|
|
|
|
|
|
checkCalendarDate(minDate, dayPicker, monthPicker, yearPicker);
|
|
|
|
|
|
|
|
buttonTextView.setPadding(AndroidUtilities.dp(34), 0, AndroidUtilities.dp(34), 0);
|
|
|
|
buttonTextView.setGravity(Gravity.CENTER);
|
|
|
|
buttonTextView.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
|
|
|
|
buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
buttonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
buttonTextView.setText(LocaleController.getString("JumpToDate", R.string.JumpToDate));
|
|
|
|
buttonTextView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
|
|
|
|
container.addView(buttonTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM, 16, 15, 16, 16));
|
|
|
|
buttonTextView.setOnClickListener(v -> {
|
|
|
|
checkCalendarDate(minDate, dayPicker, monthPicker, yearPicker);
|
|
|
|
calendar.set(Calendar.YEAR, yearPicker.getValue());
|
|
|
|
calendar.set(Calendar.MONTH, monthPicker.getValue());
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, dayPicker.getValue());
|
|
|
|
calendar.set(Calendar.MINUTE, 0);
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
calendar.set(Calendar.SECOND, 0);
|
|
|
|
callback.run((int) (calendar.getTimeInMillis() / 1000));
|
|
|
|
builder.getDismissRunnable().run();
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.setCustomView(container);
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BottomSheet createMuteAlert(BaseFragment fragment, final long dialog_id) {
|
|
|
|
if (fragment == null || fragment.getParentActivity() == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
BottomSheet.Builder builder = new BottomSheet.Builder(fragment.getParentActivity());
|
2019-12-31 14:08:08 +01:00
|
|
|
builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications), true);
|
2015-06-29 19:12:11 +02:00
|
|
|
CharSequence[] items = new CharSequence[]{
|
|
|
|
LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)),
|
|
|
|
LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)),
|
|
|
|
LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)),
|
|
|
|
LocaleController.getString("MuteDisable", R.string.MuteDisable)
|
|
|
|
};
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setItems(items, (dialogInterface, i) -> {
|
2019-05-14 14:08:05 +02:00
|
|
|
int setting;
|
2019-03-03 21:40:48 +01:00
|
|
|
if (i == 0) {
|
2019-05-14 14:08:05 +02:00
|
|
|
setting = NotificationsController.SETTING_MUTE_HOUR;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (i == 1) {
|
2019-05-14 14:08:05 +02:00
|
|
|
setting = NotificationsController.SETTING_MUTE_8_HOURS;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (i == 2) {
|
2019-05-14 14:08:05 +02:00
|
|
|
setting = NotificationsController.SETTING_MUTE_2_DAYS;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else {
|
2019-05-14 14:08:05 +02:00
|
|
|
setting = NotificationsController.SETTING_MUTE_FOREVER;
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
NotificationsController.getInstance(UserConfig.selectedAccount).setDialogNotificationsSettings(dialog_id, setting);
|
2020-09-30 15:48:47 +02:00
|
|
|
if (BulletinFactory.canShowBulletin(fragment)) {
|
|
|
|
BulletinFactory.createMuteBulletin(fragment, setting).show();
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
);
|
|
|
|
return builder.create();
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public static void createReportAlert(final Context context, final long dialog_id, final int messageId, final BaseFragment parentFragment) {
|
2016-03-16 13:26:32 +01:00
|
|
|
if (context == null || parentFragment == null) {
|
2019-01-23 18:03:33 +01:00
|
|
|
return;
|
2016-03-16 13:26:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BottomSheet.Builder builder = new BottomSheet.Builder(context);
|
2019-12-31 14:08:08 +01:00
|
|
|
builder.setTitle(LocaleController.getString("ReportChat", R.string.ReportChat), true);
|
2016-03-16 13:26:32 +01:00
|
|
|
CharSequence[] items = new CharSequence[]{
|
|
|
|
LocaleController.getString("ReportChatSpam", R.string.ReportChatSpam),
|
|
|
|
LocaleController.getString("ReportChatViolence", R.string.ReportChatViolence),
|
2019-01-23 18:03:33 +01:00
|
|
|
LocaleController.getString("ReportChatChild", R.string.ReportChatChild),
|
2016-03-16 13:26:32 +01:00
|
|
|
LocaleController.getString("ReportChatPornography", R.string.ReportChatPornography),
|
|
|
|
LocaleController.getString("ReportChatOther", R.string.ReportChatOther)
|
|
|
|
};
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setItems(items, (dialogInterface, i) -> {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (i == 4) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("dialog_id", dialog_id);
|
|
|
|
args.putLong("message_id", messageId);
|
|
|
|
parentFragment.presentFragment(new ReportOtherActivity(args));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TLObject req;
|
|
|
|
TLRPC.InputPeer peer = MessagesController.getInstance(UserConfig.selectedAccount).getInputPeer((int) dialog_id);
|
|
|
|
if (messageId != 0) {
|
|
|
|
TLRPC.TL_messages_report request = new TLRPC.TL_messages_report();
|
|
|
|
request.peer = peer;
|
|
|
|
request.id.add(messageId);
|
|
|
|
if (i == 0) {
|
|
|
|
request.reason = new TLRPC.TL_inputReportReasonSpam();
|
|
|
|
} else if (i == 1) {
|
|
|
|
request.reason = new TLRPC.TL_inputReportReasonViolence();
|
|
|
|
} else if (i == 2) {
|
|
|
|
request.reason = new TLRPC.TL_inputReportReasonChildAbuse();
|
|
|
|
} else if (i == 3) {
|
|
|
|
request.reason = new TLRPC.TL_inputReportReasonPornography();
|
|
|
|
}
|
|
|
|
req = request;
|
|
|
|
} else {
|
|
|
|
TLRPC.TL_account_reportPeer request = new TLRPC.TL_account_reportPeer();
|
|
|
|
request.peer = peer;
|
|
|
|
if (i == 0) {
|
|
|
|
request.reason = new TLRPC.TL_inputReportReasonSpam();
|
|
|
|
} else if (i == 1) {
|
|
|
|
request.reason = new TLRPC.TL_inputReportReasonViolence();
|
|
|
|
} else if (i == 2) {
|
|
|
|
request.reason = new TLRPC.TL_inputReportReasonChildAbuse();
|
|
|
|
} else if (i == 3) {
|
|
|
|
request.reason = new TLRPC.TL_inputReportReasonPornography();
|
|
|
|
}
|
|
|
|
req = request;
|
|
|
|
}
|
|
|
|
ConnectionsManager.getInstance(UserConfig.selectedAccount).sendRequest(req, (response, error) -> {
|
2018-08-27 10:33:11 +02:00
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
});
|
|
|
|
Toast.makeText(context, LocaleController.getString("ReportChatSent", R.string.ReportChatSent), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2016-03-16 13:26:32 +01:00
|
|
|
);
|
2019-01-23 18:03:33 +01:00
|
|
|
BottomSheet sheet = builder.create();
|
|
|
|
parentFragment.showDialog(sheet);
|
2016-03-16 13:26:32 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private static String getFloodWaitString(String error) {
|
|
|
|
int time = Utilities.parseInt(error);
|
|
|
|
String timeString;
|
|
|
|
if (time < 60) {
|
|
|
|
timeString = LocaleController.formatPluralString("Seconds", time);
|
|
|
|
} else {
|
|
|
|
timeString = LocaleController.formatPluralString("Minutes", time / 60);
|
|
|
|
}
|
|
|
|
return LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString);
|
|
|
|
}
|
|
|
|
|
2016-03-16 13:26:32 +01:00
|
|
|
public static void showFloodWaitAlert(String error, final BaseFragment fragment) {
|
|
|
|
if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int time = Utilities.parseInt(error);
|
|
|
|
String timeString;
|
|
|
|
if (time < 60) {
|
|
|
|
timeString = LocaleController.formatPluralString("Seconds", time);
|
|
|
|
} else {
|
|
|
|
timeString = LocaleController.formatPluralString("Minutes", time / 60);
|
|
|
|
}
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2017-03-31 01:58:05 +02:00
|
|
|
fragment.showDialog(builder.create(), true, null);
|
2016-03-16 13:26:32 +01:00
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public static void showSendMediaAlert(int result, final BaseFragment fragment) {
|
|
|
|
if (result == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
if (result == 1) {
|
|
|
|
builder.setMessage(LocaleController.getString("ErrorSendRestrictedStickers", R.string.ErrorSendRestrictedStickers));
|
|
|
|
} else if (result == 2) {
|
|
|
|
builder.setMessage(LocaleController.getString("ErrorSendRestrictedMedia", R.string.ErrorSendRestrictedMedia));
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (result == 3) {
|
|
|
|
builder.setMessage(LocaleController.getString("ErrorSendRestrictedPolls", R.string.ErrorSendRestrictedPolls));
|
|
|
|
} else if (result == 4) {
|
|
|
|
builder.setMessage(LocaleController.getString("ErrorSendRestrictedStickersAll", R.string.ErrorSendRestrictedStickersAll));
|
|
|
|
} else if (result == 5) {
|
|
|
|
builder.setMessage(LocaleController.getString("ErrorSendRestrictedMediaAll", R.string.ErrorSendRestrictedMediaAll));
|
|
|
|
} else if (result == 6) {
|
|
|
|
builder.setMessage(LocaleController.getString("ErrorSendRestrictedPollsAll", R.string.ErrorSendRestrictedPollsAll));
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
fragment.showDialog(builder.create(), true, null);
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
public static void showAddUserAlert(String error, final BaseFragment fragment, boolean isChannel, TLObject request) {
|
2015-09-24 22:52:02 +02:00
|
|
|
if (error == null || fragment == null || fragment.getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
switch (error) {
|
|
|
|
case "PEER_FLOOD":
|
|
|
|
builder.setMessage(LocaleController.getString("NobodyLikesSpam2", R.string.NobodyLikesSpam2));
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setNegativeButton(LocaleController.getString("MoreInfo", R.string.MoreInfo), (dialogInterface, i) -> MessagesController.getInstance(fragment.getCurrentAccount()).openByUserName("spambot", fragment, 1));
|
2015-09-24 22:52:02 +02:00
|
|
|
break;
|
|
|
|
case "USER_BLOCKED":
|
2015-10-29 18:10:07 +01:00
|
|
|
case "USER_BOT":
|
2015-09-24 22:52:02 +02:00
|
|
|
case "USER_ID_INVALID":
|
2015-11-26 22:04:02 +01:00
|
|
|
if (isChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelUserCantAdd", R.string.ChannelUserCantAdd));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("GroupUserCantAdd", R.string.GroupUserCantAdd));
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
break;
|
|
|
|
case "USERS_TOO_MUCH":
|
2015-11-26 22:04:02 +01:00
|
|
|
if (isChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelUserAddLimit", R.string.ChannelUserAddLimit));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("GroupUserAddLimit", R.string.GroupUserAddLimit));
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
break;
|
|
|
|
case "USER_NOT_MUTUAL_CONTACT":
|
2015-11-26 22:04:02 +01:00
|
|
|
if (isChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelUserLeftError", R.string.ChannelUserLeftError));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("GroupUserLeftError", R.string.GroupUserLeftError));
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
break;
|
2015-10-29 18:10:07 +01:00
|
|
|
case "ADMINS_TOO_MUCH":
|
2015-11-26 22:04:02 +01:00
|
|
|
if (isChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelUserCantAdmin", R.string.ChannelUserCantAdmin));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("GroupUserCantAdmin", R.string.GroupUserCantAdmin));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "BOTS_TOO_MUCH":
|
|
|
|
if (isChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelUserCantBot", R.string.ChannelUserCantBot));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("GroupUserCantBot", R.string.GroupUserCantBot));
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
break;
|
2016-03-06 02:49:31 +01:00
|
|
|
case "USER_PRIVACY_RESTRICTED":
|
|
|
|
if (isChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("InviteToChannelError", R.string.InviteToChannelError));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("InviteToGroupError", R.string.InviteToGroupError));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "USERS_TOO_FEW":
|
|
|
|
builder.setMessage(LocaleController.getString("CreateGroupError", R.string.CreateGroupError));
|
|
|
|
break;
|
2016-04-22 15:49:00 +02:00
|
|
|
case "USER_RESTRICTED":
|
|
|
|
builder.setMessage(LocaleController.getString("UserRestricted", R.string.UserRestricted));
|
|
|
|
break;
|
2017-03-31 01:58:05 +02:00
|
|
|
case "YOU_BLOCKED_USER":
|
|
|
|
builder.setMessage(LocaleController.getString("YouBlockedUser", R.string.YouBlockedUser));
|
|
|
|
break;
|
2017-07-08 18:32:04 +02:00
|
|
|
case "CHAT_ADMIN_BAN_REQUIRED":
|
|
|
|
case "USER_KICKED":
|
2020-03-30 14:00:09 +02:00
|
|
|
if (request instanceof TLRPC.TL_channels_inviteToChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("AddUserErrorBlacklisted", R.string.AddUserErrorBlacklisted));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("AddAdminErrorBlacklisted", R.string.AddAdminErrorBlacklisted));
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
break;
|
|
|
|
case "CHAT_ADMIN_INVITE_REQUIRED":
|
|
|
|
builder.setMessage(LocaleController.getString("AddAdminErrorNotAMember", R.string.AddAdminErrorNotAMember));
|
|
|
|
break;
|
|
|
|
case "USER_ADMIN_INVALID":
|
|
|
|
builder.setMessage(LocaleController.getString("AddBannedErrorAdmin", R.string.AddBannedErrorAdmin));
|
|
|
|
break;
|
2019-07-18 15:01:39 +02:00
|
|
|
case "CHANNELS_ADMIN_PUBLIC_TOO_MUCH":
|
|
|
|
builder.setMessage(LocaleController.getString("PublicChannelsTooMuch", R.string.PublicChannelsTooMuch));
|
|
|
|
break;
|
|
|
|
case "CHANNELS_ADMIN_LOCATED_TOO_MUCH":
|
|
|
|
builder.setMessage(LocaleController.getString("LocatedChannelsTooMuch", R.string.LocatedChannelsTooMuch));
|
|
|
|
break;
|
|
|
|
case "CHANNELS_TOO_MUCH":
|
2019-12-31 14:08:08 +01:00
|
|
|
builder.setTitle(LocaleController.getString("ChannelTooMuchTitle", R.string.ChannelTooMuchTitle));
|
2019-09-10 12:56:11 +02:00
|
|
|
if (request instanceof TLRPC.TL_channels_createChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelTooMuch", R.string.ChannelTooMuch));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelTooMuchJoin", R.string.ChannelTooMuchJoin));
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
break;
|
2019-12-31 14:08:08 +01:00
|
|
|
case "USER_CHANNELS_TOO_MUCH":
|
|
|
|
builder.setTitle(LocaleController.getString("ChannelTooMuchTitle", R.string.ChannelTooMuchTitle));
|
|
|
|
builder.setMessage(LocaleController.getString("UserChannelTooMuchJoin", R.string.UserChannelTooMuchJoin));
|
|
|
|
break;
|
2016-04-22 15:49:00 +02:00
|
|
|
default:
|
2017-07-08 18:32:04 +02:00
|
|
|
builder.setMessage(LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error);
|
2016-04-22 15:49:00 +02:00
|
|
|
break;
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2017-03-31 01:58:05 +02:00
|
|
|
fragment.showDialog(builder.create(), true, null);
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public static Dialog createColorSelectDialog(Activity parentActivity, final long dialog_id, final int globalType, final Runnable onSelect) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int currentColor;
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
2019-01-23 18:03:33 +01:00
|
|
|
if (dialog_id != 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (preferences.contains("color_" + dialog_id)) {
|
|
|
|
currentColor = preferences.getInt("color_" + dialog_id, 0xff0000ff);
|
|
|
|
} else {
|
|
|
|
if ((int) dialog_id < 0) {
|
|
|
|
currentColor = preferences.getInt("GroupLed", 0xff0000ff);
|
|
|
|
} else {
|
|
|
|
currentColor = preferences.getInt("MessagesLed", 0xff0000ff);
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (globalType == NotificationsController.TYPE_PRIVATE) {
|
|
|
|
currentColor = preferences.getInt("MessagesLed", 0xff0000ff);
|
|
|
|
} else if (globalType == NotificationsController.TYPE_GROUP) {
|
|
|
|
currentColor = preferences.getInt("GroupLed", 0xff0000ff);
|
|
|
|
} else {
|
|
|
|
currentColor = preferences.getInt("ChannelLed", 0xff0000ff);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
final LinearLayout linearLayout = new LinearLayout(parentActivity);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
2019-05-14 14:08:05 +02:00
|
|
|
String[] descriptions = new String[]{LocaleController.getString("ColorRed", R.string.ColorRed),
|
2017-03-31 01:58:05 +02:00
|
|
|
LocaleController.getString("ColorOrange", R.string.ColorOrange),
|
|
|
|
LocaleController.getString("ColorYellow", R.string.ColorYellow),
|
|
|
|
LocaleController.getString("ColorGreen", R.string.ColorGreen),
|
|
|
|
LocaleController.getString("ColorCyan", R.string.ColorCyan),
|
|
|
|
LocaleController.getString("ColorBlue", R.string.ColorBlue),
|
|
|
|
LocaleController.getString("ColorViolet", R.string.ColorViolet),
|
|
|
|
LocaleController.getString("ColorPink", R.string.ColorPink),
|
|
|
|
LocaleController.getString("ColorWhite", R.string.ColorWhite)};
|
2019-05-14 14:08:05 +02:00
|
|
|
final int[] selectedColor = new int[]{currentColor};
|
2017-03-31 01:58:05 +02:00
|
|
|
for (int a = 0; a < 9; a++) {
|
|
|
|
RadioColorCell cell = new RadioColorCell(parentActivity);
|
|
|
|
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
|
|
|
cell.setTag(a);
|
|
|
|
cell.setCheckColor(TextColorCell.colors[a], TextColorCell.colors[a]);
|
|
|
|
cell.setTextAndValue(descriptions[a], currentColor == TextColorCell.colorsToSave[a]);
|
|
|
|
linearLayout.addView(cell);
|
2018-08-27 10:33:11 +02:00
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
int count = linearLayout.getChildCount();
|
|
|
|
for (int a1 = 0; a1 < count; a1++) {
|
|
|
|
RadioColorCell cell1 = (RadioColorCell) linearLayout.getChildAt(a1);
|
|
|
|
cell1.setChecked(cell1 == v, true);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
selectedColor[0] = TextColorCell.colorsToSave[(Integer) v.getTag()];
|
2017-03-31 01:58:05 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
|
|
|
|
builder.setView(linearLayout);
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), (dialogInterface, which) -> {
|
|
|
|
final SharedPreferences preferences1 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
|
|
|
SharedPreferences.Editor editor = preferences1.edit();
|
2019-01-23 18:03:33 +01:00
|
|
|
if (dialog_id != 0) {
|
|
|
|
editor.putInt("color_" + dialog_id, selectedColor[0]);
|
|
|
|
} else if (globalType == NotificationsController.TYPE_PRIVATE) {
|
2018-08-27 10:33:11 +02:00
|
|
|
editor.putInt("MessagesLed", selectedColor[0]);
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (globalType == NotificationsController.TYPE_GROUP) {
|
2018-08-27 10:33:11 +02:00
|
|
|
editor.putInt("GroupLed", selectedColor[0]);
|
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
editor.putInt("ChannelLed", selectedColor[0]);
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
editor.commit();
|
|
|
|
if (onSelect != null) {
|
|
|
|
onSelect.run();
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
});
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled), (dialog, which) -> {
|
|
|
|
final SharedPreferences preferences12 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
|
|
|
SharedPreferences.Editor editor = preferences12.edit();
|
2019-01-23 18:03:33 +01:00
|
|
|
if (dialog_id != 0) {
|
|
|
|
editor.putInt("color_" + dialog_id, 0);
|
|
|
|
} else if (globalType == NotificationsController.TYPE_PRIVATE) {
|
2018-08-27 10:33:11 +02:00
|
|
|
editor.putInt("MessagesLed", 0);
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (globalType == NotificationsController.TYPE_GROUP) {
|
2018-08-27 10:33:11 +02:00
|
|
|
editor.putInt("GroupLed", 0);
|
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
editor.putInt("ChannelLed", 0);
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
editor.commit();
|
|
|
|
if (onSelect != null) {
|
|
|
|
onSelect.run();
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
});
|
2019-01-23 18:03:33 +01:00
|
|
|
if (dialog_id != 0) {
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Default", R.string.Default), (dialog, which) -> {
|
|
|
|
final SharedPreferences preferences13 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
|
|
|
SharedPreferences.Editor editor = preferences13.edit();
|
|
|
|
editor.remove("color_" + dialog_id);
|
|
|
|
editor.commit();
|
|
|
|
if (onSelect != null) {
|
|
|
|
onSelect.run();
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return builder.create();
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public static Dialog createVibrationSelectDialog(Activity parentActivity, final long dialog_id, final boolean globalGroup, final boolean globalAll, final Runnable onSelect) {
|
2017-03-31 01:58:05 +02:00
|
|
|
String prefix;
|
|
|
|
if (dialog_id != 0) {
|
|
|
|
prefix = "vibrate_";
|
|
|
|
} else {
|
|
|
|
prefix = globalGroup ? "vibrate_group" : "vibrate_messages";
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
return createVibrationSelectDialog(parentActivity, dialog_id, prefix, onSelect);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public static Dialog createVibrationSelectDialog(Activity parentActivity, final long dialog_id, final String prefKeyPrefix, final Runnable onSelect) {
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
2019-05-14 14:08:05 +02:00
|
|
|
final int[] selected = new int[1];
|
|
|
|
String[] descriptions;
|
2017-03-31 01:58:05 +02:00
|
|
|
if (dialog_id != 0) {
|
|
|
|
selected[0] = preferences.getInt(prefKeyPrefix + dialog_id, 0);
|
|
|
|
if (selected[0] == 3) {
|
|
|
|
selected[0] = 2;
|
|
|
|
} else if (selected[0] == 2) {
|
|
|
|
selected[0] = 3;
|
|
|
|
}
|
|
|
|
descriptions = new String[]{
|
|
|
|
LocaleController.getString("VibrationDefault", R.string.VibrationDefault),
|
|
|
|
LocaleController.getString("Short", R.string.Short),
|
|
|
|
LocaleController.getString("Long", R.string.Long),
|
|
|
|
LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled)
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
selected[0] = preferences.getInt(prefKeyPrefix, 0);
|
|
|
|
if (selected[0] == 0) {
|
|
|
|
selected[0] = 1;
|
|
|
|
} else if (selected[0] == 1) {
|
|
|
|
selected[0] = 2;
|
|
|
|
} else if (selected[0] == 2) {
|
|
|
|
selected[0] = 0;
|
|
|
|
}
|
|
|
|
descriptions = new String[]{
|
|
|
|
LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
|
|
|
|
LocaleController.getString("VibrationDefault", R.string.VibrationDefault),
|
|
|
|
LocaleController.getString("Short", R.string.Short),
|
|
|
|
LocaleController.getString("Long", R.string.Long),
|
|
|
|
LocaleController.getString("OnlyIfSilent", R.string.OnlyIfSilent)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
final LinearLayout linearLayout = new LinearLayout(parentActivity);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
2019-01-23 18:03:33 +01:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
for (int a = 0; a < descriptions.length; a++) {
|
|
|
|
RadioColorCell cell = new RadioColorCell(parentActivity);
|
|
|
|
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
|
|
|
cell.setTag(a);
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
2017-03-31 01:58:05 +02:00
|
|
|
cell.setTextAndValue(descriptions[a], selected[0] == a);
|
|
|
|
linearLayout.addView(cell);
|
2018-08-27 10:33:11 +02:00
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
selected[0] = (Integer) v.getTag();
|
|
|
|
|
|
|
|
final SharedPreferences preferences1 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
|
|
|
SharedPreferences.Editor editor = preferences1.edit();
|
|
|
|
if (dialog_id != 0) {
|
|
|
|
if (selected[0] == 0) {
|
|
|
|
editor.putInt(prefKeyPrefix + dialog_id, 0);
|
|
|
|
} else if (selected[0] == 1) {
|
|
|
|
editor.putInt(prefKeyPrefix + dialog_id, 1);
|
|
|
|
} else if (selected[0] == 2) {
|
|
|
|
editor.putInt(prefKeyPrefix + dialog_id, 3);
|
|
|
|
} else if (selected[0] == 3) {
|
|
|
|
editor.putInt(prefKeyPrefix + dialog_id, 2);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
|
|
|
if (selected[0] == 0) {
|
|
|
|
editor.putInt(prefKeyPrefix, 2);
|
|
|
|
} else if (selected[0] == 1) {
|
|
|
|
editor.putInt(prefKeyPrefix, 0);
|
|
|
|
} else if (selected[0] == 2) {
|
|
|
|
editor.putInt(prefKeyPrefix, 1);
|
|
|
|
} else if (selected[0] == 3) {
|
|
|
|
editor.putInt(prefKeyPrefix, 3);
|
|
|
|
} else if (selected[0] == 4) {
|
|
|
|
editor.putInt(prefKeyPrefix, 4);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
editor.commit();
|
2019-01-23 18:03:33 +01:00
|
|
|
builder.getDismissRunnable().run();
|
2018-08-27 10:33:11 +02:00
|
|
|
if (onSelect != null) {
|
|
|
|
onSelect.run();
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate));
|
|
|
|
builder.setView(linearLayout);
|
|
|
|
builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
return builder.create();
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public static Dialog createLocationUpdateDialog(final Activity parentActivity, TLRPC.User user, final MessagesStorage.IntCallback callback) {
|
2019-05-14 14:08:05 +02:00
|
|
|
final int[] selected = new int[1];
|
2017-12-08 18:35:59 +01:00
|
|
|
|
|
|
|
String[] descriptions = new String[]{
|
|
|
|
LocaleController.getString("SendLiveLocationFor15m", R.string.SendLiveLocationFor15m),
|
|
|
|
LocaleController.getString("SendLiveLocationFor1h", R.string.SendLiveLocationFor1h),
|
|
|
|
LocaleController.getString("SendLiveLocationFor8h", R.string.SendLiveLocationFor8h),
|
|
|
|
};
|
|
|
|
|
|
|
|
final LinearLayout linearLayout = new LinearLayout(parentActivity);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
|
|
|
TextView titleTextView = new TextView(parentActivity);
|
|
|
|
if (user != null) {
|
|
|
|
titleTextView.setText(LocaleController.formatString("LiveLocationAlertPrivate", R.string.LiveLocationAlertPrivate, UserObject.getFirstName(user)));
|
|
|
|
} else {
|
|
|
|
titleTextView.setText(LocaleController.getString("LiveLocationAlertGroup", R.string.LiveLocationAlertGroup));
|
|
|
|
}
|
|
|
|
titleTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
titleTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
|
|
|
linearLayout.addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 0, 24, 8));
|
|
|
|
|
|
|
|
for (int a = 0; a < descriptions.length; a++) {
|
|
|
|
RadioColorCell cell = new RadioColorCell(parentActivity);
|
|
|
|
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
|
|
|
cell.setTag(a);
|
|
|
|
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
|
|
|
cell.setTextAndValue(descriptions[a], selected[0] == a);
|
|
|
|
linearLayout.addView(cell);
|
2018-08-27 10:33:11 +02:00
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
int num = (Integer) v.getTag();
|
|
|
|
selected[0] = num;
|
|
|
|
int count = linearLayout.getChildCount();
|
|
|
|
for (int a1 = 0; a1 < count; a1++) {
|
|
|
|
View child = linearLayout.getChildAt(a1);
|
|
|
|
if (child instanceof RadioColorCell) {
|
|
|
|
((RadioColorCell) child).setChecked(child == v, true);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
2019-07-18 15:01:39 +02:00
|
|
|
builder.setTopImage(new ShareLocationDrawable(parentActivity, 0), Theme.getColor(Theme.key_dialogTopBackground));
|
2017-12-08 18:35:59 +01:00
|
|
|
builder.setView(linearLayout);
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("ShareFile", R.string.ShareFile), (dialog, which) -> {
|
|
|
|
int time;
|
|
|
|
if (selected[0] == 0) {
|
|
|
|
time = 15 * 60;
|
|
|
|
} else if (selected[0] == 1) {
|
|
|
|
time = 60 * 60;
|
|
|
|
} else {
|
|
|
|
time = 8 * 60 * 60;
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
callback.run(time);
|
2017-12-08 18:35:59 +01:00
|
|
|
});
|
|
|
|
builder.setNeutralButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
return builder.create();
|
|
|
|
}
|
|
|
|
|
2020-10-30 11:26:29 +01:00
|
|
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
|
|
public static AlertDialog.Builder createBackgroundLocationPermissionDialog(Activity activity, TLRPC.User selfUser, Runnable cancelRunnable) {
|
|
|
|
if (activity == null || Build.VERSION.SDK_INT < 29) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
|
String svg = RLottieDrawable.readRes(null, Theme.getCurrentTheme().isDark() ? R.raw.permission_map_dark : R.raw.permission_map);
|
|
|
|
String pinSvg = RLottieDrawable.readRes(null, Theme.getCurrentTheme().isDark() ? R.raw.permission_pin_dark : R.raw.permission_pin);
|
|
|
|
FrameLayout frameLayout = new FrameLayout(activity);
|
|
|
|
frameLayout.setClipToOutline(true);
|
|
|
|
frameLayout.setOutlineProvider(new ViewOutlineProvider() {
|
|
|
|
@Override
|
|
|
|
public void getOutline(View view, Outline outline) {
|
|
|
|
outline.setRoundRect(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight() + AndroidUtilities.dp(6), AndroidUtilities.dp(6));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
View background = new View(activity);
|
|
|
|
background.setBackground(SvgHelper.getDrawable(svg));
|
|
|
|
frameLayout.addView(background, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 0));
|
|
|
|
|
|
|
|
View pin = new View(activity);
|
|
|
|
pin.setBackground(SvgHelper.getDrawable(pinSvg));
|
|
|
|
frameLayout.addView(pin, LayoutHelper.createFrame(60, 82, Gravity.CENTER, 0, 0, 0, 0));
|
|
|
|
|
|
|
|
BackupImageView imageView = new BackupImageView(activity);
|
|
|
|
imageView.setRoundRadius(AndroidUtilities.dp(26));
|
|
|
|
imageView.setImage(ImageLocation.getForUser(selfUser, false), "50_50", (Drawable) null, selfUser);
|
|
|
|
frameLayout.addView(imageView, LayoutHelper.createFrame(52, 52, Gravity.CENTER, 0, 0, 0, 11));
|
|
|
|
|
|
|
|
builder.setTopView(frameLayout);
|
|
|
|
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("PermissionBackgroundLocation", R.string.PermissionBackgroundLocation)));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> {
|
|
|
|
if (activity.checkSelfPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
activity.requestPermissions(new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION}, 30);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), ((dialog, which) -> cancelRunnable.run()));
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AlertDialog.Builder createContactsPermissionDialog(Activity parentActivity, MessagesStorage.IntCallback callback) {
|
2018-07-30 04:07:02 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
builder.setTopImage(R.drawable.permissions_contacts, Theme.getColor(Theme.key_dialogTopBackground));
|
|
|
|
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("ContactsPermissionAlert", R.string.ContactsPermissionAlert)));
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("ContactsPermissionAlertContinue", R.string.ContactsPermissionAlertContinue), (dialog, which) -> callback.run(1));
|
|
|
|
builder.setNegativeButton(LocaleController.getString("ContactsPermissionAlertNotNow", R.string.ContactsPermissionAlertNotNow), (dialog, which) -> callback.run(0));
|
2018-07-30 04:07:02 +02:00
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public static Dialog createFreeSpaceDialog(final LaunchActivity parentActivity) {
|
2019-05-14 14:08:05 +02:00
|
|
|
final int[] selected = new int[1];
|
2017-12-08 18:35:59 +01:00
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
if (SharedConfig.keepMedia == 2) {
|
2017-12-08 18:35:59 +01:00
|
|
|
selected[0] = 3;
|
2019-08-22 01:53:26 +02:00
|
|
|
} else if (SharedConfig.keepMedia == 0) {
|
2017-12-08 18:35:59 +01:00
|
|
|
selected[0] = 1;
|
2019-08-22 01:53:26 +02:00
|
|
|
} else if (SharedConfig.keepMedia == 1) {
|
2017-12-08 18:35:59 +01:00
|
|
|
selected[0] = 2;
|
2019-08-22 01:53:26 +02:00
|
|
|
} else if (SharedConfig.keepMedia == 3) {
|
2017-12-08 18:35:59 +01:00
|
|
|
selected[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
String[] descriptions = new String[]{
|
|
|
|
LocaleController.formatPluralString("Days", 3),
|
|
|
|
LocaleController.formatPluralString("Weeks", 1),
|
|
|
|
LocaleController.formatPluralString("Months", 1),
|
|
|
|
LocaleController.getString("LowDiskSpaceNeverRemove", R.string.LowDiskSpaceNeverRemove)
|
|
|
|
};
|
|
|
|
|
|
|
|
final LinearLayout linearLayout = new LinearLayout(parentActivity);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
|
|
|
TextView titleTextView = new TextView(parentActivity);
|
|
|
|
titleTextView.setText(LocaleController.getString("LowDiskSpaceTitle2", R.string.LowDiskSpaceTitle2));
|
|
|
|
titleTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
titleTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
|
|
|
linearLayout.addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 0, 24, 8));
|
|
|
|
|
|
|
|
for (int a = 0; a < descriptions.length; a++) {
|
|
|
|
RadioColorCell cell = new RadioColorCell(parentActivity);
|
|
|
|
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
|
|
|
cell.setTag(a);
|
|
|
|
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
|
|
|
cell.setTextAndValue(descriptions[a], selected[0] == a);
|
|
|
|
linearLayout.addView(cell);
|
2018-08-27 10:33:11 +02:00
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
int num = (Integer) v.getTag();
|
|
|
|
if (num == 0) {
|
|
|
|
selected[0] = 3;
|
|
|
|
} else if (num == 1) {
|
|
|
|
selected[0] = 0;
|
|
|
|
} else if (num == 2) {
|
|
|
|
selected[0] = 1;
|
|
|
|
} else if (num == 3) {
|
|
|
|
selected[0] = 2;
|
|
|
|
}
|
|
|
|
int count = linearLayout.getChildCount();
|
|
|
|
for (int a1 = 0; a1 < count; a1++) {
|
|
|
|
View child = linearLayout.getChildAt(a1);
|
|
|
|
if (child instanceof RadioColorCell) {
|
|
|
|
((RadioColorCell) child).setChecked(child == v, true);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
builder.setTitle(LocaleController.getString("LowDiskSpaceTitle", R.string.LowDiskSpaceTitle));
|
|
|
|
builder.setMessage(LocaleController.getString("LowDiskSpaceMessage", R.string.LowDiskSpaceMessage));
|
|
|
|
builder.setView(linearLayout);
|
2019-08-22 01:53:26 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> SharedConfig.setKeepMedia(selected[0]));
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setNeutralButton(LocaleController.getString("ClearMediaCache", R.string.ClearMediaCache), (dialog, which) -> parentActivity.presentFragment(new CacheControlActivity()));
|
2017-12-08 18:35:59 +01:00
|
|
|
return builder.create();
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public static Dialog createPrioritySelectDialog(Activity parentActivity, final long dialog_id, final int globalType, final Runnable onSelect) {
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
2019-05-14 14:08:05 +02:00
|
|
|
final int[] selected = new int[1];
|
|
|
|
String[] descriptions;
|
2017-03-31 01:58:05 +02:00
|
|
|
if (dialog_id != 0) {
|
|
|
|
selected[0] = preferences.getInt("priority_" + dialog_id, 3);
|
|
|
|
if (selected[0] == 3) {
|
|
|
|
selected[0] = 0;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (selected[0] == 4) {
|
|
|
|
selected[0] = 1;
|
|
|
|
} else if (selected[0] == 5) {
|
|
|
|
selected[0] = 2;
|
|
|
|
} else if (selected[0] == 0) {
|
|
|
|
selected[0] = 3;
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
selected[0] = 4;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
descriptions = new String[]{
|
|
|
|
LocaleController.getString("NotificationsPrioritySettings", R.string.NotificationsPrioritySettings),
|
2018-07-30 04:07:02 +02:00
|
|
|
LocaleController.getString("NotificationsPriorityLow", R.string.NotificationsPriorityLow),
|
|
|
|
LocaleController.getString("NotificationsPriorityMedium", R.string.NotificationsPriorityMedium),
|
2017-03-31 01:58:05 +02:00
|
|
|
LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh),
|
2018-07-30 04:07:02 +02:00
|
|
|
LocaleController.getString("NotificationsPriorityUrgent", R.string.NotificationsPriorityUrgent)
|
2017-03-31 01:58:05 +02:00
|
|
|
};
|
|
|
|
} else {
|
2020-10-30 11:26:29 +01:00
|
|
|
if (globalType == NotificationsController.TYPE_PRIVATE) {
|
|
|
|
selected[0] = preferences.getInt("priority_messages", 1);
|
|
|
|
} else if (globalType == NotificationsController.TYPE_GROUP) {
|
|
|
|
selected[0] = preferences.getInt("priority_group", 1);
|
|
|
|
} else if (globalType == NotificationsController.TYPE_CHANNEL) {
|
|
|
|
selected[0] = preferences.getInt("priority_channel", 1);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (selected[0] == 4) {
|
|
|
|
selected[0] = 0;
|
|
|
|
} else if (selected[0] == 5) {
|
|
|
|
selected[0] = 1;
|
|
|
|
} else if (selected[0] == 0) {
|
|
|
|
selected[0] = 2;
|
|
|
|
} else {
|
|
|
|
selected[0] = 3;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
descriptions = new String[]{
|
2018-07-30 04:07:02 +02:00
|
|
|
LocaleController.getString("NotificationsPriorityLow", R.string.NotificationsPriorityLow),
|
|
|
|
LocaleController.getString("NotificationsPriorityMedium", R.string.NotificationsPriorityMedium),
|
2017-03-31 01:58:05 +02:00
|
|
|
LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh),
|
2018-07-30 04:07:02 +02:00
|
|
|
LocaleController.getString("NotificationsPriorityUrgent", R.string.NotificationsPriorityUrgent)
|
2017-03-31 01:58:05 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
final LinearLayout linearLayout = new LinearLayout(parentActivity);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
2019-01-23 18:03:33 +01:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
for (int a = 0; a < descriptions.length; a++) {
|
|
|
|
RadioColorCell cell = new RadioColorCell(parentActivity);
|
|
|
|
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
|
|
|
cell.setTag(a);
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
2017-03-31 01:58:05 +02:00
|
|
|
cell.setTextAndValue(descriptions[a], selected[0] == a);
|
|
|
|
linearLayout.addView(cell);
|
2018-08-27 10:33:11 +02:00
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
selected[0] = (Integer) v.getTag();
|
|
|
|
|
|
|
|
final SharedPreferences preferences1 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
|
|
|
SharedPreferences.Editor editor = preferences1.edit();
|
|
|
|
if (dialog_id != 0) {
|
|
|
|
int option;
|
|
|
|
if (selected[0] == 0) {
|
|
|
|
option = 3;
|
|
|
|
} else if (selected[0] == 1) {
|
|
|
|
option = 4;
|
|
|
|
} else if (selected[0] == 2) {
|
|
|
|
option = 5;
|
|
|
|
} else if (selected[0] == 3) {
|
|
|
|
option = 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
2018-08-27 10:33:11 +02:00
|
|
|
option = 1;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
editor.putInt("priority_" + dialog_id, option);
|
|
|
|
} else {
|
|
|
|
int option;
|
|
|
|
if (selected[0] == 0) {
|
|
|
|
option = 4;
|
|
|
|
} else if (selected[0] == 1) {
|
|
|
|
option = 5;
|
|
|
|
} else if (selected[0] == 2) {
|
|
|
|
option = 0;
|
|
|
|
} else {
|
|
|
|
option = 1;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (globalType == NotificationsController.TYPE_PRIVATE) {
|
|
|
|
editor.putInt("priority_messages", option);
|
|
|
|
selected[0] = preferences.getInt("priority_messages", 1);
|
|
|
|
} else if (globalType == NotificationsController.TYPE_GROUP) {
|
|
|
|
editor.putInt("priority_group", option);
|
|
|
|
selected[0] = preferences.getInt("priority_group", 1);
|
|
|
|
} else if (globalType == NotificationsController.TYPE_CHANNEL) {
|
|
|
|
editor.putInt("priority_channel", option);
|
|
|
|
selected[0] = preferences.getInt("priority_channel", 1);
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
editor.commit();
|
2019-01-23 18:03:33 +01:00
|
|
|
builder.getDismissRunnable().run();
|
2018-08-27 10:33:11 +02:00
|
|
|
if (onSelect != null) {
|
|
|
|
onSelect.run();
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
builder.setTitle(LocaleController.getString("NotificationsImportance", R.string.NotificationsImportance));
|
2017-03-31 01:58:05 +02:00
|
|
|
builder.setView(linearLayout);
|
|
|
|
builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
return builder.create();
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public static Dialog createPopupSelectDialog(Activity parentActivity, final int globalType, final Runnable onSelect) {
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
2019-05-14 14:08:05 +02:00
|
|
|
final int[] selected = new int[1];
|
2019-01-23 18:03:33 +01:00
|
|
|
if (globalType == NotificationsController.TYPE_PRIVATE) {
|
2017-03-31 01:58:05 +02:00
|
|
|
selected[0] = preferences.getInt("popupAll", 0);
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (globalType == NotificationsController.TYPE_GROUP) {
|
2017-03-31 01:58:05 +02:00
|
|
|
selected[0] = preferences.getInt("popupGroup", 0);
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
|
|
|
selected[0] = preferences.getInt("popupChannel", 0);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
String[] descriptions = new String[]{
|
2017-03-31 01:58:05 +02:00
|
|
|
LocaleController.getString("NoPopup", R.string.NoPopup),
|
|
|
|
LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn),
|
|
|
|
LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff),
|
|
|
|
LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup)
|
|
|
|
};
|
|
|
|
|
|
|
|
final LinearLayout linearLayout = new LinearLayout(parentActivity);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
2019-01-23 18:03:33 +01:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
for (int a = 0; a < descriptions.length; a++) {
|
|
|
|
RadioColorCell cell = new RadioColorCell(parentActivity);
|
|
|
|
cell.setTag(a);
|
|
|
|
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
2017-03-31 01:58:05 +02:00
|
|
|
cell.setTextAndValue(descriptions[a], selected[0] == a);
|
|
|
|
linearLayout.addView(cell);
|
2018-08-27 10:33:11 +02:00
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
selected[0] = (Integer) v.getTag();
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
final SharedPreferences preferences1 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
|
|
|
SharedPreferences.Editor editor = preferences1.edit();
|
2019-01-23 18:03:33 +01:00
|
|
|
if (globalType == NotificationsController.TYPE_PRIVATE) {
|
|
|
|
editor.putInt("popupAll", selected[0]);
|
|
|
|
} else if (globalType == NotificationsController.TYPE_GROUP) {
|
|
|
|
editor.putInt("popupGroup", selected[0]);
|
|
|
|
} else {
|
|
|
|
editor.putInt("popupChannel", selected[0]);
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
editor.commit();
|
|
|
|
builder.getDismissRunnable().run();
|
2018-08-27 10:33:11 +02:00
|
|
|
if (onSelect != null) {
|
|
|
|
onSelect.run();
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
builder.setTitle(LocaleController.getString("PopupNotification", R.string.PopupNotification));
|
|
|
|
builder.setView(linearLayout);
|
|
|
|
builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
return builder.create();
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public static Dialog createSingleChoiceDialog(Activity parentActivity, final String[] options, final String title, final int selected, final DialogInterface.OnClickListener listener) {
|
2017-03-31 01:58:05 +02:00
|
|
|
final LinearLayout linearLayout = new LinearLayout(parentActivity);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
2018-07-30 04:07:02 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
2017-03-31 01:58:05 +02:00
|
|
|
for (int a = 0; a < options.length; a++) {
|
|
|
|
RadioColorCell cell = new RadioColorCell(parentActivity);
|
|
|
|
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
|
|
|
cell.setTag(a);
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
2017-03-31 01:58:05 +02:00
|
|
|
cell.setTextAndValue(options[a], selected == a);
|
|
|
|
linearLayout.addView(cell);
|
2018-08-27 10:33:11 +02:00
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
int sel = (Integer) v.getTag();
|
2019-01-23 18:03:33 +01:00
|
|
|
builder.getDismissRunnable().run();
|
2018-08-27 10:33:11 +02:00
|
|
|
listener.onClick(null, sel);
|
2017-03-31 01:58:05 +02:00
|
|
|
});
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
builder.setTitle(title);
|
|
|
|
builder.setView(linearLayout);
|
|
|
|
builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
return builder.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AlertDialog.Builder createTTLAlert(final Context context, final TLRPC.EncryptedChat encryptedChat) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
builder.setTitle(LocaleController.getString("MessageLifetime", R.string.MessageLifetime));
|
|
|
|
final NumberPicker numberPicker = new NumberPicker(context);
|
|
|
|
numberPicker.setMinValue(0);
|
|
|
|
numberPicker.setMaxValue(20);
|
|
|
|
if (encryptedChat.ttl > 0 && encryptedChat.ttl < 16) {
|
|
|
|
numberPicker.setValue(encryptedChat.ttl);
|
|
|
|
} else if (encryptedChat.ttl == 30) {
|
|
|
|
numberPicker.setValue(16);
|
|
|
|
} else if (encryptedChat.ttl == 60) {
|
|
|
|
numberPicker.setValue(17);
|
|
|
|
} else if (encryptedChat.ttl == 60 * 60) {
|
|
|
|
numberPicker.setValue(18);
|
|
|
|
} else if (encryptedChat.ttl == 60 * 60 * 24) {
|
|
|
|
numberPicker.setValue(19);
|
|
|
|
} else if (encryptedChat.ttl == 60 * 60 * 24 * 7) {
|
|
|
|
numberPicker.setValue(20);
|
|
|
|
} else if (encryptedChat.ttl == 0) {
|
|
|
|
numberPicker.setValue(0);
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
numberPicker.setFormatter(value -> {
|
|
|
|
if (value == 0) {
|
|
|
|
return LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever);
|
|
|
|
} else if (value >= 1 && value < 16) {
|
|
|
|
return LocaleController.formatTTLString(value);
|
|
|
|
} else if (value == 16) {
|
|
|
|
return LocaleController.formatTTLString(30);
|
|
|
|
} else if (value == 17) {
|
|
|
|
return LocaleController.formatTTLString(60);
|
|
|
|
} else if (value == 18) {
|
|
|
|
return LocaleController.formatTTLString(60 * 60);
|
|
|
|
} else if (value == 19) {
|
|
|
|
return LocaleController.formatTTLString(60 * 60 * 24);
|
|
|
|
} else if (value == 20) {
|
|
|
|
return LocaleController.formatTTLString(60 * 60 * 24 * 7);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
return "";
|
2017-03-31 01:58:05 +02:00
|
|
|
});
|
|
|
|
builder.setView(numberPicker);
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), (dialog, which) -> {
|
|
|
|
int oldValue = encryptedChat.ttl;
|
|
|
|
which = numberPicker.getValue();
|
|
|
|
if (which >= 0 && which < 16) {
|
|
|
|
encryptedChat.ttl = which;
|
|
|
|
} else if (which == 16) {
|
|
|
|
encryptedChat.ttl = 30;
|
|
|
|
} else if (which == 17) {
|
|
|
|
encryptedChat.ttl = 60;
|
|
|
|
} else if (which == 18) {
|
|
|
|
encryptedChat.ttl = 60 * 60;
|
|
|
|
} else if (which == 19) {
|
|
|
|
encryptedChat.ttl = 60 * 60 * 24;
|
|
|
|
} else if (which == 20) {
|
|
|
|
encryptedChat.ttl = 60 * 60 * 24 * 7;
|
|
|
|
}
|
|
|
|
if (oldValue != encryptedChat.ttl) {
|
|
|
|
SecretChatHelper.getInstance(UserConfig.selectedAccount).sendTTLMessage(encryptedChat, null);
|
|
|
|
MessagesStorage.getInstance(UserConfig.selectedAccount).updateEncryptedChatTTL(encryptedChat);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return builder;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
public interface AccountSelectDelegate {
|
|
|
|
void didSelectAccount(int account);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AlertDialog createAccountSelectDialog(Activity parentActivity, final AccountSelectDelegate delegate) {
|
|
|
|
if (UserConfig.getActivatedAccountsCount() < 2) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
final Runnable dismissRunnable = builder.getDismissRunnable();
|
|
|
|
final AlertDialog[] alertDialog = new AlertDialog[1];
|
|
|
|
|
|
|
|
final LinearLayout linearLayout = new LinearLayout(parentActivity);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
|
|
|
|
TLRPC.User u = UserConfig.getInstance(a).getCurrentUser();
|
|
|
|
if (u != null) {
|
|
|
|
AccountSelectCell cell = new AccountSelectCell(parentActivity);
|
|
|
|
cell.setAccount(a, false);
|
|
|
|
cell.setPadding(AndroidUtilities.dp(14), 0, AndroidUtilities.dp(14), 0);
|
|
|
|
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
2019-01-23 18:03:33 +01:00
|
|
|
linearLayout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
|
2018-08-27 10:33:11 +02:00
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
if (alertDialog[0] != null) {
|
|
|
|
alertDialog[0].setOnDismissListener(null);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
dismissRunnable.run();
|
|
|
|
AccountSelectCell cell1 = (AccountSelectCell) v;
|
|
|
|
delegate.didSelectAccount(cell1.getAccountNumber());
|
2018-07-30 04:07:02 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.setTitle(LocaleController.getString("SelectAccount", R.string.SelectAccount));
|
|
|
|
builder.setView(linearLayout);
|
|
|
|
builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
return alertDialog[0] = builder.create();
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
// public static AlertDialog createExpireDateAlert(final Context context, final boolean month, final int[] result, final Runnable callback) {
|
|
|
|
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
// builder.setTitle(month ? LocaleController.getString("PaymentCardExpireDateMonth", R.string.PaymentCardExpireDateMonth) : LocaleController.getString("PaymentCardExpireDateYear", R.string.PaymentCardExpireDateYear));
|
|
|
|
// final NumberPicker numberPicker = new NumberPicker(context);
|
|
|
|
// final int currentYear;
|
|
|
|
// if (month) {
|
|
|
|
// numberPicker.setMinValue(1);
|
|
|
|
// numberPicker.setMaxValue(12);
|
|
|
|
// currentYear = 0;
|
|
|
|
// } else {
|
|
|
|
// Calendar rightNow = Calendar.getInstance();
|
|
|
|
// currentYear = rightNow.get(Calendar.YEAR);
|
|
|
|
// numberPicker.setMinValue(0);
|
|
|
|
// numberPicker.setMaxValue(30);
|
|
|
|
// }
|
|
|
|
// numberPicker.setFormatter(new NumberPicker.Formatter() {
|
|
|
|
// @Override
|
|
|
|
// public String format(int value) {
|
|
|
|
// if (month) {
|
|
|
|
// return String.format(Locale.US, "%02d", value);
|
|
|
|
// } else {
|
|
|
|
// return String.format(Locale.US, "%02d", value + currentYear);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// builder.setView(numberPicker);
|
|
|
|
// builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() {
|
|
|
|
// @Override
|
|
|
|
// public void onClick(DialogInterface dialog, int which) {
|
|
|
|
// result[0] = month ? numberPicker.getValue() : ((numberPicker.getValue() + currentYear) % 100);
|
|
|
|
// callback.run();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// return builder.create();
|
|
|
|
// }
|
|
|
|
|
|
|
|
public interface PaymentAlertDelegate {
|
|
|
|
void didPressedNewCard();
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
public static void createDeleteMessagesAlert(BaseFragment fragment, TLRPC.User user, TLRPC.Chat chat, TLRPC.EncryptedChat encryptedChat, TLRPC.ChatFull chatInfo, long mergeDialogId, MessageObject selectedMessage, SparseArray<MessageObject>[] selectedMessages, MessageObject.GroupedMessages selectedGroup, boolean scheduled, int loadParticipant, Runnable onDelete) {
|
2019-05-14 14:08:05 +02:00
|
|
|
if (fragment == null || user == null && chat == null && encryptedChat == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Activity activity = fragment.getParentActivity();
|
|
|
|
if (activity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int currentAccount = fragment.getCurrentAccount();
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
|
int count;
|
|
|
|
if (selectedGroup != null) {
|
|
|
|
count = selectedGroup.messages.size();
|
|
|
|
} else if (selectedMessage != null) {
|
|
|
|
count = 1;
|
|
|
|
} else {
|
|
|
|
count = selectedMessages[0].size() + selectedMessages[1].size();
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
long dialogId;
|
|
|
|
if (encryptedChat != null) {
|
|
|
|
dialogId = ((long) encryptedChat.id) << 32;
|
|
|
|
} else if (user != null) {
|
|
|
|
dialogId = user.id;
|
|
|
|
} else {
|
|
|
|
dialogId = -chat.id;
|
|
|
|
}
|
|
|
|
|
2020-07-26 10:03:38 +02:00
|
|
|
int currentDate = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
|
|
|
|
boolean hasNonDiceMessages = false;
|
|
|
|
if (selectedMessage != null) {
|
|
|
|
hasNonDiceMessages = !selectedMessage.isDice() || Math.abs(currentDate - selectedMessage.messageOwner.date) > 24 * 60 * 60;
|
|
|
|
} else {
|
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
for (int b = 0; b < selectedMessages[a].size(); b++) {
|
|
|
|
MessageObject msg = selectedMessages[a].valueAt(b);
|
|
|
|
if (!msg.isDice() || Math.abs(currentDate - msg.messageOwner.date) > 24 * 60 * 60) {
|
|
|
|
hasNonDiceMessages = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
final boolean[] checks = new boolean[3];
|
2020-02-08 05:13:55 +01:00
|
|
|
final boolean[] deleteForAll = {true};
|
2019-05-14 14:08:05 +02:00
|
|
|
TLRPC.User actionUser = null;
|
|
|
|
boolean canRevokeInbox = user != null && MessagesController.getInstance(currentAccount).canRevokePmInbox;
|
|
|
|
int revokeTimeLimit;
|
|
|
|
if (user != null) {
|
|
|
|
revokeTimeLimit = MessagesController.getInstance(currentAccount).revokeTimePmLimit;
|
|
|
|
} else {
|
|
|
|
revokeTimeLimit = MessagesController.getInstance(currentAccount).revokeTimeLimit;
|
|
|
|
}
|
|
|
|
boolean hasDeleteForAllCheck = false;
|
|
|
|
boolean hasNotOut = false;
|
|
|
|
int myMessagesCount = 0;
|
|
|
|
boolean canDeleteInbox = encryptedChat == null && user != null && canRevokeInbox && revokeTimeLimit == 0x7fffffff;
|
2019-09-10 12:56:11 +02:00
|
|
|
if (chat != null && chat.megagroup && !scheduled) {
|
2019-05-14 14:08:05 +02:00
|
|
|
boolean canBan = ChatObject.canBlockUsers(chat);
|
|
|
|
if (selectedMessage != null) {
|
|
|
|
if (selectedMessage.messageOwner.action == null || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty ||
|
|
|
|
selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser ||
|
|
|
|
selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink ||
|
|
|
|
selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
|
2020-09-30 15:48:47 +02:00
|
|
|
actionUser = MessagesController.getInstance(currentAccount).getUser(selectedMessage.messageOwner.from_id.user_id);
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
|
|
|
boolean hasOutgoing = !selectedMessage.isSendError() && selectedMessage.getDialogId() == mergeDialogId && (selectedMessage.messageOwner.action == null || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) && selectedMessage.isOut() && (currentDate - selectedMessage.messageOwner.date) <= revokeTimeLimit;
|
|
|
|
if (hasOutgoing) {
|
|
|
|
myMessagesCount++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int from_id = -1;
|
|
|
|
for (int a = 1; a >= 0; a--) {
|
|
|
|
int channelId = 0;
|
|
|
|
for (int b = 0; b < selectedMessages[a].size(); b++) {
|
|
|
|
MessageObject msg = selectedMessages[a].valueAt(b);
|
|
|
|
if (from_id == -1) {
|
2020-09-30 15:48:47 +02:00
|
|
|
from_id = msg.getFromChatId();
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
if (from_id < 0 || from_id != msg.getSenderId()) {
|
2019-05-14 14:08:05 +02:00
|
|
|
from_id = -2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (from_id == -2) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int a = 1; a >= 0; a--) {
|
|
|
|
for (int b = 0; b < selectedMessages[a].size(); b++) {
|
|
|
|
MessageObject msg = selectedMessages[a].valueAt(b);
|
|
|
|
if (a == 1) {
|
|
|
|
if (msg.isOut() && msg.messageOwner.action == null) {
|
|
|
|
if ((currentDate - msg.messageOwner.date) <= revokeTimeLimit) {
|
|
|
|
myMessagesCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (from_id != -1) {
|
|
|
|
actionUser = MessagesController.getInstance(currentAccount).getUser(from_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (actionUser != null && actionUser.id != UserConfig.getInstance(currentAccount).getClientUserId()) {
|
|
|
|
if (loadParticipant == 1 && !chat.creator) {
|
|
|
|
final AlertDialog[] progressDialog = new AlertDialog[]{new AlertDialog(activity, 3)};
|
|
|
|
|
|
|
|
TLRPC.TL_channels_getParticipant req = new TLRPC.TL_channels_getParticipant();
|
|
|
|
req.channel = MessagesController.getInputChannel(chat);
|
|
|
|
req.user_id = MessagesController.getInstance(currentAccount).getInputUser(actionUser);
|
|
|
|
int requestId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
try {
|
|
|
|
progressDialog[0].dismiss();
|
|
|
|
} catch (Throwable ignore) {
|
|
|
|
|
|
|
|
}
|
|
|
|
progressDialog[0] = null;
|
|
|
|
int loadType = 2;
|
|
|
|
if (response != null) {
|
|
|
|
TLRPC.TL_channels_channelParticipant participant = (TLRPC.TL_channels_channelParticipant) response;
|
|
|
|
if (!(participant.participant instanceof TLRPC.TL_channelParticipantAdmin || participant.participant instanceof TLRPC.TL_channelParticipantCreator)) {
|
|
|
|
loadType = 0;
|
|
|
|
}
|
2020-10-15 02:39:36 +02:00
|
|
|
} else if (error != null && "USER_NOT_PARTICIPANT".equals(error.text)) {
|
|
|
|
loadType = 0;
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
createDeleteMessagesAlert(fragment, user, chat, encryptedChat, chatInfo, mergeDialogId, selectedMessage, selectedMessages, selectedGroup, scheduled, loadType, onDelete);
|
2019-05-14 14:08:05 +02:00
|
|
|
}));
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (progressDialog[0] == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
progressDialog[0].setOnCancelListener(dialog -> ConnectionsManager.getInstance(currentAccount).cancelRequest(requestId, true));
|
|
|
|
fragment.showDialog(progressDialog[0]);
|
|
|
|
}, 1000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FrameLayout frameLayout = new FrameLayout(activity);
|
|
|
|
int num = 0;
|
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
if ((loadParticipant == 2 || !canBan) && a == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CheckBoxCell cell = new CheckBoxCell(activity, 1);
|
|
|
|
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
|
|
|
cell.setTag(a);
|
|
|
|
if (a == 0) {
|
|
|
|
cell.setText(LocaleController.getString("DeleteBanUser", R.string.DeleteBanUser), "", false, false);
|
|
|
|
} else if (a == 1) {
|
|
|
|
cell.setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", false, false);
|
2020-10-30 11:26:29 +01:00
|
|
|
} else {
|
2019-05-14 14:08:05 +02:00
|
|
|
cell.setText(LocaleController.formatString("DeleteAllFrom", R.string.DeleteAllFrom, ContactsController.formatName(actionUser.first_name, actionUser.last_name)), "", false, false);
|
|
|
|
}
|
|
|
|
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
|
|
|
|
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 48 * num, 0, 0));
|
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
if (!v.isEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CheckBoxCell cell13 = (CheckBoxCell) v;
|
|
|
|
Integer num1 = (Integer) cell13.getTag();
|
|
|
|
checks[num1] = !checks[num1];
|
|
|
|
cell13.setChecked(checks[num1], true);
|
|
|
|
});
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
builder.setView(frameLayout);
|
2020-07-26 10:03:38 +02:00
|
|
|
} else if (!hasNotOut && myMessagesCount > 0 && hasNonDiceMessages) {
|
2019-05-14 14:08:05 +02:00
|
|
|
hasDeleteForAllCheck = true;
|
|
|
|
FrameLayout frameLayout = new FrameLayout(activity);
|
|
|
|
CheckBoxCell cell = new CheckBoxCell(activity, 1);
|
|
|
|
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
|
|
|
if (chat != null && hasNotOut) {
|
2020-02-08 04:05:56 +01:00
|
|
|
cell.setText(LocaleController.getString("DeleteForAll", R.string.DeleteForAll), "", true, false);
|
2019-05-14 14:08:05 +02:00
|
|
|
} else {
|
2020-02-08 04:05:56 +01:00
|
|
|
cell.setText(LocaleController.getString("DeleteMessagesOption", R.string.DeleteMessagesOption), "", true, false);
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
|
|
|
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
|
|
|
|
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
|
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
CheckBoxCell cell12 = (CheckBoxCell) v;
|
|
|
|
deleteForAll[0] = !deleteForAll[0];
|
|
|
|
cell12.setChecked(deleteForAll[0], true);
|
|
|
|
});
|
|
|
|
builder.setView(frameLayout);
|
|
|
|
builder.setCustomViewOffset(9);
|
|
|
|
} else {
|
|
|
|
actionUser = null;
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
} else if (!scheduled && !ChatObject.isChannel(chat) && encryptedChat == null) {
|
2020-08-14 18:58:22 +02:00
|
|
|
if (user != null && user.id != UserConfig.getInstance(currentAccount).getClientUserId() && (!user.bot || user.support) || chat != null) {
|
2019-05-14 14:08:05 +02:00
|
|
|
if (selectedMessage != null) {
|
2020-10-30 11:26:29 +01:00
|
|
|
boolean hasOutgoing = !selectedMessage.isSendError() && (
|
|
|
|
selectedMessage.messageOwner.action == null ||
|
|
|
|
selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty ||
|
|
|
|
selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall ||
|
|
|
|
selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage ||
|
|
|
|
selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionGeoProximityReached) && (selectedMessage.isOut() || canRevokeInbox || ChatObject.hasAdminRights(chat)) && (currentDate - selectedMessage.messageOwner.date) <= revokeTimeLimit;
|
2019-05-14 14:08:05 +02:00
|
|
|
if (hasOutgoing) {
|
|
|
|
myMessagesCount++;
|
|
|
|
}
|
|
|
|
hasNotOut = !selectedMessage.isOut();
|
|
|
|
} else {
|
|
|
|
for (int a = 1; a >= 0; a--) {
|
|
|
|
for (int b = 0; b < selectedMessages[a].size(); b++) {
|
|
|
|
MessageObject msg = selectedMessages[a].valueAt(b);
|
2020-10-30 11:26:29 +01:00
|
|
|
if (!(msg.messageOwner.action == null ||
|
|
|
|
msg.messageOwner.action instanceof TLRPC.TL_messageActionEmpty ||
|
|
|
|
msg.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall ||
|
|
|
|
msg.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage ||
|
|
|
|
msg.messageOwner.action instanceof TLRPC.TL_messageActionGeoProximityReached)) {
|
2019-05-14 14:08:05 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((msg.isOut() || canRevokeInbox) || chat != null && ChatObject.canBlockUsers(chat)) {
|
|
|
|
if ((currentDate - msg.messageOwner.date) <= revokeTimeLimit) {
|
|
|
|
myMessagesCount++;
|
|
|
|
if (!hasNotOut && !msg.isOut()) {
|
|
|
|
hasNotOut = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-26 10:03:38 +02:00
|
|
|
if (myMessagesCount > 0 && hasNonDiceMessages) {
|
2019-05-14 14:08:05 +02:00
|
|
|
hasDeleteForAllCheck = true;
|
|
|
|
FrameLayout frameLayout = new FrameLayout(activity);
|
|
|
|
CheckBoxCell cell = new CheckBoxCell(activity, 1);
|
|
|
|
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
|
|
|
if (canDeleteInbox) {
|
2020-02-08 04:05:56 +01:00
|
|
|
cell.setText(LocaleController.formatString("DeleteMessagesOptionAlso", R.string.DeleteMessagesOptionAlso, UserObject.getFirstName(user)), "", true, false);
|
2019-05-14 14:08:05 +02:00
|
|
|
} else if (chat != null && (hasNotOut || myMessagesCount == count)) {
|
2020-02-08 04:05:56 +01:00
|
|
|
cell.setText(LocaleController.getString("DeleteForAll", R.string.DeleteForAll), "", true, false);
|
2019-05-14 14:08:05 +02:00
|
|
|
} else {
|
2020-02-08 04:05:56 +01:00
|
|
|
cell.setText(LocaleController.getString("DeleteMessagesOption", R.string.DeleteMessagesOption), "", true, false);
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
|
|
|
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
|
|
|
|
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
|
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
CheckBoxCell cell1 = (CheckBoxCell) v;
|
|
|
|
deleteForAll[0] = !deleteForAll[0];
|
|
|
|
cell1.setChecked(deleteForAll[0], true);
|
|
|
|
});
|
|
|
|
builder.setView(frameLayout);
|
|
|
|
builder.setCustomViewOffset(9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final TLRPC.User userFinal = actionUser;
|
|
|
|
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
|
|
|
|
ArrayList<Integer> ids = null;
|
|
|
|
if (selectedMessage != null) {
|
|
|
|
ids = new ArrayList<>();
|
|
|
|
ArrayList<Long> random_ids = null;
|
|
|
|
if (selectedGroup != null) {
|
|
|
|
for (int a = 0; a < selectedGroup.messages.size(); a++) {
|
|
|
|
MessageObject messageObject = selectedGroup.messages.get(a);
|
|
|
|
ids.add(messageObject.getId());
|
|
|
|
if (encryptedChat != null && messageObject.messageOwner.random_id != 0 && messageObject.type != 10) {
|
|
|
|
if (random_ids == null) {
|
|
|
|
random_ids = new ArrayList<>();
|
|
|
|
}
|
|
|
|
random_ids.add(messageObject.messageOwner.random_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ids.add(selectedMessage.getId());
|
|
|
|
if (encryptedChat != null && selectedMessage.messageOwner.random_id != 0 && selectedMessage.type != 10) {
|
|
|
|
random_ids = new ArrayList<>();
|
|
|
|
random_ids.add(selectedMessage.messageOwner.random_id);
|
|
|
|
}
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
MessagesController.getInstance(currentAccount).deleteMessages(ids, random_ids, encryptedChat, dialogId, selectedMessage.messageOwner.peer_id.channel_id, deleteForAll[0], scheduled);
|
2019-05-14 14:08:05 +02:00
|
|
|
} else {
|
|
|
|
for (int a = 1; a >= 0; a--) {
|
|
|
|
ids = new ArrayList<>();
|
|
|
|
for (int b = 0; b < selectedMessages[a].size(); b++) {
|
|
|
|
ids.add(selectedMessages[a].keyAt(b));
|
|
|
|
}
|
|
|
|
ArrayList<Long> random_ids = null;
|
|
|
|
int channelId = 0;
|
|
|
|
if (!ids.isEmpty()) {
|
|
|
|
MessageObject msg = selectedMessages[a].get(ids.get(0));
|
2020-10-30 11:26:29 +01:00
|
|
|
if (msg.messageOwner.peer_id.channel_id != 0) {
|
2020-09-30 15:48:47 +02:00
|
|
|
channelId = msg.messageOwner.peer_id.channel_id;
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (encryptedChat != null) {
|
|
|
|
random_ids = new ArrayList<>();
|
|
|
|
for (int b = 0; b < selectedMessages[a].size(); b++) {
|
|
|
|
MessageObject msg = selectedMessages[a].valueAt(b);
|
|
|
|
if (msg.messageOwner.random_id != 0 && msg.type != 10) {
|
|
|
|
random_ids.add(msg.messageOwner.random_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
MessagesController.getInstance(currentAccount).deleteMessages(ids, random_ids, encryptedChat, dialogId, channelId, deleteForAll[0], scheduled);
|
2019-05-14 14:08:05 +02:00
|
|
|
selectedMessages[a].clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (userFinal != null) {
|
|
|
|
if (checks[0]) {
|
|
|
|
MessagesController.getInstance(currentAccount).deleteUserFromChat(chat.id, userFinal, chatInfo);
|
|
|
|
}
|
|
|
|
if (checks[1]) {
|
|
|
|
TLRPC.TL_channels_reportSpam req = new TLRPC.TL_channels_reportSpam();
|
|
|
|
req.channel = MessagesController.getInputChannel(chat);
|
|
|
|
req.user_id = MessagesController.getInstance(currentAccount).getInputUser(userFinal);
|
|
|
|
req.id = ids;
|
|
|
|
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (checks[2]) {
|
|
|
|
MessagesController.getInstance(currentAccount).deleteUserChannelHistory(chat, userFinal, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (onDelete != null) {
|
|
|
|
onDelete.run();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (count == 1) {
|
|
|
|
builder.setTitle(LocaleController.getString("DeleteSingleMessagesTitle", R.string.DeleteSingleMessagesTitle));
|
|
|
|
} else {
|
|
|
|
builder.setTitle(LocaleController.formatString("DeleteMessagesTitle", R.string.DeleteMessagesTitle, LocaleController.formatPluralString("messages", count)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chat != null && hasNotOut) {
|
|
|
|
if (hasDeleteForAllCheck && myMessagesCount != count) {
|
|
|
|
builder.setMessage(LocaleController.formatString("DeleteMessagesTextGroupPart", R.string.DeleteMessagesTextGroupPart, LocaleController.formatPluralString("messages", myMessagesCount)));
|
|
|
|
} else if (count == 1) {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteSingleMessage", R.string.AreYouSureDeleteSingleMessage));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteFewMessages", R.string.AreYouSureDeleteFewMessages));
|
|
|
|
}
|
|
|
|
} else if (hasDeleteForAllCheck && !canDeleteInbox && myMessagesCount != count) {
|
|
|
|
if (chat != null) {
|
|
|
|
builder.setMessage(LocaleController.formatString("DeleteMessagesTextGroup", R.string.DeleteMessagesTextGroup, LocaleController.formatPluralString("messages", myMessagesCount)));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("DeleteMessagesText", R.string.DeleteMessagesText, LocaleController.formatPluralString("messages", myMessagesCount), UserObject.getFirstName(user))));
|
|
|
|
}
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (chat != null && chat.megagroup && !scheduled) {
|
2019-05-14 14:08:05 +02:00
|
|
|
if (count == 1) {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteSingleMessageMega", R.string.AreYouSureDeleteSingleMessageMega));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteFewMessagesMega", R.string.AreYouSureDeleteFewMessagesMega));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (count == 1) {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteSingleMessage", R.string.AreYouSureDeleteSingleMessage));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteFewMessages", R.string.AreYouSureDeleteFewMessages));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
fragment.showDialog(dialog);
|
|
|
|
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
|
|
|
if (button != null) {
|
|
|
|
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
|
|
|
|
}
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
|
|
|
|
public static void createThemeCreateDialog(BaseFragment fragment, int type, Theme.ThemeInfo switchToTheme, Theme.ThemeAccent switchToAccent) {
|
|
|
|
if (fragment == null || fragment.getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Context context = fragment.getParentActivity();
|
|
|
|
final EditTextBoldCursor editText = new EditTextBoldCursor(context);
|
|
|
|
editText.setBackgroundDrawable(Theme.createEditTextDrawable(context, true));
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
builder.setTitle(LocaleController.getString("NewTheme", R.string.NewTheme));
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
builder.setPositiveButton(LocaleController.getString("Create", R.string.Create), (dialog, which) -> {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
LinearLayout linearLayout = new LinearLayout(context);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
builder.setView(linearLayout);
|
|
|
|
|
|
|
|
final TextView message = new TextView(context);
|
|
|
|
if (type != 0) {
|
|
|
|
message.setText(AndroidUtilities.replaceTags(LocaleController.getString("EnterThemeNameEdit", R.string.EnterThemeNameEdit)));
|
|
|
|
} else {
|
|
|
|
message.setText(LocaleController.getString("EnterThemeName", R.string.EnterThemeName));
|
|
|
|
}
|
|
|
|
message.setTextSize(16);
|
|
|
|
message.setPadding(AndroidUtilities.dp(23), AndroidUtilities.dp(12), AndroidUtilities.dp(23), AndroidUtilities.dp(6));
|
|
|
|
message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
linearLayout.addView(message, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
|
|
|
|
editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
editText.setMaxLines(1);
|
|
|
|
editText.setLines(1);
|
|
|
|
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
|
|
|
|
editText.setGravity(Gravity.LEFT | Gravity.TOP);
|
|
|
|
editText.setSingleLine(true);
|
|
|
|
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
|
|
|
editText.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
editText.setCursorSize(AndroidUtilities.dp(20));
|
|
|
|
editText.setCursorWidth(1.5f);
|
|
|
|
editText.setPadding(0, AndroidUtilities.dp(4), 0, 0);
|
|
|
|
linearLayout.addView(editText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT, 24, 6, 24, 0));
|
|
|
|
editText.setOnEditorActionListener((textView, i, keyEvent) -> {
|
|
|
|
AndroidUtilities.hideKeyboard(textView);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
editText.setText(generateThemeName(switchToAccent));
|
|
|
|
editText.setSelection(editText.length());
|
|
|
|
|
|
|
|
final AlertDialog alertDialog = builder.create();
|
|
|
|
alertDialog.setOnShowListener(dialog -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
editText.requestFocus();
|
|
|
|
AndroidUtilities.showKeyboard(editText);
|
|
|
|
}));
|
|
|
|
fragment.showDialog(alertDialog);
|
|
|
|
editText.requestFocus();
|
|
|
|
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
|
|
|
|
if (fragment.getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (editText.length() == 0) {
|
2020-07-26 18:07:20 +02:00
|
|
|
VibrateUtil.vibrate();
|
2019-12-31 14:08:08 +01:00
|
|
|
AndroidUtilities.shakeView(editText, 2, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (fragment instanceof ThemePreviewActivity) {
|
|
|
|
Theme.applyPreviousTheme();
|
|
|
|
fragment.finishFragment();
|
|
|
|
}
|
|
|
|
if (switchToAccent != null) {
|
|
|
|
switchToTheme.setCurrentAccentId(switchToAccent.id);
|
|
|
|
Theme.refreshThemeColors();
|
|
|
|
Utilities.searchQueue.postRunnable(() -> AndroidUtilities.runOnUIThread(() -> processCreate(editText, alertDialog, fragment)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
processCreate(editText, alertDialog, fragment);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void processCreate(EditTextBoldCursor editText, AlertDialog alertDialog, BaseFragment fragment) {
|
2019-12-31 20:46:59 +01:00
|
|
|
if (fragment == null || fragment.getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
AndroidUtilities.hideKeyboard(editText);
|
|
|
|
Theme.ThemeInfo themeInfo = Theme.createNewTheme(editText.getText().toString());
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.themeListUpdated);
|
|
|
|
|
|
|
|
ThemeEditorView themeEditorView = new ThemeEditorView();
|
|
|
|
themeEditorView.show(fragment.getParentActivity(), themeInfo);
|
|
|
|
alertDialog.dismiss();
|
|
|
|
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
if (preferences.getBoolean("themehint", false)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
preferences.edit().putBoolean("themehint", true).commit();
|
|
|
|
try {
|
|
|
|
Toast.makeText(fragment.getParentActivity(), LocaleController.getString("CreateNewThemeHelp", R.string.CreateNewThemeHelp), Toast.LENGTH_LONG).show();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String generateThemeName(Theme.ThemeAccent accent) {
|
|
|
|
List<String> adjectives = Arrays.asList(
|
|
|
|
"Ancient",
|
|
|
|
"Antique",
|
|
|
|
"Autumn",
|
|
|
|
"Baby",
|
|
|
|
"Barely",
|
|
|
|
"Baroque",
|
|
|
|
"Blazing",
|
|
|
|
"Blushing",
|
|
|
|
"Bohemian",
|
|
|
|
"Bubbly",
|
|
|
|
"Burning",
|
|
|
|
"Buttered",
|
|
|
|
"Classic",
|
|
|
|
"Clear",
|
|
|
|
"Cool",
|
|
|
|
"Cosmic",
|
|
|
|
"Cotton",
|
|
|
|
"Cozy",
|
|
|
|
"Crystal",
|
|
|
|
"Dark",
|
|
|
|
"Daring",
|
|
|
|
"Darling",
|
|
|
|
"Dawn",
|
|
|
|
"Dazzling",
|
|
|
|
"Deep",
|
|
|
|
"Deepest",
|
|
|
|
"Delicate",
|
|
|
|
"Delightful",
|
|
|
|
"Divine",
|
|
|
|
"Double",
|
|
|
|
"Downtown",
|
|
|
|
"Dreamy",
|
|
|
|
"Dusky",
|
|
|
|
"Dusty",
|
|
|
|
"Electric",
|
|
|
|
"Enchanted",
|
|
|
|
"Endless",
|
|
|
|
"Evening",
|
|
|
|
"Fantastic",
|
|
|
|
"Flirty",
|
|
|
|
"Forever",
|
|
|
|
"Frigid",
|
|
|
|
"Frosty",
|
|
|
|
"Frozen",
|
|
|
|
"Gentle",
|
|
|
|
"Heavenly",
|
|
|
|
"Hyper",
|
|
|
|
"Icy",
|
|
|
|
"Infinite",
|
|
|
|
"Innocent",
|
|
|
|
"Instant",
|
|
|
|
"Luscious",
|
|
|
|
"Lunar",
|
|
|
|
"Lustrous",
|
|
|
|
"Magic",
|
|
|
|
"Majestic",
|
|
|
|
"Mambo",
|
|
|
|
"Midnight",
|
|
|
|
"Millenium",
|
|
|
|
"Morning",
|
|
|
|
"Mystic",
|
|
|
|
"Natural",
|
|
|
|
"Neon",
|
|
|
|
"Night",
|
|
|
|
"Opaque",
|
|
|
|
"Paradise",
|
|
|
|
"Perfect",
|
|
|
|
"Perky",
|
|
|
|
"Polished",
|
|
|
|
"Powerful",
|
|
|
|
"Rich",
|
|
|
|
"Royal",
|
|
|
|
"Sheer",
|
|
|
|
"Simply",
|
|
|
|
"Sizzling",
|
|
|
|
"Solar",
|
|
|
|
"Sparkling",
|
|
|
|
"Splendid",
|
|
|
|
"Spicy",
|
|
|
|
"Spring",
|
|
|
|
"Stellar",
|
|
|
|
"Sugared",
|
|
|
|
"Summer",
|
|
|
|
"Sunny",
|
|
|
|
"Super",
|
|
|
|
"Sweet",
|
|
|
|
"Tender",
|
|
|
|
"Tenacious",
|
|
|
|
"Tidal",
|
|
|
|
"Toasted",
|
|
|
|
"Totally",
|
|
|
|
"Tranquil",
|
|
|
|
"Tropical",
|
|
|
|
"True",
|
|
|
|
"Twilight",
|
|
|
|
"Twinkling",
|
|
|
|
"Ultimate",
|
|
|
|
"Ultra",
|
|
|
|
"Velvety",
|
|
|
|
"Vibrant",
|
|
|
|
"Vintage",
|
|
|
|
"Virtual",
|
|
|
|
"Warm",
|
|
|
|
"Warmest",
|
|
|
|
"Whipped",
|
|
|
|
"Wild",
|
|
|
|
"Winsome"
|
|
|
|
);
|
|
|
|
|
|
|
|
List<String> subjectives = Arrays.asList(
|
|
|
|
"Ambrosia",
|
|
|
|
"Attack",
|
|
|
|
"Avalanche",
|
|
|
|
"Blast",
|
|
|
|
"Bliss",
|
|
|
|
"Blossom",
|
|
|
|
"Blush",
|
|
|
|
"Burst",
|
|
|
|
"Butter",
|
|
|
|
"Candy",
|
|
|
|
"Carnival",
|
|
|
|
"Charm",
|
|
|
|
"Chiffon",
|
|
|
|
"Cloud",
|
|
|
|
"Comet",
|
|
|
|
"Delight",
|
|
|
|
"Dream",
|
|
|
|
"Dust",
|
|
|
|
"Fantasy",
|
|
|
|
"Flame",
|
|
|
|
"Flash",
|
|
|
|
"Fire",
|
|
|
|
"Freeze",
|
|
|
|
"Frost",
|
|
|
|
"Glade",
|
|
|
|
"Glaze",
|
|
|
|
"Gleam",
|
|
|
|
"Glimmer",
|
|
|
|
"Glitter",
|
|
|
|
"Glow",
|
|
|
|
"Grande",
|
|
|
|
"Haze",
|
|
|
|
"Highlight",
|
|
|
|
"Ice",
|
|
|
|
"Illusion",
|
|
|
|
"Intrigue",
|
|
|
|
"Jewel",
|
|
|
|
"Jubilee",
|
|
|
|
"Kiss",
|
|
|
|
"Lights",
|
|
|
|
"Lollypop",
|
|
|
|
"Love",
|
|
|
|
"Luster",
|
|
|
|
"Madness",
|
|
|
|
"Matte",
|
|
|
|
"Mirage",
|
|
|
|
"Mist",
|
|
|
|
"Moon",
|
|
|
|
"Muse",
|
|
|
|
"Myth",
|
|
|
|
"Nectar",
|
|
|
|
"Nova",
|
|
|
|
"Parfait",
|
|
|
|
"Passion",
|
|
|
|
"Pop",
|
|
|
|
"Rain",
|
|
|
|
"Reflection",
|
|
|
|
"Rhapsody",
|
|
|
|
"Romance",
|
|
|
|
"Satin",
|
|
|
|
"Sensation",
|
|
|
|
"Silk",
|
|
|
|
"Shine",
|
|
|
|
"Shadow",
|
|
|
|
"Shimmer",
|
|
|
|
"Sky",
|
|
|
|
"Spice",
|
|
|
|
"Star",
|
|
|
|
"Sugar",
|
|
|
|
"Sunrise",
|
|
|
|
"Sunset",
|
|
|
|
"Sun",
|
|
|
|
"Twist",
|
|
|
|
"Unbound",
|
|
|
|
"Velvet",
|
|
|
|
"Vibrant",
|
|
|
|
"Waters",
|
|
|
|
"Wine",
|
|
|
|
"Wink",
|
|
|
|
"Wonder",
|
|
|
|
"Zone"
|
|
|
|
);
|
|
|
|
|
|
|
|
HashMap<Integer, String> colors = new HashMap<>();
|
|
|
|
colors.put(0x8e0000, "Berry");
|
|
|
|
colors.put(0xdec196, "Brandy");
|
|
|
|
colors.put(0x800b47, "Cherry");
|
|
|
|
colors.put(0xff7f50, "Coral");
|
|
|
|
colors.put(0xdb5079, "Cranberry");
|
|
|
|
colors.put(0xdc143c, "Crimson");
|
|
|
|
colors.put(0xe0b0ff, "Mauve");
|
|
|
|
colors.put(0xffc0cb, "Pink");
|
|
|
|
colors.put(0xff0000, "Red");
|
|
|
|
colors.put(0xff007f, "Rose");
|
|
|
|
colors.put(0x80461b, "Russet");
|
|
|
|
colors.put(0xff2400, "Scarlet");
|
|
|
|
colors.put(0xf1f1f1, "Seashell");
|
|
|
|
colors.put(0xff3399, "Strawberry");
|
|
|
|
colors.put(0xffbf00, "Amber");
|
|
|
|
colors.put(0xeb9373, "Apricot");
|
|
|
|
colors.put(0xfbe7b2, "Banana");
|
|
|
|
colors.put(0xa1c50a, "Citrus");
|
|
|
|
colors.put(0xb06500, "Ginger");
|
|
|
|
colors.put(0xffd700, "Gold");
|
|
|
|
colors.put(0xfde910, "Lemon");
|
|
|
|
colors.put(0xffa500, "Orange");
|
|
|
|
colors.put(0xffe5b4, "Peach");
|
|
|
|
colors.put(0xff6b53, "Persimmon");
|
|
|
|
colors.put(0xe4d422, "Sunflower");
|
|
|
|
colors.put(0xf28500, "Tangerine");
|
|
|
|
colors.put(0xffc87c, "Topaz");
|
|
|
|
colors.put(0xffff00, "Yellow");
|
|
|
|
colors.put(0x384910, "Clover");
|
|
|
|
colors.put(0x83aa5d, "Cucumber");
|
|
|
|
colors.put(0x50c878, "Emerald");
|
|
|
|
colors.put(0xb5b35c, "Olive");
|
|
|
|
colors.put(0x00ff00, "Green");
|
|
|
|
colors.put(0x00a86b, "Jade");
|
|
|
|
colors.put(0x29ab87, "Jungle");
|
|
|
|
colors.put(0xbfff00, "Lime");
|
|
|
|
colors.put(0x0bda51, "Malachite");
|
|
|
|
colors.put(0x98ff98, "Mint");
|
|
|
|
colors.put(0xaddfad, "Moss");
|
|
|
|
colors.put(0x315ba1, "Azure");
|
|
|
|
colors.put(0x0000ff, "Blue");
|
|
|
|
colors.put(0x0047ab, "Cobalt");
|
|
|
|
colors.put(0x4f69c6, "Indigo");
|
|
|
|
colors.put(0x017987, "Lagoon");
|
|
|
|
colors.put(0x71d9e2, "Aquamarine");
|
|
|
|
colors.put(0x120a8f, "Ultramarine");
|
|
|
|
colors.put(0x000080, "Navy");
|
|
|
|
colors.put(0x2f519e, "Sapphire");
|
|
|
|
colors.put(0x76d7ea, "Sky");
|
|
|
|
colors.put(0x008080, "Teal");
|
|
|
|
colors.put(0x40e0d0, "Turquoise");
|
|
|
|
colors.put(0x9966cc, "Amethyst");
|
|
|
|
colors.put(0x4d0135, "Blackberry");
|
|
|
|
colors.put(0x614051, "Eggplant");
|
|
|
|
colors.put(0xc8a2c8, "Lilac");
|
|
|
|
colors.put(0xb57edc, "Lavender");
|
|
|
|
colors.put(0xccccff, "Periwinkle");
|
|
|
|
colors.put(0x843179, "Plum");
|
|
|
|
colors.put(0x660099, "Purple");
|
|
|
|
colors.put(0xd8bfd8, "Thistle");
|
|
|
|
colors.put(0xda70d6, "Orchid");
|
|
|
|
colors.put(0x240a40, "Violet");
|
|
|
|
colors.put(0x3f2109, "Bronze");
|
|
|
|
colors.put(0x370202, "Chocolate");
|
|
|
|
colors.put(0x7b3f00, "Cinnamon");
|
|
|
|
colors.put(0x301f1e, "Cocoa");
|
|
|
|
colors.put(0x706555, "Coffee");
|
|
|
|
colors.put(0x796989, "Rum");
|
|
|
|
colors.put(0x4e0606, "Mahogany");
|
|
|
|
colors.put(0x782d19, "Mocha");
|
|
|
|
colors.put(0xc2b280, "Sand");
|
|
|
|
colors.put(0x882d17, "Sienna");
|
|
|
|
colors.put(0x780109, "Maple");
|
|
|
|
colors.put(0xf0e68c, "Khaki");
|
|
|
|
colors.put(0xb87333, "Copper");
|
|
|
|
colors.put(0xb94e48, "Chestnut");
|
|
|
|
colors.put(0xeed9c4, "Almond");
|
|
|
|
colors.put(0xfffdd0, "Cream");
|
|
|
|
colors.put(0xb9f2ff, "Diamond");
|
|
|
|
colors.put(0xa98307, "Honey");
|
|
|
|
colors.put(0xfffff0, "Ivory");
|
|
|
|
colors.put(0xeae0c8, "Pearl");
|
|
|
|
colors.put(0xeff2f3, "Porcelain");
|
|
|
|
colors.put(0xd1bea8, "Vanilla");
|
|
|
|
colors.put(0xffffff, "White");
|
|
|
|
colors.put(0x808080, "Gray");
|
|
|
|
colors.put(0x000000, "Black");
|
|
|
|
colors.put(0xe8f1d4, "Chrome");
|
|
|
|
colors.put(0x36454f, "Charcoal");
|
|
|
|
colors.put(0x0c0b1d, "Ebony");
|
|
|
|
colors.put(0xc0c0c0, "Silver");
|
|
|
|
colors.put(0xf5f5f5, "Smoke");
|
|
|
|
colors.put(0x262335, "Steel");
|
|
|
|
colors.put(0x4fa83d, "Apple");
|
|
|
|
colors.put(0x80b3c4, "Glacier");
|
|
|
|
colors.put(0xfebaad, "Melon");
|
|
|
|
colors.put(0xc54b8c, "Mulberry");
|
|
|
|
colors.put(0xa9c6c2, "Opal");
|
|
|
|
colors.put(0x54a5f8, "Blue");
|
|
|
|
|
|
|
|
int color;
|
|
|
|
if (accent == null) {
|
|
|
|
Theme.ThemeInfo themeInfo = Theme.getCurrentTheme();
|
|
|
|
accent = themeInfo.getAccent(false);
|
|
|
|
}
|
|
|
|
if (accent != null && accent.accentColor != 0) {
|
|
|
|
color = accent.accentColor;
|
|
|
|
} else {
|
|
|
|
color = AndroidUtilities.calcDrawableColor(Theme.getCachedWallpaper())[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
String minKey = null;
|
|
|
|
int minValue = Integer.MAX_VALUE;
|
|
|
|
int r1 = Color.red(color);
|
|
|
|
int g1 = Color.green(color);
|
|
|
|
int b1 = Color.blue(color);
|
|
|
|
|
|
|
|
for (HashMap.Entry<Integer, String> entry : colors.entrySet()) {
|
|
|
|
Integer value = entry.getKey();
|
|
|
|
int r2 = Color.red(value);
|
|
|
|
int g2 = Color.green(value);
|
|
|
|
int b2 = Color.blue(value);
|
|
|
|
|
|
|
|
int rMean = (r1 + r2) / 2;
|
|
|
|
int r = r1 - r2;
|
|
|
|
int g = g1 - g2;
|
|
|
|
int b = b1 - b2;
|
|
|
|
int d = (((512 + rMean) * r * r) >> 8) + (4 * g * g) + (((767 - rMean) * b * b) >> 8);
|
|
|
|
|
|
|
|
if (d < minValue) {
|
|
|
|
minKey = entry.getValue();
|
|
|
|
minValue = d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String result;
|
|
|
|
if (Utilities.random.nextInt() % 2 == 0) {
|
|
|
|
result = adjectives.get(Utilities.random.nextInt(adjectives.size())) + " " + minKey;
|
|
|
|
} else {
|
|
|
|
result = minKey + " " + subjectives.get(Utilities.random.nextInt(subjectives.size()));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|