导航菜单

页面标题

页面副标题

Weicon v2.1.4 - DefaultFetchNotificationManager.java 源代码

正在查看: Weicon v2.1.4 应用的 DefaultFetchNotificationManager.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.tonyodev.fetch2;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Build;
import androidx.activity.ComponentDialog$;
import androidx.core.app.NotificationCompat;
import com.tonyodev.fetch2.DownloadNotification;
import com.tonyodev.fetch2.util.FetchDefaults;
import com.tonyodev.fetch2.util.NotificationUtilsKt;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import kotlin.Metadata;
import kotlin.TypeCastException;
import kotlin.Unit;
import kotlin.io.path.LinkFollowing$;
import kotlin.jvm.internal.Intrinsics;

@Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0080\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010#\n\u0002\u0010\b\n\u0000\n\u0002\u0010%\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010 \n\u0002\b\u0006\n\u0002\u0010\u000b\n\u0002\b\b\b&\u0018\u00002\u00020\u0001B\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u0010\u0010\u0017\u001a\u00020\u00182\u0006\u0010\u0019\u001a\u00020\u000bH\u0016J\b\u0010\u001a\u001a\u00020\u0018H\u0016J\u0018\u0010\u001b\u001a\u00020\u00182\u0006\u0010\u0002\u001a\u00020\u00032\u0006\u0010\u0011\u001a\u00020\u0012H\u0016J\u0018\u0010\u001c\u001a\u00020\u001d2\u0006\u0010\u001e\u001a\u00020\u00102\u0006\u0010\u001f\u001a\u00020 H\u0016J\u0018\u0010!\u001a\u00020\u00142\u0006\u0010\u0019\u001a\u00020\u000b2\u0006\u0010\u0002\u001a\u00020\u0003H\u0016J\u0010\u0010\"\u001a\u00020\u00142\u0006\u0010#\u001a\u00020$H\u0016J\u0018\u0010%\u001a\u00020\u00142\u0006\u0010\u0002\u001a\u00020\u00032\u0006\u0010&\u001a\u00020'H\u0002J\u0010\u0010(\u001a\u00020)2\u0006\u0010*\u001a\u00020\u0014H&J&\u0010+\u001a\u00020\u001d2\u0006\u0010,\u001a\u00020\u000b2\f\u0010-\u001a\b\u0012\u0004\u0012\u00020\u00100.2\u0006\u0010\u001f\u001a\u00020 H\u0016J\u0018\u0010/\u001a\u00020\u000e2\u0006\u0010\u0019\u001a\u00020\u000b2\u0006\u0010,\u001a\u00020\u000bH\u0017J\b\u00100\u001a\u00020'H\u0016J\u0018\u00101\u001a\u00020\u00142\u0006\u0010\u0002\u001a\u00020\u00032\u0006\u0010\u001e\u001a\u00020\u0010H\u0016J\b\u00102\u001a\u00020\u0018H\u0002J\u0010\u00103\u001a\u00020\u00182\u0006\u0010,\u001a\u00020\u000bH\u0016J\u0010\u00104\u001a\u0002052\u0006\u0010#\u001a\u00020$H\u0016J\b\u00106\u001a\u00020\u0018H\u0016J\u0010\u00107\u001a\u0002052\u0006\u0010\u001e\u001a\u00020\u0010H\u0016J\u0010\u00108\u001a\u0002052\u0006\u0010\u001e\u001a\u00020\u0010H\u0016J\b\u00109\u001a\u00020\u0018H\u0016J.\u0010:\u001a\u0002052\u0006\u0010,\u001a\u00020\u000b2\u0006\u0010;\u001a\u00020\u000e2\f\u0010-\u001a\b\u0012\u0004\u0012\u00020\u00100.2\u0006\u0010\u0002\u001a\u00020\u0003H\u0016J \u0010<\u001a\u00020\u00182\u0006\u0010;\u001a\u00020\u000e2\u0006\u0010\u001e\u001a\u00020\u00102\u0006\u0010\u0002\u001a\u00020\u0003H\u0016R\u0014\u0010\u0005\u001a\u00020\u00068VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b\u0007\u0010\bR\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\t\u001a\b\u0012\u0004\u0012\u00020\u000b0\nX\u0082\u0004¢\u0006\u0002\n\u0000R\u001a\u0010\f\u001a\u000e\u0012\u0004\u0012\u00020\u000b\u0012\u0004\u0012\u00020\u000e0\rX\u0082\u0004¢\u0006\u0002\n\u0000R\u001a\u0010\u000f\u001a\u000e\u0012\u0004\u0012\u00020\u000b\u0012\u0004\u0012\u00020\u00100\rX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0011\u001a\u00020\u0012X\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u0013\u001a\u00020\u0014X\u0096\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0015\u0010\u0016¨\u0006="}, d2 = {"Lcom/tonyodev/fetch2/DefaultFetchNotificationManager;", "Lcom/tonyodev/fetch2/FetchNotificationManager;", "context", "Landroid/content/Context;", "(Landroid/content/Context;)V", "broadcastReceiver", "Landroid/content/BroadcastReceiver;", "getBroadcastReceiver", "()Landroid/content/BroadcastReceiver;", "downloadNotificationExcludeSet", "", "", "downloadNotificationsBuilderMap", "", "Landroidx/core/app/NotificationCompat$Builder;", "downloadNotificationsMap", "Lcom/tonyodev/fetch2/DownloadNotification;", "notificationManager", "Landroid/app/NotificationManager;", "notificationManagerAction", "", "getNotificationManagerAction", "()Ljava/lang/String;", "cancelNotification", "", "notificationId", "cancelOngoingNotifications", "createNotificationChannels", "getActionPendingIntent", "Landroid/app/PendingIntent;", "downloadNotification", "actionType", "Lcom/tonyodev/fetch2/DownloadNotification$ActionType;", "getChannelId", "getDownloadNotificationTitle", "download", "Lcom/tonyodev/fetch2/Download;", "getEtaText", "etaInMilliSeconds", "", "getFetchInstanceForNamespace", "Lcom/tonyodev/fetch2/Fetch;", "namespace", "getGroupActionPendingIntent", "groupId", "downloadNotifications", "", "getNotificationBuilder", "getNotificationTimeOutMillis", "getSubtitleText", "initialize", "notify", "postDownloadUpdate", "", "registerBroadcastReceiver", "shouldCancelNotification", "shouldUpdateNotification", "unregisterBroadcastReceiver", "updateGroupSummaryNotification", "notificationBuilder", "updateNotification", "fetch2_release"}, k = 1, mv = {1, 1, 16})
public abstract class DefaultFetchNotificationManager implements FetchNotificationManager {
    private final Context context;
    private final Set<Integer> downloadNotificationExcludeSet;
    private final Map<Integer, NotificationCompat.Builder> downloadNotificationsBuilderMap;
    private final Map<Integer, DownloadNotification> downloadNotificationsMap;
    private final NotificationManager notificationManager;
    private final String notificationManagerAction;

