From beea48775ae23eb3475fc6b203dec56536509ef0 Mon Sep 17 00:00:00 2001 From: haanhvu Date: Tue, 3 Dec 2024 17:25:14 +0700 Subject: [PATCH] Clean up --- .../wolvic/ui/viewmodel/WindowViewModel.java | 2 + .../ui/widgets/NavigationBarWidget.java | 2 +- .../wolvic/ui/widgets/WindowWidget.java | 76 ++++++------------- .../com/igalia/wolvic/ui/widgets/Windows.java | 8 +- app/src/main/res/layout/tray.xml | 2 +- 5 files changed, 33 insertions(+), 57 deletions(-) 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 627ef164e29..70310f55747 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 @@ -581,9 +581,11 @@ public void setIsActiveWindow(boolean isActiveWindow) { } public void setCurrentContentType(Windows.ContentType contentType) { + // No need to store lastContentType when we switch content types in library if (!currentContentType.getValue().isLibraryContent() || !contentType.isLibraryContent()) { lastContentType.postValue(currentContentType.getValue()); } + currentContentType.postValue(contentType); } 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 b6e76499206..66ed1f33e23 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 @@ -1381,7 +1381,7 @@ public void onSwitchMode() { public void onAddons() { hideMenu(); - mAttachedWindow.showPanel(Windows.ContentType.ADDONS); + mAttachedWindow.showLibraryPanel(Windows.ContentType.ADDONS); } @Override 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 de01e8ba52c..21618b68359 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 @@ -510,24 +510,20 @@ public Windows.ContentType getSelectedPanel() { } private void hideLibraryPanel() { - if (mViewModel.getCurrentContentType().getValue().isLibraryContent()) { + if (getCurrentContentType().isLibraryContent()) { hidePanel(true); } } Runnable mRestoreFirstPaint; - public void showPanel(Windows.ContentType panelType) { - /*if (panelType == Windows.ContentType.WEB_CONTENT) { - hidePanel(); - } else {*/ - showPanel(panelType, true); - //} + public void showLibraryPanel(Windows.ContentType panelType) { + assert panelType != Windows.ContentType.NEW_TAB && panelType != Windows.ContentType.WEB_CONTENT && panelType != Windows.ContentType.NOTIFICATIONS; + showLibraryPanel(panelType, true); } - private void showPanel(Windows.ContentType contentType, boolean switchSurface) { + private void showLibraryPanel(Windows.ContentType contentType, boolean switchSurface) { if (mLibrary == null) { - Log.e("New Tab PR", "showPanel(): mLibrary is null"); return; } @@ -535,35 +531,26 @@ private void showPanel(Windows.ContentType contentType, boolean switchSurface) { mViewModel.setIsFindInPage(false); mViewModel.setCurrentContentType(contentType); mViewModel.setUrl(contentType.URL); - //if (mView == null) { - if (mView != mLibrary) { - Log.e("New Tab PR", "mView == null"); + if (mView == null) { setView(mLibrary, switchSurface); mLibrary.selectPanel(contentType); mLibrary.onShow(); - //if (mRestoreFirstPaint == null && !isFirstPaintReady() && (mFirstDrawCallback != null) && (mSurface != null)) { if (mRestoreFirstPaint == null) { - Log.e("New Tab PR", "if clause is run"); - final Runnable firstDrawCallback = mFirstDrawCallback; - //onFirstContentfulPaint(mSession.getWSession()); + onFirstContentfulPaint(mSession.getWSession()); mRestoreFirstPaint = () -> { setFirstPaintReady(false); - //setFirstDrawCallback(firstDrawCallback); - /*if (mWidgetManager != null) { + if (mFirstDrawCallback != null) { + final Runnable firstDrawCallback = mFirstDrawCallback; + setFirstDrawCallback(firstDrawCallback); + } + if (mWidgetManager != null) { mWidgetManager.updateWidget(WindowWidget.this); - }*/ + } }; - } else { - Log.e("New Tab PR", "if clause is NOT run"); } - //} else if (mView == mLibrary) { - } else { - Log.e("New Tab PR", "mView == mLibrary"); + } else if (mView == mLibrary) { mLibrary.selectPanel(contentType); } - //else { - //Log.e("New Tab PR", "Other case"); - //} } public void showNewTab() { @@ -573,17 +560,17 @@ public void showNewTab() { mViewModel.setUrl(Windows.ContentType.NEW_TAB.URL); mViewModel.enableBackToNewTab(false); setView(mNewTab, true); - onFirstContentfulPaint(mSession.getWSession()); - //if (mRestoreFirstPaint == null && !isFirstPaintReady() && (mFirstDrawCallback != null) && (mSurface != null)) { if (mRestoreFirstPaint == null) { - final Runnable firstDrawCallback = mFirstDrawCallback; - //onFirstContentfulPaint(mSession.getWSession()); + onFirstContentfulPaint(mSession.getWSession()); mRestoreFirstPaint = () -> { setFirstPaintReady(false); - //setFirstDrawCallback(firstDrawCallback); - /*if (mWidgetManager != null) { + if (mFirstDrawCallback != null) { + final Runnable firstDrawCallback = mFirstDrawCallback; + setFirstDrawCallback(firstDrawCallback); + } + if (mWidgetManager != null) { mWidgetManager.updateWidget(WindowWidget.this); - }*/ + } }; } } @@ -602,7 +589,6 @@ private void hidePanel(boolean switchSurface) { mRestoreFirstPaint.run(); mRestoreFirstPaint = null; } - //if (mViewModel.getBackToNewTabEnabled().getValue().get()) { if (mViewModel.lastContentType.getValue() == Windows.ContentType.NEW_TAB) { showNewTab(); } else { @@ -614,23 +600,16 @@ public void hideNewTab() { if (mViewModel.getCurrentContentType().getValue() == Windows.ContentType.NEW_TAB) { mViewModel.enableBackToNewTab(true); hideNewTab(true); - } else { - Log.e("New Tab PR", "Current content type is not New Tab"); } } private void hideNewTab(boolean switchSurface) { if (mView != null && mNewTab != null) { unsetView(mNewTab, switchSurface); - } else { - Log.e("New Tab PR", "Cannot unset New Tab view"); } if (switchSurface && mRestoreFirstPaint != null) { - Log.e("New Tab PR", "mRestoreFirstPaint is not null => Can make null"); mRestoreFirstPaint.run(); mRestoreFirstPaint = null; - } else { - Log.e("New Tab PR", "mRestoreFirstPaint is already null => Cannot make mRestoreFirstPaint null"); } } @@ -2073,23 +2052,18 @@ WResult onLoadRequest(WSession aSession, @NonNull LoadRequest aReq Uri uri = Uri.parse(aRequest.uri); if (UrlUtils.isAboutPage(uri.toString())) { if(UrlUtils.isBookmarksUrl(uri.toString())) { - //hideNewTab(); - showPanel(Windows.ContentType.BOOKMARKS); + showLibraryPanel(Windows.ContentType.BOOKMARKS); } else if (UrlUtils.isHistoryUrl(uri.toString())) { - //hideNewTab(); - showPanel(Windows.ContentType.HISTORY); + showLibraryPanel(Windows.ContentType.HISTORY); } else if (UrlUtils.isDownloadsUrl(uri.toString())) { - //hideNewTab(); - showPanel(Windows.ContentType.DOWNLOADS); + showLibraryPanel(Windows.ContentType.DOWNLOADS); } else if (UrlUtils.isAddonsUrl(uri.toString())) { - //hideNewTab(); - showPanel(Windows.ContentType.ADDONS); + showLibraryPanel(Windows.ContentType.ADDONS); } else if (UrlUtils.isNewTabUrl(uri.toString())) { - //hideLibraryPanel(); showNewTab(); } else { 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 58b662b2fca..6f57480f645 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 @@ -653,7 +653,7 @@ public void exitImmersiveMode() { } private void closeLibraryPanelInFocusedWindowIfNeeded() { - if (!mFocusedWindow.isNativeContentVisible() || mFocusedWindow.getCurrentContentType() == ContentType.NEW_TAB) + if (!mFocusedWindow.getCurrentContentType().isLibraryContent()) return; mFocusedWindow.hidePanel(); } @@ -1219,14 +1219,14 @@ public void onAddWindowClicked() { @Override public void onLibraryClicked() { - if (mFocusedWindow.isNativeContentVisible() && mFocusedWindow.getCurrentContentType() != ContentType.NEW_TAB) { + if (mFocusedWindow.getCurrentContentType().isLibraryContent()) { mFocusedWindow.hidePanel(); } else if (mDownloadsManager.isDownloading()) { - mFocusedWindow.showPanel(ContentType.DOWNLOADS); + mFocusedWindow.showLibraryPanel(ContentType.DOWNLOADS); } else { - mFocusedWindow.showPanel(ContentType.BOOKMARKS); + mFocusedWindow.showLibraryPanel(ContentType.BOOKMARKS); } } diff --git a/app/src/main/res/layout/tray.xml b/app/src/main/res/layout/tray.xml index ae016014eb7..7e8c3a61014 100644 --- a/app/src/main/res/layout/tray.xml +++ b/app/src/main/res/layout/tray.xml @@ -191,7 +191,7 @@