Skip to content

Commit

Permalink
State of tray buttons for Bookmarks and Downloads
Browse files Browse the repository at this point in the history
Ensure that the state of the tray buttons for bookmarks and downloads
stays consistent in all cases.

This fixes several bugs, including one where the state of these
buttons was not updated when the user navigated to another section
within the Library, and another where the icon padding was not always
updated correctly.

The main change is that LibraryPanel defines a Controller interface
that is used to set the current panel content. This is called from
the navigation buttons within the Library, so the containing
WindowWidget is able to update its state accordingly.
  • Loading branch information
felipeerias committed Jan 8, 2025
1 parent ad5d105 commit 437fd13
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import androidx.annotation.NonNull;

import com.igalia.wolvic.ui.widgets.Windows;

public interface LibraryNavigationDelegate {
default void onButtonClick(@NonNull View view) {}
default void onButtonClick(Windows.ContentType contentType) {}
default void onClose(@NonNull View view) {}
default void onBack(@NonNull View view) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.res.Configuration;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -38,6 +39,11 @@ public class LibraryPanel extends FrameLayout {
private SystemNotificationsView mSystemNotificationsView;
private LibraryView mCurrentView;
private Windows.ContentType mCurrentPanel;
private Controller mController;

public interface Controller {
void setPanelContent(Windows.ContentType contentType);
}

public LibraryPanel(@NonNull Context context) {
super(context);
Expand Down Expand Up @@ -113,9 +119,11 @@ public void onBack(@NonNull View view) {
}

@Override
public void onButtonClick(@NonNull View view) {
public void onButtonClick(Windows.ContentType contentType) {
requestFocus();
selectTab(view);
if (mController != null) {
mController.setPanelContent(contentType);
}
}
});
mBinding.executePendingBindings();
Expand Down Expand Up @@ -177,6 +185,10 @@ public void onDestroy() {
mSystemNotificationsView.onDestroy();
}

public void setController(Controller controller) {
mController = controller;
}

public Windows.ContentType getSelectedPanelType() {
if (mCurrentView == mBookmarksView) {
return Windows.ContentType.BOOKMARKS;
Expand All @@ -201,7 +213,13 @@ public Windows.ContentType getSelectedPanelType() {
}
}

private void selectTab(@NonNull View view) {
public void selectPanel(Windows.ContentType panelType) {
mCurrentPanel = panelType;

if (panelType == Windows.ContentType.WEB_CONTENT) {
panelType = getSelectedPanelType();
}

mBinding.tabcontent.removeAllViews();

if (BuildConfig.FLAVOR_backend.equals("chromium")) {
Expand All @@ -214,60 +232,36 @@ private void selectTab(@NonNull View view) {
mBinding.downloads.setActiveMode(false);
mBinding.addons.setActiveMode(false);
mBinding.notifications.setActiveMode(false);
if(view.getId() == R.id.bookmarks){
selectBookmarks();

} else if(view.getId() == R.id.history){
selectHistory();

} else if(view.getId() == R.id.downloads){
selectDownloads();

} else if(view.getId() == R.id.addons){
selectAddons();

} else if (view.getId() == R.id.notifications) {
selectNotifications();

} else if (view.getId() == R.id.web_apps) {
selectWebApps();
}

mBinding.setCanGoBack(mCurrentView.canGoBack());
mCurrentView.onShow();

mBinding.searchBar.setQuery("", false);
mBinding.searchBar.clearFocus();
mBinding.searchBar.setVisibility(mCurrentView.supportsSearch() ? View.VISIBLE : View.INVISIBLE);
}

public void selectPanel(Windows.ContentType panelType) {
mCurrentPanel = panelType;

if (panelType == Windows.ContentType.WEB_CONTENT) {
panelType = getSelectedPanelType();
}
switch (panelType) {
case WEB_CONTENT:
break;
case BOOKMARKS:
selectTab(mBinding.bookmarks);
selectBookmarks();
break;
case WEB_APPS:
selectTab(mBinding.webApps);
selectWebApps();
break;
case HISTORY:
selectTab(mBinding.history);
selectHistory();
break;
case DOWNLOADS:
selectTab(mBinding.downloads);
selectDownloads();
break;
case ADDONS:
selectTab(mBinding.addons);
selectAddons();
break;
case NOTIFICATIONS:
selectTab(mBinding.notifications);
selectNotifications();
break;
}

mBinding.setCanGoBack(mCurrentView.canGoBack());
mCurrentView.onShow();

mBinding.searchBar.setQuery("", false);
mBinding.searchBar.clearFocus();
mBinding.searchBar.setVisibility(mCurrentView.supportsSearch() ? View.VISIBLE : View.INVISIBLE);
}

private void selectBookmarks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ private void animateButtonPadding(UIButton button, int paddingEnd, int duration)
return;
}

if (button.getAnimation() != null) {
button.getAnimation().cancel();
}

int paddingStart = button.getPaddingLeft();
button.animate()
.setDuration(duration)
Expand Down Expand Up @@ -605,6 +609,10 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {
}

private Observer<Windows.ContentType> mCurrentContentTypeObserver = contentType -> {
// Prevent a race condition in case the animation runs faster than the data binding.
mBinding.bookmarksButton.setActiveMode(contentType != Windows.ContentType.WEB_CONTENT && contentType != Windows.ContentType.DOWNLOADS);
mBinding.downloadsButton.setActiveMode(contentType == Windows.ContentType.DOWNLOADS);

if (contentType == Windows.ContentType.WEB_CONTENT) {
animateButtonPadding(mBinding.bookmarksButton, mMaxPadding, ICON_ANIMATION_DURATION);
animateButtonPadding(mBinding.downloadsButton, mMaxPadding, ICON_ANIMATION_DURATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ private void initialize(Context aContext) {
setupListeners(mSession);

mLibrary = new LibraryPanel(aContext);
mLibrary.setController(this::showPanel);

SessionStore.get().getBookmarkStore().addListener(mBookmarksListener);

Expand Down
13 changes: 7 additions & 6 deletions app/src/main/res/layout/library.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="com.igalia.wolvic.ui.widgets.Windows.ContentType"/>
<variable
name="delegate"
type="com.igalia.wolvic.ui.delegates.LibraryNavigationDelegate" />
Expand Down Expand Up @@ -31,32 +32,32 @@
style="@style/libraryButtonStartTheme"
android:src="@drawable/ic_icon_bookmark"
android:id="@+id/bookmarks"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"/>
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.BOOKMARKS) : void}"/>
<com.igalia.wolvic.ui.views.UIButton
style="@style/libraryButtonMiddleTheme"
android:src="@drawable/ic_icon_webapps"
android:id="@+id/web_apps"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"/>
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.WEB_APPS) : void}"/>
<com.igalia.wolvic.ui.views.UIButton
style="@style/libraryButtonMiddleTheme"
android:src="@drawable/ic_icon_history"
android:id="@+id/history"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"/>
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.HISTORY) : void}"/>
<com.igalia.wolvic.ui.views.UIButton
style="@style/libraryButtonMiddleTheme"
android:src="@drawable/ic_icon_downloads"
android:id="@+id/downloads"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"/>
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.DOWNLOADS) : void}"/>
<com.igalia.wolvic.ui.views.UIButton
style="@style/libraryButtonMiddleTheme"
android:src="@drawable/ic_icon_addons"
android:id="@+id/addons"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"/>
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.ADDONS) : void}"/>
<com.igalia.wolvic.ui.views.UIButton
style="@style/libraryButtonMiddleTheme"
android:src="@drawable/ic_icon_dialog_notification"
android:id="@+id/notifications"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.NOTIFICATIONS) : void}"
visibleGone="@{supportsSystemNotifications}"/>
</LinearLayout>
</FrameLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/tray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
style="@style/trayButtonMiddleTheme"
android:src="@drawable/ic_icon_bookmark"
android:tooltipText="@{viewmodel.currentContentType == ContentType.BOOKMARKS ? @string/close_bookmarks_tooltip : @string/open_bookmarks_tooltip}"
app:activeMode="@{viewmodel.currentContentType == ContentType.BOOKMARKS}"
app:activeMode="@{viewmodel.currentContentType != ContentType.WEB_CONTENT &amp;&amp; viewmodel.currentContentType != ContentType.DOWNLOADS}"
app:clipDrawable="@drawable/ic_icon_library_clip"
app:tooltipDensity="@dimen/tray_tooltip_density"
app:tooltipLayout="@layout/tooltip_tray"
Expand Down

0 comments on commit 437fd13

Please sign in to comment.