    @Metadata(bv = {1, 0, 3}, k = 3, mv = {1, 1, 16})
    public final class WhenMappings {
        public static final int[] $EnumSwitchMapping$0;
        public static final int[] $EnumSwitchMapping$1;
        public static final int[] $EnumSwitchMapping$2;

        static {
            int[] iArr = new int[DownloadNotification.ActionType.values().length];
            $EnumSwitchMapping$0 = iArr;
            iArr[DownloadNotification.ActionType.CANCEL.ordinal()] = 1;
            iArr[DownloadNotification.ActionType.DELETE.ordinal()] = 2;
            iArr[DownloadNotification.ActionType.RESUME.ordinal()] = 3;
            iArr[DownloadNotification.ActionType.PAUSE.ordinal()] = 4;
            iArr[DownloadNotification.ActionType.RETRY.ordinal()] = 5;
            int[] iArr2 = new int[DownloadNotification.ActionType.values().length];
            $EnumSwitchMapping$1 = iArr2;
            iArr2[DownloadNotification.ActionType.CANCEL_ALL.ordinal()] = 1;
            iArr2[DownloadNotification.ActionType.DELETE_ALL.ordinal()] = 2;
            iArr2[DownloadNotification.ActionType.RESUME_ALL.ordinal()] = 3;
            iArr2[DownloadNotification.ActionType.PAUSE_ALL.ordinal()] = 4;
            iArr2[DownloadNotification.ActionType.RETRY_ALL.ordinal()] = 5;
            int[] iArr3 = new int[Status.values().length];
            $EnumSwitchMapping$2 = iArr3;
            iArr3[Status.COMPLETED.ordinal()] = 1;
            iArr3[Status.FAILED.ordinal()] = 2;
        }
    }

