Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
haanhvu committed Dec 3, 2024
1 parent 63bf929 commit beea487
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ public void onSwitchMode() {
public void onAddons() {
hideMenu();

mAttachedWindow.showPanel(Windows.ContentType.ADDONS);
mAttachedWindow.showLibraryPanel(Windows.ContentType.ADDONS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,60 +510,47 @@ 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;
}

hideNewTab();
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() {
Expand All @@ -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);
}*/
}
};
}
}
Expand All @@ -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 {
Expand All @@ -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");
}
}

Expand Down Expand Up @@ -2073,23 +2052,18 @@ WResult<WAllowOrDeny> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
}

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 @@ -191,7 +191,7 @@
<com.igalia.wolvic.ui.views.UIButton
android:id="@+id/libraryButton"
style="@style/trayButtonMiddleTheme"
android:tooltipText="@{viewmodel.isNativeContentVisible ? @string/close_library_tooltip : @string/open_library_tooltip}"
android:tooltipText="@{viewmodel.isNativeContentVisible &amp;&amp; viewmodel.currentContentType != ContentType.NEW_TAB? @string/close_library_tooltip : @string/open_library_tooltip}"
app:tooltipDensity="@dimen/tray_tooltip_density"
app:tooltipPosition="bottom"
app:tooltipLayout="@layout/tooltip_tray"
Expand Down

0 comments on commit beea487

Please sign in to comment.