blob: d900825c6f6ef2189a29f208988bb41aa5dd8c96 [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
23/**
Katherine Kuanbe18de02011-06-07 12:38:29 -070024 * Group meta-data loader. Loads all groups or just a single group from the
25 * database (if given a {@link Uri}).
Dmitri Plotnikove843f912010-09-16 15:21:48 -070026 */
27public final class GroupMetaDataLoader extends CursorLoader {
28
29 private final static String[] COLUMNS = new String[] {
30 Groups.ACCOUNT_NAME,
31 Groups.ACCOUNT_TYPE,
32 Groups._ID,
33 Groups.TITLE,
34 Groups.AUTO_ADD,
35 Groups.FAVORITES,
Katherine Kuanc6b8afe2011-06-22 19:03:50 -070036 Groups.GROUP_IS_READ_ONLY,
Dmitri Plotnikove843f912010-09-16 15:21:48 -070037 };
38
39 public final static int ACCOUNT_NAME = 0;
40 public final static int ACCOUNT_TYPE = 1;
41 public final static int GROUP_ID = 2;
42 public final static int TITLE = 3;
43 public final static int AUTO_ADD = 4;
44 public final static int FAVORITES = 5;
Katherine Kuanc6b8afe2011-06-22 19:03:50 -070045 public final static int IS_READ_ONLY = 6;
Dmitri Plotnikove843f912010-09-16 15:21:48 -070046
Katherine Kuanbe18de02011-06-07 12:38:29 -070047 public GroupMetaDataLoader(Context context, Uri groupUri) {
48 super(context, ensureIsGroupUri(groupUri), COLUMNS, Groups.ACCOUNT_TYPE + " NOT NULL AND "
Dmitri Plotnikov234e7842010-11-29 16:10:20 -080049 + Groups.ACCOUNT_NAME + " NOT NULL", null, null);
Dmitri Plotnikove843f912010-09-16 15:21:48 -070050 }
Katherine Kuanbe18de02011-06-07 12:38:29 -070051
52 /**
53 * Ensures that this is a valid group URI. If invalid, then an exception is
54 * thrown. Otherwise, the original URI is returned.
55 */
56 private static Uri ensureIsGroupUri(final Uri groupUri) {
57 // TODO: Fix ContactsProvider2 getType method to resolve the group Uris
58 if (groupUri == null) {
59 throw new IllegalArgumentException("Uri must not be null");
60 }
61 if (!groupUri.toString().startsWith(Groups.CONTENT_URI.toString())) {
62 throw new IllegalArgumentException("Invalid group Uri: " + groupUri);
63 }
64 return groupUri;
65 }
Dmitri Plotnikove843f912010-09-16 15:21:48 -070066}