From 998f673675ef31c895ab35a62a060ab3c61d3a54 Mon Sep 17 00:00:00 2001 From: Felipe Erias Date: Tue, 26 Nov 2024 11:32:26 +0900 Subject: [PATCH] Better tracking of the specific window content type Replace the integer constants for the library sections in WindowWidget with an enum that also includes the about: URL for each one. WindowViewModel.currentContentType keeps track of the specific content being shown in the window at each moment, which will make it easier to implement the native UI New Tab page and reorganise the library. WindowViewModel.isNativeContentVisible depends on the previous field and provides a boolean value so the current bindings keep working. This PR should not cause any major behaviour changes. --- .../com/igalia/wolvic/VRBrowserActivity.java | 3 +- .../wolvic/ui/viewmodel/WindowViewModel.java | 62 ++++++++++--------- .../wolvic/ui/views/library/LibraryPanel.java | 38 ++++++------ .../ui/widgets/NavigationBarWidget.java | 11 +--- .../igalia/wolvic/ui/widgets/TrayWidget.java | 7 +-- .../wolvic/ui/widgets/WindowWidget.java | 47 +++++++------- .../com/igalia/wolvic/ui/widgets/Windows.java | 50 ++++++++------- .../ui/widgets/menus/HamburgerMenuWidget.java | 2 +- .../com/igalia/wolvic/utils/UrlUtils.java | 23 ++++++- app/src/main/res/layout/navigation_url.xml | 12 ++-- app/src/main/res/layout/tray.xml | 4 +- 11 files changed, 140 insertions(+), 119 deletions(-) diff --git a/app/src/common/shared/com/igalia/wolvic/VRBrowserActivity.java b/app/src/common/shared/com/igalia/wolvic/VRBrowserActivity.java index 0e9801afe9..7019542929 100644 --- a/app/src/common/shared/com/igalia/wolvic/VRBrowserActivity.java +++ b/app/src/common/shared/com/igalia/wolvic/VRBrowserActivity.java @@ -82,7 +82,6 @@ import com.igalia.wolvic.ui.widgets.WindowWidget; import com.igalia.wolvic.ui.widgets.Windows; import com.igalia.wolvic.ui.widgets.dialogs.CrashDialogWidget; -import com.igalia.wolvic.ui.widgets.dialogs.DeprecatedVersionDialogWidget; import com.igalia.wolvic.ui.widgets.dialogs.LegalDocumentDialogWidget; import com.igalia.wolvic.ui.widgets.dialogs.PromptDialogWidget; import com.igalia.wolvic.ui.widgets.dialogs.SendTabDialogWidget; @@ -1104,7 +1103,7 @@ void handleMotionEvent(final int aHandle, final int aDevice, final boolean aFocu // We shouldn't divide the scale factor when we pass the motion event to the web engine if (widget instanceof WindowWidget) { WindowWidget windowWidget = (WindowWidget) widget; - if (!windowWidget.isLibraryVisible()) { + if (!windowWidget.isNativeContentVisible()) { scale = 1.0f; } } diff --git a/app/src/common/shared/com/igalia/wolvic/ui/viewmodel/WindowViewModel.java b/app/src/common/shared/com/igalia/wolvic/ui/viewmodel/WindowViewModel.java index d707cd9393..c44a285ed4 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/viewmodel/WindowViewModel.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/viewmodel/WindowViewModel.java @@ -6,6 +6,7 @@ import android.text.Spannable; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; +import android.util.Log; import android.util.TypedValue; import android.webkit.URLUtil; @@ -22,6 +23,7 @@ import com.igalia.wolvic.browser.SettingsStore; import com.igalia.wolvic.browser.api.WContentBlocking; import com.igalia.wolvic.ui.widgets.Windows; +import com.igalia.wolvic.utils.SystemUtils; import com.igalia.wolvic.utils.UrlUtils; import java.io.UnsupportedEncodingException; @@ -29,6 +31,8 @@ public class WindowViewModel extends AndroidViewModel { + private static final String LOGTAG = SystemUtils.createLogtag(WindowViewModel.class); + private int mURLProtocolColor; private int mURLWebsiteColor; @@ -48,7 +52,8 @@ public class WindowViewModel extends AndroidViewModel { private MutableLiveData isInsecure; private MutableLiveData isActiveWindow; private MediatorLiveData isTitleBarVisible; - private MutableLiveData isLibraryVisible; + private MutableLiveData currentContentType; + private MediatorLiveData isNativeContentVisible; private MutableLiveData isLoading; private MutableLiveData isMicrophoneEnabled; private MutableLiveData isBookmarked; @@ -128,7 +133,12 @@ public WindowViewModel(Application application) { isTitleBarVisible.addSource(isOnlyWindow, mIsTitleBarVisibleObserver); isTitleBarVisible.setValue(new ObservableBoolean(true)); - isLibraryVisible = new MutableLiveData<>(new ObservableBoolean(false)); + currentContentType = new MutableLiveData<>(Windows.ContentType.WEB_CONTENT); + isNativeContentVisible = new MediatorLiveData<>(); + isNativeContentVisible.addSource(currentContentType, contentType -> + isNativeContentVisible.setValue(new ObservableBoolean(contentType != Windows.ContentType.WEB_CONTENT)) + ); + isNativeContentVisible.setValue(new ObservableBoolean(currentContentType.getValue() != Windows.ContentType.WEB_CONTENT)); isLoading = new MutableLiveData<>(new ObservableBoolean(false)); isMicrophoneEnabled = new MutableLiveData<>(new ObservableBoolean(true)); @@ -151,7 +161,7 @@ public WindowViewModel(Application application) { isInsecureVisible = new MediatorLiveData<>(); isInsecureVisible.addSource(isInsecure, mIsInsecureVisibleObserver); isInsecureVisible.addSource(isPrivateSession, mIsInsecureVisibleObserver); - isInsecureVisible.addSource(isLibraryVisible, mIsInsecureVisibleObserver); + isInsecureVisible.addSource(isNativeContentVisible, mIsInsecureVisibleObserver); isInsecureVisible.setValue(new ObservableBoolean(false)); isMediaAvailable = new MutableLiveData<>(new ObservableBoolean(false)); @@ -172,13 +182,14 @@ public WindowViewModel(Application application) { isUrlBarButtonsVisible.addSource(isDrmUsed, mIsUrlBarButtonsVisibleObserver); isUrlBarButtonsVisible.addSource(isPopUpAvailable, mIsUrlBarButtonsVisibleObserver); isUrlBarButtonsVisible.addSource(isWebXRUsed, mIsUrlBarButtonsVisibleObserver); - isUrlBarButtonsVisible.addSource(isLibraryVisible, mIsUrlBarButtonsVisibleObserver); + isUrlBarButtonsVisible.addSource(isNativeContentVisible, mIsUrlBarButtonsVisibleObserver); isUrlBarButtonsVisible.addSource(isFocused, mIsUrlBarButtonsVisibleObserver); isUrlBarButtonsVisible.setValue(new ObservableBoolean(false)); isUrlBarIconsVisible = new MediatorLiveData<>(); isUrlBarIconsVisible.addSource(isLoading, mIsUrlBarIconsVisibleObserver); isUrlBarIconsVisible.addSource(isInsecureVisible, mIsUrlBarIconsVisibleObserver); + isUrlBarIconsVisible.addSource(isNativeContentVisible, mIsUrlBarIconsVisibleObserver); isUrlBarIconsVisible.setValue(new ObservableBoolean(false)); mWidth = new MutableLiveData<>(new ObservableInt()); @@ -228,7 +239,7 @@ public void onChanged(ObservableBoolean o) { @Override public void onChanged(Spannable aUrl) { String url = aUrl.toString(); - if (isLibraryVisible.getValue().get()) { + if (isNativeContentVisible.getValue().get()) { url = getApplication().getString(R.string.url_library_title); } else { @@ -260,7 +271,7 @@ public void onChanged(ObservableBoolean o) { (UrlUtils.isDataUri(aUrl) && isPrivateSession.getValue().get()) || UrlUtils.isFileUri(aUrl) || UrlUtils.isHomeUri(getApplication(), aUrl) || - isLibraryVisible.getValue().get() || + isNativeContentVisible.getValue().get() || UrlUtils.isBlankUri(getApplication(), aUrl)) { isInsecureVisible.postValue(new ObservableBoolean(false)); @@ -281,7 +292,7 @@ public void onChanged(Spannable aUrl) { if (UrlUtils.isPrivateAboutPage(getApplication(), url) || (UrlUtils.isDataUri(url) && isPrivateSession.getValue().get()) || UrlUtils.isHomeUri(getApplication(), aUrl.toString()) || - isLibraryVisible.getValue().get() || + isNativeContentVisible.getValue().get() || UrlUtils.isBlankUri(getApplication(), aUrl.toString())) { navigationBarUrl.postValue(""); @@ -297,7 +308,7 @@ public void onChanged(ObservableBoolean o) { String aUrl = url.getValue().toString(); isUrlBarButtonsVisible.postValue(new ObservableBoolean( !isFocused.getValue().get() && - !isLibraryVisible.getValue().get() && + !isNativeContentVisible.getValue().get() && !UrlUtils.isContentFeed(getApplication(), aUrl) && !UrlUtils.isPrivateAboutPage(getApplication(), aUrl) && (URLUtil.isHttpUrl(aUrl) || URLUtil.isHttpsUrl(aUrl)) && @@ -316,7 +327,7 @@ public void onChanged(ObservableBoolean o) { @Override public void onChanged(ObservableBoolean o) { isUrlBarIconsVisible.postValue(new ObservableBoolean( - !isLibraryVisible.getValue().get() && + !isNativeContentVisible.getValue().get() && (isLoading.getValue().get() || isInsecureVisible.getValue().get()) )); @@ -370,21 +381,20 @@ public void setUrl(@Nullable String url) { setUrl(new SpannableString(url)); } - public void setUrl(@Nullable Spannable url) { + private void setUrl(@Nullable Spannable url) { if (url == null) { return; } - String aURL = url.toString(); - - int index = -1; + String aURL; try { - aURL = URLDecoder.decode(aURL, "UTF-8"); + aURL = URLDecoder.decode(url.toString(), "UTF-8"); } catch (UnsupportedEncodingException | IllegalArgumentException e) { - e.printStackTrace(); + Log.w(LOGTAG, "Unable to decode URL [ " + url + " ] : " + e); aURL = ""; } + int index = -1; if (aURL.startsWith("jar:")) { return; @@ -404,21 +414,18 @@ public void setUrl(@Nullable Spannable url) { // Update the URL bar only if the URL is different than the current one and // the URL bar is not focused to avoid override user input if (!getUrl().getValue().toString().equalsIgnoreCase(aURL) && !getIsFocused().getValue().get()) { - this.url.postValue(new SpannableString(aURL)); if (index > 0) { SpannableString spannable = new SpannableString(aURL); ForegroundColorSpan color1 = new ForegroundColorSpan(mURLProtocolColor); ForegroundColorSpan color2 = new ForegroundColorSpan(mURLWebsiteColor); spannable.setSpan(color1, 0, index + 3, 0); spannable.setSpan(color2, index + 3, aURL.length(), 0); - this.url.postValue(url); + this.url.postValue(spannable); } else { this.url.postValue(url); } } - - this.url.postValue(url); } @NonNull @@ -427,7 +434,7 @@ public MutableLiveData getHint() { } private String getHintValue() { - if (isLibraryVisible.getValue().get()) { + if (isNativeContentVisible.getValue().get()) { return getApplication().getString(R.string.url_library_title); } else { @@ -563,18 +570,17 @@ public void setIsActiveWindow(boolean isActiveWindow) { this.isActiveWindow.setValue(new ObservableBoolean(isActiveWindow)); } - public void setIsLibraryVisible(boolean isLibraryVisible) { - this.isLibraryVisible.postValue(new ObservableBoolean(isLibraryVisible)); - this.url.postValue(this.getUrl().getValue()); + public void setCurrentContentType(Windows.ContentType contentType) { + currentContentType.postValue(contentType); } - public void setIsPanelVisible(boolean isVisible) { - setIsLibraryVisible(isVisible); + @NonNull + public MutableLiveData getCurrentContentType() { + return currentContentType; } - @NonNull - public MutableLiveData getIsLibraryVisible() { - return isLibraryVisible; + public MutableLiveData getIsNativeContentVisible() { + return isNativeContentVisible; } @NonNull 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 b378130026..7140d88953 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 @@ -37,7 +37,7 @@ public class LibraryPanel extends FrameLayout { private AddonsView mAddonsView; private SystemNotificationsView mSystemNotificationsView; private LibraryView mCurrentView; - private @Windows.PanelType int mCurrentPanel; + private Windows.ContentType mCurrentPanel; public LibraryPanel(@NonNull Context context) { super(context); @@ -64,7 +64,7 @@ protected void initialize() { mDownloadsView = new DownloadsView(getContext(), this); mAddonsView = new AddonsView(getContext(), this); mSystemNotificationsView = new SystemNotificationsView(getContext(), this); - mCurrentPanel = Windows.BOOKMARKS; + mCurrentPanel = Windows.ContentType.BOOKMARKS; updateUI(); } @@ -177,27 +177,27 @@ public void onDestroy() { mSystemNotificationsView.onDestroy(); } - public @Windows.PanelType int getSelectedPanelType() { + public Windows.ContentType getSelectedPanelType() { if (mCurrentView == mBookmarksView) { - return Windows.BOOKMARKS; + return Windows.ContentType.BOOKMARKS; } else if (mCurrentView == mWebAppsView) { - return Windows.WEB_APPS; + return Windows.ContentType.WEB_APPS; } else if (mCurrentView == mHistoryView) { - return Windows.HISTORY; + return Windows.ContentType.HISTORY; } else if (mCurrentView == mDownloadsView) { - return Windows.DOWNLOADS; + return Windows.ContentType.DOWNLOADS; } else if (mCurrentView == mAddonsView) { - return Windows.ADDONS; + return Windows.ContentType.ADDONS; } else if (mCurrentView == mSystemNotificationsView) { - return Windows.NOTIFICATIONS; + return Windows.ContentType.NOTIFICATIONS; } else { - return Windows.NONE; + return Windows.ContentType.WEB_CONTENT; } } @@ -241,30 +241,30 @@ private void selectTab(@NonNull View view) { mBinding.searchBar.setVisibility(mCurrentView.supportsSearch() ? View.VISIBLE : View.INVISIBLE); } - public void selectPanel(@Windows.PanelType int panelType) { + public void selectPanel(Windows.ContentType panelType) { mCurrentPanel = panelType; - if (panelType == Windows.NONE) { + if (panelType == Windows.ContentType.WEB_CONTENT) { panelType = getSelectedPanelType(); } switch (panelType) { - case Windows.NONE: - case Windows.BOOKMARKS: + case WEB_CONTENT: + case BOOKMARKS: selectTab(mBinding.bookmarks); break; - case Windows.WEB_APPS: + case WEB_APPS: selectTab(mBinding.webApps); break; - case Windows.HISTORY: + case HISTORY: selectTab(mBinding.history); break; - case Windows.DOWNLOADS: + case DOWNLOADS: selectTab(mBinding.downloads); break; - case Windows.ADDONS: + case ADDONS: selectTab(mBinding.addons); break; - case Windows.NOTIFICATIONS: + case NOTIFICATIONS: selectTab(mBinding.notifications); break; } diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/NavigationBarWidget.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/NavigationBarWidget.java index 5e62273569..dc513a4129 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/NavigationBarWidget.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/NavigationBarWidget.java @@ -15,11 +15,9 @@ import android.content.res.Configuration; import android.graphics.Canvas; import android.graphics.Rect; -import android.net.Uri; import androidx.preference.PreferenceManager; import android.util.AttributeSet; import android.util.Log; -import android.util.Pair; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -1379,12 +1377,7 @@ public void onSwitchMode() { public void onAddons() { hideMenu(); - if (!mAttachedWindow.isLibraryVisible()) { - mAttachedWindow.switchPanel(Windows.ADDONS); - - } else if (mAttachedWindow.getSelectedPanel() != Windows.ADDONS) { - mAttachedWindow.showPanel(Windows.ADDONS); - } + mAttachedWindow.showPanel(Windows.ContentType.ADDONS); } @Override @@ -1460,7 +1453,7 @@ public void showPopUpsBlockedNotification() { mBlockedCount++; final int currentCount = mBlockedCount; postDelayed(() -> { - if (currentCount == mBlockedCount && !mViewModel.getIsLibraryVisible().getValue().get()) { + if (currentCount == mBlockedCount && !mViewModel.getIsNativeContentVisible().getValue().get()) { showNotification(POPUP_NOTIFICATION_ID, mBinding.navigationBarNavigation.urlBar.getPopUpButton(), NotificationManager.Notification.TOP, 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 a8c6773d1a..8b83af51ab 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 @@ -35,7 +35,6 @@ import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; -import com.igalia.wolvic.BuildConfig; import com.igalia.wolvic.R; import com.igalia.wolvic.VRBrowserActivity; import com.igalia.wolvic.VRBrowserApplication; @@ -578,7 +577,7 @@ public void detachFromWindow() { mWidgetPlacement.parentHandle = -1; if (mViewModel != null) { - mViewModel.getIsLibraryVisible().removeObserver(mIsLibraryVisible); + mViewModel.getIsNativeContentVisible().removeObserver(mIsNativeContentVisible); mViewModel.getIsPrivateSession().removeObserver(mIsPrivateSession); mViewModel = null; } @@ -601,7 +600,7 @@ public void attachToWindow(@NonNull WindowWidget aWindow) { (VRBrowserActivity)getContext(), ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication())) .get(String.valueOf(mAttachedWindow.hashCode()), WindowViewModel.class); - mViewModel.getIsLibraryVisible().observe((VRBrowserActivity)getContext(), mIsLibraryVisible); + mViewModel.getIsNativeContentVisible().observe((VRBrowserActivity)getContext(), mIsNativeContentVisible); mViewModel.getIsPrivateSession().observe((VRBrowserActivity)getContext(), mIsPrivateSession); mBinding.setViewmodel(mViewModel); @@ -611,7 +610,7 @@ public void attachToWindow(@NonNull WindowWidget aWindow) { mIsWindowAttached = true; } - private Observer mIsLibraryVisible = aBoolean -> { + private Observer mIsNativeContentVisible = aBoolean -> { if (mBinding.libraryButton.isHovered()) { return; } 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 ba3db0c8cc..06e9b5ed28 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 @@ -330,7 +330,7 @@ public void hide(@HideFlags int aHideFlag) { @Override protected void onDismiss() { - if (mViewModel.getIsLibraryVisible().getValue().get()) { + if (mViewModel.getIsNativeContentVisible().getValue().get()) { if (!mLibrary.onBack()) { hidePanel(); } @@ -485,8 +485,8 @@ private void unsetView(View view, boolean switchSurface) { } } - public boolean isLibraryVisible() { - return mViewModel.getIsLibraryVisible().getValue().get(); + public boolean isNativeContentVisible() { + return mViewModel.getIsNativeContentVisible().getValue().get(); } public int getWindowWidth() { @@ -497,40 +497,35 @@ public int getWindowHeight() { return mWidgetPlacement.height; } - public @Windows.PanelType - int getSelectedPanel() { + public Windows.ContentType getSelectedPanel() { return mLibrary.getSelectedPanelType(); } private void hideLibraryPanel() { - if (mViewModel.getIsLibraryVisible().getValue().get()) { + if (mViewModel.getIsNativeContentVisible().getValue().get()) { hidePanel(true); } } - public void switchPanel(@Windows.PanelType int panelType) { - if (mViewModel.getIsLibraryVisible().getValue().get()) { - hidePanel(true); + Runnable mRestoreFirstPaint; + public void showPanel(Windows.ContentType panelType) { + if (panelType == Windows.ContentType.WEB_CONTENT) { + hidePanel(); } else { showPanel(panelType, true); } } - Runnable mRestoreFirstPaint; - - public void showPanel(@Windows.PanelType int panelType) { - showPanel(panelType, true); - } - - private void showPanel(@Windows.PanelType int panelType, boolean switchSurface) { + private void showPanel(Windows.ContentType contentType, boolean switchSurface) { if (mLibrary != null) { if (mView == null) { setView(mLibrary, switchSurface); - mLibrary.selectPanel(panelType); + mLibrary.selectPanel(contentType); mLibrary.onShow(); mViewModel.setIsFindInPage(false); - mViewModel.setIsPanelVisible(true); + mViewModel.setCurrentContentType(contentType); + mViewModel.setUrl(contentType.URL); if (mRestoreFirstPaint == null && !isFirstPaintReady() && (mFirstDrawCallback != null) && (mSurface != null)) { final Runnable firstDrawCallback = mFirstDrawCallback; onFirstContentfulPaint(mSession.getWSession()); @@ -544,7 +539,7 @@ private void showPanel(@Windows.PanelType int panelType, boolean switchSurface) } } else if (mView == mLibrary) { - mLibrary.selectPanel(panelType); + mLibrary.selectPanel(contentType); } } } @@ -557,7 +552,7 @@ private void hidePanel(boolean switchSurface) { if (mView != null && mLibrary != null) { unsetView(mLibrary, switchSurface); mLibrary.onHide(); - mViewModel.setIsPanelVisible(false); + mViewModel.setCurrentContentType(Windows.ContentType.WEB_CONTENT); } if (switchSurface && mRestoreFirstPaint != null) { mRestoreFirstPaint.run(); @@ -1127,12 +1122,12 @@ public void setVisible(boolean aVisible) { } mWidgetPlacement.visible = aVisible; if (!aVisible) { - if (mViewModel.getIsLibraryVisible().getValue().get()) { + if (mViewModel.getIsNativeContentVisible().getValue().get()) { mWidgetManager.popWorldBrightness(this); } } else { - if (mViewModel.getIsLibraryVisible().getValue().get()) { + if (mViewModel.getIsNativeContentVisible().getValue().get()) { mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS); } } @@ -2003,16 +1998,16 @@ WResult onLoadRequest(WSession aSession, @NonNull LoadRequest aReq Uri uri = Uri.parse(aRequest.uri); if (UrlUtils.isAboutPage(uri.toString())) { if(UrlUtils.isBookmarksUrl(uri.toString())) { - showPanel(Windows.BOOKMARKS); + showPanel(Windows.ContentType.BOOKMARKS); } else if (UrlUtils.isHistoryUrl(uri.toString())) { - showPanel(Windows.HISTORY); + showPanel(Windows.ContentType.HISTORY); } else if (UrlUtils.isDownloadsUrl(uri.toString())) { - showPanel(Windows.DOWNLOADS); + showPanel(Windows.ContentType.DOWNLOADS); } else if (UrlUtils.isAddonsUrl(uri.toString())) { - showPanel(Windows.ADDONS); + showPanel(Windows.ContentType.ADDONS); } else { hideLibraryPanel(); diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java index d544c6bf9d..cbaf7b95df 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java @@ -52,9 +52,9 @@ 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.concurrent.Executor; import java.util.stream.Collectors; import mozilla.components.concept.sync.AccountObserver; @@ -98,7 +98,7 @@ class WindowState { int textureHeight; float worldWidth; int tabIndex = -1; - @PanelType int panelType = Windows.NONE; + ContentType panelType = ContentType.WEB_CONTENT; public void load(@NonNull WindowWidget aWindow, WindowsState aState, int aTabIndex) { WidgetPlacement widgetPlacement; @@ -117,11 +117,11 @@ public void load(@NonNull WindowWidget aWindow, WindowsState aState, int aTabInd textureHeight = widgetPlacement.height; worldWidth = widgetPlacement.worldWidth; tabIndex = aTabIndex; - if (aWindow.isLibraryVisible()) { + if (aWindow.isNativeContentVisible()) { panelType = aWindow.getSelectedPanel(); } else { - panelType = Windows.NONE; + panelType = ContentType.WEB_CONTENT; } } } @@ -163,15 +163,20 @@ class WindowsState { private DownloadsManager mDownloadsManager; private ConnectivityReceiver mConnectivityReceived; - @IntDef(value = {NONE, BOOKMARKS, WEB_APPS, HISTORY, DOWNLOADS, ADDONS, NOTIFICATIONS}) - public @interface PanelType {} - public static final int NONE = 0; - public static final int BOOKMARKS = 1; - public static final int WEB_APPS = 2; - public static final int HISTORY = 3; - public static final int DOWNLOADS = 4; - public static final int ADDONS = 5; - public static final int NOTIFICATIONS = 6; + public enum ContentType { + WEB_CONTENT(""), + BOOKMARKS(UrlUtils.ABOUT_BOOKMARKS), + WEB_APPS(UrlUtils.ABOUT_WEBAPPS), + HISTORY(UrlUtils.ABOUT_HISTORY), + DOWNLOADS(UrlUtils.ABOUT_DOWNLOADS), + ADDONS(UrlUtils.ABOUT_ADDONS), + NOTIFICATIONS(UrlUtils.ABOUT_NOTIFICATIONS); + public final String URL; + + ContentType(String url) { + this.URL = url; + } + } public enum WindowPlacement{ FRONT(0), @@ -379,7 +384,7 @@ private WindowWidget addRestoredWindow(@NonNull WindowState aState, @Nullable Se case ADDONS: newWindow.getSession().loadUri(UrlUtils.ABOUT_ADDONS); break; - case NONE: + case WEB_CONTENT: break; } } @@ -626,9 +631,9 @@ public void exitImmersiveMode() { } private void closeLibraryPanelInFocusedWindowIfNeeded() { - if (!mFocusedWindow.isLibraryVisible()) + if (!mFocusedWindow.isNativeContentVisible()) return; - mFocusedWindow.switchPanel(NONE); + mFocusedWindow.hidePanel(); } public void enterPrivateMode() { @@ -1192,11 +1197,14 @@ public void onAddWindowClicked() { @Override public void onLibraryClicked() { - if (mDownloadsManager.isDownloading()) { - mFocusedWindow.switchPanel(Windows.DOWNLOADS); + if (mFocusedWindow.isNativeContentVisible()) { + mFocusedWindow.hidePanel(); + + } else if (mDownloadsManager.isDownloading()) { + mFocusedWindow.showPanel(ContentType.DOWNLOADS); } else { - mFocusedWindow.switchPanel(Windows.NONE); + mFocusedWindow.showPanel(ContentType.BOOKMARKS); } } @@ -1768,7 +1776,7 @@ public void showWebAppAddedNotification() { } public boolean isSessionFocused(@NonNull Session session) { - return mRegularWindows.stream().anyMatch(window -> window.getSession() == session && !window.isLibraryVisible() && session.isPrivateMode() == mPrivateMode) || - mPrivateWindows.stream().anyMatch(window -> window.getSession() == session && !window.isLibraryVisible() && session.isPrivateMode() == mPrivateMode ); + return mRegularWindows.stream().anyMatch(window -> window.getSession() == session && !window.isNativeContentVisible() && session.isPrivateMode() == mPrivateMode) || + mPrivateWindows.stream().anyMatch(window -> window.getSession() == session && !window.isNativeContentVisible() && session.isPrivateMode() == mPrivateMode); } } diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/menus/HamburgerMenuWidget.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/menus/HamburgerMenuWidget.java index 40c6b165c7..33598b1821 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/menus/HamburgerMenuWidget.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/menus/HamburgerMenuWidget.java @@ -202,7 +202,7 @@ private void updateItems() { }).build()); String url = activeSession.getCurrentUri(); - boolean showAddons = (URLUtil.isHttpsUrl(url) || URLUtil.isHttpUrl(url)) && !mWidgetManager.getFocusedWindow().isLibraryVisible(); + boolean showAddons = (URLUtil.isHttpsUrl(url) || URLUtil.isHttpUrl(url)) && !mWidgetManager.getFocusedWindow().isNativeContentVisible(); final SessionState tab = ComponentsAdapter.get().getSessionStateForSession(activeSession); if (tab != null && showAddons) { final List extensions = ComponentsAdapter.get().getSortedEnabledExtensions(); diff --git a/app/src/common/shared/com/igalia/wolvic/utils/UrlUtils.java b/app/src/common/shared/com/igalia/wolvic/utils/UrlUtils.java index 00567d996c..9b496b2ab6 100644 --- a/app/src/common/shared/com/igalia/wolvic/utils/UrlUtils.java +++ b/app/src/common/shared/com/igalia/wolvic/utils/UrlUtils.java @@ -208,6 +208,26 @@ public static boolean isAddonsUrl(@Nullable String url) { return url.equalsIgnoreCase(ABOUT_ADDONS); } + public static final String ABOUT_WEBAPPS = "about://webapps"; + + public static boolean isWebAppsUrl(@Nullable String url) { + if (url == null) { + return false; + } + + return url.equalsIgnoreCase(ABOUT_WEBAPPS); + } + + public static final String ABOUT_NOTIFICATIONS = "about://notifications"; + + public static boolean isNotificationsUrl(@Nullable String url) { + if (url == null) { + return false; + } + + return url.equalsIgnoreCase(ABOUT_NOTIFICATIONS); + } + public static final String WEB_EXTENSION_URL = "moz-extension://"; public static boolean isWebExtensionUrl(@Nullable String url) { @@ -225,7 +245,8 @@ public static boolean isPrivateUrl(@Nullable String url) { } public static boolean isAboutPage(@Nullable String url) { - return isHistoryUrl(url) || isBookmarksUrl(url) || isDownloadsUrl(url) || isAddonsUrl(url) || isPrivateUrl(url); + return isHistoryUrl(url) || isBookmarksUrl(url) || isDownloadsUrl(url) || isAddonsUrl(url) || + isWebAppsUrl(url) || isNotificationsUrl(url) || isPrivateUrl(url); } public static boolean isContentFeed(Context aContext, @Nullable String url) { diff --git a/app/src/main/res/layout/navigation_url.xml b/app/src/main/res/layout/navigation_url.xml index a4821aff38..67c949106e 100644 --- a/app/src/main/res/layout/navigation_url.xml +++ b/app/src/main/res/layout/navigation_url.xml @@ -228,8 +228,8 @@ + app:visibleGone="@{viewmodel.isWebApp && !(viewmodel.isNativeContentVisible || viewmodel.isUrlEmpty) && !viewmodel.isFocused}" /> + app:activeMode="@{viewmodel.isNativeContentVisible}"/>