Home | History | Annotate | Download | only in data
      1 /*
      2  * Copyright (C) 2015 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.messaging.datamodel.data;
     17 
     18 import android.content.Intent;
     19 import android.net.Uri;
     20 
     21 import com.android.messaging.datamodel.binding.BindableData;
     22 
     23 /**
     24  * Bridges between any particpant/contact related data and data displayed in the PersonItemView.
     25  */
     26 public abstract class PersonItemData extends BindableData {
     27     /**
     28      * The UI component that listens for data change and update accordingly.
     29      */
     30     public interface PersonItemDataListener {
     31         void onPersonDataUpdated(PersonItemData data);
     32         void onPersonDataFailed(PersonItemData data, Exception exception);
     33     }
     34 
     35     private PersonItemDataListener mListener;
     36 
     37     public abstract Uri getAvatarUri();
     38     public abstract String getDisplayName();
     39     public abstract String getDetails();
     40     public abstract Intent getClickIntent();
     41     public abstract long getContactId();
     42     public abstract String getLookupKey();
     43     public abstract String getNormalizedDestination();
     44 
     45     public void setListener(final PersonItemDataListener listener) {
     46         if (isBound()) {
     47             mListener = listener;
     48         }
     49     }
     50 
     51     protected void notifyDataUpdated() {
     52         if (isBound() && mListener != null) {
     53             mListener.onPersonDataUpdated(this);
     54         }
     55     }
     56 
     57     protected void notifyDataFailed(final Exception exception) {
     58         if (isBound() && mListener != null) {
     59             mListener.onPersonDataFailed(this, exception);
     60         }
     61     }
     62 
     63     @Override
     64     protected void unregisterListeners() {
     65         mListener = null;
     66     }
     67 }
     68