Skip to content

Commit

Permalink
Create New Tab page and add an option to set New Tab page as homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
haanhvu committed Dec 5, 2024
1 parent 91873b5 commit 4d02e46
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class WindowViewModel extends AndroidViewModel {
private int mURLWebsiteColor;

private MutableLiveData<Spannable> url;
private MutableLiveData<Spannable> urlForwardFromNewTab;
private MutableLiveData<String> hint;
private MutableLiveData<ObservableBoolean> isWindowVisible;
private MutableLiveData<Windows.WindowPlacement> placement;
Expand All @@ -53,7 +54,9 @@ 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;
private MutableLiveData<ObservableBoolean> isMicrophoneEnabled;
private MutableLiveData<ObservableBoolean> isBookmarked;
Expand All @@ -64,6 +67,7 @@ public class WindowViewModel extends AndroidViewModel {
private MutableLiveData<ObservableBoolean> isPopUpAvailable;
private MutableLiveData<ObservableBoolean> isPopUpBlocked;
private MutableLiveData<ObservableBoolean> canGoForward;
private MutableLiveData<ObservableBoolean> canGoForwardFromNewTab;
private MutableLiveData<ObservableBoolean> canGoBack;
private MutableLiveData<ObservableBoolean> isInVRVideo;
private MutableLiveData<ObservableBoolean> autoEnteredVRVideo;
Expand Down Expand Up @@ -92,6 +96,7 @@ public WindowViewModel(Application application) {
mURLWebsiteColor = typedValue.data;

url = new MutableLiveData<>(new SpannableString(""));
urlForwardFromNewTab = new MutableLiveData<>(new SpannableString(""));
hint = new MutableLiveData<>("");
isWindowVisible = new MutableLiveData<>(new ObservableBoolean(true));
placement = new MutableLiveData<>(Windows.WindowPlacement.FRONT);
Expand Down Expand Up @@ -134,11 +139,15 @@ 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))
isNativeContentVisible.setValue(new ObservableBoolean(contentType != Windows.ContentType.WEB_CONTENT && contentType != Windows.ContentType.NEW_TAB))
);
isNativeContentVisible.setValue(new ObservableBoolean(currentContentType.getValue() != Windows.ContentType.WEB_CONTENT));
isNativeContentVisible.setValue(new ObservableBoolean(currentContentType.getValue() != Windows.ContentType.WEB_CONTENT && currentContentType.getValue() != Windows.ContentType.NEW_TAB));

backToNewTabEnabled = new MutableLiveData<>(new ObservableBoolean(false));

