• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.systemui.statusbar.notification.collection.listbuilder.pluggable;
18 
19 import android.annotation.Nullable;
20 
21 import com.android.systemui.statusbar.notification.collection.NotifPipeline;
22 
23 /**
24  * Generic superclass for chunks of code that can plug into the {@link NotifPipeline}.
25  *
26  * A pluggable is fundamentally three things:
27  * 1. A name (for debugging purposes)
28  * 2. The functionality that the pluggable provides to the pipeline (this is determined by the
29  *    subclass).
30  * 3. A way for the pluggable to inform the pipeline that its state has changed and the pipeline
31  *    should be rerun (in this case, the invalidate() method).
32  *
33  * @param <This> The type of the subclass. Subclasses should bind their own type here.
34  */
35 public abstract class Pluggable<This> {
36     private final String mName;
37     @Nullable private PluggableListener<This> mListener;
38 
Pluggable(String name)39     Pluggable(String name) {
40         mName = name;
41     }
42 
getName()43     public final String getName() {
44         return mName;
45     }
46 
47     /**
48      * Call this method when something has caused this pluggable's behavior to change. The pipeline
49      * will be re-run.
50      */
invalidateList()51     public final void invalidateList() {
52         if (mListener != null) {
53             mListener.onPluggableInvalidated((This) this);
54         }
55     }
56 
57     /** Set a listener to be notified when a pluggable is invalidated. */
setInvalidationListener(PluggableListener<This> listener)58     public final void setInvalidationListener(PluggableListener<This> listener) {
59         mListener = listener;
60     }
61 
62     /**
63      * Called on the pluggable once at the end of every pipeline run. Override this method to
64      * perform any necessary cleanup.
65      */
onCleanup()66     public void onCleanup() { }
67 
68     /**
69      * Listener interface for when pluggables are invalidated.
70      *
71      * @param <T> The type of pluggable that is being listened to.
72      */
73     public interface PluggableListener<T> {
74         /** Called whenever {@link #invalidateList()} is called on this pluggable. */
onPluggableInvalidated(T pluggable)75         void onPluggableInvalidated(T pluggable);
76     }
77 }
78