Update to 3.18.0

This commit is contained in:
DrKLO 2017-03-31 02:58:05 +03:00
parent 64e8ec3fbd
commit 6a1cf64f6f
2548 changed files with 138705 additions and 66425 deletions

View file

@ -3,7 +3,7 @@
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013-2016.
* Copyright Nikolai Kudashov, 2013-2017.
*/
package org.telegram.messenger;
@ -12,12 +12,9 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
@ -45,7 +42,6 @@ import org.telegram.ui.PopupNotificationActivity;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
public class NotificationsController {
@ -68,7 +64,7 @@ public class NotificationsController {
private boolean notifyCheck = false;
private int lastOnlineFromOtherDevice = 0;
private boolean inChatSoundEnabled = true;
private int lastBadgeCount;
private int lastBadgeCount = -1;
private String launcherClassName;
private Runnable notificationDelayRunnable;
@ -90,7 +86,7 @@ public class NotificationsController {
public static NotificationsController getInstance() {
NotificationsController localInstance = Instance;
if (localInstance == null) {
synchronized (MessagesController.class) {
synchronized (NotificationsController.class) {
localInstance = Instance;
if (localInstance == null) {
Instance = localInstance = new NotificationsController();
@ -108,12 +104,12 @@ public class NotificationsController {
try {
audioManager = (AudioManager) ApplicationLoader.applicationContext.getSystemService(Context.AUDIO_SERVICE);
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
try {
alarmManager = (AlarmManager) ApplicationLoader.applicationContext.getSystemService(Context.ALARM_SERVICE);
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
try {
@ -121,13 +117,13 @@ public class NotificationsController {
notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
notificationDelayWakelock.setReferenceCounted(false);
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
notificationDelayRunnable = new Runnable() {
@Override
public void run() {
FileLog.e("tmessages", "delay reached");
FileLog.e("delay reached");
if (!delayedPushMessages.isEmpty()) {
showOrUpdateNotification(true);
delayedPushMessages.clear();
@ -137,7 +133,7 @@ public class NotificationsController {
notificationDelayWakelock.release();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
}
};
@ -164,7 +160,7 @@ public class NotificationsController {
notificationDelayWakelock.release();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
setBadge(0);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
@ -192,7 +188,7 @@ public class NotificationsController {
notificationsQueue.postRunnable(new Runnable() {
@Override
public void run() {
FileLog.e("tmessages", "set last online from other device = " + time);
FileLog.e("set last online from other device = " + time);
lastOnlineFromOtherDevice = time;
}
});
@ -218,6 +214,128 @@ public class NotificationsController {
return false;
}
protected void showSingleBackgroundNotification() {
notificationsQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
if (!ApplicationLoader.mainInterfacePaused) {
return;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
boolean notifyDisabled = false;
int needVibrate = 0;
String choosenSoundPath = null;
int ledColor = 0xff0000ff;
int priority = 0;
int vibrateOverride;
if (!preferences.getBoolean("EnableAll", true)) {
notifyDisabled = true;
}
String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath();
if (!notifyDisabled) {
vibrateOverride = 0;
choosenSoundPath = null;
boolean vibrateOnlyIfSilent = false;
if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
choosenSoundPath = null;
} else if (choosenSoundPath == null) {
choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath);
}
needVibrate = preferences.getInt("vibrate_messages", 0);
priority = preferences.getInt("priority_group", 1);
ledColor = preferences.getInt("MessagesLed", 0xff0000ff);
if (needVibrate == 4) {
vibrateOnlyIfSilent = true;
needVibrate = 0;
}
if (needVibrate == 2 && (vibrateOverride == 1 || vibrateOverride == 3) || needVibrate != 2 && vibrateOverride == 2 || vibrateOverride != 0 && vibrateOverride != 4) {
needVibrate = vibrateOverride;
}
if (vibrateOnlyIfSilent && needVibrate != 2) {
try {
int mode = audioManager.getRingerMode();
if (mode != AudioManager.RINGER_MODE_SILENT && mode != AudioManager.RINGER_MODE_VIBRATE) {
needVibrate = 2;
}
} catch (Exception e) {
FileLog.e(e);
}
}
}
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
intent.setFlags(32768);
PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
String name = LocaleController.getString("AppName", R.string.AppName);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext)
.setContentTitle(name)
.setSmallIcon(R.drawable.notification)
.setAutoCancel(true)
.setNumber(total_unread_count)
.setContentIntent(contentIntent)
.setGroup("messages")
.setGroupSummary(true)
.setColor(0xff2ca5e0);
mBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
String lastMessage = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
mBuilder.setContentText(lastMessage);
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(lastMessage));
if (priority == 0) {
mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
} else if (priority == 1) {
mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
} else if (priority == 2) {
mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
}
if (!notifyDisabled) {
if (lastMessage.length() > 100) {
lastMessage = lastMessage.substring(0, 100).replace('\n', ' ').trim() + "...";
}
mBuilder.setTicker(lastMessage);
if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
if (choosenSoundPath.equals(defaultPath)) {
mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION);
} else {
mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION);
}
}
if (ledColor != 0) {
mBuilder.setLights(ledColor, 1000, 1000);
}
if (needVibrate == 2 || MediaController.getInstance().isRecordingAudio()) {
mBuilder.setVibrate(new long[]{0, 0});
} else if (needVibrate == 1) {
mBuilder.setVibrate(new long[]{0, 100, 0, 100});
} else if (needVibrate == 0 || needVibrate == 4) {
mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE);
} else if (needVibrate == 3) {
mBuilder.setVibrate(new long[]{0, 1000});
}
} else {
mBuilder.setVibrate(new long[]{0, 0});
}
notificationManager.notify(1, mBuilder.build());
} catch (Exception e) {
FileLog.e(e);
}
}
});
}
protected void forceShowPopupForReply() {
notificationsQueue.postRunnable(new Runnable() {
@Override
@ -456,8 +574,22 @@ public class NotificationsController {
added = true;
Boolean value = settingsCache.get(dialog_id);
boolean isChat = (int) dialog_id < 0;
popup = (int) dialog_id == 0 ? 0 : preferences.getInt(isChat ? "popupGroup" : "popupAll", 0);
int lower_id = (int) dialog_id;
boolean isChat = lower_id < 0;
if (lower_id != 0) {
if (preferences.getBoolean("custom_" + dialog_id, false)) {
popup = preferences.getInt("popup_" + dialog_id, 0);
} else {
popup = 0;
}
if (popup == 0) {
popup = preferences.getInt((int) dialog_id < 0 ? "popupGroup" : "popupAll", 0);
} else if (popup == 1) {
popup = 3;
} else if (popup == 2) {
popup = 0;
}
}
if (value == null) {
int notifyOverride = getNotifyOverride(preferences, dialog_id);
value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true) || isChat && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0);
@ -611,7 +743,8 @@ public class NotificationsController {
HashMap<Long, Boolean> settingsCache = new HashMap<>();
if (messages != null) {
for (TLRPC.Message message : messages) {
for (int a = 0; a < messages.size(); a++) {
TLRPC.Message message = messages.get(a);
long mid = message.id;
if (message.to_id.channel_id != 0) {
mid |= ((long) message.to_id.channel_id) << 32;
@ -694,38 +827,7 @@ public class NotificationsController {
return;
}
lastBadgeCount = count;
try {
ContentValues cv = new ContentValues();
cv.put("tag", "org.telegram.messenger/org.telegram.ui.LaunchActivity");
cv.put("count", count);
ApplicationLoader.applicationContext.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv);
} catch (Throwable e) {
//ignore
}
try {
if (launcherClassName == null) {
launcherClassName = getLauncherClassName(ApplicationLoader.applicationContext);
}
if (launcherClassName == null) {
return;
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
try {
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
intent.putExtra("badge_count", count);
intent.putExtra("badge_count_package_name", ApplicationLoader.applicationContext.getPackageName());
intent.putExtra("badge_count_class_name", launcherClassName);
ApplicationLoader.applicationContext.sendBroadcast(intent);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
} catch (Throwable e) {
FileLog.e("tmessages", e);
}
NotificationBadge.applyCount(count);
}
});
}
@ -791,8 +893,13 @@ public class NotificationsController {
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
String date = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(((long) messageObject.messageOwner.date) * 1000), LocaleController.getInstance().formatterDay.format(((long) messageObject.messageOwner.date) * 1000));
msg = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, UserConfig.getCurrentUser().first_name, date, messageObject.messageOwner.action.title, messageObject.messageOwner.action.address);
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionGameScore) {
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionGameScore || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPaymentSent) {
msg = messageObject.messageText.toString();
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall) {
TLRPC.PhoneCallDiscardReason reason = messageObject.messageOwner.action.reason;
if (!messageObject.isOut() && (reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed)) {
msg = LocaleController.getString("CallMessageIncomingMissed", R.string.CallMessageIncomingMissed);
}
}
} else {
if (messageObject.isMediaEmpty()) {
@ -1063,104 +1170,53 @@ public class NotificationsController {
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionGameScore) {
msg = messageObject.messageText.toString();
}
} else {
if (ChatObject.isChannel(chat) && !chat.megagroup) {
if (messageObject.messageOwner.post) {
if (messageObject.isMediaEmpty()) {
if (!shortMessage && messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, messageObject.messageOwner.message);
} else {
msg = LocaleController.formatString("ChannelMessageNoText", R.string.ChannelMessageNoText, name, chat.title);
}
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDDBC " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("ChannelMessagePhoto", R.string.ChannelMessagePhoto, name, chat.title);
}
} else if (messageObject.isVideo()) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDCF9 " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("ChannelMessageVideo", R.string.ChannelMessageVideo, name, chat.title);
}
} else if (messageObject.isVoice()) {
msg = LocaleController.formatString("ChannelMessageAudio", R.string.ChannelMessageAudio, name, chat.title);
} else if (messageObject.isMusic()) {
msg = LocaleController.formatString("ChannelMessageMusic", R.string.ChannelMessageMusic, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
msg = LocaleController.formatString("ChannelMessageContact", R.string.ChannelMessageContact, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
msg = LocaleController.formatString("ChannelMessageMap", R.string.ChannelMessageMap, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
if (messageObject.isSticker()) {
String emoji = messageObject.getStickerEmoji();
if (emoji != null) {
msg = LocaleController.formatString("ChannelMessageStickerEmoji", R.string.ChannelMessageStickerEmoji, name, chat.title, emoji);
} else {
msg = LocaleController.formatString("ChannelMessageSticker", R.string.ChannelMessageSticker, name, chat.title);
}
} else if (messageObject.isGif()) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83C\uDFAC " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("ChannelMessageGIF", R.string.ChannelMessageGIF, name, chat.title);
}
} else {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDCCE " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("ChannelMessageDocument", R.string.ChannelMessageDocument, name, chat.title);
}
}
} else if (ChatObject.isChannel(chat) && !chat.megagroup) {
if (messageObject.messageOwner.post) {
if (messageObject.isMediaEmpty()) {
if (!shortMessage && messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, messageObject.messageOwner.message);
} else {
msg = LocaleController.formatString("ChannelMessageNoText", R.string.ChannelMessageNoText, name);
}
} else {
if (messageObject.isMediaEmpty()) {
if (!shortMessage && messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, messageObject.messageOwner.message);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83D\uDDBC " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("ChannelMessagePhoto", R.string.ChannelMessagePhoto, name);
}
} else if (messageObject.isVideo()) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83D\uDCF9 " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("ChannelMessageVideo", R.string.ChannelMessageVideo, name);
}
} else if (messageObject.isVoice()) {
msg = LocaleController.formatString("ChannelMessageAudio", R.string.ChannelMessageAudio, name);
} else if (messageObject.isMusic()) {
msg = LocaleController.formatString("ChannelMessageMusic", R.string.ChannelMessageMusic, name);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
msg = LocaleController.formatString("ChannelMessageContact", R.string.ChannelMessageContact, name);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
msg = LocaleController.formatString("ChannelMessageMap", R.string.ChannelMessageMap, name);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
if (messageObject.isSticker()) {
String emoji = messageObject.getStickerEmoji();
if (emoji != null) {
msg = LocaleController.formatString("ChannelMessageStickerEmoji", R.string.ChannelMessageStickerEmoji, name, emoji);
} else {
msg = LocaleController.formatString("ChannelMessageGroupNoText", R.string.ChannelMessageGroupNoText, name, chat.title);
msg = LocaleController.formatString("ChannelMessageSticker", R.string.ChannelMessageSticker, name);
}
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
} else if (messageObject.isGif()) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDDBC " + messageObject.messageOwner.media.caption);
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83C\uDFAC " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("ChannelMessageGroupPhoto", R.string.ChannelMessageGroupPhoto, name, chat.title);
msg = LocaleController.formatString("ChannelMessageGIF", R.string.ChannelMessageGIF, name);
}
} else if (messageObject.isVideo()) {
} else {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDCF9 " + messageObject.messageOwner.media.caption);
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83D\uDCCE " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("ChannelMessageGroupVideo", R.string.ChannelMessageGroupVideo, name, chat.title);
}
} else if (messageObject.isVoice()) {
msg = LocaleController.formatString("ChannelMessageGroupAudio", R.string.ChannelMessageGroupAudio, name, chat.title);
} else if (messageObject.isMusic()) {
msg = LocaleController.formatString("ChannelMessageGroupMusic", R.string.ChannelMessageGroupMusic, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
msg = LocaleController.formatString("ChannelMessageGroupContact", R.string.ChannelMessageGroupContact, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
msg = LocaleController.formatString("ChannelMessageGroupMap", R.string.ChannelMessageGroupMap, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
if (messageObject.isSticker()) {
String emoji = messageObject.getStickerEmoji();
if (emoji != null) {
msg = LocaleController.formatString("ChannelMessageGroupStickerEmoji", R.string.ChannelMessageGroupStickerEmoji, name, chat.title, emoji);
} else {
msg = LocaleController.formatString("ChannelMessageGroupSticker", R.string.ChannelMessageGroupSticker, name, chat.title);
}
} else if (messageObject.isGif()) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83C\uDFAC " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("ChannelMessageGroupGif", R.string.ChannelMessageGroupGif, name, chat.title);
}
} else {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDCCE " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("ChannelMessageGroupDocument", R.string.ChannelMessageGroupDocument, name, chat.title);
}
msg = LocaleController.formatString("ChannelMessageDocument", R.string.ChannelMessageDocument, name);
}
}
}
@ -1169,53 +1225,102 @@ public class NotificationsController {
if (!shortMessage && messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, messageObject.messageOwner.message);
} else {
msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, name, chat.title);
msg = LocaleController.formatString("ChannelMessageGroupNoText", R.string.ChannelMessageGroupNoText, name, chat.title);
}
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDDBC " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("NotificationMessageGroupPhoto", R.string.NotificationMessageGroupPhoto, name, chat.title);
msg = LocaleController.formatString("ChannelMessageGroupPhoto", R.string.ChannelMessageGroupPhoto, name, chat.title);
}
} else if (messageObject.isVideo()) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDCF9 " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("NotificationMessageGroupVideo", R.string.NotificationMessageGroupVideo, name, chat.title);
msg = LocaleController.formatString("ChannelMessageGroupVideo", R.string.ChannelMessageGroupVideo, name, chat.title);
}
} else if (messageObject.isVoice()) {
msg = LocaleController.formatString("NotificationMessageGroupAudio", R.string.NotificationMessageGroupAudio, name, chat.title);
msg = LocaleController.formatString("ChannelMessageGroupAudio", R.string.ChannelMessageGroupAudio, name, chat.title);
} else if (messageObject.isMusic()) {
msg = LocaleController.formatString("NotificationMessageGroupMusic", R.string.NotificationMessageGroupMusic, name, chat.title);
msg = LocaleController.formatString("ChannelMessageGroupMusic", R.string.ChannelMessageGroupMusic, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
msg = LocaleController.formatString("NotificationMessageGroupContact", R.string.NotificationMessageGroupContact, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
msg = LocaleController.formatString("NotificationMessageGroupGame", R.string.NotificationMessageGroupGame, name, chat.title, messageObject.messageOwner.media.game.title);
msg = LocaleController.formatString("ChannelMessageGroupContact", R.string.ChannelMessageGroupContact, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
msg = LocaleController.formatString("NotificationMessageGroupMap", R.string.NotificationMessageGroupMap, name, chat.title);
msg = LocaleController.formatString("ChannelMessageGroupMap", R.string.ChannelMessageGroupMap, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
if (messageObject.isSticker()) {
String emoji = messageObject.getStickerEmoji();
if (emoji != null) {
msg = LocaleController.formatString("NotificationMessageGroupStickerEmoji", R.string.NotificationMessageGroupStickerEmoji, name, chat.title, emoji);
msg = LocaleController.formatString("ChannelMessageGroupStickerEmoji", R.string.ChannelMessageGroupStickerEmoji, name, chat.title, emoji);
} else {
msg = LocaleController.formatString("NotificationMessageGroupSticker", R.string.NotificationMessageGroupSticker, name, chat.title);
msg = LocaleController.formatString("ChannelMessageGroupSticker", R.string.ChannelMessageGroupSticker, name, chat.title);
}
} else if (messageObject.isGif()) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83C\uDFAC " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("NotificationMessageGroupGif", R.string.NotificationMessageGroupGif, name, chat.title);
msg = LocaleController.formatString("ChannelMessageGroupGif", R.string.ChannelMessageGroupGif, name, chat.title);
}
} else {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDCCE " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("NotificationMessageGroupDocument", R.string.NotificationMessageGroupDocument, name, chat.title);
msg = LocaleController.formatString("ChannelMessageGroupDocument", R.string.ChannelMessageGroupDocument, name, chat.title);
}
}
}
}
} else {
if (messageObject.isMediaEmpty()) {
if (!shortMessage && messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, messageObject.messageOwner.message);
} else {
msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, name, chat.title);
}
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDDBC " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("NotificationMessageGroupPhoto", R.string.NotificationMessageGroupPhoto, name, chat.title);
}
} else if (messageObject.isVideo()) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDCF9 " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("NotificationMessageGroupVideo", R.string.NotificationMessageGroupVideo, name, chat.title);
}
} else if (messageObject.isVoice()) {
msg = LocaleController.formatString("NotificationMessageGroupAudio", R.string.NotificationMessageGroupAudio, name, chat.title);
} else if (messageObject.isMusic()) {
msg = LocaleController.formatString("NotificationMessageGroupMusic", R.string.NotificationMessageGroupMusic, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
msg = LocaleController.formatString("NotificationMessageGroupContact", R.string.NotificationMessageGroupContact, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
msg = LocaleController.formatString("NotificationMessageGroupGame", R.string.NotificationMessageGroupGame, name, chat.title, messageObject.messageOwner.media.game.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
msg = LocaleController.formatString("NotificationMessageGroupMap", R.string.NotificationMessageGroupMap, name, chat.title);
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
if (messageObject.isSticker()) {
String emoji = messageObject.getStickerEmoji();
if (emoji != null) {
msg = LocaleController.formatString("NotificationMessageGroupStickerEmoji", R.string.NotificationMessageGroupStickerEmoji, name, chat.title, emoji);
} else {
msg = LocaleController.formatString("NotificationMessageGroupSticker", R.string.NotificationMessageGroupSticker, name, chat.title);
}
} else if (messageObject.isGif()) {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83C\uDFAC " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("NotificationMessageGroupGif", R.string.NotificationMessageGroupGif, name, chat.title);
}
} else {
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.media.caption)) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDCCE " + messageObject.messageOwner.media.caption);
} else {
msg = LocaleController.formatString("NotificationMessageGroupDocument", R.string.NotificationMessageGroupDocument, name, chat.title);
}
}
}
}
} else {
if (ChatObject.isChannel(chat) && !chat.megagroup) {
@ -1240,30 +1345,10 @@ public class NotificationsController {
alarmManager.cancel(pintent);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
}
private static String getLauncherClassName(Context context) {
try {
PackageManager pm = context.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resolveInfos) {
String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
if (pkgName.equalsIgnoreCase(context.getPackageName())) {
return resolveInfo.activityInfo.name;
}
}
} catch (Throwable e) {
FileLog.e("tmessages", e);
}
return null;
}
private boolean isPersonalMessage(MessageObject messageObject) {
return messageObject.messageOwner.to_id != null && messageObject.messageOwner.to_id.chat_id == 0 && messageObject.messageOwner.to_id.channel_id == 0
&& (messageObject.messageOwner.action == null || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty);
@ -1296,7 +1381,7 @@ public class NotificationsController {
}
});
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
}
@ -1328,12 +1413,12 @@ public class NotificationsController {
soundPool.play(soundRecord, 1.0f, 1.0f, 1, 0, 1.0f);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
}
});
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
}*/
@ -1346,7 +1431,7 @@ public class NotificationsController {
return;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
try {
@ -1368,7 +1453,11 @@ public class NotificationsController {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
if (status == 0) {
soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
try {
soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
} catch (Exception e) {
FileLog.e(e);
}
}
}
});
@ -1378,26 +1467,30 @@ public class NotificationsController {
soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1);
}
if (soundIn != 0) {
soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f);
try {
soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f);
} catch (Exception e) {
FileLog.e(e);
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
}
});
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
}
private void scheduleNotificationDelay(boolean onlineReason) {
try {
FileLog.e("tmessages", "delay notification start, onlineReason = " + onlineReason);
FileLog.e("delay notification start, onlineReason = " + onlineReason);
notificationDelayWakelock.acquire(10000);
AndroidUtilities.cancelRunOnUIThread(notificationDelayRunnable);
AndroidUtilities.runOnUIThread(notificationDelayRunnable, (onlineReason ? 3 * 1000 : 1000));
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
showOrUpdateNotification(notifyCheck);
}
}
@ -1457,7 +1550,7 @@ public class NotificationsController {
boolean notifyDisabled = false;
int needVibrate = 0;
String choosenSoundPath = null;
int ledColor = 0xff00ff00;
int ledColor = 0xff0000ff;
boolean inAppSounds;
boolean inAppVibrate;
boolean inAppPreview = false;
@ -1472,8 +1565,15 @@ public class NotificationsController {
}
if (!notifyDisabled && dialog_id == override_dialog_id && chat != null) {
int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2);
int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60);
int notifyMaxCount;
int notifyDelay;
if (preferences.getBoolean("custom_" + dialog_id, false)) {
notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2);
notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60);
} else {
notifyMaxCount = 2;
notifyDelay = 3 * 60;
}
if (notifyMaxCount != 0) {
Point dialogInfo = smartNotificationsDialogs.get(dialog_id);
if (dialogInfo == null) {
@ -1501,11 +1601,19 @@ public class NotificationsController {
inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true);
inAppPreview = preferences.getBoolean("EnableInAppPreview", true);
inAppPriority = preferences.getBoolean("EnableInAppPriority", false);
vibrateOverride = preferences.getInt("vibrate_" + dialog_id, 0);
priorityOverride = preferences.getInt("priority_" + dialog_id, 3);
boolean custom;
if (custom = preferences.getBoolean("custom_" + dialog_id, false)) {
vibrateOverride = preferences.getInt("vibrate_" + dialog_id, 0);
priorityOverride = preferences.getInt("priority_" + dialog_id, 3);
choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null);
} else {
vibrateOverride = 0;
priorityOverride = 3;
choosenSoundPath = null;
}
boolean vibrateOnlyIfSilent = false;
choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null);
if (chat_id != 0) {
if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
choosenSoundPath = null;
@ -1514,7 +1622,7 @@ public class NotificationsController {
}
needVibrate = preferences.getInt("vibrate_group", 0);
priority = preferences.getInt("priority_group", 1);
ledColor = preferences.getInt("GroupLed", 0xff00ff00);
ledColor = preferences.getInt("GroupLed", 0xff0000ff);
} else if (user_id != 0) {
if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
choosenSoundPath = null;
@ -1523,10 +1631,12 @@ public class NotificationsController {
}
needVibrate = preferences.getInt("vibrate_messages", 0);
priority = preferences.getInt("priority_group", 1);
ledColor = preferences.getInt("MessagesLed", 0xff00ff00);
ledColor = preferences.getInt("MessagesLed", 0xff0000ff);
}
if (preferences.contains("color_" + dialog_id)) {
ledColor = preferences.getInt("color_" + dialog_id, 0);
if (custom) {
if (preferences.contains("color_" + dialog_id)) {
ledColor = preferences.getInt("color_" + dialog_id, 0);
}
}
if (priorityOverride != 3) {
@ -1537,7 +1647,7 @@ public class NotificationsController {
vibrateOnlyIfSilent = true;
needVibrate = 0;
}
if (needVibrate == 2 && (vibrateOverride == 1 || vibrateOverride == 3 || vibrateOverride == 5) || needVibrate != 2 && vibrateOverride == 2 || vibrateOverride != 0) {
if (needVibrate == 2 && (vibrateOverride == 1 || vibrateOverride == 3) || needVibrate != 2 && vibrateOverride == 2 || vibrateOverride != 0 && vibrateOverride != 4) {
needVibrate = vibrateOverride;
}
if (!ApplicationLoader.mainInterfacePaused) {
@ -1560,7 +1670,7 @@ public class NotificationsController {
needVibrate = 2;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
}
}
@ -1762,7 +1872,7 @@ public class NotificationsController {
scheduleNotificationRepeat();
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
}
@ -1852,7 +1962,7 @@ public class NotificationsController {
NotificationCompat.Action wearReplyAction = null;
if (!ChatObject.isChannel(chat) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) {
if ((!ChatObject.isChannel(chat) || chat != null && chat.megagroup) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) {
Intent msgReplyIntent = new Intent();
msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
msgReplyIntent.setAction("org.telegram.messenger.ACTION_MESSAGE_REPLY");
@ -1873,7 +1983,7 @@ public class NotificationsController {
} else {
replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name);
}
wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build();
wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).setAllowGeneratedReplies(true).addRemoteInput(remoteInputWear).build();
}
Integer count = pushDialogs.get(dialog_id);
@ -1918,6 +2028,18 @@ public class NotificationsController {
wearableExtender.addAction(wearReplyAction);
}
String dismissalID=null;
if(chat!=null)
dismissalID="tgchat"+chat.id+"_"+max_id;
else if(user!=null)
dismissalID="tguser"+user.id+"_"+max_id;
wearableExtender.setDismissalId(dismissalID);
NotificationCompat.WearableExtender summaryExtender=new NotificationCompat.WearableExtender();
summaryExtender.setDismissalId("summary_"+dismissalID);
notificationBuilder.extend(summaryExtender);
NotificationCompat.Builder builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext)
.setContentTitle(name)
.setSmallIcon(R.drawable.notification)
@ -1974,7 +2096,7 @@ public class NotificationsController {
return;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
notificationsQueue.postRunnable(new Runnable() {
@Override
@ -1990,7 +2112,11 @@ public class NotificationsController {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
if (status == 0) {
soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
try {
soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
} catch (Exception e) {
FileLog.e(e);
}
}
}
});
@ -2000,10 +2126,14 @@ public class NotificationsController {
soundOut = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_out, 1);
}
if (soundOut != 0) {
soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f);
try {
soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f);
} catch (Exception e) {
FileLog.e(e);
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
FileLog.e(e);
}
}
});