Skip to content

Commit

Permalink
Fix the error in the flow new tab - web page - open library - close l…
Browse files Browse the repository at this point in the history
…ibrary - back to new tab
  • Loading branch information
haanhvu committed Dec 1, 2024
1 parent 3ce39b7 commit 6e6592c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class WindowViewModel extends AndroidViewModel {
private MutableLiveData<ObservableBoolean> isActiveWindow;
private MediatorLiveData<ObservableBoolean> isTitleBarVisible;
private MutableLiveData<Windows.ContentType> currentContentType;
public MutableLiveData<Windows.ContentType> lastContentType;
private MediatorLiveData<ObservableBoolean> isNativeContentVisible;
private MutableLiveData<ObservableBoolean> backToNewTabEnabled;
private MutableLiveData<ObservableBoolean> isLoading;
Expand Down Expand Up @@ -135,6 +136,7 @@ public WindowViewModel(Application application) {
isTitleBarVisible.setValue(new ObservableBoolean(true));

currentContentType = new MutableLiveData<>(Windows.ContentType.WEB_CONTENT);
lastContentType = new MutableLiveData<>(Windows.ContentType.WEB_CONTENT);
isNativeContentVisible = new MediatorLiveData<>();
isNativeContentVisible.addSource(currentContentType, contentType ->
isNativeContentVisible.setValue(new ObservableBoolean(contentType != Windows.ContentType.WEB_CONTENT))
Expand Down Expand Up @@ -579,6 +581,9 @@ public void setIsActiveWindow(boolean isActiveWindow) {
}

public void setCurrentContentType(Windows.ContentType contentType) {
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 @@ -510,7 +510,7 @@ public Windows.ContentType getSelectedPanel() {
}

private void hideLibraryPanel() {
if (mViewModel.getIsNativeContentVisible().getValue().get() && mViewModel.getCurrentContentType().getValue() != Windows.ContentType.NEW_TAB) {
if (mViewModel.getCurrentContentType().getValue().isLibraryContent()) {
hidePanel(true);
}
}
Expand Down Expand Up @@ -589,12 +589,12 @@ private void hidePanel(boolean switchSurface) {
mRestoreFirstPaint.run();
mRestoreFirstPaint = null;
}
if (mViewModel.getBackToNewTabEnabled().getValue().get()) {
//if (mViewModel.getBackToNewTabEnabled().getValue().get()) {
if (mViewModel.lastContentType.getValue() == Windows.ContentType.NEW_TAB) {
showNewTab();
} else {
mViewModel.setCurrentContentType(Windows.ContentType.WEB_CONTENT);
}
mViewModel.enableBackToNewTab(false);
}

public void hideNewTab() {
Expand Down Expand Up @@ -2053,23 +2053,23 @@ 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();
//hideNewTab();
showPanel(Windows.ContentType.BOOKMARKS);

} else if (UrlUtils.isHistoryUrl(uri.toString())) {
hideNewTab();
//hideNewTab();
showPanel(Windows.ContentType.HISTORY);

} else if (UrlUtils.isDownloadsUrl(uri.toString())) {
hideNewTab();
//hideNewTab();
showPanel(Windows.ContentType.DOWNLOADS);

} else if (UrlUtils.isAddonsUrl(uri.toString())) {
hideNewTab();
//hideNewTab();
showPanel(Windows.ContentType.ADDONS);

} else if (UrlUtils.isNewTabUrl(uri.toString())) {
hideLibraryPanel();
//hideLibraryPanel();
showNewTab();

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,18 @@ public enum ContentType {

@NonNull
public final String URL;

ContentType(@NonNull String url) {
this.URL = url;
}

public boolean isLibraryContent() {
return (this.URL == UrlUtils.ABOUT_BOOKMARKS ||
this.URL == UrlUtils.ABOUT_WEBAPPS ||
this.URL == UrlUtils.ABOUT_HISTORY ||
this.URL == UrlUtils.ABOUT_DOWNLOADS ||
this.URL == UrlUtils.ABOUT_ADDONS);
};
}

public enum WindowPlacement{
Expand Down

0 comments on commit 6e6592c

Please sign in to comment.