| Index: chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkEditActivity.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkEditActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkEditActivity.java
|
| index b84119b88a26f8d3637bb530f622d8f96ca484b1..c8dac7cbe09232e74ef1bcb8e5e8a8caa4a2bcb1 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkEditActivity.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkEditActivity.java
|
| @@ -7,34 +7,19 @@ package org.chromium.chrome.browser.bookmarks;
|
| import android.content.Intent;
|
| import android.os.Bundle;
|
| import android.support.v7.widget.Toolbar;
|
| -import android.text.format.Formatter;
|
| import android.view.Menu;
|
| import android.view.MenuItem;
|
| import android.view.View;
|
| -import android.widget.Button;
|
| import android.widget.TextView;
|
|
|
| import org.chromium.base.Log;
|
| -import org.chromium.base.metrics.RecordHistogram;
|
| -import org.chromium.base.metrics.RecordUserAction;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem;
|
| import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkModelObserver;
|
| -import org.chromium.chrome.browser.offlinepages.ClientId;
|
| -import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
|
| -import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.DeletePageCallback;
|
| -import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.OfflinePageModelObserver;
|
| -import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.SavePageCallback;
|
| -import org.chromium.chrome.browser.offlinepages.OfflinePageItem;
|
| -import org.chromium.chrome.browser.offlinepages.OfflinePageUtils;
|
| import org.chromium.chrome.browser.util.UrlUtilities;
|
| import org.chromium.chrome.browser.widget.EmptyAlertEditText;
|
| import org.chromium.chrome.browser.widget.TintedDrawable;
|
| import org.chromium.components.bookmarks.BookmarkId;
|
| -import org.chromium.content_public.browser.WebContents;
|
| -import org.chromium.net.NetworkChangeNotifier;
|
| -
|
| -import java.util.List;
|
|
|
| /**
|
| * The activity that enables the user to modify the title, url and parent folder of a bookmark.
|
| @@ -42,32 +27,17 @@ import java.util.List;
|
| public class BookmarkEditActivity extends BookmarkActivityBase {
|
| /** The intent extra specifying the ID of the bookmark to be edited. */
|
| public static final String INTENT_BOOKMARK_ID = "BookmarkEditActivity.BookmarkId";
|
| - public static final String INTENT_WEB_CONTENTS = "BookmarkEditActivity.WebContents";
|
|
|
| private static final String TAG = "BookmarkEdit";
|
|
|
| - private enum OfflineButtonType {
|
| - NONE,
|
| - SAVE,
|
| - REMOVE,
|
| - VISIT,
|
| - }
|
| -
|
| private BookmarkModel mModel;
|
| - private OfflinePageBridge mOfflinePageBridge;
|
| private BookmarkId mBookmarkId;
|
| private EmptyAlertEditText mTitleEditText;
|
| private EmptyAlertEditText mUrlEditText;
|
| private TextView mFolderTextView;
|
|
|
| - private WebContents mWebContents;
|
| -
|
| private MenuItem mDeleteButton;
|
|
|
| - private NetworkChangeNotifier.ConnectionTypeObserver mConnectionObserver;
|
| - private OfflineButtonType mOfflineButtonType = OfflineButtonType.NONE;
|
| - private OfflinePageModelObserver mOfflinePageModelObserver;
|
| -
|
| private BookmarkModelObserver mBookmarkModelObserver = new BookmarkModelObserver() {
|
| @Override
|
| public void bookmarkModelChanged() {
|
| @@ -85,11 +55,7 @@ public class BookmarkEditActivity extends BookmarkActivityBase {
|
| protected void onCreate(Bundle savedInstanceState) {
|
| super.onCreate(savedInstanceState);
|
|
|
| - int title = OfflinePageUtils.getStringId(R.string.edit_bookmark);
|
| - setTitle(title);
|
| - BookmarkUtils.setTaskDescriptionInDocumentMode(this, getString(title));
|
| mModel = new BookmarkModel();
|
| - mOfflinePageBridge = mModel.getOfflinePageBridge();
|
| mBookmarkId = BookmarkId.getBookmarkIdFromString(
|
| getIntent().getStringExtra(INTENT_BOOKMARK_ID));
|
| mModel.addObserver(mBookmarkModelObserver);
|
| @@ -112,34 +78,6 @@ public class BookmarkEditActivity extends BookmarkActivityBase {
|
| }
|
| });
|
|
|
| - if (mOfflinePageBridge != null && OfflinePageBridge.canSavePage(
|
| - mModel.getBookmarkById(mBookmarkId).getUrl())) {
|
| - mConnectionObserver = new NetworkChangeNotifier.ConnectionTypeObserver() {
|
| - public void onConnectionTypeChanged(int connectionType) {
|
| - updateOfflineSection();
|
| - }
|
| - };
|
| - NetworkChangeNotifier.init(this);
|
| - NetworkChangeNotifier.getInstance().addConnectionTypeObserver(mConnectionObserver);
|
| -
|
| - mOfflinePageModelObserver = new OfflinePageModelObserver() {
|
| - @Override
|
| - public void offlinePageDeleted(long offlineId, ClientId clientId) {
|
| - BookmarkId bookmarkId = BookmarkModel.getBookmarkIdForOfflineClientId(clientId);
|
| - if (mBookmarkId.equals(bookmarkId)) {
|
| - updateOfflineSection();
|
| - }
|
| - }
|
| - };
|
| -
|
| - mOfflinePageBridge.addObserver(mOfflinePageModelObserver);
|
| - // Make offline page section visible and find controls.
|
| - findViewById(R.id.offline_page_group).setVisibility(View.VISIBLE);
|
| - getIntent().setExtrasClassLoader(WebContents.class.getClassLoader());
|
| - mWebContents = getIntent().getParcelableExtra(INTENT_WEB_CONTENTS);
|
| - updateOfflineSection();
|
| - }
|
| -
|
| Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
| setSupportActionBar(toolbar);
|
| getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
| @@ -205,22 +143,6 @@ public class BookmarkEditActivity extends BookmarkActivityBase {
|
| && mModel.getBookmarkById(mBookmarkId).isUrlEditable()) {
|
| String fixedUrl = UrlUtilities.fixupUrl(url);
|
| if (fixedUrl != null && !fixedUrl.equals(originalUrl)) {
|
| - ClientId clientId = ClientId.createClientIdForBookmarkId(mBookmarkId);
|
| - if (mOfflinePageBridge != null) {
|
| - mOfflinePageBridge.getPagesByClientId(
|
| - clientId, new OfflinePageBridge.MultipleOfflinePageItemCallback() {
|
| - @Override
|
| - public void onResult(List<OfflinePageItem> items) {
|
| - // Bookmarks ensures only one item will be present per
|
| - // client ID.
|
| - assert items.size() <= 1;
|
| -
|
| - recordUrlChangeHistogram(!items.isEmpty());
|
| - }
|
| - });
|
| - } else {
|
| - recordUrlChangeHistogram(false);
|
| - }
|
| mModel.setBookmarkUrl(mBookmarkId, fixedUrl);
|
| }
|
| }
|
| @@ -229,144 +151,14 @@ public class BookmarkEditActivity extends BookmarkActivityBase {
|
| super.onStop();
|
| }
|
|
|
| - private void recordUrlChangeHistogram(boolean hasOfflinePage) {
|
| - RecordHistogram.recordBooleanHistogram(
|
| - "OfflinePages.Edit.BookmarkUrlChangedForOfflinePage", hasOfflinePage);
|
| - }
|
| -
|
| @Override
|
| protected void onDestroy() {
|
| - recordOfflineButtonAction(false);
|
| - if (mOfflinePageBridge != null) {
|
| - mOfflinePageBridge.removeObserver(mOfflinePageModelObserver);
|
| - mOfflinePageBridge = null;
|
| - }
|
| -
|
| - if (mConnectionObserver != null) {
|
| - NetworkChangeNotifier.getInstance().removeConnectionTypeObserver(mConnectionObserver);
|
| - }
|
| -
|
| mModel.removeObserver(mBookmarkModelObserver);
|
| mModel.destroy();
|
| mModel = null;
|
| super.onDestroy();
|
| }
|
|
|
| - private void updateOfflineSection() {
|
| - assert mOfflinePageBridge != null;
|
| -
|
| - // It is possible that callback arrives after the activity was dismissed.
|
| - // See http://crbug.com/566939
|
| - if (mModel == null) return;
|
| -
|
| - mOfflinePageBridge.checkOfflinePageMetadata();
|
| -
|
| - ClientId clientId = ClientId.createClientIdForBookmarkId(mBookmarkId);
|
| - mOfflinePageBridge.getPagesByClientId(
|
| - clientId, new OfflinePageBridge.MultipleOfflinePageItemCallback() {
|
| - @Override
|
| - public void onResult(List<OfflinePageItem> items) {
|
| - offlineItemsRetrieved(items);
|
| - }
|
| - });
|
| - }
|
| -
|
| - private void offlineItemsRetrieved(List<OfflinePageItem> items) {
|
| - // It is possible that callback arrives after the activity was dismissed.
|
| - // See http://crbug.com/566939
|
| - if (mModel == null || mOfflinePageBridge == null) return;
|
| -
|
| - Button saveRemoveVisitButton = (Button) findViewById(R.id.offline_page_save_remove_button);
|
| - TextView offlinePageInfoTextView = (TextView) findViewById(R.id.offline_page_info_text);
|
| -
|
| - // Bookmarks should enforce that only one item exists per client ID.
|
| - OfflinePageItem offlinePage = null;
|
| - if (items.size() > 0) offlinePage = items.get(0);
|
| -
|
| - if (offlinePage != null) {
|
| - // Offline page exists. Show information and button to remove.
|
| - offlinePageInfoTextView.setText(
|
| - getString(OfflinePageUtils.getStringId(
|
| - R.string.offline_pages_as_bookmarks_offline_page_size),
|
| - Formatter.formatFileSize(this, offlinePage.getFileSize())));
|
| - updateButtonToDeleteOfflinePage(saveRemoveVisitButton);
|
| - saveRemoveVisitButton.setVisibility(View.VISIBLE);
|
| - } else if (mWebContents != null && !mWebContents.isDestroyed() && mOfflinePageBridge != null
|
| - && mOfflinePageBridge.canSavePage(mWebContents.getLastCommittedUrl())) {
|
| - // Offline page is not saved, but a bookmarked page is opened. Show save button.
|
| - offlinePageInfoTextView.setText(
|
| - getString(OfflinePageUtils.getStringId(R.string.bookmark_offline_page_none)));
|
| - updateButtonToSaveOfflinePage(saveRemoveVisitButton);
|
| - saveRemoveVisitButton.setVisibility(View.VISIBLE);
|
| - } else {
|
| - // Offline page is not saved, and edit page was opened from the bookmarks UI, which
|
| - // means there is no action the user can take any action - hide button.
|
| - offlinePageInfoTextView.setText(getString(OfflinePageUtils.getStringId(
|
| - R.string.offline_pages_as_bookmarks_offline_page_visit)));
|
| - updateButtonToVisitOfflinePage(saveRemoveVisitButton);
|
| - if (NetworkChangeNotifier.isOnline()) {
|
| - saveRemoveVisitButton.setVisibility(View.VISIBLE);
|
| - } else {
|
| - saveRemoveVisitButton.setVisibility(View.GONE);
|
| - }
|
| - }
|
| - saveRemoveVisitButton.setEnabled(true);
|
| - }
|
| -
|
| - private void updateButtonToDeleteOfflinePage(final Button button) {
|
| - mOfflineButtonType = OfflineButtonType.REMOVE;
|
| - button.setText(getString(R.string.remove));
|
| - button.setOnClickListener(new View.OnClickListener() {
|
| - @Override
|
| - public void onClick(View v) {
|
| - recordOfflineButtonAction(true);
|
| - button.setEnabled(false);
|
| - ClientId clientId = ClientId.createClientIdForBookmarkId(mBookmarkId);
|
| - mOfflinePageBridge.deletePage(clientId, new DeletePageCallback() {
|
| - @Override
|
| - public void onDeletePageDone(int deletePageResult) {
|
| - // TODO(fgorski): Add snackbar upon failure.
|
| - // Always update UI, as buttons might be disabled.
|
| - updateOfflineSection();
|
| - }
|
| - });
|
| - }
|
| - });
|
| - }
|
| -
|
| - private void updateButtonToSaveOfflinePage(final Button button) {
|
| - mOfflineButtonType = OfflineButtonType.SAVE;
|
| - button.setText(getString(R.string.save));
|
| - button.setOnClickListener(new View.OnClickListener() {
|
| - @Override
|
| - public void onClick(View v) {
|
| - recordOfflineButtonAction(true);
|
| - ClientId clientId = ClientId.createClientIdForBookmarkId(mBookmarkId);
|
| - button.setEnabled(false);
|
| - mOfflinePageBridge.savePage(mWebContents, clientId, new SavePageCallback() {
|
| - @Override
|
| - public void onSavePageDone(int savePageResult, String url, long offlineId) {
|
| - // TODO(fgorski): Add snackbar upon failure.
|
| - // Always update UI, as buttons might be disabled.
|
| - updateOfflineSection();
|
| - }
|
| - });
|
| - }
|
| - });
|
| - }
|
| -
|
| - private void updateButtonToVisitOfflinePage(Button button) {
|
| - mOfflineButtonType = OfflineButtonType.VISIT;
|
| - button.setText(getString(R.string.bookmark_btn_offline_page_visit));
|
| - button.setOnClickListener(new View.OnClickListener() {
|
| - @Override
|
| - public void onClick(View v) {
|
| - recordOfflineButtonAction(true);
|
| - openBookmark();
|
| - }
|
| - });
|
| - }
|
| -
|
| private void openBookmark() {
|
| // TODO(kkimlabs): Refactor this out to handle the intent in ChromeActivity.
|
| // If this activity was started via startActivityForResult(), set the result. Otherwise,
|
| @@ -381,36 +173,4 @@ public class BookmarkEditActivity extends BookmarkActivityBase {
|
| }
|
| finish();
|
| }
|
| -
|
| - private void recordOfflineButtonAction(boolean clicked) {
|
| - // If button type is not set, it means that either offline section is not shown or we have
|
| - // already recorded the click action.
|
| - if (mOfflineButtonType == OfflineButtonType.NONE) {
|
| - return;
|
| - }
|
| -
|
| - assert mOfflineButtonType == OfflineButtonType.SAVE
|
| - || mOfflineButtonType == OfflineButtonType.REMOVE
|
| - || mOfflineButtonType == OfflineButtonType.VISIT;
|
| -
|
| - if (clicked) {
|
| - if (mOfflineButtonType == OfflineButtonType.SAVE) {
|
| - RecordUserAction.record("OfflinePages.Edit.SaveButtonClicked");
|
| - } else if (mOfflineButtonType == OfflineButtonType.REMOVE) {
|
| - RecordUserAction.record("OfflinePages.Edit.RemoveButtonClicked");
|
| - } else if (mOfflineButtonType == OfflineButtonType.VISIT) {
|
| - RecordUserAction.record("OfflinePages.Edit.VisitButtonClicked");
|
| - }
|
| - } else {
|
| - if (mOfflineButtonType == OfflineButtonType.SAVE) {
|
| - RecordUserAction.record("OfflinePages.Edit.SaveButtonNotClicked");
|
| - } else if (mOfflineButtonType == OfflineButtonType.REMOVE) {
|
| - RecordUserAction.record("OfflinePages.Edit.RemoveButtonNotClicked");
|
| - } else if (mOfflineButtonType == OfflineButtonType.VISIT) {
|
| - RecordUserAction.record("OfflinePages.Edit.VisitButtonNotClicked");
|
| - }
|
| - }
|
| -
|
| - mOfflineButtonType = OfflineButtonType.NONE;
|
| - }
|
| }
|
|
|