• 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.provider.BaseColumns;
20 
21 import com.android.ex.photo.provider.PhotoContract.PhotoViewColumns;
22 
23 import com.android.messaging.datamodel.DatabaseHelper.MessageColumns;
24 import com.android.messaging.datamodel.DatabaseHelper.PartColumns;
25 import com.android.messaging.datamodel.DatabaseHelper.ParticipantColumns;
26 import com.android.messaging.util.ContentType;
27 
28 /**
29  * View for the image parts for the conversation. It is used to provide the photoviewer with a
30  * a data source for all the photos in a conversation, so that the photoviewer can support paging
31  * through all the photos of the conversation. The columns of the view are a superset of
32  * {@link com.android.ex.photo.provider.PhotoContract.PhotoViewColumns}.
33  */
34 public class ConversationImagePartsView {
35     private static final String VIEW_NAME = "conversation_image_parts_view";
36 
37     private static final String CREATE_SQL = "CREATE VIEW " +
38             VIEW_NAME + " AS SELECT "
39             + DatabaseHelper.MESSAGES_TABLE + '.' + MessageColumns.CONVERSATION_ID
40             + " as " + Columns.CONVERSATION_ID + ", "
41             + DatabaseHelper.PARTS_TABLE + '.' + PartColumns.CONTENT_URI
42             + " as " + Columns.URI + ", "
43             + DatabaseHelper.PARTICIPANTS_TABLE + '.' + ParticipantColumns.FULL_NAME
44             + " as " + Columns.SENDER_FULL_NAME + ", "
45             + DatabaseHelper.PARTS_TABLE + '.' + PartColumns.CONTENT_URI
46             + " as " + Columns.CONTENT_URI + ", "
47             // Use NULL as the thumbnail uri
48             + " NULL as " + Columns.THUMBNAIL_URI + ", "
49             + DatabaseHelper.PARTS_TABLE + '.' + PartColumns.CONTENT_TYPE
50             + " as " + Columns.CONTENT_TYPE + ", "
51             //
52             // Columns in addition to those specified by PhotoContract
53             //
54             + DatabaseHelper.PARTICIPANTS_TABLE + '.' + ParticipantColumns.DISPLAY_DESTINATION
55             + " as " + Columns.DISPLAY_DESTINATION + ", "
56             + DatabaseHelper.MESSAGES_TABLE + '.' + MessageColumns.RECEIVED_TIMESTAMP
57             + " as " + Columns.RECEIVED_TIMESTAMP + ", "
58             + DatabaseHelper.MESSAGES_TABLE + '.' + MessageColumns.STATUS
59             + " as " + Columns.STATUS + " "
60 
61             + " FROM " + DatabaseHelper.MESSAGES_TABLE + " LEFT JOIN " + DatabaseHelper.PARTS_TABLE
62             + " ON (" + DatabaseHelper.MESSAGES_TABLE + "." + MessageColumns._ID
63             + "=" + DatabaseHelper.PARTS_TABLE + "." + PartColumns.MESSAGE_ID + ") "
64             + " LEFT JOIN " + DatabaseHelper.PARTICIPANTS_TABLE + " ON ("
65             + DatabaseHelper.MESSAGES_TABLE + '.' +  MessageColumns.SENDER_PARTICIPANT_ID
66             + '=' + DatabaseHelper.PARTICIPANTS_TABLE + '.' + ParticipantColumns._ID + ")"
67 
68             // "content_type like 'image/%'"
69             + " WHERE " + DatabaseHelper.PARTS_TABLE + "." + PartColumns.CONTENT_TYPE
70             + " like '" + ContentType.IMAGE_PREFIX + "%'"
71 
72             + " ORDER BY "
73             + DatabaseHelper.MESSAGES_TABLE + '.' + MessageColumns.RECEIVED_TIMESTAMP + " ASC, "
74             + DatabaseHelper.PARTS_TABLE + '.' + PartColumns._ID + " ASC";
75 
76     static class Columns implements BaseColumns {
77         static final String CONVERSATION_ID = MessageColumns.CONVERSATION_ID;
78         static final String URI = PhotoViewColumns.URI;
79         static final String SENDER_FULL_NAME = PhotoViewColumns.NAME;
80         static final String CONTENT_URI = PhotoViewColumns.CONTENT_URI;
81         static final String THUMBNAIL_URI = PhotoViewColumns.THUMBNAIL_URI;
82         static final String CONTENT_TYPE = PhotoViewColumns.CONTENT_TYPE;
83         // Columns in addition to those specified by PhotoContract
84         static final String DISPLAY_DESTINATION = ParticipantColumns.DISPLAY_DESTINATION;
85         static final String RECEIVED_TIMESTAMP = MessageColumns.RECEIVED_TIMESTAMP;
86         static final String STATUS = MessageColumns.STATUS;
87     }
88 
89     public interface PhotoViewQuery {
90         public final String[] PROJECTION = {
91             PhotoViewColumns.URI,
92             PhotoViewColumns.NAME,
93             PhotoViewColumns.CONTENT_URI,
94             PhotoViewColumns.THUMBNAIL_URI,
95             PhotoViewColumns.CONTENT_TYPE,
96             // Columns in addition to those specified by PhotoContract
97             Columns.DISPLAY_DESTINATION,
98             Columns.RECEIVED_TIMESTAMP,
99             Columns.STATUS,
100         };
101 
102         public final int INDEX_URI = 0;
103         public final int INDEX_SENDER_FULL_NAME = 1;
104         public final int INDEX_CONTENT_URI = 2;
105         public final int INDEX_THUMBNAIL_URI = 3;
106         public final int INDEX_CONTENT_TYPE = 4;
107         // Columns in addition to those specified by PhotoContract
108         public final int INDEX_DISPLAY_DESTINATION = 5;
109         public final int INDEX_RECEIVED_TIMESTAMP = 6;
110         public final int INDEX_STATUS = 7;
111     }
112 
getViewName()113     static final String getViewName() {
114         return VIEW_NAME;
115     }
116 
getCreateSql()117     static final String getCreateSql() {
118         return CREATE_SQL;
119     }
120 }
121