1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package com.update.check.action; 17 18 import java.util.ArrayList; 19 import java.util.LinkedHashMap; 20 import java.util.List; 21 22 /** 23 * DataUpdateNotifier 24 * 25 * @since 23-04-07 26 */ 27 public class DataUpdateNotifier { 28 private static DataUpdateNotifier dataUpdateNotifier = new DataUpdateNotifier(); 29 30 private List<UpdateListener> listeners = new ArrayList<>(); 31 DataUpdateNotifier()32 private DataUpdateNotifier() { 33 } 34 35 /** 36 * DataUpdateNotifier 37 * 38 * @return return dataUpdateNotifier; 39 */ getInstance()40 public static DataUpdateNotifier getInstance() { 41 return dataUpdateNotifier; 42 } 43 44 /** 45 * UpdateListener 46 * 47 * @since 23-04-07 48 */ 49 public interface UpdateListener { 50 /** 51 * onUpdate 52 * 53 * @param chooseType chooseType 54 * @param type restart or choose type 55 */ onUpdate(LinkedHashMap<String, Boolean> chooseType, String type)56 void onUpdate(LinkedHashMap<String, Boolean> chooseType, String type); 57 } 58 59 /** 60 * notifyDataChange 61 * 62 * @param chooseType chooseType 63 * @param type restart or choose type 64 */ notifyDataChange(LinkedHashMap<String, Boolean> chooseType, String type)65 public void notifyDataChange(LinkedHashMap<String, Boolean> chooseType, String type) { 66 for (UpdateListener listener : listeners) { 67 listener.onUpdate(chooseType, type); 68 } 69 } 70 71 /** 72 * addUpdateListener 73 * 74 * @param listener listener 75 */ addUpdateListener(UpdateListener listener)76 public void addUpdateListener(UpdateListener listener) { 77 listeners.add(listener); 78 } 79 80 } 81