1 /*
2  * Copyright 2024 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.photopicker.core.events
18 
19 /* Convenience alias for classes that implement [Event] */
20 typealias RegisteredEventClass = Class<out Event>
21 
22 /**
23  * The definition of Photopicker events that can be sent through the Event bus.
24  *
25  * Event definitions should indicate where they are intended to be dispatched from.
26  *
27  * In general, favor adding a new event over re-using or re-purposing an existing event to avoid
28  * conflicts or unintended side effects.
29  *
30  * See [Events] for implementation details and guidance on how to use the event bus. Ensure that any
31  * events added are properly registered with the [FeatureManager].
32  */
33 interface Event {
34 
35     /**
36      * All events must contain a dispatcherToken which signifies which feature dispatched this
37      * event. If the feature is not registered in the claiming feature's [eventsProduced] registry
38      * this will cause an error.
39      */
40     val dispatcherToken: String
41 
42     /**
43      * Individual elements wishing to indicate a user choice for the current [Selection] should
44      * dispatch [MediaSelectionConfirmed] to begin the sequence of preparing media. No further
45      * action is required, Preloading will be chosen based on the current [PhotopickerConfiguration]
46      * and available set of [PhotopickerFeature].
47      */
48     data class MediaSelectionConfirmed(override val dispatcherToken: String) : Event
49 
50     /**
51      * For showing a message to the user in a snackbar.
52      *
53      * @see [SnackbarFeature] for snackbar implementation details.
54      */
55     data class ShowSnackbarMessage(override val dispatcherToken: String, val message: String) :
56         Event
57 }
58