Kate Mobile v109.1版本的 MD5 值为:fcd76ded5f363ecbfac46035a4ed2a23

以下内容为反编译后的 MessagesNotification.java 源代码,内容仅作参考


package com.perm.kate.notifications;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import android.service.notification.StatusBarNotification;
import android.text.TextUtils;
import androidx.core.app.NotificationCompat;
import androidx.core.app.Person;
import androidx.core.app.RemoteInput;
import androidx.core.graphics.drawable.IconCompat;
import com.perm.kate.BlockActivity;
import com.perm.kate.DialogsActivity;
import com.perm.kate.Helper;
import com.perm.kate.HiddenChats;
import com.perm.kate.KApplication;
import com.perm.kate.MessageThreadActivity;
import com.perm.kate.R;
import com.perm.kate.Settings;
import com.perm.kate.ThreadIdHelper;
import com.perm.kate.WearReceiver;
import com.perm.kate.api.Api;
import com.perm.kate.api.Group;
import com.perm.kate.api.User;
import com.perm.kate.push.C2DMReceiver;
import com.perm.kate.theme.ColorTheme;
import com.perm.utils.ChatNotificationsHelper;
import com.perm.utils.SilentMode;
import com.perm.utils.SleepModeHelper;
import java.io.File;
public abstract class MessagesNotification {
    private static void addWearableReplyAction(Context context, Long l, Long l2, NotificationCompat.Builder builder) {
        String string = context.getResources().getString(R.string.label_replay);
        RemoteInput build = new RemoteInput.Builder("extra_voice_reply").setLabel(string).setChoices(context.getResources().getStringArray(R.array.wear_replies)).build();
        Intent intent = new Intent(context, WearReceiver.class);
        intent.setAction("reply");
        if (l2 != null) {
            intent.putExtra("chat_id", l2);
        } else {
            intent.putExtra("from_id", l);
        }
        builder.extend(new NotificationCompat.WearableExtender().addAction(new NotificationCompat.Action.Builder(R.drawable.ic_action_send_now_dark, context.getString(R.string.label_replay), PendingIntent.getBroadcast(context, 0, intent, 167772160)).addRemoteInput(build).build()));
    }

    public static void cancel(Context context) {
    }

    public static void cancel(Context context, long j) {
        ((NotificationManager) context.getSystemService("notification")).cancel(Long.toString(j), 2);
    }

