• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.messaging.datamodel;
18 
19 import android.content.Context;
20 import android.database.sqlite.SQLiteDatabase;
21 import android.net.Uri;
22 import android.text.TextUtils;
23 
24 import com.android.messaging.Factory;
25 import com.android.messaging.datamodel.action.Action;
26 import com.android.messaging.datamodel.action.ActionService;
27 import com.android.messaging.datamodel.action.BackgroundWorker;
28 import com.android.messaging.datamodel.data.BlockedParticipantsData;
29 import com.android.messaging.datamodel.data.BlockedParticipantsData.BlockedParticipantsDataListener;
30 import com.android.messaging.datamodel.data.ContactListItemData;
31 import com.android.messaging.datamodel.data.ContactPickerData;
32 import com.android.messaging.datamodel.data.ContactPickerData.ContactPickerDataListener;
33 import com.android.messaging.datamodel.data.ConversationData;
34 import com.android.messaging.datamodel.data.ConversationData.ConversationDataListener;
35 import com.android.messaging.datamodel.data.ConversationListData;
36 import com.android.messaging.datamodel.data.ConversationListData.ConversationListDataListener;
37 import com.android.messaging.datamodel.data.DraftMessageData;
38 import com.android.messaging.datamodel.data.GalleryGridItemData;
39 import com.android.messaging.datamodel.data.LaunchConversationData;
40 import com.android.messaging.datamodel.data.LaunchConversationData.LaunchConversationDataListener;
41 import com.android.messaging.datamodel.data.MediaPickerData;
42 import com.android.messaging.datamodel.data.MessagePartData;
43 import com.android.messaging.datamodel.data.ParticipantData;
44 import com.android.messaging.datamodel.data.ParticipantListItemData;
45 import com.android.messaging.datamodel.data.PeopleAndOptionsData;
46 import com.android.messaging.datamodel.data.PeopleAndOptionsData.PeopleAndOptionsDataListener;
47 import com.android.messaging.datamodel.data.PeopleOptionsItemData;
48 import com.android.messaging.datamodel.data.SettingsData;
49 import com.android.messaging.datamodel.data.SettingsData.SettingsDataListener;
50 import com.android.messaging.datamodel.data.SubscriptionListData;
51 import com.android.messaging.datamodel.data.VCardContactItemData;
52 import com.android.messaging.util.Assert.DoesNotRunOnMainThread;
53 import com.android.messaging.util.ConnectivityUtil;
54 
55 public abstract class DataModel {
56     private String mFocusedConversation;
57     private boolean mConversationListScrolledToNewestConversation;
58 
get()59     public static DataModel get() {
60         return Factory.get().getDataModel();
61     }
62 
startActionService(final Action action)63     public static final void startActionService(final Action action) {
64         get().getActionService().startAction(action);
65     }
66 
scheduleAction(final Action action, final int code, final long delayMs)67     public static final void scheduleAction(final Action action,
68             final int code, final long delayMs) {
69         get().getActionService().scheduleAction(action, code, delayMs);
70     }
71 
createConversationListData(final Context context, final ConversationListDataListener listener, final boolean archivedMode)72     public abstract ConversationListData createConversationListData(final Context context,
73             final ConversationListDataListener listener, final boolean archivedMode);
74 
createConversationData(final Context context, final ConversationDataListener listener, final String conversationId)75     public abstract ConversationData createConversationData(final Context context,
76             final ConversationDataListener listener, final String conversationId);
77 
createContactListItemData()78     public abstract ContactListItemData createContactListItemData();
79 
createContactPickerData(final Context context, final ContactPickerDataListener listener)80     public abstract ContactPickerData createContactPickerData(final Context context,
81             final ContactPickerDataListener listener);
82 
createMediaPickerData(final Context context)83     public abstract MediaPickerData createMediaPickerData(final Context context);
84 
createGalleryGridItemData()85     public abstract GalleryGridItemData createGalleryGridItemData();
86 
createLaunchConversationData( LaunchConversationDataListener listener)87     public abstract LaunchConversationData createLaunchConversationData(
88             LaunchConversationDataListener listener);
89 
createPeopleOptionsItemData(final Context context)90     public abstract PeopleOptionsItemData createPeopleOptionsItemData(final Context context);
91 
createPeopleAndOptionsData(final String conversationId, final Context context, final PeopleAndOptionsDataListener listener)92     public abstract PeopleAndOptionsData createPeopleAndOptionsData(final String conversationId,
93             final Context context, final PeopleAndOptionsDataListener listener);
94 
createVCardContactItemData(final Context context, final MessagePartData data)95     public abstract VCardContactItemData createVCardContactItemData(final Context context,
96             final MessagePartData data);
97 
createVCardContactItemData(final Context context, final Uri vCardUri)98     public abstract VCardContactItemData createVCardContactItemData(final Context context,
99             final Uri vCardUri);
100 
createParticipantListItemData( final ParticipantData participant)101     public abstract ParticipantListItemData createParticipantListItemData(
102             final ParticipantData participant);
103 
createBlockedParticipantsData(Context context, BlockedParticipantsDataListener listener)104     public abstract BlockedParticipantsData createBlockedParticipantsData(Context context,
105             BlockedParticipantsDataListener listener);
106 
createSubscriptonListData(Context context)107     public abstract SubscriptionListData createSubscriptonListData(Context context);
108 
createSettingsData(Context context, SettingsDataListener listener)109     public abstract SettingsData createSettingsData(Context context, SettingsDataListener listener);
110 
createDraftMessageData(String conversationId)111     public abstract DraftMessageData createDraftMessageData(String conversationId);
112 
getActionService()113     public abstract ActionService getActionService();
114 
getBackgroundWorkerForActionService()115     public abstract BackgroundWorker getBackgroundWorkerForActionService();
116 
117     @DoesNotRunOnMainThread
getDatabase()118     public abstract DatabaseWrapper getDatabase();
119 
120     // Allow DataModel to coordinate with activity lifetime events.
onActivityResume()121     public abstract void onActivityResume();
122 
onCreateTables(final SQLiteDatabase db)123     abstract void onCreateTables(final SQLiteDatabase db);
124 
setFocusedConversation(final String conversationId)125     public void setFocusedConversation(final String conversationId) {
126         mFocusedConversation = conversationId;
127     }
128 
isFocusedConversation(final String conversationId)129     public boolean isFocusedConversation(final String conversationId) {
130         return !TextUtils.isEmpty(mFocusedConversation)
131                 && TextUtils.equals(mFocusedConversation, conversationId);
132     }
133 
setConversationListScrolledToNewestConversation( final boolean scrolledToNewestConversation)134     public void setConversationListScrolledToNewestConversation(
135             final boolean scrolledToNewestConversation) {
136         mConversationListScrolledToNewestConversation = scrolledToNewestConversation;
137     }
138 
isConversationListScrolledToNewestConversation()139     public boolean isConversationListScrolledToNewestConversation() {
140         return mConversationListScrolledToNewestConversation;
141     }
142 
143     /**
144      * If a new message is received in the specified conversation, will the user be able to
145      * observe it in some UI within the app?
146      * @param conversationId conversation with the new incoming message
147      */
isNewMessageObservable(final String conversationId)148     public boolean isNewMessageObservable(final String conversationId) {
149         return isConversationListScrolledToNewestConversation()
150                 || isFocusedConversation(conversationId);
151     }
152 
onApplicationCreated()153     public abstract void onApplicationCreated();
154 
getConnectivityUtil()155     public abstract ConnectivityUtil getConnectivityUtil();
156 
getSyncManager()157     public abstract SyncManager getSyncManager();
158 }
159