Skip to content

Commit

Permalink
Allow bookmarking selected tabs in tabs dialog (#1553)
Browse files Browse the repository at this point in the history
This feature allows users to bookmark multiple opened tabs by just clicking on a button. The tabs dialog now shows a new button that allows users to bookmark the previously selected tabs.

Fixes #1298
  • Loading branch information
haanhvu authored Oct 2, 2024
1 parent 8026a64 commit 92294a3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/src/common/shared/com/igalia/wolvic/ui/widgets/TabsWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class TabsWidget extends UIDialog {
protected UITextButton mSelectTabsButton;
protected UITextButton mDoneButton;
protected UITextButton mCloseTabsButton;
protected UITextButton mBookmarkTabsButton;
protected UITextButton mCloseTabsAllButton;
protected UITextButton mSelectAllButton;
protected UITextButton mUnselectTabs;
Expand All @@ -51,6 +52,7 @@ public interface TabDelegate {
void onTabSelect(Session aTab);
void onTabAdd();
void onTabsClose(List<Session> aTabs);
void onTabsBookmark(List<Session> aTabs);
}

public TabsWidget(Context aContext) {
Expand Down Expand Up @@ -128,6 +130,14 @@ public void updateUI() {
onDismiss();
});

mBookmarkTabsButton = findViewById(R.id.tabsBookmarkButton);
mBookmarkTabsButton.setOnClickListener(v -> {
if (mTabDelegate != null) {
mTabDelegate.onTabsBookmark(mSelectedTabs);
}
onDismiss();
});

mCloseTabsAllButton = findViewById(R.id.tabsCloseAllButton);
mCloseTabsAllButton.setOnClickListener(v -> {
if (mTabDelegate != null) {
Expand Down Expand Up @@ -357,11 +367,13 @@ private void updateSelectionMode() {
mTabsSelectModeView.setVisibility(mSelecting ? View.VISIBLE : View.GONE);
if (mSelectedTabs.size() > 0) {
mCloseTabsButton.setVisibility(View.VISIBLE);
mBookmarkTabsButton.setVisibility(View.VISIBLE);
mUnselectTabs.setVisibility(View.VISIBLE);
mCloseTabsAllButton.setVisibility(View.GONE);
mSelectAllButton.setVisibility(View.GONE);
} else {
mCloseTabsButton.setVisibility(View.GONE);
mBookmarkTabsButton.setVisibility(View.GONE);
mUnselectTabs.setVisibility(View.GONE);
mCloseTabsAllButton.setVisibility(View.VISIBLE);
mSelectAllButton.setVisibility(View.VISIBLE);
Expand Down
23 changes: 23 additions & 0 deletions app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.igalia.wolvic.R;
import com.igalia.wolvic.VRBrowserApplication;
import com.igalia.wolvic.browser.Accounts;
import com.igalia.wolvic.browser.BookmarksStore;
import com.igalia.wolvic.browser.HistoryStore;
import com.igalia.wolvic.browser.Media;
import com.igalia.wolvic.browser.Services;
Expand Down Expand Up @@ -50,6 +51,7 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Executor;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -1503,6 +1505,27 @@ public void onTabsClose(List<Session> aTabs) {
closeTabs(aTabs, mPrivateMode, true);
}

public void onTabsBookmark(List<Session> aTabs) {
for (Session tab: aTabs) {
String url = tab.getCurrentUri();

if (StringUtils.isEmpty(url)) {
continue;
}

BookmarksStore bookmarkStore = SessionStore.get().getBookmarkStore();
Executor executor = ((VRBrowserApplication)mContext.getApplicationContext()).getExecutors().mainThread();
bookmarkStore.isBookmarked(url).thenAcceptAsync(bookmarked -> {
if (!bookmarked) {
bookmarkStore.addBookmark(url, tab.getCurrentTitle());
}
}, executor).exceptionally(throwable -> {
Log.d(LOGTAG, "Error checking bookmark: " + throwable.getLocalizedMessage());
return null;
});
}
}

public void closeTab(@NonNull Session aTab) {
if (isSessionFocused(aTab)) {
closeTabs(Collections.singletonList(aTab), mPrivateMode, true);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/tabs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
android:visibility="gone"
android:text="@string/tabs_close_selected" />

<com.igalia.wolvic.ui.views.UITextButton
android:id="@+id/tabsBookmarkButton"
style="@style/tabsButton"
android:visibility="gone"
android:text="@string/tabs_bookmark_selected" />

<com.igalia.wolvic.ui.views.UITextButton
android:id="@+id/tabsCloseAllButton"
style="@style/tabsButton"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,10 @@
the Select` button. When clicked it closes all the previously selected tabs -->
<string name="tabs_close_selected">Close tabs</string>

<!-- This string is displayed in a button on the header of the tabs dialog, after selection mode is enabled with
the Select` button. When clicked it bookmarks all the previously selected tabs -->
<string name="tabs_bookmark_selected">Bookmark tabs</string>

<!-- This string is displayed in a button on the header of the tabs dialog.
When clicked it closes all the available tabs -->
<string name="tabs_close_all">Close all</string>
Expand Down

0 comments on commit 92294a3

Please sign in to comment.