Fixed bugs in the BookmarksFragment and BookmarkManager
This commit is contained in:
parent
7f965b0829
commit
05efb4eb72
@ -66,7 +66,6 @@ public class BookmarkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return true if the BookmarkManager was initialized, false otherwise
|
* @return true if the BookmarkManager was initialized, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean isReady() {
|
public boolean isReady() {
|
||||||
@ -75,6 +74,7 @@ public class BookmarkManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Look for bookmark using the url
|
* Look for bookmark using the url
|
||||||
|
*
|
||||||
* @param url the lookup url
|
* @param url the lookup url
|
||||||
* @return the bookmark as an {@link HistoryItem} or null
|
* @return the bookmark as an {@link HistoryItem} or null
|
||||||
*/
|
*/
|
||||||
@ -358,7 +358,6 @@ public class BookmarkManager {
|
|||||||
* done very frequently.
|
* done very frequently.
|
||||||
*
|
*
|
||||||
* @param sort force to sort the returned bookmarkList
|
* @param sort force to sort the returned bookmarkList
|
||||||
*
|
|
||||||
* @return returns a list of bookmarks that can be sorted
|
* @return returns a list of bookmarks that can be sorted
|
||||||
*/
|
*/
|
||||||
public synchronized List<HistoryItem> getAllBookmarks(boolean sort) {
|
public synchronized List<HistoryItem> getAllBookmarks(boolean sort) {
|
||||||
@ -404,6 +403,15 @@ public class BookmarkManager {
|
|||||||
return mCurrentFolder.isEmpty();
|
return mCurrentFolder.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current folder
|
||||||
|
*
|
||||||
|
* @return the current folder
|
||||||
|
*/
|
||||||
|
public String getCurrentFolder() {
|
||||||
|
return mCurrentFolder;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method is used internally for searching the bookmarks
|
* Method is used internally for searching the bookmarks
|
||||||
*
|
*
|
||||||
|
@ -58,11 +58,11 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
|
|
||||||
// Event bus
|
// Event bus
|
||||||
@Inject
|
@Inject
|
||||||
Bus eventBus;
|
Bus mEventBus;
|
||||||
|
|
||||||
// Dialog builder
|
// Dialog builder
|
||||||
@Inject
|
@Inject
|
||||||
BookmarksDialogBuilder bookmarksDialogBuilder;
|
BookmarksDialogBuilder mBookmarksDialogBuilder;
|
||||||
|
|
||||||
// Adapter
|
// Adapter
|
||||||
private BookmarkViewAdapter mBookmarkAdapter;
|
private BookmarkViewAdapter mBookmarkAdapter;
|
||||||
@ -81,7 +81,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
private int mIconColor;
|
private int mIconColor;
|
||||||
|
|
||||||
// Init asynchronously the bookmark manager
|
// Init asynchronously the bookmark manager
|
||||||
private final Runnable initBookmarkManager = new Runnable() {
|
private final Runnable mInitBookmarkManager = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
@ -106,7 +106,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(item.getTitle(), true),
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(item.getTitle(), true),
|
||||||
true);
|
true);
|
||||||
} else {
|
} else {
|
||||||
eventBus.post(new BookmarkEvents.Clicked(item));
|
mEventBus.post(new BookmarkEvents.Clicked(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -120,6 +120,12 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
@ -142,7 +148,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Must be called here, only here we have a reference to the ListView
|
// Must be called here, only here we have a reference to the ListView
|
||||||
new Thread(initBookmarkManager).run();
|
new Thread(mInitBookmarkManager).run();
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,13 +170,13 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
eventBus.register(this);
|
mEventBus.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
eventBus.unregister(this);
|
mEventBus.unregister(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -180,7 +186,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
mBookmarks.add(item);
|
mBookmarks.add(item);
|
||||||
Collections.sort(mBookmarks, new BookmarkManager.SortIgnoreCase());
|
Collections.sort(mBookmarks, new BookmarkManager.SortIgnoreCase());
|
||||||
mBookmarkAdapter.notifyDataSetChanged();
|
mBookmarkAdapter.notifyDataSetChanged();
|
||||||
eventBus
|
mEventBus
|
||||||
.post(new BookmarkEvents.Added(item));
|
.post(new BookmarkEvents.Added(item));
|
||||||
updateBookmarkIndicator(event.url);
|
updateBookmarkIndicator(event.url);
|
||||||
}
|
}
|
||||||
@ -193,12 +199,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void bookmarkChanged(BookmarkEvents.BookmarkChanged event) {
|
public void bookmarkChanged(BookmarkEvents.BookmarkChanged event) {
|
||||||
// final int size = mBookmarks.size();
|
String folder = mBookmarkManager.getCurrentFolder();
|
||||||
mBookmarks.remove(event.oldBookmark);
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(folder, true), false);
|
||||||
// assert mBookmarks.size() < size;
|
|
||||||
mBookmarks.add(event.newBookmark);
|
|
||||||
mBookmarkAdapter.notifyDataSetChanged();
|
|
||||||
Collections.sort(mBookmarks, new BookmarkManager.SortIgnoreCase());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBookmarkIndicator(final String url) {
|
private void updateBookmarkIndicator(final String url) {
|
||||||
@ -214,8 +216,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void userPressedBack(final BrowserEvents.UserPressedBack event) {
|
public void userPressedBack(final BrowserEvents.UserPressedBack event) {
|
||||||
if (mBookmarkManager.isRootFolder()) {
|
if (mBookmarkManager.isRootFolder()) {
|
||||||
eventBus
|
mEventBus.post(new BookmarkEvents.CloseBookmarks());
|
||||||
.post(new BookmarkEvents.CloseBookmarks());
|
|
||||||
} else {
|
} else {
|
||||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true);
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true);
|
||||||
}
|
}
|
||||||
@ -223,21 +224,24 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void bookmarkDeleted(final BookmarkEvents.Deleted event) {
|
public void bookmarkDeleted(final BookmarkEvents.Deleted event) {
|
||||||
// final int size = mBookmarks.size();
|
|
||||||
mBookmarks.remove(event.item);
|
mBookmarks.remove(event.item);
|
||||||
// assert mBookmarks.size() < size;
|
if (event.item.isFolder()) {
|
||||||
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
||||||
|
} else {
|
||||||
mBookmarkAdapter.notifyDataSetChanged();
|
mBookmarkAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setBookmarkDataSet(List<HistoryItem> items, boolean animate) {
|
private void setBookmarkDataSet(List<HistoryItem> items, boolean animate) {
|
||||||
mBookmarks.clear();
|
mBookmarks.clear();
|
||||||
mBookmarks.addAll(items);
|
mBookmarks.addAll(items);
|
||||||
mBookmarkAdapter.notifyDataSetChanged();
|
mBookmarkAdapter.notifyDataSetChanged();
|
||||||
final int resource;
|
final int resource;
|
||||||
if (mBookmarkManager.isRootFolder())
|
if (mBookmarkManager.isRootFolder()) {
|
||||||
resource = R.drawable.ic_action_star;
|
resource = R.drawable.ic_action_star;
|
||||||
else
|
} else {
|
||||||
resource = R.drawable.ic_action_back;
|
resource = R.drawable.ic_action_back;
|
||||||
|
}
|
||||||
|
|
||||||
final Animation startRotation = new Animation() {
|
final Animation startRotation = new Animation() {
|
||||||
@Override
|
@Override
|
||||||
@ -289,9 +293,9 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
|
|
||||||
private void handleLongPress(final HistoryItem item, final int position) {
|
private void handleLongPress(final HistoryItem item, final int position) {
|
||||||
if (item.isFolder()) {
|
if (item.isFolder()) {
|
||||||
bookmarksDialogBuilder.showBookmarkFolderLongPressedDialog(getContext(), item);
|
mBookmarksDialogBuilder.showBookmarkFolderLongPressedDialog(getContext(), item);
|
||||||
} else {
|
} else {
|
||||||
bookmarksDialogBuilder.showLongPressedDialogForUrl(getContext(), item);
|
mBookmarksDialogBuilder.showLongPressedDialogForUrl(getContext(), item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +303,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
case R.id.action_add_bookmark:
|
case R.id.action_add_bookmark:
|
||||||
eventBus.post(new BookmarkEvents.WantToBookmarkCurrentPage());
|
mEventBus.post(new BookmarkEvents.WantToBookmarkCurrentPage());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user