Skip to content

Commit

Permalink
Add and use new ContentType for New Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
haanhvu committed Nov 30, 2024
1 parent 197dde6 commit 7050cf5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class WindowViewModel extends AndroidViewModel {
private MediatorLiveData<ObservableBoolean> isTitleBarVisible;
private MutableLiveData<Windows.ContentType> currentContentType;
private MediatorLiveData<ObservableBoolean> isNativeContentVisible;
private MutableLiveData<ObservableBoolean> isNewTabVisible;
private MutableLiveData<ObservableBoolean> backToNewTabEnabled;
private MutableLiveData<ObservableBoolean> isLoading;
private MutableLiveData<ObservableBoolean> isMicrophoneEnabled;
Expand Down Expand Up @@ -141,7 +140,6 @@ public WindowViewModel(Application application) {
isNativeContentVisible.setValue(new ObservableBoolean(contentType != Windows.ContentType.WEB_CONTENT))
);
isNativeContentVisible.setValue(new ObservableBoolean(currentContentType.getValue() != Windows.ContentType.WEB_CONTENT));
isNewTabVisible = new MutableLiveData<>(new ObservableBoolean(false));
backToNewTabEnabled = new MutableLiveData<>(new ObservableBoolean(false));

isLoading = new MutableLiveData<>(new ObservableBoolean(false));
Expand All @@ -166,7 +164,6 @@ public WindowViewModel(Application application) {
isInsecureVisible.addSource(isInsecure, mIsInsecureVisibleObserver);
isInsecureVisible.addSource(isPrivateSession, mIsInsecureVisibleObserver);
isInsecureVisible.addSource(isNativeContentVisible, mIsInsecureVisibleObserver);
isInsecureVisible.addSource(isNewTabVisible, mIsInsecureVisibleObserver);
isInsecureVisible.setValue(new ObservableBoolean(false));

isMediaAvailable = new MutableLiveData<>(new ObservableBoolean(false));
Expand All @@ -188,7 +185,6 @@ public WindowViewModel(Application application) {
isUrlBarButtonsVisible.addSource(isPopUpAvailable, mIsUrlBarButtonsVisibleObserver);
isUrlBarButtonsVisible.addSource(isWebXRUsed, mIsUrlBarButtonsVisibleObserver);
isUrlBarButtonsVisible.addSource(isNativeContentVisible, mIsUrlBarButtonsVisibleObserver);
isUrlBarButtonsVisible.addSource(isNewTabVisible, mIsUrlBarButtonsVisibleObserver);
isUrlBarButtonsVisible.addSource(isFocused, mIsUrlBarButtonsVisibleObserver);
isUrlBarButtonsVisible.setValue(new ObservableBoolean(false));

Expand Down Expand Up @@ -245,10 +241,10 @@ public void onChanged(ObservableBoolean o) {
@Override
public void onChanged(Spannable aUrl) {
String url = aUrl.toString();
if (isNativeContentVisible.getValue().get()) {
if (isNativeContentVisible.getValue().get() && currentContentType.getValue() != Windows.ContentType.NEW_TAB) {
url = getApplication().getString(R.string.url_library_title);

} else if (isNewTabVisible.getValue().get()) {
} else if (currentContentType.getValue() == Windows.ContentType.NEW_TAB) {
url = getApplication().getString(R.string.url_new_tab_title);

} else {
Expand Down Expand Up @@ -281,7 +277,6 @@ public void onChanged(ObservableBoolean o) {
UrlUtils.isFileUri(aUrl) ||
UrlUtils.isHomeUri(getApplication(), aUrl) ||
isNativeContentVisible.getValue().get() ||
isNewTabVisible.getValue().get() ||
UrlUtils.isBlankUri(getApplication(), aUrl)) {
isInsecureVisible.postValue(new ObservableBoolean(false));

Expand All @@ -303,7 +298,6 @@ public void onChanged(Spannable aUrl) {
(UrlUtils.isDataUri(url) && isPrivateSession.getValue().get()) ||
UrlUtils.isHomeUri(getApplication(), aUrl.toString()) ||
isNativeContentVisible.getValue().get() ||
isNewTabVisible.getValue().get() ||
UrlUtils.isBlankUri(getApplication(), aUrl.toString())) {
navigationBarUrl.postValue("");

Expand All @@ -320,7 +314,6 @@ public void onChanged(ObservableBoolean o) {
isUrlBarButtonsVisible.postValue(new ObservableBoolean(
!isFocused.getValue().get() &&
!isNativeContentVisible.getValue().get() &&
!isNewTabVisible.getValue().get() &&
!UrlUtils.isContentFeed(getApplication(), aUrl) &&
!UrlUtils.isPrivateAboutPage(getApplication(), aUrl) &&
(URLUtil.isHttpUrl(aUrl) || URLUtil.isHttpsUrl(aUrl)) &&
Expand All @@ -340,7 +333,6 @@ public void onChanged(ObservableBoolean o) {
public void onChanged(ObservableBoolean o) {
isUrlBarIconsVisible.postValue(new ObservableBoolean(
!isNativeContentVisible.getValue().get() &&
!isNewTabVisible.getValue().get() &&
(isLoading.getValue().get() ||
isInsecureVisible.getValue().get())
));
Expand Down Expand Up @@ -447,10 +439,10 @@ public MutableLiveData<String> getHint() {
}

private String getHintValue() {
if (isNativeContentVisible.getValue().get()) {
if (isNativeContentVisible.getValue().get() && currentContentType.getValue() != Windows.ContentType.NEW_TAB) {
return getApplication().getString(R.string.url_library_title);

} else if (isNewTabVisible.getValue().get()) {
} else if (currentContentType.getValue() == Windows.ContentType.NEW_TAB) {
return getApplication().getString(R.string.url_new_tab_title);

} else {
Expand Down Expand Up @@ -599,20 +591,10 @@ public MutableLiveData<ObservableBoolean> getIsNativeContentVisible() {
return isNativeContentVisible;
}

public void setIsNewTabVisible(boolean isNewTabVisible) {
this.isNewTabVisible.postValue(new ObservableBoolean(isNewTabVisible));
this.url.postValue(this.getUrl().getValue());
}

public void enableBackToNewTab(boolean backToNewTabEnabled) {
this.backToNewTabEnabled.postValue(new ObservableBoolean(backToNewTabEnabled));
}

@NonNull
public MutableLiveData<ObservableBoolean> getIsNewTabVisible() {
return isNewTabVisible;
}

@NonNull
public MutableLiveData<ObservableBoolean> getBackToNewTabEnabled() {
return backToNewTabEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public void onDestroy() {
mSystemNotificationsView.onDestroy();
}

@NonNull
public Windows.ContentType getSelectedPanelType() {
if (mCurrentView == mBookmarksView) {
return Windows.ContentType.BOOKMARKS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ public boolean isNativeContentVisible() {
return mViewModel.getIsNativeContentVisible().getValue().get();
}

public Windows.ContentType getCurrentContentType() {
return mViewModel.getCurrentContentType().getValue();
}

public int getWindowWidth() {
return mWidgetPlacement.width;
}
Expand All @@ -500,12 +504,13 @@ public int getWindowHeight() {
return mWidgetPlacement.height;
}

@NonNull
public Windows.ContentType getSelectedPanel() {
return mLibrary.getSelectedPanelType();
}

private void hideLibraryPanel() {
if (mViewModel.getIsNativeContentVisible().getValue().get()) {
if (mViewModel.getIsNativeContentVisible().getValue().get() && mViewModel.getCurrentContentType().getValue() != Windows.ContentType.NEW_TAB) {
hidePanel(true);
}
}
Expand Down Expand Up @@ -544,16 +549,15 @@ private void showPanel(Windows.ContentType contentType, boolean switchSurface) {
}
};
}
} else if (mView == mLibrary) {
mLibrary.selectPanel(contentType);
}
}

public void showNewTab() {
if (mNewTab != null) {
setView(mNewTab, true);
mViewModel.setIsFindInPage(false);
mViewModel.setIsNewTabVisible(true);
mViewModel.setCurrentContentType(Windows.ContentType.NEW_TAB);
mViewModel.setUrl(Windows.ContentType.NEW_TAB.URL);
mViewModel.enableBackToNewTab(false);
onFirstContentfulPaint(mSession.getWSession());
if (mRestoreFirstPaint == null && !isFirstPaintReady() && (mFirstDrawCallback != null) && (mSurface != null)) {
Expand Down Expand Up @@ -590,9 +594,8 @@ private void hidePanel(boolean switchSurface) {
}

public void hideNewTab() {
if (mViewModel.getIsNewTabVisible().getValue().get()) {
if (mViewModel.getCurrentContentType().getValue() == Windows.ContentType.NEW_TAB) {
hideNewTab(true);
mViewModel.setIsNewTabVisible(false);
mViewModel.enableBackToNewTab(true);
}
}
Expand Down
18 changes: 13 additions & 5 deletions app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class WindowState {
int textureHeight;
float worldWidth;
int tabIndex = -1;

// NOTE: Enum values may be null when deserialized by GSON.
ContentType contentType = ContentType.WEB_CONTENT;

Expand All @@ -119,8 +120,11 @@ public void load(@NonNull WindowWidget aWindow, WindowsState aState, int aTabInd
worldWidth = widgetPlacement.worldWidth;
tabIndex = aTabIndex;
if (aWindow.isNativeContentVisible()) {
contentType = aWindow.getSelectedPanel();

if (aWindow.getCurrentContentType() == ContentType.NEW_TAB) {
contentType = ContentType.NEW_TAB;
} else {
contentType = aWindow.getSelectedPanel();
}
} else {
contentType = ContentType.WEB_CONTENT;
}
Expand Down Expand Up @@ -171,7 +175,8 @@ public enum ContentType {
HISTORY(UrlUtils.ABOUT_HISTORY),
DOWNLOADS(UrlUtils.ABOUT_DOWNLOADS),
ADDONS(UrlUtils.ABOUT_ADDONS),
NOTIFICATIONS(UrlUtils.ABOUT_NOTIFICATIONS);
NOTIFICATIONS(UrlUtils.ABOUT_NOTIFICATIONS),
NEW_TAB(UrlUtils.ABOUT_NEWTAB);

@NonNull
public final String URL;
Expand Down Expand Up @@ -389,6 +394,9 @@ private WindowWidget addRestoredWindow(@NonNull WindowState aState, @Nullable Se
case ADDONS:
newWindow.getSession().loadUri(UrlUtils.ABOUT_ADDONS);
break;
case NEW_TAB:
newWindow.getSession().loadUri(UrlUtils.ABOUT_NEWTAB);
break;
case WEB_CONTENT:
break;
}
Expand Down Expand Up @@ -636,7 +644,7 @@ public void exitImmersiveMode() {
}

private void closeLibraryPanelInFocusedWindowIfNeeded() {
if (!mFocusedWindow.isNativeContentVisible())
if (!mFocusedWindow.isNativeContentVisible() || mFocusedWindow.getCurrentContentType() == ContentType.NEW_TAB)
return;
mFocusedWindow.hidePanel();
}
Expand Down Expand Up @@ -1202,7 +1210,7 @@ public void onAddWindowClicked() {

@Override
public void onLibraryClicked() {
if (mFocusedWindow.isNativeContentVisible()) {
if (mFocusedWindow.isNativeContentVisible() && mFocusedWindow.getCurrentContentType() != ContentType.NEW_TAB) {
mFocusedWindow.hidePanel();

} else if (mDownloadsManager.isDownloading()) {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/layout/tray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tool="http://schemas.android.com/tools">
<data>
<import type="com.igalia.wolvic.ui.widgets.Windows.ContentType" />

<variable
name="viewmodel"
type="com.igalia.wolvic.ui.viewmodel.WindowViewModel" />
Expand Down Expand Up @@ -195,7 +197,7 @@
app:tooltipLayout="@layout/tooltip_tray"
android:src="@drawable/ic_icon_library"
app:clipDrawable="@drawable/ic_icon_library_clip"
app:activeMode="@{viewmodel.isNativeContentVisible}"/>
app:activeMode="@{viewmodel.isNativeContentVisible &amp;&amp; viewmodel.currentContentType != ContentType.NEW_TAB}"/>
<com.google.android.material.textview.MaterialTextView
android:layout_width="12dp"
android:layout_height="12dp"
Expand Down

0 comments on commit 7050cf5

Please sign in to comment.