1 /*
2  * Copyright 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.car.calendar;
18 
19 import android.view.ViewGroup;
20 
21 import androidx.recyclerview.widget.RecyclerView;
22 
23 /**
24  * Represents an item that can be displayed in the calendar list. It will hold the data needed to
25  * populate the {@link androidx.recyclerview.widget.RecyclerView.ViewHolder} passed in to the {@link
26  * #bind(RecyclerView.ViewHolder)} method.
27  */
28 interface CalendarItem {
29 
30     /** Returns the type of this calendar item instance. */
getType()31     Type getType();
32 
33     /** Bind the view holder with the data represented by this item. */
bind(RecyclerView.ViewHolder holder)34     void bind(RecyclerView.ViewHolder holder);
35 
36     /** The type of the calendar item which knows how to create a view holder for */
37     enum Type {
38         EVENT {
39             @Override
createViewHolder(ViewGroup parent)40             RecyclerView.ViewHolder createViewHolder(ViewGroup parent) {
41                 return new EventCalendarItem.EventViewHolder(parent);
42             }
43         },
44         TITLE {
45             @Override
createViewHolder(ViewGroup parent)46             RecyclerView.ViewHolder createViewHolder(ViewGroup parent) {
47                 return new TitleCalendarItem.TitleViewHolder(parent);
48             }
49         },
50         ALL_DAY_EVENTS {
51             @Override
createViewHolder(ViewGroup parent)52             RecyclerView.ViewHolder createViewHolder(ViewGroup parent) {
53                 return new AllDayEventsItem.AllDayEventsViewHolder(parent);
54             }
55         };
56 
57         /** Creates a view holder for this type of calendar item. */
createViewHolder(ViewGroup parent)58         abstract RecyclerView.ViewHolder createViewHolder(ViewGroup parent);
59     }
60 }
61