    public static void display(Context context, String str, Long l, Long l2) {
        long makeThreadId;
        boolean showMessage;
        String string;
        String string2;
        String str2;
        boolean z;
        NotificationCompat.Builder builder;
        Bitmap bitmap;
        int i;
        SharedPreferences sharedPreferences;
        boolean isEnabled;
        boolean z2;
        Notification build;
        Uri uri;
        boolean z3;
        Uri uri2;
        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        boolean z4 = defaultSharedPreferences.getBoolean("key_not_men_all", true);
        if (str != null) {
            if (!str.contains("[id" + C2DMReceiver.getPushAccount() + "|")) {
                if (z4) {
                }
            }
            makeThreadId = ThreadIdHelper.makeThreadId(l2, l);
            showMessage = getShowMessage(context, makeThreadId);
            if (showMessage) {
                string = context.getString(R.string.label_menu_messages);
                string2 = context.getString(R.string.label_menu_messages);
                str2 = "";
            } else {
                string = makeNotificationText(str, l, context);
                CharSequence chatTitle = getChatTitle(l2);
                if (TextUtils.isEmpty(chatTitle)) {
                    string2 = getUserName(l);
                    str2 = Api.unescape(str);
                } else {
                    string2 = chatTitle.toString();
                    str2 = getUserName(l) + ": " + Api.unescape(str);
                }
            }
            z = !KApplication.isTwoPaneMessages() && MessageThreadActivity.getShowLeftPane();
            Intent intent = new Intent(context, !z ? MessageThreadActivity.class : DialogsActivity.class);
            intent.setFlags(603979776);
            builder = new NotificationCompat.Builder(context);
            builder.setTicker(string);
            builder.setContentTitle(string2);
            builder.setContentText(str2);
            builder.setWhen(System.currentTimeMillis());
            builder.setSmallIcon(Utils.getMessagesIconId(context));
            if (showMessage) {
                bitmap = null;
            } else {
                bitmap = getLargeIcon(context, l);
                if (bitmap != null) {
                    builder.setLargeIcon(bitmap);
                }
            }
            builder.setContentIntent(PendingIntent.getActivity(context, 1, intent, 67108864));
            i = Build.VERSION.SDK_INT;
            if (i >= 24) {
                builder.setStyle(new NotificationCompat.BigTextStyle().bigText(str2));
                sharedPreferences = defaultSharedPreferences;
            } else {
                Notification activeNotification = getActiveNotification(Long.toString(makeThreadId), 2);
                NotificationCompat.MessagingStyle extractMessagingStyleFromNotification = activeNotification != null ? NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(activeNotification) : null;
                if (extractMessagingStyleFromNotification == null) {
                    extractMessagingStyleFromNotification = new NotificationCompat.MessagingStyle(new Person.Builder().setName("Вы").build());
                }
                Person.Builder name = new Person.Builder().setName(string2);
                if (bitmap != null) {
                    name.setIcon(IconCompat.createWithBitmap(bitmap));
                }
                sharedPreferences = defaultSharedPreferences;
                extractMessagingStyleFromNotification.addMessage(str2, System.currentTimeMillis(), name.build());
                builder.setStyle(extractMessagingStyleFromNotification);
            }
            if (PreferenceManager.getDefaultSharedPreferences(KApplication.current).getBoolean("headsup_notifications", true) && !PreferenceManager.getDefaultSharedPreferences(KApplication.current).getBoolean("key_popup_reply", false)) {
                builder.setPriority(1);
            }
            if (!z && (l2 != null || l != null)) {
                Intent intent2 = new Intent(context, MessageThreadActivity.class);
                intent2.setFlags(402653184);
                if (l2 == null) {
                    intent2.putExtra("com.perm.kate.chat_id", l2);
                } else {
                    intent2.putExtra("com.perm.kate.message_uid", l);
                }
                builder.addAction(R.drawable.ic_reply_grey, context.getText(R.string.label_menu_messages), PendingIntent.getActivity(context, l2 == null ? l2.intValue() : l.intValue(), intent2, 301989888));
            }
            setColor(builder);
            addWearableReplyAction(context, l, l2, builder);
            if (i >= 24 && (l2 != null || l != null)) {
                RemoteInput build2 = new RemoteInput.Builder("extra_voice_reply").setLabel(context.getResources().getString(R.string.label_replay)).build();
                Intent intent3 = new Intent(context, WearReceiver.class);
                intent3.setAction("reply");
                if (l2 == null) {
                    intent3.putExtra("chat_id", l2);
                } else {
                    intent3.putExtra("from_id", l);
                }
                builder.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_reply_grey, context.getString(R.string.label_replay), PendingIntent.getBroadcast(context, (int) makeThreadId, intent3, 167772160)).addRemoteInput(build2).build());
            }
            if (l2 == null || l != null) {
                Intent intent4 = new Intent(context, WearReceiver.class);
                intent4.setAction("read");
                if (l2 == null) {
                    intent4.putExtra("chat_id", l2);
                } else {
                    intent4.putExtra("from_id", l);
                }
                builder.addAction(R.drawable.eye, context.getText(R.string.mark_as_read), PendingIntent.getBroadcast(context, (int) makeThreadId, intent4, 167772160));
            }
            isEnabled = SilentMode.isEnabled();
            boolean isActiveSleepMode = SleepModeHelper.isActiveSleepMode(context);
            z2 = isEnabled && !isActiveSleepMode && (sharedPreferences.getBoolean(context.getString(R.string.key_notify_sound), true) || i >= 26);
            if (i >= 26) {
                builder.setChannelId(Utils.getChannelId("messages", z2));
            }
            builder.setCategory("msg");
            build = builder.build();
            if (!isEnabled && !isActiveSleepMode && sharedPreferences.getBoolean("key_notify_vibration", false)) {
                build.vibrate = Utils.getVibratePattern(context, sharedPreferences);
            }
            if (!z2) {
                if (sharedPreferences.getBoolean(context.getString(R.string.key_notify_sound_default), true)) {
                    uri2 = Uri.parse("android.resource://" + context.getPackageName() + "/raw/notification_sound");
                    build.sound = uri2;
                } else {
                    uri = null;
                    String fileRingtoneFix = fileRingtoneFix(sharedPreferences.getString(context.getString(R.string.key_notify_ringtone), null));
                    if (fileRingtoneFix != null) {
                        uri2 = Uri.parse(fileRingtoneFix);
                        build.sound = uri2;
                    } else {
                        z3 = true;
                        build.defaults |= 1;
                    }
                }
                z3 = true;
                if (sharedPreferences.getBoolean("key_notify_led", z3)) {
                    build.ledARGB = Settings.getLedColor(context);
                    build.ledOnMS = 300;
                    build.ledOffMS = 1000;
                    build.flags |= z3;
                }
                build.flags |= 16;
                if (i >= 26) {
                    if (z2) {
                        Utils.createNotificationChannelHigh(context, "messages", R.string.label_menu_messages, uri2);
                    } else {
                        Utils.createNotificationChannel(context, "messages", R.string.label_menu_messages, z2, uri2);
                    }
                }
                ((NotificationManager) context.getSystemService("notification")).notify(Long.toString(makeThreadId), 2, build);
            }
            uri = null;
            z3 = true;
            uri2 = uri;
            if (sharedPreferences.getBoolean("key_notify_led", z3)) {
            }
            build.flags |= 16;
            if (i >= 26) {
            }
            ((NotificationManager) context.getSystemService("notification")).notify(Long.toString(makeThreadId), 2, build);
        }
        if (ChatNotificationsHelper.isDisabledChat(context, l, l2)) {
            return;
        }
        makeThreadId = ThreadIdHelper.makeThreadId(l2, l);
        showMessage = getShowMessage(context, makeThreadId);
        if (showMessage) {
        }
        if (KApplication.isTwoPaneMessages()) {
        }
        Intent intent5 = new Intent(context, !z ? MessageThreadActivity.class : DialogsActivity.class);
        intent5.setFlags(603979776);
        builder = new NotificationCompat.Builder(context);
        builder.setTicker(string);
        builder.setContentTitle(string2);
        builder.setContentText(str2);
        builder.setWhen(System.currentTimeMillis());
        builder.setSmallIcon(Utils.getMessagesIconId(context));
        if (showMessage) {
        }
        builder.setContentIntent(PendingIntent.getActivity(context, 1, intent5, 67108864));
        i = Build.VERSION.SDK_INT;
        if (i >= 24) {
        }
        if (PreferenceManager.getDefaultSharedPreferences(KApplication.current).getBoolean("headsup_notifications", true)) {
            builder.setPriority(1);
        }
        if (!z) {
            Intent intent22 = new Intent(context, MessageThreadActivity.class);
            intent22.setFlags(402653184);
            if (l2 == null) {
            }
            builder.addAction(R.drawable.ic_reply_grey, context.getText(R.string.label_menu_messages), PendingIntent.getActivity(context, l2 == null ? l2.intValue() : l.intValue(), intent22, 301989888));
        }
        setColor(builder);
        addWearableReplyAction(context, l, l2, builder);
        if (i >= 24) {
            RemoteInput build22 = new RemoteInput.Builder("extra_voice_reply").setLabel(context.getResources().getString(R.string.label_replay)).build();
            Intent intent32 = new Intent(context, WearReceiver.class);
            intent32.setAction("reply");
            if (l2 == null) {
            }
            builder.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_reply_grey, context.getString(R.string.label_replay), PendingIntent.getBroadcast(context, (int) makeThreadId, intent32, 167772160)).addRemoteInput(build22).build());
        }
        if (l2 == null) {
        }
        Intent intent42 = new Intent(context, WearReceiver.class);
        intent42.setAction("read");
        if (l2 == null) {
        }
        builder.addAction(R.drawable.eye, context.getText(R.string.mark_as_read), PendingIntent.getBroadcast(context, (int) makeThreadId, intent42, 167772160));
        isEnabled = SilentMode.isEnabled();
        boolean isActiveSleepMode2 = SleepModeHelper.isActiveSleepMode(context);
        if (isEnabled) {
        }
        if (i >= 26) {
        }
        builder.setCategory("msg");
        build = builder.build();
        if (!isEnabled) {
            build.vibrate = Utils.getVibratePattern(context, sharedPreferences);
        }
        if (!z2) {
        }
        uri2 = uri;
        if (sharedPreferences.getBoolean("key_notify_led", z3)) {
        }
        build.flags |= 16;
        if (i >= 26) {
        }
        ((NotificationManager) context.getSystemService("notification")).notify(Long.toString(makeThreadId), 2, build);
    }

    public static String fileRingtoneFix(String str) {
        int i;
        if (str != null) {
            String str2 = Build.MODEL;
            if ((str2.startsWith("Redmi") || str2.startsWith("Mi ") || str2.startsWith("MI ") || str2.equals("DUA-L22") || str2.equals("MIX") || str2.equals("Impress_Lion_4G") || str2.equals("ZB633KL") || str2.equals("TECNO F4 Pro") || str2.equals("POCOPHONE F1") || str2.equals("ZB602KL") || str2.equals("CLT-L29") || str2.startsWith("Mi-") || str2.equals("LLD-L31")) && (i = Build.VERSION.SDK_INT) >= 24 && i <= 29 && str.startsWith("file:///storage")) {
                return null;
            }
            return str;
        }
        return str;
    }

    static Notification getActiveNotification(String str, int i) {
        StatusBarNotification[] activeNotifications;
        int id;
        String tag;
        Notification notification;
        try {
            activeNotifications = ((NotificationManager) KApplication.current.getSystemService("notification")).getActiveNotifications();
            for (StatusBarNotification statusBarNotification : activeNotifications) {
                id = statusBarNotification.getId();
                if (id == i) {
                    tag = statusBarNotification.getTag();
                    if (tag.equals(str)) {
                        notification = statusBarNotification.getNotification();
                        return notification;
                    }
                }
            }
            return null;
        } catch (Throwable th) {
            th.printStackTrace();
            Helper.reportError(th);
            return null;
        }
    }

    public static Bitmap getBitmapFromMemoryOrSdCache(String str) {
        if (KApplication.getImageLoader().isCachedInMemory(str)) {
            return KApplication.getImageLoader().getFromMemoryCache(str);
        }
        File cacheFile = KApplication.getImageLoader().getCacheFile(str);
        if (cacheFile.exists()) {
            return KApplication.getImageLoader().decodeFile(cacheFile, 300, 300, false, false);
        }
        return null;
    }

    private static CharSequence getChatTitle(Long l) {
        if (l == null) {
            return "";
        }
        try {
            return KApplication.db.fetchChatName(l.longValue(), KApplication.longPoll.isStarted() ? Long.parseLong(KApplication.session.getMid()) : C2DMReceiver.getPushAccount());
        } catch (Throwable th) {
            th.printStackTrace();
            Helper.reportError(th);
            return "";
        }
    }

    private static Bitmap getLargeIcon(Context context, Long l) {
        String str;
        if (l == null) {
            return null;
        }
        if (User.isVirtualUser(l.longValue())) {
            Group fetchGroup = KApplication.db.fetchGroup(User.virtualUserIdToGroupId(l.longValue()));
            if (fetchGroup != null) {
                str = fetchGroup.photo_medium;
            }
            str = null;
        } else {
            User fetchUser = KApplication.db.fetchUser(l.longValue());
            if (fetchUser != null) {
                str = fetchUser.photo_medium_rec;
            }
            str = null;
        }
        if (str == null) {
            return null;
        }
        return getBitmapFromMemoryOrSdCache(str);
    }

    public static boolean getShowMessage(Context context, long j) {
        boolean z = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(context.getString(R.string.key_message_in_notification), true);
        if (BlockActivity.getBlockFlag(context)) {
            z = false;
        }
        if (HiddenChats.isHiddenNow(j)) {
            return false;
        }
        return z;
    }

    private static String getUserName(Long l) {
        if (l == null) {
            return "";
        }
        if (User.isVirtualUser(l.longValue())) {
            Group fetchGroup = KApplication.db.fetchGroup(User.virtualUserIdToGroupId(l.longValue()));
            return fetchGroup != null ? fetchGroup.name : "";
        }
        User fetchUser = KApplication.db.fetchUser(l.longValue());
        if (fetchUser != null) {
            return fetchUser.first_name + " " + fetchUser.last_name;
        }
        return "";
    }

    private static String makeNotificationText(String str, Long l, Context context) {
        try {
            String userName = getUserName(l);
            String str2 = "";
            if (userName != null) {
                str2 = "" + userName;
            }
            if (str2.length() != 0 && str != null && str.length() != 0) {
                str2 = str2 + ": ";
            }
            if (str != null) {
                return str2 + Api.unescape(str);
            }
            return str2;
        } catch (Throwable th) {
            th.printStackTrace();
            Helper.reportError(th);
            return context.getString(R.string.label_menu_messages);
        }
    }

    public static void setColor(NotificationCompat.Builder builder) {
        builder.setColor(ColorTheme.getColorTheme().getHeaderBgColor());
    }
}