diff --git a/app/src/common/shared/com/igalia/wolvic/ui/delegates/LibraryNavigationDelegate.java b/app/src/common/shared/com/igalia/wolvic/ui/delegates/LibraryNavigationDelegate.java index bb6ea3650d0..1d04f1b4414 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/delegates/LibraryNavigationDelegate.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/delegates/LibraryNavigationDelegate.java @@ -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) {} } \ No newline at end of file diff --git a/app/src/common/shared/com/igalia/wolvic/ui/views/library/LibraryPanel.java b/app/src/common/shared/com/igalia/wolvic/ui/views/library/LibraryPanel.java index 7140d88953f..86c293a32d4 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/views/library/LibraryPanel.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/views/library/LibraryPanel.java @@ -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; @@ -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); @@ -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(); @@ -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; @@ -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")) { @@ -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() { diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/TrayWidget.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/TrayWidget.java index 8c600061750..bd0b7d8e283 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/TrayWidget.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/TrayWidget.java @@ -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) @@ -605,6 +609,10 @@ public void attachToWindow(@NonNull WindowWidget aWindow) { } private Observer 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); diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java index 821e68f7313..69a32cf89eb 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java @@ -217,6 +217,7 @@ private void initialize(Context aContext) { setupListeners(mSession); mLibrary = new LibraryPanel(aContext); + mLibrary.setController(this::showPanel); SessionStore.get().getBookmarkStore().addListener(mBookmarksListener); diff --git a/app/src/main/res/layout/library.xml b/app/src/main/res/layout/library.xml index a99a9564e42..b63d4d7c332 100644 --- a/app/src/main/res/layout/library.xml +++ b/app/src/main/res/layout/library.xml @@ -1,6 +1,7 @@ + @@ -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}"/> + android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.WEB_APPS) : void}"/> + android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.HISTORY) : void}"/> + android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.DOWNLOADS) : void}"/> + android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.ADDONS) : void}"/> diff --git a/app/src/main/res/layout/tray.xml b/app/src/main/res/layout/tray.xml index a026fb8c10f..7187dd70470 100644 --- a/app/src/main/res/layout/tray.xml +++ b/app/src/main/res/layout/tray.xml @@ -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 && viewmodel.currentContentType != ContentType.DOWNLOADS}" app:clipDrawable="@drawable/ic_icon_library_clip" app:tooltipDensity="@dimen/tray_tooltip_density" app:tooltipLayout="@layout/tooltip_tray"