| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.bookmarks; | 5 package org.chromium.chrome.browser.bookmarks; |
| 6 | 6 |
| 7 import android.net.Uri; | 7 import android.net.Uri; |
| 8 import android.text.TextUtils; | 8 import android.text.TextUtils; |
| 9 | 9 |
| 10 import org.chromium.chrome.browser.UrlConstants; | 10 import org.chromium.chrome.browser.UrlConstants; |
| 11 import org.chromium.components.bookmarks.BookmarkId; | 11 import org.chromium.components.bookmarks.BookmarkId; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * A class representing the UI state of the {@link BookmarkManager}. All | 14 * A class representing the UI state of the {@link BookmarkManager}. All |
| 15 * states can be uniquely identified by a URL. | 15 * states can be uniquely identified by a URL. |
| 16 */ | 16 */ |
| 17 class BookmarkUIState { | 17 class BookmarkUIState { |
| 18 static final int STATE_LOADING = 1; | 18 static final int STATE_LOADING = 1; |
| 19 static final int STATE_FOLDER = 2; | 19 static final int STATE_FOLDER = 2; |
| 20 static final int STATE_SEARCHING = 3; |
| 20 private static final int STATE_INVALID = 0; | 21 private static final int STATE_INVALID = 0; |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * One of the STATE_* constants. | 24 * One of the STATE_* constants. |
| 24 */ | 25 */ |
| 25 int mState; | 26 int mState; |
| 26 String mUrl; | 27 String mUrl; |
| 27 BookmarkId mFolder; | 28 BookmarkId mFolder; |
| 28 | 29 |
| 29 static BookmarkUIState createLoadingState() { | 30 static BookmarkUIState createLoadingState() { |
| 30 BookmarkUIState state = new BookmarkUIState(); | 31 BookmarkUIState state = new BookmarkUIState(); |
| 31 state.mState = STATE_LOADING; | 32 state.mState = STATE_LOADING; |
| 32 state.mUrl = ""; | 33 state.mUrl = ""; |
| 33 return state; | 34 return state; |
| 34 } | 35 } |
| 35 | 36 |
| 37 static BookmarkUIState createSearchState() { |
| 38 BookmarkUIState state = new BookmarkUIState(); |
| 39 state.mState = STATE_SEARCHING; |
| 40 state.mUrl = ""; |
| 41 return state; |
| 42 } |
| 43 |
| 36 static BookmarkUIState createFolderState(BookmarkId folder, | 44 static BookmarkUIState createFolderState(BookmarkId folder, |
| 37 BookmarkModel bookmarkModel) { | 45 BookmarkModel bookmarkModel) { |
| 38 return createStateFromUrl(createFolderUrl(folder), bookmarkModel); | 46 return createStateFromUrl(createFolderUrl(folder), bookmarkModel); |
| 39 } | 47 } |
| 40 | 48 |
| 41 /** | 49 /** |
| 42 * @see #createStateFromUrl(Uri, BookmarkModel) | 50 * @see #createStateFromUrl(Uri, BookmarkModel) |
| 43 */ | 51 */ |
| 44 static BookmarkUIState createStateFromUrl(String url, BookmarkModel bookmark
Model) { | 52 static BookmarkUIState createStateFromUrl(String url, BookmarkModel bookmark
Model) { |
| 45 return createStateFromUrl(Uri.parse(url), bookmarkModel); | 53 return createStateFromUrl(Uri.parse(url), bookmarkModel); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 if (mUrl == null || mState == STATE_INVALID) return false; | 108 if (mUrl == null || mState == STATE_INVALID) return false; |
| 101 | 109 |
| 102 if (mState == STATE_FOLDER) { | 110 if (mState == STATE_FOLDER) { |
| 103 return mFolder != null && bookmarkModel.doesBookmarkExist(mFolder) | 111 return mFolder != null && bookmarkModel.doesBookmarkExist(mFolder) |
| 104 && !mFolder.equals(bookmarkModel.getRootFolderId()); | 112 && !mFolder.equals(bookmarkModel.getRootFolderId()); |
| 105 } | 113 } |
| 106 | 114 |
| 107 return true; | 115 return true; |
| 108 } | 116 } |
| 109 } | 117 } |
| OLD | NEW |