|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -151,7 +157,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, |
|
|
|
// TODO this code depend way too much on BrowserActivity
|
|
|
|
// TODO this code depend way too much on BrowserActivity
|
|
|
|
super.onActivityCreated(savedInstanceState); |
|
|
|
super.onActivityCreated(savedInstanceState); |
|
|
|
final BrowserActivity activity = (BrowserActivity) getActivity(); |
|
|
|
final BrowserActivity activity = (BrowserActivity) getActivity(); |
|
|
|
final PreferenceManager preferenceManager =PreferenceManager.getInstance(); |
|
|
|
final PreferenceManager preferenceManager = PreferenceManager.getInstance(); |
|
|
|
boolean darkTheme = preferenceManager.getUseTheme() != 0 || activity.isIncognito(); |
|
|
|
boolean darkTheme = preferenceManager.getUseTheme() != 0 || activity.isIncognito(); |
|
|
|
mWebpageBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_webpage, darkTheme); |
|
|
|
mWebpageBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_webpage, darkTheme); |
|
|
|
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme); |
|
|
|
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme); |
|
|
@ -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,10 +224,12 @@ 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()) { |
|
|
|
mBookmarkAdapter.notifyDataSetChanged(); |
|
|
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
mBookmarkAdapter.notifyDataSetChanged(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setBookmarkDataSet(List<HistoryItem> items, boolean animate) { |
|
|
|
private void setBookmarkDataSet(List<HistoryItem> items, boolean animate) { |
|
|
@ -234,10 +237,11 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, |
|
|
|
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; |
|
|
|