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.car.uxr;
18 
19 import androidx.annotation.NonNull;
20 import androidx.lifecycle.DefaultLifecycleObserver;
21 import androidx.lifecycle.LifecycleOwner;
22 
23 import com.android.car.ui.recyclerview.ContentLimiting;
24 
25 /**
26  * An implementation of {@link UxrContentLimiter} interface that also provides the functionality
27  * necessary for a {@link DefaultLifecycleObserver}.
28  *
29  * <p>Relies heavily on the {@link UxrContentLimiterImpl} implementation of the
30  * {@link UxrContentLimiter} interface.
31  *
32  * <p>For example, you could do the following to get yourself a lifecycle aware {@link
33  * UxrContentLimiter}:
34  * <pre>{@code
35  * new LifeCycleObserverUxrContentLimiter(new UxrContentLimiterImpl(context,xmlRes));
36  * }</pre>
37  */
38 public class LifeCycleObserverUxrContentLimiter
39         implements UxrContentLimiter, DefaultLifecycleObserver {
40 
41     private final UxrContentLimiterImpl mDelegate;
42 
LifeCycleObserverUxrContentLimiter(UxrContentLimiterImpl delegate)43     public LifeCycleObserverUxrContentLimiter(UxrContentLimiterImpl delegate) {
44         mDelegate = delegate;
45     }
46 
47     @Override
onStart(@onNull LifecycleOwner owner)48     public void onStart(@NonNull LifecycleOwner owner) {
49         mDelegate.start();
50     }
51 
52     @Override
onStop(@onNull LifecycleOwner owner)53     public void onStop(@NonNull LifecycleOwner owner) {
54         mDelegate.stop();
55     }
56 
57     @Override
setAdapter(ContentLimiting adapter)58     public void setAdapter(ContentLimiting adapter) {
59         mDelegate.setAdapter(adapter);
60     }
61 }
62