    @Override
    public abstract Fetch getFetchInstanceForNamespace(String namespace);

    @Override
    public long getNotificationTimeOutMillis() {
        return 10000L;
    }

    public DefaultFetchNotificationManager(Context context) {
        Intrinsics.checkParameterIsNotNull(context, "context");
        Context applicationContext = context.getApplicationContext();
        Intrinsics.checkExpressionValueIsNotNull(applicationContext, "context.applicationContext");
        this.context = applicationContext;
        Object systemService = context.getSystemService("notification");
        if (systemService == null) {
            throw new TypeCastException("null cannot be cast to non-null type android.app.NotificationManager");
        }
        this.notificationManager = (NotificationManager) systemService;
        this.downloadNotificationsMap = new LinkedHashMap();
        this.downloadNotificationsBuilderMap = new LinkedHashMap();
        this.downloadNotificationExcludeSet = new LinkedHashSet();
        this.notificationManagerAction = "DEFAULT_FETCH2_NOTIFICATION_MANAGER_ACTION_" + System.currentTimeMillis();
        initialize();
    }

    @Override
    public String getNotificationManagerAction() {
        return this.notificationManagerAction;
    }

    @Override
    public BroadcastReceiver getBroadcastReceiver() {
        return new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                NotificationUtilsKt.onDownloadNotificationActionTriggered(context, intent, DefaultFetchNotificationManager.this);
            }
        };
    }

    private final void initialize() {
        registerBroadcastReceiver();
        createNotificationChannels(this.context, this.notificationManager);
    }

    @Override
    public void registerBroadcastReceiver() {
        this.context.registerReceiver(getBroadcastReceiver(), new IntentFilter(getNotificationManagerAction()));
    }

    @Override
    public void unregisterBroadcastReceiver() {
        this.context.unregisterReceiver(getBroadcastReceiver());
    }

    @Override
    public void createNotificationChannels(Context context, NotificationManager notificationManager) {
        Intrinsics.checkParameterIsNotNull(context, "context");
        Intrinsics.checkParameterIsNotNull(notificationManager, "notificationManager");
        if (Build.VERSION.SDK_INT >= 26) {
            String string = context.getString(R.string.fetch_notification_default_channel_id);
            Intrinsics.checkExpressionValueIsNotNull(string, "context.getString(R.stri…ation_default_channel_id)");
            if (ComponentDialog$.ExternalSyntheticApiModelOutline0.m(notificationManager, string) == null) {
                String string2 = context.getString(R.string.fetch_notification_default_channel_name);
                Intrinsics.checkExpressionValueIsNotNull(string2, "context.getString(R.stri…ion_default_channel_name)");
                LinkFollowing$.ExternalSyntheticApiModelOutline0.m$1();
                ComponentDialog$.ExternalSyntheticApiModelOutline0.m(notificationManager, ComponentDialog$.ExternalSyntheticApiModelOutline0.m(string, string2, 3));
            }
        }
    }

    @Override
    public String getChannelId(int notificationId, Context context) {
        Intrinsics.checkParameterIsNotNull(context, "context");
        String string = context.getString(R.string.fetch_notification_default_channel_id);
        Intrinsics.checkExpressionValueIsNotNull(string, "context.getString(R.stri…ation_default_channel_id)");
        return string;
    }

    @Override
    public boolean updateGroupSummaryNotification(int groupId, NotificationCompat.Builder notificationBuilder, List<? extends DownloadNotification> downloadNotifications, Context context) {
        Intrinsics.checkParameterIsNotNull(notificationBuilder, "notificationBuilder");
        Intrinsics.checkParameterIsNotNull(downloadNotifications, "downloadNotifications");
        Intrinsics.checkParameterIsNotNull(context, "context");
        NotificationCompat.Style inboxStyle = new NotificationCompat.InboxStyle();
        for (DownloadNotification downloadNotification : downloadNotifications) {
            inboxStyle.addLine(downloadNotification.getTotal() + ' ' + getSubtitleText(context, downloadNotification));
        }
        notificationBuilder.setPriority(0).setSmallIcon(android.R.drawable.stat_sys_download_done).setContentTitle(context.getString(R.string.fetch_notification_default_channel_name)).setContentText("").setStyle(inboxStyle).setOnlyAlertOnce(true).setGroup(String.valueOf(groupId)).setGroupSummary(true);
        return false;
    }

    @Override
    public void updateNotification(NotificationCompat.Builder notificationBuilder, DownloadNotification downloadNotification, Context context) {
        Intrinsics.checkParameterIsNotNull(notificationBuilder, "notificationBuilder");
        Intrinsics.checkParameterIsNotNull(downloadNotification, "downloadNotification");
        Intrinsics.checkParameterIsNotNull(context, "context");
        notificationBuilder.setPriority(0).setSmallIcon(downloadNotification.isDownloading() ? android.R.drawable.stat_sys_download : android.R.drawable.stat_sys_download_done).setContentTitle(downloadNotification.getTitle()).setContentText(getSubtitleText(context, downloadNotification)).setOngoing(downloadNotification.isOnGoingNotification()).setGroup(String.valueOf(downloadNotification.getGroupId())).setGroupSummary(false);
        if (downloadNotification.isFailed() || downloadNotification.isCompleted()) {
            notificationBuilder.setProgress(0, 0, false);
        } else {
            notificationBuilder.setProgress(downloadNotification.getProgressIndeterminate() ? 0 : 100, downloadNotification.getProgress() >= 0 ? downloadNotification.getProgress() : 0, downloadNotification.getProgressIndeterminate());
        }
        if (downloadNotification.isDownloading()) {
            notificationBuilder.setTimeoutAfter(getNotificationTimeOutMillis()).addAction(R.drawable.fetch_notification_pause, context.getString(R.string.fetch_notification_download_pause), getActionPendingIntent(downloadNotification, DownloadNotification.ActionType.PAUSE)).addAction(R.drawable.fetch_notification_cancel, context.getString(R.string.fetch_notification_download_cancel), getActionPendingIntent(downloadNotification, DownloadNotification.ActionType.CANCEL));
            return;
        }
        if (downloadNotification.isPaused()) {
            notificationBuilder.setTimeoutAfter(getNotificationTimeOutMillis()).addAction(R.drawable.fetch_notification_resume, context.getString(R.string.fetch_notification_download_resume), getActionPendingIntent(downloadNotification, DownloadNotification.ActionType.RESUME)).addAction(R.drawable.fetch_notification_cancel, context.getString(R.string.fetch_notification_download_cancel), getActionPendingIntent(downloadNotification, DownloadNotification.ActionType.CANCEL));
        } else if (downloadNotification.isQueued()) {
            notificationBuilder.setTimeoutAfter(getNotificationTimeOutMillis());
        } else {
            notificationBuilder.setTimeoutAfter(FetchDefaults.DEFAULT_NOTIFICATION_TIMEOUT_AFTER_RESET);
        }
    }

    @Override
    public PendingIntent getActionPendingIntent(DownloadNotification downloadNotification, DownloadNotification.ActionType actionType) {
        PendingIntent broadcast;
        Intrinsics.checkParameterIsNotNull(downloadNotification, "downloadNotification");
        Intrinsics.checkParameterIsNotNull(actionType, "actionType");
        synchronized (this.downloadNotificationsMap) {
            Intent intent = new Intent(getNotificationManagerAction());
            intent.putExtra(FetchIntent.EXTRA_NAMESPACE, downloadNotification.getNamespace());
            intent.putExtra(FetchIntent.EXTRA_DOWNLOAD_ID, downloadNotification.getNotificationId());
            intent.putExtra(FetchIntent.EXTRA_NOTIFICATION_ID, downloadNotification.getNotificationId());
            int i = 0;
            intent.putExtra(FetchIntent.EXTRA_GROUP_ACTION, false);
            intent.putExtra(FetchIntent.EXTRA_NOTIFICATION_GROUP_ID, downloadNotification.getGroupId());
            int i2 = WhenMappings.$EnumSwitchMapping$0[actionType.ordinal()];
            if (i2 == 1) {
                i = 4;
            } else if (i2 == 2) {
                i = 2;
            } else if (i2 == 3) {
                i = 1;
            } else if (i2 != 4) {
                i = 5;
                if (i2 != 5) {
                    i = -1;
                }
            }
            intent.putExtra(FetchIntent.EXTRA_ACTION_TYPE, i);
            broadcast = PendingIntent.getBroadcast(this.context, downloadNotification.getNotificationId() + i, intent, 134217728);
            Intrinsics.checkExpressionValueIsNotNull(broadcast, "PendingIntent.getBroadca…tent.FLAG_UPDATE_CURRENT)");
        }
        return broadcast;
    }

    @Override
    public PendingIntent getGroupActionPendingIntent(int groupId, List<? extends DownloadNotification> downloadNotifications, DownloadNotification.ActionType actionType) {
        PendingIntent broadcast;
        Intrinsics.checkParameterIsNotNull(downloadNotifications, "downloadNotifications");
        Intrinsics.checkParameterIsNotNull(actionType, "actionType");
        synchronized (this.downloadNotificationsMap) {
            Intent intent = new Intent(getNotificationManagerAction());
            intent.putExtra(FetchIntent.EXTRA_NOTIFICATION_GROUP_ID, groupId);
            intent.putExtra(FetchIntent.EXTRA_DOWNLOAD_NOTIFICATIONS, new ArrayList(downloadNotifications));
            intent.putExtra(FetchIntent.EXTRA_GROUP_ACTION, true);
            int i = WhenMappings.$EnumSwitchMapping$1[actionType.ordinal()];
            int i2 = i != 1 ? i != 2 ? i != 3 ? i != 4 ? i != 5 ? -1 : 10 : 6 : 7 : 9 : 8;
            intent.putExtra(FetchIntent.EXTRA_ACTION_TYPE, i2);
            broadcast = PendingIntent.getBroadcast(this.context, groupId + i2, intent, 134217728);
            Intrinsics.checkExpressionValueIsNotNull(broadcast, "PendingIntent.getBroadca…tent.FLAG_UPDATE_CURRENT)");
        }
        return broadcast;
    }

    @Override
    public void cancelNotification(int notificationId) {
        synchronized (this.downloadNotificationsMap) {
            this.notificationManager.cancel(notificationId);
            this.downloadNotificationsBuilderMap.remove(Integer.valueOf(notificationId));
            this.downloadNotificationExcludeSet.remove(Integer.valueOf(notificationId));
            DownloadNotification downloadNotification = this.downloadNotificationsMap.get(Integer.valueOf(notificationId));
            if (downloadNotification != null) {
                this.downloadNotificationsMap.remove(Integer.valueOf(notificationId));
                notify(downloadNotification.getGroupId());
            }
            Unit unit = Unit.INSTANCE;
        }
    }

    @Override
    public void cancelOngoingNotifications() {
        synchronized (this.downloadNotificationsMap) {
            Iterator<DownloadNotification> it = this.downloadNotificationsMap.values().iterator();
            while (it.hasNext()) {
                DownloadNotification next = it.next();
                if (!next.isFailed() && !next.isCompleted()) {
                    this.notificationManager.cancel(next.getNotificationId());
                    this.downloadNotificationsBuilderMap.remove(Integer.valueOf(next.getNotificationId()));
                    this.downloadNotificationExcludeSet.remove(Integer.valueOf(next.getNotificationId()));
                    it.remove();
                    notify(next.getGroupId());
                }
            }
            Unit unit = Unit.INSTANCE;
        }
    }

    @Override
    public void notify(int groupId) {
        synchronized (this.downloadNotificationsMap) {
            Collection<DownloadNotification> values = this.downloadNotificationsMap.values();
            ArrayList arrayList = new ArrayList();
            for (Object obj : values) {
                if (((DownloadNotification) obj).getGroupId() == groupId) {
                    arrayList.add(obj);
                }
            }
            ArrayList arrayList2 = arrayList;
            NotificationCompat.Builder notificationBuilder = getNotificationBuilder(groupId, groupId);
            boolean updateGroupSummaryNotification = updateGroupSummaryNotification(groupId, notificationBuilder, arrayList2, this.context);
            for (DownloadNotification downloadNotification : arrayList2) {
                if (shouldUpdateNotification(downloadNotification)) {
                    int notificationId = downloadNotification.getNotificationId();
                    NotificationCompat.Builder notificationBuilder2 = getNotificationBuilder(notificationId, groupId);
                    updateNotification(notificationBuilder2, downloadNotification, this.context);
                    this.notificationManager.notify(notificationId, notificationBuilder2.build());
                    int i = WhenMappings.$EnumSwitchMapping$2[downloadNotification.getStatus().ordinal()];
                    if (i == 1 || i == 2) {
                        this.downloadNotificationExcludeSet.add(Integer.valueOf(downloadNotification.getNotificationId()));
                    }
                }
            }
            if (updateGroupSummaryNotification) {
                this.notificationManager.notify(groupId, notificationBuilder.build());
            }
            Unit unit = Unit.INSTANCE;
        }
    }

    @Override
    public boolean shouldUpdateNotification(DownloadNotification downloadNotification) {
        Intrinsics.checkParameterIsNotNull(downloadNotification, "downloadNotification");
        return !this.downloadNotificationExcludeSet.contains(Integer.valueOf(downloadNotification.getNotificationId()));
    }

    @Override
    public boolean shouldCancelNotification(DownloadNotification downloadNotification) {
        Intrinsics.checkParameterIsNotNull(downloadNotification, "downloadNotification");
        return downloadNotification.isPaused();
    }

    @Override
    public boolean postDownloadUpdate(Download download) {
        Intrinsics.checkParameterIsNotNull(download, "download");
        synchronized (this.downloadNotificationsMap) {
            if (this.downloadNotificationsMap.size() > 50) {
                this.downloadNotificationsBuilderMap.clear();
                this.downloadNotificationsMap.clear();
            }
            DownloadNotification downloadNotification = this.downloadNotificationsMap.get(Integer.valueOf(download.getId()));
            if (downloadNotification == null) {
                downloadNotification = new DownloadNotification();
            }
            downloadNotification.setStatus(download.getStatus());
            downloadNotification.setProgress(download.getProgress());
            downloadNotification.setNotificationId(download.getId());
            downloadNotification.setGroupId(download.getGroup());
            downloadNotification.setEtaInMilliSeconds(download.getEtaInMilliSeconds());
            downloadNotification.setDownloadedBytesPerSecond(download.getDownloadedBytesPerSecond());
            downloadNotification.setTotal(download.getTotal());
            downloadNotification.setDownloaded(download.getDownloaded());
            downloadNotification.setNamespace(download.getNamespace());
            downloadNotification.setTitle(getDownloadNotificationTitle(download));
            this.downloadNotificationsMap.put(Integer.valueOf(download.getId()), downloadNotification);
            if (this.downloadNotificationExcludeSet.contains(Integer.valueOf(downloadNotification.getNotificationId())) && !downloadNotification.isFailed() && !downloadNotification.isCompleted()) {
                this.downloadNotificationExcludeSet.remove(Integer.valueOf(downloadNotification.getNotificationId()));
            }
            if (!downloadNotification.isCancelledNotification() && !shouldCancelNotification(downloadNotification)) {
                notify(download.getGroup());
            }
            cancelNotification(downloadNotification.getNotificationId());
        }
        return true;
    }

    @Override
    public NotificationCompat.Builder getNotificationBuilder(int notificationId, int groupId) {
        NotificationCompat.Builder builder;
        synchronized (this.downloadNotificationsMap) {
            builder = this.downloadNotificationsBuilderMap.get(Integer.valueOf(notificationId));
            if (builder == null) {
                Context context = this.context;
                builder = new NotificationCompat.Builder(context, getChannelId(notificationId, context));
            }
            this.downloadNotificationsBuilderMap.put(Integer.valueOf(notificationId), builder);
            builder.setGroup(String.valueOf(notificationId)).setStyle((NotificationCompat.Style) null).setProgress(0, 0, false).setContentTitle((CharSequence) null).setContentText((CharSequence) null).setContentIntent((PendingIntent) null).setGroupSummary(false).setTimeoutAfter(FetchDefaults.DEFAULT_NOTIFICATION_TIMEOUT_AFTER_RESET).setOngoing(false).setGroup(String.valueOf(groupId)).setOnlyAlertOnce(true).setSmallIcon(android.R.drawable.stat_sys_download_done).mActions.clear();
        }
        return builder;
    }

    @Override
    public String getDownloadNotificationTitle(Download download) {
        Intrinsics.checkParameterIsNotNull(download, "download");
        String lastPathSegment = download.getFileUri().getLastPathSegment();
        if (lastPathSegment == null) {
            Uri parse = Uri.parse(download.getUrl());
            Intrinsics.checkExpressionValueIsNotNull(parse, "Uri.parse(download.url)");
            lastPathSegment = parse.getLastPathSegment();
        }
        return lastPathSegment != null ? lastPathSegment : download.getUrl();
    }

    @Override
    public String getSubtitleText(Context context, DownloadNotification downloadNotification) {
        Intrinsics.checkParameterIsNotNull(context, "context");
        Intrinsics.checkParameterIsNotNull(downloadNotification, "downloadNotification");
        if (downloadNotification.isCompleted()) {
            String string = context.getString(R.string.fetch_notification_download_complete);
            Intrinsics.checkExpressionValueIsNotNull(string, "context.getString(R.stri…cation_download_complete)");
            return string;
        }
        if (downloadNotification.isFailed()) {
            String string2 = context.getString(R.string.fetch_notification_download_failed);
            Intrinsics.checkExpressionValueIsNotNull(string2, "context.getString(R.stri…fication_download_failed)");
            return string2;
        }
        if (downloadNotification.isPaused()) {
            String string3 = context.getString(R.string.fetch_notification_download_paused);
            Intrinsics.checkExpressionValueIsNotNull(string3, "context.getString(R.stri…fication_download_paused)");
            return string3;
        }
        if (downloadNotification.isQueued()) {
            String string4 = context.getString(R.string.fetch_notification_download_starting);
            Intrinsics.checkExpressionValueIsNotNull(string4, "context.getString(R.stri…cation_download_starting)");
            return string4;
        }
        if (downloadNotification.getEtaInMilliSeconds() >= 0) {
            return getEtaText(context, downloadNotification.getEtaInMilliSeconds());
        }
        String string5 = context.getString(R.string.fetch_notification_download_downloading);
        Intrinsics.checkExpressionValueIsNotNull(string5, "context.getString(R.stri…ion_download_downloading)");
        return string5;
    }

    private final String getEtaText(Context context, long etaInMilliSeconds) {
        long j = etaInMilliSeconds / 1000;
        long j2 = 3600;
        long j3 = j / j2;
        long j4 = j - (j2 * j3);
        long j5 = 60;
        long j6 = j4 / j5;
        long j7 = j4 - (j5 * j6);
        if (j3 > 0) {
            String string = context.getString(R.string.fetch_notification_download_eta_hrs, Long.valueOf(j3), Long.valueOf(j6), Long.valueOf(j7));
            Intrinsics.checkExpressionValueIsNotNull(string, "context.getString(R.stri… hours, minutes, seconds)");
            return string;
        }
        if (j6 > 0) {
            String string2 = context.getString(R.string.fetch_notification_download_eta_min, Long.valueOf(j6), Long.valueOf(j7));
            Intrinsics.checkExpressionValueIsNotNull(string2, "context.getString(R.stri…ta_min, minutes, seconds)");
            return string2;
        }
        String string3 = context.getString(R.string.fetch_notification_download_eta_sec, Long.valueOf(j7));
        Intrinsics.checkExpressionValueIsNotNull(string3, "context.getString(R.stri…ownload_eta_sec, seconds)");
        return string3;
    }
}