1 /* 2 * Copyright (C) 2022 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 package com.android.systemui.complication; 17 18 import androidx.lifecycle.ViewModel; 19 20 import javax.inject.Inject; 21 22 /** 23 * {@link ComplicationViewModel} is an abstraction over {@link Complication}, providing the model 24 * from which any view-related interpretation of the {@link Complication} should be derived from. 25 */ 26 public class ComplicationViewModel extends ViewModel { 27 private final Complication mComplication; 28 private final ComplicationId mId; 29 private final Complication.Host mHost; 30 31 /** 32 * Default constructor for generating a {@link ComplicationViewModel}. 33 * @param complication The {@link Complication} represented by the view model. 34 * @param id The {@link ComplicationId} tied to this {@link Complication}. 35 * @param host The environment {@link Complication.Host}. 36 */ 37 @Inject ComplicationViewModel(Complication complication, ComplicationId id, Complication.Host host)38 public ComplicationViewModel(Complication complication, ComplicationId id, 39 Complication.Host host) { 40 mComplication = complication; 41 mId = id; 42 mHost = host; 43 } 44 45 /** 46 * Returns the {@link ComplicationId} for this {@link Complication} for stable id association. 47 */ getId()48 public ComplicationId getId() { 49 return mId; 50 } 51 52 /** 53 * Returns the underlying {@link Complication}. Should only as a redirection - for example, 54 * using the {@link Complication} to generate view. Any property should be surfaced through 55 * this ViewModel. 56 */ getComplication()57 public Complication getComplication() { 58 return mComplication; 59 } 60 61 /** 62 * Requests the dream exit on behalf of the {@link Complication}. 63 */ exitDream()64 public void exitDream() { 65 mHost.requestExitDream(); 66 } 67 68 @Override toString()69 public String toString() { 70 return mId + "=" + mComplication.toString(); 71 } 72 } 73