blob: 8cdca2ecd6e46c7e7e5d6cd58cbd979ab5f61560 [file] [log] [blame]
Dmitri Plotnikove843f912010-09-16 15:21:48 -07001/*
2 * Copyright (C) 2010 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 */
Dmitri Plotnikov18ffaa22010-12-03 14:28:00 -080016package com.android.contacts;
Dmitri Plotnikove843f912010-09-16 15:21:48 -070017
18import android.content.Context;
19import android.content.CursorLoader;
Katherine Kuanbe18de02011-06-07 12:38:29 -070020import android.net.Uri;
Dmitri Plotnikove843f912010-09-16 15:21:48 -070021import android.provider.ContactsContract.Groups;
22
Wenyi Wang9afadde2016-06-16 15:10:59 -070023import com.android.contacts.group.GroupUtil;
24
Dmitri Plotnikove843f912010-09-16 15:21:48 -070025/**
Katherine Kuanbe18de02011-06-07 12:38:29 -070026 * Group meta-data loader. Loads all groups or just a single group from the
27 * database (if given a {@link Uri}).
Dmitri Plotnikove843f912010-09-16 15:21:48 -070028 */
29public final class GroupMetaDataLoader extends CursorLoader {
30
31 private final static String[] COLUMNS = new String[] {
32 Groups.ACCOUNT_NAME,
33 Groups.ACCOUNT_TYPE,
Dave Santoro2b3f3c52011-07-26 17:35:42 -070034 Groups.DATA_SET,
Dmitri Plotnikove843f912010-09-16 15:21:48 -070035 Groups._ID,
36 Groups.TITLE,
37 Groups.AUTO_ADD,
38 Groups.FAVORITES,
Katherine Kuanc6b8afe2011-06-22 19:03:50 -070039 Groups.GROUP_IS_READ_ONLY,
Isaac Katzenelson26707342011-07-07 16:15:06 -070040 Groups.DELETED,
Dmitri Plotnikove843f912010-09-16 15:21:48 -070041 };
42
43 public final static int ACCOUNT_NAME = 0;
44 public final static int ACCOUNT_TYPE = 1;
Dave Santoro2b3f3c52011-07-26 17:35:42 -070045 public final static int DATA_SET = 2;
46 public final static int GROUP_ID = 3;
47 public final static int TITLE = 4;
48 public final static int AUTO_ADD = 5;
49 public final static int FAVORITES = 6;
50 public final static int IS_READ_ONLY = 7;
51 public final static int DELETED = 8;
Dmitri Plotnikove843f912010-09-16 15:21:48 -070052
Katherine Kuanbe18de02011-06-07 12:38:29 -070053 public GroupMetaDataLoader(Context context, Uri groupUri) {
Walter Jang72f99882016-05-26 09:01:31 -070054 super(context, ensureIsGroupUri(groupUri), COLUMNS,
55 Groups.ACCOUNT_TYPE + " NOT NULL AND " + Groups.ACCOUNT_NAME + " NOT NULL AND "
56 + Groups.DELETED + "=0",
Wenyi Wang9afadde2016-06-16 15:10:59 -070057 null, GroupUtil.getGroupsSortOrder());
Dmitri Plotnikove843f912010-09-16 15:21:48 -070058 }
Katherine Kuanbe18de02011-06-07 12:38:29 -070059
60 /**
61 * Ensures that this is a valid group URI. If invalid, then an exception is
62 * thrown. Otherwise, the original URI is returned.
63 */
64 private static Uri ensureIsGroupUri(final Uri groupUri) {
65 // TODO: Fix ContactsProvider2 getType method to resolve the group Uris
66 if (groupUri == null) {
67 throw new IllegalArgumentException("Uri must not be null");
68 }
69 if (!groupUri.toString().startsWith(Groups.CONTENT_URI.toString())) {
70 throw new IllegalArgumentException("Invalid group Uri: " + groupUri);
71 }
72 return groupUri;
73 }
Dmitri Plotnikove843f912010-09-16 15:21:48 -070074}