Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.enhancedbookmarks; | |
| 6 | |
| 7 import android.os.Bundle; | |
| 8 import android.support.v7.widget.Toolbar; | |
| 9 import android.view.Menu; | |
| 10 import android.view.MenuItem; | |
| 11 import android.view.View; | |
| 12 import android.widget.EditText; | |
| 13 import android.widget.TextView; | |
| 14 | |
| 15 import com.google.android.apps.chrome.R; | |
| 16 | |
| 17 import org.chromium.chrome.browser.BookmarksBridge.BookmarkItem; | |
| 18 import org.chromium.chrome.browser.BookmarksBridge.BookmarkModelObserver; | |
| 19 import org.chromium.chrome.browser.UrlUtilities; | |
| 20 import org.chromium.chrome.browser.enhanced_bookmarks.EnhancedBookmarksModel; | |
| 21 import org.chromium.components.bookmarks.BookmarkId; | |
| 22 | |
| 23 /** | |
| 24 * The activity that enables the user to modify the title, url and parent folder of a bookmark. | |
| 25 */ | |
| 26 public class EnhancedBookmarkEditActivity extends EnhancedBookmarkActivityBase { | |
| 27 /** The name of the extra in the intent to pass the bookmark id. */ | |
|
newt (away)
2015/06/17 23:53:25
"The intent extra specifying the ID of the bookmar
Ian Wen
2015/06/18 01:19:34
Done.
| |
| 28 public static final String INTENT_BOOKMARK_ID = "EnhancedBookmarkEditActivit y.BookmarkId"; | |
| 29 | |
| 30 private EnhancedBookmarksModel mEnhancedBookmarksModel; | |
| 31 private BookmarkId mBookmarkId; | |
| 32 private EditText mTitleEditText; | |
| 33 private EditText mUrlEditText; | |
| 34 private TextView mFolderTextView; | |
| 35 | |
| 36 private MenuItem mDeleteButton; | |
| 37 | |
| 38 private BookmarkModelObserver mBookmarkModelObserver = new BookmarkModelObse rver() { | |
| 39 @Override | |
| 40 public void bookmarkNodeRemoved(BookmarkItem parent, int oldIndex, Bookm arkItem node, | |
| 41 boolean isDoingExtensiveChanges) { | |
| 42 if (mBookmarkId.equals(node.getId())) { | |
| 43 finish(); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 @Override | |
| 48 public void bookmarkNodeMoved(BookmarkItem oldParent, int oldIndex, Book markItem newParent, | |
| 49 int newIndex) { | |
| 50 BookmarkId movedBookmark = mEnhancedBookmarksModel.getChildAt(newPar ent.getId(), | |
| 51 newIndex); | |
| 52 if (movedBookmark.equals(mBookmarkId)) { | |
| 53 mFolderTextView.setText(newParent.getTitle()); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 @Override | |
| 58 public void bookmarkNodeChanged(BookmarkItem node) { | |
| 59 if (mBookmarkId.equals(node.getId()) || node.getId().equals( | |
| 60 mEnhancedBookmarksModel.getBookmarkById(mBookmarkId).getPare ntId())) { | |
| 61 updateViewContent(); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 @Override | |
| 66 public void bookmarkModelChanged() { | |
| 67 } | |
| 68 }; | |
| 69 | |
| 70 @Override | |
| 71 protected void onCreate(Bundle savedInstanceState) { | |
| 72 super.onCreate(savedInstanceState); | |
| 73 EnhancedBookmarkUtils.setTaskDescriptionInDocumentMode(this, | |
| 74 getString(R.string.edit_bookmark)); | |
| 75 mEnhancedBookmarksModel = new EnhancedBookmarksModel(); | |
| 76 mBookmarkId = BookmarkId.getBookmarkIdFromString( | |
| 77 getIntent().getStringExtra(INTENT_BOOKMARK_ID)); | |
| 78 mEnhancedBookmarksModel.addModelObserver(mBookmarkModelObserver); | |
| 79 | |
| 80 setContentView(R.layout.eb_edit); | |
| 81 mTitleEditText = (EditText) findViewById(R.id.title_text); | |
| 82 mUrlEditText = (EditText) findViewById(R.id.url_text); | |
| 83 mFolderTextView = (TextView) findViewById(R.id.folder_text); | |
| 84 mFolderTextView.setOnClickListener(new View.OnClickListener() { | |
| 85 @Override | |
| 86 public void onClick(View v) { | |
| 87 EnhancedBookmarkFolderSelectActivity.startFolderSelectActivity( | |
| 88 EnhancedBookmarkEditActivity.this, mBookmarkId); | |
| 89 } | |
| 90 }); | |
| 91 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 92 setSupportActionBar(toolbar); | |
| 93 getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 94 | |
| 95 updateViewContent(); | |
| 96 } | |
| 97 | |
| 98 private void updateViewContent() { | |
| 99 BookmarkItem bookmarkItem = mEnhancedBookmarksModel.getBookmarkById(mBoo kmarkId); | |
| 100 mTitleEditText.setText(bookmarkItem.getTitle()); | |
| 101 mUrlEditText.setText(bookmarkItem.getUrl()); | |
| 102 mFolderTextView.setText( | |
| 103 mEnhancedBookmarksModel.getBookmarkTitle(bookmarkItem.getParentI d())); | |
| 104 } | |
| 105 | |
| 106 @Override | |
| 107 public boolean onCreateOptionsMenu(Menu menu) { | |
| 108 mDeleteButton = menu.add(0, Menu.NONE, 0, | |
|
newt (away)
2015/06/17 23:53:25
menu.add(R.string.enhanced_bookmark_action_bar_del
Ian Wen
2015/06/18 01:19:34
Done.
| |
| 109 getResources().getString(R.string.enhanced_bookmark_action_bar_d elete)).setIcon( | |
| 110 R.drawable.btn_trash); | |
| 111 mDeleteButton.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); | |
| 112 return super.onCreateOptionsMenu(menu); | |
| 113 } | |
| 114 | |
| 115 @Override | |
| 116 public boolean onOptionsItemSelected(MenuItem item) { | |
| 117 if (item == mDeleteButton) { | |
| 118 mEnhancedBookmarksModel.deleteBookmarks(mBookmarkId); | |
| 119 finish(); | |
| 120 return true; | |
| 121 } else if (item.getItemId() == android.R.id.home) { | |
| 122 onBackPressed(); | |
| 123 return true; | |
| 124 } | |
| 125 return super.onOptionsItemSelected(item); | |
| 126 } | |
| 127 | |
| 128 @Override | |
| 129 public void onBackPressed() { | |
| 130 String newTitle = mTitleEditText.getText().toString().trim(); | |
| 131 String newUrl = mUrlEditText.getText().toString().trim(); | |
| 132 newUrl = UrlUtilities.fixupUrl(newUrl); | |
| 133 if (newUrl == null) newUrl = ""; | |
| 134 mEnhancedBookmarksModel.setBookmarkTitle(mBookmarkId, newTitle); | |
| 135 mEnhancedBookmarksModel.setBookmarkUrl(mBookmarkId, newUrl); | |
| 136 | |
| 137 // TODO(ianewn): use EmptyAlertEditText.validate() when EmptyAlertEditTe xt is landed. | |
| 138 if (newTitle.isEmpty() || newUrl.isEmpty()) return; | |
| 139 super.onBackPressed(); | |
| 140 } | |
|
Kibeom Kim (inactive)
2015/06/18 00:25:37
Q1: How are you planning to structure invalid url
newt (away)
2015/06/18 00:31:26
If we had a cancel or "x" button, the user could p
Ian Wen
2015/06/18 01:19:34
1. https://codereview.chromium.org/1187013002/.
2
Kibeom Kim (inactive)
2015/06/18 02:28:13
(I thought we had a proper URL validation but It s
Ian Wen
2015/06/18 17:27:13
Done.
| |
| 141 | |
| 142 @Override | |
| 143 protected void onDestroy() { | |
| 144 mEnhancedBookmarksModel.removeModelObserver(mBookmarkModelObserver); | |
| 145 mEnhancedBookmarksModel.destroy(); | |
| 146 mEnhancedBookmarksModel = null; | |
| 147 super.onDestroy(); | |
| 148 } | |
| 149 } | |
| OLD | NEW |