Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -388,6 +389,32 @@ public ArrayList<Session> getSortedSessions(boolean aPrivateMode) {
return result;
}

public ArrayList<Session> getDuplicateSessions(boolean aPrivateMode) {
ArrayList<Session> duplicates = new ArrayList<>();
HashSet<String> uris = new HashSet<>();
ArrayList<Session> sessions = getSortedSessions(aPrivateMode);

for (Session session : sessions) {
if (session.isActive() && !session.getCurrentUri().isEmpty()) {
uris.add(session.getCurrentUri());
}
}

for (Session session : sessions) {
String uri = session.getCurrentUri();

if (session.isActive() || session.isWebExtensionSession() || uri.isEmpty()) {
continue;
}

if (!uris.add(uri)) {
duplicates.add(session);
}
}

return duplicates;
}

public void setPermissionDelegate(PermissionDelegate delegate) {
mPermissionDelegate = delegate;
}
Expand Down
14 changes: 14 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 @@ -40,6 +40,7 @@ public class TabsWidget extends UIDialog {
protected UITextButton mCloseTabsButton;
protected UITextButton mBookmarkTabsButton;
protected UITextButton mCloseTabsAllButton;
protected UITextButton mCloseDuplicateTabsButton;
protected UITextButton mSelectAllButton;
protected UITextButton mUnselectTabs;
protected LinearLayout mTabsSelectModeView;
Expand Down Expand Up @@ -133,6 +134,16 @@ public void updateUI() {
onDismiss();
});

mCloseDuplicateTabsButton = findViewById(R.id.tabsCloseDuplicatesButton);
mCloseDuplicateTabsButton.setOnClickListener(v -> {
if (mTabDelegate != null) {
mTabDelegate.onTabsClose(SessionStore.get().getDuplicateSessions(mPrivateMode));
}

refreshTabs();
updateSelectionMode();
});

mSelectAllButton = findViewById(R.id.tabsSelectAllButton);
mSelectAllButton.setOnClickListener(v -> {
mSelectedTabs = new ArrayList<>(mAdapter.mTabs);
Expand Down Expand Up @@ -356,12 +367,15 @@ private void updateSelectionMode() {
mBookmarkTabsButton.setVisibility(View.VISIBLE);
mUnselectTabs.setVisibility(View.VISIBLE);
mCloseTabsAllButton.setVisibility(View.GONE);
mCloseDuplicateTabsButton.setVisibility(View.GONE);
mSelectAllButton.setVisibility(View.GONE);
} else {
mCloseTabsButton.setVisibility(View.GONE);
mBookmarkTabsButton.setVisibility(View.GONE);
mUnselectTabs.setVisibility(View.GONE);
mCloseTabsAllButton.setVisibility(View.VISIBLE);
mCloseDuplicateTabsButton.setVisibility(View.VISIBLE);
mCloseDuplicateTabsButton.setEnabled(!SessionStore.get().getDuplicateSessions(mPrivateMode).isEmpty());
mSelectAllButton.setVisibility(View.VISIBLE);
}

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/tabs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
android:visibility="gone"
android:text="@string/tabs_bookmark_selected" />

<com.igalia.wolvic.ui.views.UITextButton
android:id="@+id/tabsCloseDuplicatesButton"
style="@style/tabsButton"
android:text="@string/tabs_close_duplicates" />

<com.igalia.wolvic.ui.views.UITextButton
android:id="@+id/tabsCloseAllButton"
style="@style/tabsButton"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2113,6 +2113,11 @@ the Select` button. When clicked it closes all the previously selected tabs -->
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 the tabs that have the same URL as another tab,
keeping the most recently used one -->
<string name="tabs_close_duplicates">Close duplicates</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
Loading