blob: 650c3cab47ace2f04ddf6531a8fcb6ca123cd02e [file] [log] [blame]
Jeff Hamilton84029622010-08-05 14:29:28 -05001/*
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
Jeff Hamilton84029622010-08-05 14:29:28 -050019import android.content.Context;
20import android.content.CursorLoader;
Jeff Hamilton1a805652010-09-07 12:36:30 -070021import android.net.Uri;
Jeff Hamilton69bd7072010-08-17 12:38:22 -050022import android.provider.BrowserContract.Bookmarks;
John Reck1cebb442010-12-10 12:02:16 -080023import android.provider.BrowserContract.ChromeSyncColumns;
Jeff Hamilton1a805652010-09-07 12:36:30 -070024import android.text.TextUtils;
Jeff Hamilton84029622010-08-05 14:29:28 -050025
26public class BookmarksLoader extends CursorLoader {
Jeff Hamilton1a805652010-09-07 12:36:30 -070027 public static final String ARG_ACCOUNT_TYPE = "acct_type";
28 public static final String ARG_ACCOUNT_NAME = "acct_name";
Jeff Hamilton84029622010-08-05 14:29:28 -050029
30 public static final int COLUMN_INDEX_ID = 0;
31 public static final int COLUMN_INDEX_URL = 1;
32 public static final int COLUMN_INDEX_TITLE = 2;
33 public static final int COLUMN_INDEX_FAVICON = 3;
34 public static final int COLUMN_INDEX_THUMBNAIL = 4;
35 public static final int COLUMN_INDEX_TOUCH_ICON = 5;
36 public static final int COLUMN_INDEX_IS_FOLDER = 6;
Leon Scroggins III052ce662010-09-13 14:44:16 -040037 public static final int COLUMN_INDEX_PARENT = 8;
John Reck1cebb442010-12-10 12:02:16 -080038 public static final int COLUMN_INDEX_SERVER_UNIQUE = 9;
Jeff Hamilton84029622010-08-05 14:29:28 -050039
40 public static final String[] PROJECTION = new String[] {
41 Bookmarks._ID, // 0
42 Bookmarks.URL, // 1
43 Bookmarks.TITLE, // 2
44 Bookmarks.FAVICON, // 3
45 Bookmarks.THUMBNAIL, // 4
46 Bookmarks.TOUCH_ICON, // 5
47 Bookmarks.IS_FOLDER, // 6
48 Bookmarks.POSITION, // 7
Leon Scroggins III052ce662010-09-13 14:44:16 -040049 Bookmarks.PARENT, // 8
John Reck1cebb442010-12-10 12:02:16 -080050 ChromeSyncColumns.SERVER_UNIQUE, // 9
Jeff Hamilton84029622010-08-05 14:29:28 -050051 };
52
Jeff Hamilton1a805652010-09-07 12:36:30 -070053 private String mAccountType;
54 private String mAccountName;
55
56 public BookmarksLoader(Context context, String accountType, String accountName) {
57 super(context, addAccount(Bookmarks.CONTENT_URI_DEFAULT_FOLDER, accountType, accountName),
58 PROJECTION, null, null, null);
59 mAccountType = accountType;
60 mAccountName = accountName;
61 }
62
63 @Override
64 public void setUri(Uri uri) {
65 super.setUri(addAccount(uri, mAccountType, mAccountName));
66 }
67
Leon Scroggins8baaa632010-12-08 19:46:53 -050068 static Uri addAccount(Uri uri, String accountType, String accountName) {
Jeff Hamilton1a805652010-09-07 12:36:30 -070069 if (!TextUtils.isEmpty(accountType) && !TextUtils.isEmpty(accountName)) {
70 return uri.buildUpon().appendQueryParameter(Bookmarks.PARAM_ACCOUNT_TYPE, accountType).
71 appendQueryParameter(Bookmarks.PARAM_ACCOUNT_NAME, accountName).build();
72 }
73 return uri;
Jeff Hamilton84029622010-08-05 14:29:28 -050074 }
75}