1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.notification.history; 18 19 import android.app.NotificationHistory; 20 import android.graphics.drawable.Drawable; 21 22 import java.util.ArrayList; 23 import java.util.Comparator; 24 import java.util.List; 25 import java.util.Objects; 26 import java.util.Set; 27 import java.util.TreeSet; 28 29 public class NotificationHistoryPackage { 30 String pkgName; 31 int uid; 32 TreeSet<NotificationHistory.HistoricalNotification> notifications; 33 CharSequence label; 34 Drawable icon; 35 NotificationHistoryPackage(String pkgName, int uid)36 public NotificationHistoryPackage(String pkgName, int uid) { 37 this.pkgName = pkgName; 38 this.uid = uid; 39 notifications = new TreeSet<>( 40 (o1, o2) -> Long.compare(o2.getPostedTimeMs(), o1.getPostedTimeMs())); 41 } 42 getMostRecent()43 public long getMostRecent() { 44 if (notifications.isEmpty()) { 45 return 0; 46 } 47 return notifications.first().getPostedTimeMs(); 48 } 49 50 @Override equals(Object o)51 public boolean equals(Object o) { 52 if (this == o) return true; 53 if (o == null || getClass() != o.getClass()) return false; 54 NotificationHistoryPackage that = (NotificationHistoryPackage) o; 55 return uid == that.uid && 56 Objects.equals(pkgName, that.pkgName) && 57 Objects.equals(notifications, that.notifications) && 58 Objects.equals(label, that.label) && 59 Objects.equals(icon, that.icon); 60 } 61 62 @Override hashCode()63 public int hashCode() { 64 return Objects.hash(pkgName, uid, notifications, label, icon); 65 } 66 } 67