isLoading = new MutableLiveData<>(new ObservableBoolean(false));
isMicrophoneEnabled = new MutableLiveData<>(new ObservableBoolean(true));
Expand All @@ -150,6 +159,7 @@ public WindowViewModel(Application application) {
isPopUpAvailable = new MutableLiveData<>(new ObservableBoolean(false));
isPopUpBlocked = new MutableLiveData<>(new ObservableBoolean(false));
canGoForward = new MutableLiveData<>(new ObservableBoolean(false));
canGoForwardFromNewTab = new MutableLiveData<>(new ObservableBoolean(false));
canGoBack = new MutableLiveData<>(new ObservableBoolean(false));
isInVRVideo = new MutableLiveData<>(new ObservableBoolean(false));
autoEnteredVRVideo = new MutableLiveData<>(new ObservableBoolean(false));
Expand Down Expand Up @@ -239,9 +249,12 @@ 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 (currentContentType.getValue() == Windows.ContentType.NEW_TAB) {
url = getApplication().getString(R.string.url_new_tab_title);

} else {
if (UrlUtils.isPrivateAboutPage(getApplication(), url) ||
(UrlUtils.isDataUri(url) && isPrivateSession.getValue().get())) {
Expand Down Expand Up @@ -336,6 +349,7 @@ public void onChanged(ObservableBoolean o) {

public void refresh() {
url.postValue(url.getValue());
urlForwardFromNewTab.postValue(urlForwardFromNewTab.getValue());
hint.postValue(getHintValue());
isWindowVisible.postValue(isWindowVisible.getValue());
placement.postValue(placement.getValue());
Expand All @@ -352,6 +366,7 @@ public void refresh() {
isPopUpAvailable.postValue(isPopUpAvailable.getValue());
isPopUpBlocked.postValue(isPopUpBlocked.getValue());
canGoForward.postValue(canGoForward.getValue());
canGoForwardFromNewTab.postValue(canGoForwardFromNewTab.getValue());
canGoBack.postValue(canGoBack.getValue());
isInVRVideo.postValue(isInVRVideo.getValue());
autoEnteredVRVideo.postValue(autoEnteredVRVideo.getValue());
Expand All @@ -374,10 +389,18 @@ public MutableLiveData<Spannable> getUrl() {
return url;
}

public MutableLiveData<Spannable> getUrlForwardFromNewTab() {
if (urlForwardFromNewTab == null) {
urlForwardFromNewTab = new MutableLiveData<>(new SpannableString(""));
}
return urlForwardFromNewTab;
}

public void setUrl(@Nullable String url) {
if (url == null) {
return;
}

setUrl(new SpannableString(url));
}

Expand Down Expand Up @@ -421,9 +444,15 @@ private void setUrl(@Nullable Spannable url) {
spannable.setSpan(color1, 0, index + 3, 0);
spannable.setSpan(color2, index + 3, aURL.length(), 0);
this.url.postValue(spannable);
if (currentContentType.getValue() == Windows.ContentType.WEB_CONTENT && lastContentType.getValue() == Windows.ContentType.NEW_TAB) {
urlForwardFromNewTab.postValue(spannable);
}

} else {
this.url.postValue(url);
if (currentContentType.getValue() == Windows.ContentType.WEB_CONTENT && lastContentType.getValue() == Windows.ContentType.NEW_TAB) {
urlForwardFromNewTab.postValue(url);
}
}
}
}
Expand All @@ -434,9 +463,12 @@ 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 (currentContentType.getValue() == Windows.ContentType.NEW_TAB) {
return getApplication().getString(R.string.url_new_tab_title);

} else {
return getApplication().getString(R.string.search_placeholder);
}
Expand Down Expand Up @@ -571,6 +603,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 All @@ -583,6 +620,15 @@ public MutableLiveData<ObservableBoolean> getIsNativeContentVisible() {
return isNativeContentVisible;
}

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

@NonNull
public MutableLiveData<ObservableBoolean> getBackToNewTabEnabled() {
return backToNewTabEnabled;
}

@NonNull
public MutableLiveData<ObservableBoolean> getIsLoading() {
return isLoading;
Expand Down Expand Up @@ -673,6 +719,15 @@ public void setCanGoForward(boolean canGoForward) {
this.canGoForward.postValue(new ObservableBoolean(canGoForward));
}

@NonNull
public MutableLiveData<ObservableBoolean> getCanGoForwardFromNewTab() {
return canGoForwardFromNewTab;
}

public void setCanGoForwardFromNewTab(boolean canGoForwardFromNewTab) {
this.canGoForwardFromNewTab.postValue(new ObservableBoolean(canGoForwardFromNewTab));
}

@NonNull
public MutableLiveData<ObservableBoolean> getCanGoBack() {
return canGoBack;
Expand Down
42 changes: 42 additions & 0 deletions app/src/common/shared/com/igalia/wolvic/ui/views/NewTabView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.igalia.wolvic.ui.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.widget.FrameLayout;

import androidx.databinding.DataBindingUtil;

import com.igalia.wolvic.R;
import com.igalia.wolvic.VRBrowserActivity;
import com.igalia.wolvic.databinding.NewTabBinding;
import com.igalia.wolvic.ui.widgets.WidgetManagerDelegate;

public class NewTabView extends FrameLayout {

private WidgetManagerDelegate mWidgetManager;

private NewTabBinding mBinding;

public NewTabView(Context context) {
super(context);
initialize();
}

protected void initialize() {
mWidgetManager = ((VRBrowserActivity) getContext());
updateUI();
}

@SuppressLint("ClickableViewAccessibility")
public void updateUI() {
removeAllViews();

LayoutInflater inflater = LayoutInflater.from(getContext());

mBinding = DataBindingUtil.inflate(inflater, R.layout.new_tab, this, true);
mBinding.setLifecycleOwner((VRBrowserActivity)getContext());

mBinding.executePendingBindings();
}
}
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 @@ -243,6 +243,8 @@ private void updateUI() {

if (getSession().canGoBack()) {
getSession().goBack();
} else if (mViewModel.getBackToNewTabEnabled().getValue().get()) {
getSession().loadUri(UrlUtils.ABOUT_NEWTAB);
}

if (mAudio != null) {
Expand All @@ -253,7 +255,18 @@ private void updateUI() {

mBinding.navigationBarNavigation.forwardButton.setOnClickListener(v -> {
v.requestFocusFromTouch();
getSession().goForward();
if (mViewModel.getCanGoForwardFromNewTab().getValue().get()) {
String forwardUrl = mViewModel.getUrlForwardFromNewTab().getValue().toString();
getSession().loadUri(forwardUrl);

mAttachedWindow.hideNewTab();

mViewModel.setCurrentContentType(Windows.ContentType.WEB_CONTENT);
mViewModel.setUrl(forwardUrl);
mViewModel.setCanGoForwardFromNewTab(false);
} else {
getSession().goForward();
}
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
Expand Down Expand Up @@ -1020,7 +1033,10 @@ public void onLocationChange(@NonNull WSession session, @Nullable String url) {
updateTrackingProtection();
}

mBinding.navigationBarNavigation.reloadButton.setEnabled(!UrlUtils.isPrivateAboutPage(getContext(), url));
mBinding.navigationBarNavigation.reloadButton.setEnabled(
mViewModel.getCurrentContentType().getValue() != Windows.ContentType.NEW_TAB
&& !mViewModel.getIsNativeContentVisible().getValue().get()
&& !UrlUtils.isPrivateAboutPage(getContext(), url));
}

// Content delegate
Expand Down Expand Up @@ -1377,7 +1393,7 @@ public void onSwitchMode() {
public void onAddons() {
hideMenu();

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

@Override
Expand Down
Loading

0 comments on commit 4d02e46

Please sign in to comment.