1/*
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 */
16
17package com.android.browser;
18
19import android.content.Context;
20import android.content.CursorLoader;
21import android.net.Uri;
22import android.provider.BrowserContract.Bookmarks;
23import android.provider.BrowserContract.ChromeSyncColumns;
24
25public class BookmarksLoader extends CursorLoader {
26    public static final String ARG_ACCOUNT_TYPE = "acct_type";
27    public static final String ARG_ACCOUNT_NAME = "acct_name";
28
29    public static final int COLUMN_INDEX_ID = 0;
30    public static final int COLUMN_INDEX_URL = 1;
31    public static final int COLUMN_INDEX_TITLE = 2;
32    public static final int COLUMN_INDEX_FAVICON = 3;
33    public static final int COLUMN_INDEX_THUMBNAIL = 4;
34    public static final int COLUMN_INDEX_TOUCH_ICON = 5;
35    public static final int COLUMN_INDEX_IS_FOLDER = 6;
36    public static final int COLUMN_INDEX_PARENT = 8;
37    public static final int COLUMN_INDEX_SERVER_UNIQUE = 9;
38
39    public static final String[] PROJECTION = new String[] {
40        Bookmarks._ID, // 0
41        Bookmarks.URL, // 1
42        Bookmarks.TITLE, // 2
43        Bookmarks.FAVICON, // 3
44        Bookmarks.THUMBNAIL, // 4
45        Bookmarks.TOUCH_ICON, // 5
46        Bookmarks.IS_FOLDER, // 6
47        Bookmarks.POSITION, // 7
48        Bookmarks.PARENT, // 8
49        ChromeSyncColumns.SERVER_UNIQUE, // 9
50    };
51
52    String mAccountType;
53    String mAccountName;
54
55    public BookmarksLoader(Context context, String accountType, String accountName) {
56        super(context, addAccount(Bookmarks.CONTENT_URI_DEFAULT_FOLDER, accountType, accountName),
57                PROJECTION, null, null, null);
58        mAccountType = accountType;
59        mAccountName = accountName;
60    }
61
62    @Override
63    public void setUri(Uri uri) {
64        super.setUri(addAccount(uri, mAccountType, mAccountName));
65    }
66
67    static Uri addAccount(Uri uri, String accountType, String accountName) {
68        return uri.buildUpon().appendQueryParameter(Bookmarks.PARAM_ACCOUNT_TYPE, accountType).
69                appendQueryParameter(Bookmarks.PARAM_ACCOUNT_NAME, accountName).build();
70    }
71}
72