Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create New Tab page and add an option to set New Tab page as homepage #1574

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -619,13 +619,16 @@ android {
lint {
disable 'ExtraTranslation'
}
androidResources {

aaptOptions {
noCompress 'ja'
noCompress 'dat'
noCompress 'bin'
noCompress 'pak'
noCompress 'ja'
noCompress 'dat'
noCompress 'bin'
}

}

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class WindowViewModel extends AndroidViewModel {
private MutableLiveData<ObservableBoolean> isActiveWindow;
private MediatorLiveData<ObservableBoolean> isTitleBarVisible;
private MutableLiveData<ObservableBoolean> isLibraryVisible;
private MutableLiveData<ObservableBoolean> isNewTabVisible;
private MutableLiveData<ObservableBoolean> backToNewTabEnabled;
private MutableLiveData<ObservableBoolean> isLoading;
private MutableLiveData<ObservableBoolean> isMicrophoneEnabled;
private MutableLiveData<ObservableBoolean> isBookmarked;
Expand Down Expand Up @@ -129,6 +131,8 @@ public WindowViewModel(Application application) {
isTitleBarVisible.setValue(new ObservableBoolean(true));

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

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

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

Expand Down Expand Up @@ -231,6 +237,9 @@ public void onChanged(Spannable aUrl) {
if (isLibraryVisible.getValue().get()) {
url = getApplication().getString(R.string.url_library_title);

} else if (isNewTabVisible.getValue().get()) {
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 @@ -261,6 +270,7 @@ public void onChanged(ObservableBoolean o) {
UrlUtils.isFileUri(aUrl) ||
UrlUtils.isHomeUri(getApplication(), aUrl) ||
isLibraryVisible.getValue().get() ||
isNewTabVisible.getValue().get() ||
UrlUtils.isBlankUri(getApplication(), aUrl)) {
isInsecureVisible.postValue(new ObservableBoolean(false));

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

Expand All @@ -298,6 +309,7 @@ public void onChanged(ObservableBoolean o) {
isUrlBarButtonsVisible.postValue(new ObservableBoolean(
!isFocused.getValue().get() &&
!isLibraryVisible.getValue().get() &&
!isNewTabVisible.getValue().get() &&
!UrlUtils.isContentFeed(getApplication(), aUrl) &&
!UrlUtils.isPrivateAboutPage(getApplication(), aUrl) &&
(URLUtil.isHttpUrl(aUrl) || URLUtil.isHttpsUrl(aUrl)) &&
Expand All @@ -317,6 +329,7 @@ public void onChanged(ObservableBoolean o) {
public void onChanged(ObservableBoolean o) {
isUrlBarIconsVisible.postValue(new ObservableBoolean(
!isLibraryVisible.getValue().get() &&
!isNewTabVisible.getValue().get() &&
(isLoading.getValue().get() ||
isInsecureVisible.getValue().get())
));
Expand Down Expand Up @@ -430,6 +443,9 @@ private String getHintValue() {
if (isLibraryVisible.getValue().get()) {
return getApplication().getString(R.string.url_library_title);

} else if (isNewTabVisible.getValue().get()) {
return getApplication().getString(R.string.url_new_tab_title);

} else {
return getApplication().getString(R.string.search_placeholder);
}
Expand Down Expand Up @@ -577,6 +593,25 @@ public MutableLiveData<ObservableBoolean> getIsLibraryVisible() {
return isLibraryVisible;
}

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;
}

@NonNull
public MutableLiveData<ObservableBoolean> getIsLoading() {
return isLoading;
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 @@ -243,6 +243,10 @@ private void updateUI() {
mBinding.navigationBarNavigation.backButton.setOnClickListener(v -> {
v.requestFocusFromTouch();

if (mViewModel.getBackToNewTabEnabled().getValue().get()) {
mAttachedWindow.showNewTab();
}

if (getSession().canGoBack()) {
getSession().goBack();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.igalia.wolvic.telemetry.TelemetryService;
import com.igalia.wolvic.ui.adapters.WebApp;
import com.igalia.wolvic.ui.viewmodel.WindowViewModel;
import com.igalia.wolvic.ui.views.NewTabView;
import com.igalia.wolvic.ui.views.library.LibraryPanel;
import com.igalia.wolvic.ui.widgets.dialogs.PromptDialogWidget;
import com.igalia.wolvic.ui.widgets.dialogs.SelectionActionWidget;
Expand Down Expand Up @@ -134,6 +135,7 @@ public class WindowWidget extends UIWidget implements SessionChangeListener,
private Session mSession;
private int mWindowId;
private LibraryPanel mLibrary;
private NewTabView mNewTab;
private Windows.WindowPlacement mWindowPlacement = Windows.WindowPlacement.FRONT;
private Windows.WindowPlacement mWindowPlacementBeforeFullscreen = Windows.WindowPlacement.FRONT;
private float mMaxWindowScale = 3;
Expand Down Expand Up @@ -217,6 +219,7 @@ private void initialize(Context aContext) {
setupListeners(mSession);

mLibrary = new LibraryPanel(aContext);
mNewTab = new NewTabView(aContext);

SessionStore.get().getBookmarkStore().addListener(mBookmarksListener);

Expand Down Expand Up @@ -523,7 +526,29 @@ public void showPanel(@Windows.PanelType int panelType) {
showPanel(panelType, true);
}

public void showNewTab() {
if (mNewTab != null) {
setView(mNewTab, true);
mViewModel.setIsFindInPage(false);
mViewModel.setIsNewTabVisible(true);
mViewModel.enableBackToNewTab(false);
onFirstContentfulPaint(mSession.getWSession());
if (mRestoreFirstPaint == null && !isFirstPaintReady() && (mFirstDrawCallback != null) && (mSurface != null)) {
final Runnable firstDrawCallback = mFirstDrawCallback;
onFirstContentfulPaint(mSession.getWSession());
mRestoreFirstPaint = () -> {
setFirstPaintReady(false);
setFirstDrawCallback(firstDrawCallback);
if (mWidgetManager != null) {
mWidgetManager.updateWidget(WindowWidget.this);
}
};
}
}
}

private void showPanel(@Windows.PanelType int panelType, boolean switchSurface) {
hideNewTab();
if (mLibrary != null) {
if (mView == null) {
setView(mLibrary, switchSurface);
Expand All @@ -542,7 +567,6 @@ private void showPanel(@Windows.PanelType int panelType, boolean switchSurface)
}
};
}

} else if (mView == mLibrary) {
mLibrary.selectPanel(panelType);
}
Expand All @@ -563,6 +587,27 @@ private void hidePanel(boolean switchSurface) {
mRestoreFirstPaint.run();
mRestoreFirstPaint = null;
}
if (mViewModel.getBackToNewTabEnabled().getValue().get()) {
showNewTab();
}
}

public void hideNewTab() {
if (mViewModel.getIsNewTabVisible().getValue().get()) {
hideNewTab(true);
mViewModel.setIsNewTabVisible(false);
mViewModel.enableBackToNewTab(true);
}
}

private void hideNewTab(boolean switchSurface) {
if (mView != null && mNewTab != null) {
unsetView(mNewTab, switchSurface);
}
if (switchSurface && mRestoreFirstPaint != null) {
mRestoreFirstPaint.run();
mRestoreFirstPaint = null;
}
}

public void pauseCompositor() {
Expand Down Expand Up @@ -2002,23 +2047,28 @@ WResult<WAllowOrDeny> onLoadRequest(WSession aSession, @NonNull LoadRequest aReq

Uri uri = Uri.parse(aRequest.uri);
if (UrlUtils.isAboutPage(uri.toString())) {
if(UrlUtils.isBookmarksUrl(uri.toString())) {
showPanel(Windows.BOOKMARKS);
if(UrlUtils.isBookmarksUrl(uri.toString())) {
showPanel(Windows.BOOKMARKS);

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

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

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

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

} else {
hideLibraryPanel();
}
hideNewTab();
hideLibraryPanel();
}

} else {
hideNewTab();
hideLibraryPanel();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import com.igalia.wolvic.ui.views.settings.SwitchSetting;
import com.igalia.wolvic.ui.widgets.WidgetManagerDelegate;
import com.igalia.wolvic.ui.widgets.WidgetPlacement;
import com.igalia.wolvic.utils.UrlUtils;

import java.util.Objects;

class DisplayOptionsView extends SettingsView {

Expand Down Expand Up @@ -72,6 +75,10 @@ protected void updateUI() {
mBinding.msaaRadio.setOnCheckedChangeListener(mMSSAChangeListener);
setMSAAMode(mBinding.msaaRadio.getIdForValue(msaaLevel), false);

int homepageId = getHomepageId(SettingsStore.getInstance(getContext()).getHomepage());
mBinding.homepage.setOnCheckedChangeListener(mHomepageChangeListener);
setHomepage(homepageId, false);

mBinding.autoplaySwitch.setOnCheckedChangeListener(mAutoplayListener);
setAutoplay(SettingsStore.getInstance(getContext()).isAutoplayEnabled(), false);

Expand Down Expand Up @@ -165,6 +172,10 @@ public boolean isEditing() {
setMSAAMode(checkedId, true);
};

private RadioGroupSetting.OnCheckedChangeListener mHomepageChangeListener = (radioGroup, checkedId, doApply) -> {
setHomepage(checkedId, true);
};

private SwitchSetting.OnCheckedChangeListener mAutoplayListener = (compoundButton, enabled, apply) -> {
setAutoplay(enabled, true);
};
Expand Down Expand Up @@ -249,6 +260,11 @@ public boolean isEditing() {
restart = true;
}

int defaultHomepageId = getHomepageId(mDefaultHomepageUrl);
if (mBinding.homepage.getCheckedRadioButtonId() != defaultHomepageId) {
setHomepage(defaultHomepageId, true);
}

float prevDensity = SettingsStore.getInstance(getContext()).getDisplayDensity();
restart = restart | setDisplayDensity(SettingsStore.DISPLAY_DENSITY_DEFAULT);
int prevDpi = SettingsStore.getInstance(getContext()).getDisplayDpi();
Expand Down Expand Up @@ -374,11 +390,39 @@ private void setWindowMovement(boolean value, boolean doApply) {
}
}

private void setHomepage(int checkedId, boolean doApply) {
mBinding.homepage.setOnCheckedChangeListener(null);
mBinding.homepage.setChecked(checkedId, doApply);
mBinding.homepage.setOnCheckedChangeListener(mHomepageChangeListener);

if (checkedId == 0) {
mBinding.homepageEdit.setVisibility(View.GONE);
SettingsStore.getInstance(getContext()).setHomepage(UrlUtils.ABOUT_NEWTAB);
} else if (checkedId == 1) {
mBinding.homepageEdit.setVisibility(View.GONE);
SettingsStore.getInstance(getContext()).setHomepage(mDefaultHomepageUrl);
} else if (checkedId == 2) {
mBinding.homepageEdit.setVisibility(View.VISIBLE);
}
}

private int getHomepageId(String homepage) {
if (Objects.equals(homepage, UrlUtils.ABOUT_NEWTAB)) {
return 0;
} else if (Objects.equals(homepage, getContext().getString(R.string.HOMEPAGE_URL))) {
return 1;
} else {
return 2;
}
}

private void setHomepage(String newHomepage) {
mBinding.homepageEdit.setOnClickListener(null);
mBinding.homepageEdit.setFirstText(newHomepage);
SettingsStore.getInstance(getContext()).setHomepage(newHomepage);
mBinding.homepageEdit.setOnClickListener(mHomepageListener);
if (mBinding.homepageEdit.getVisibility() == VISIBLE) {
mBinding.homepageEdit.setOnClickListener(null);
mBinding.homepageEdit.setFirstText(newHomepage);
SettingsStore.getInstance(getContext()).setHomepage(newHomepage);
mBinding.homepageEdit.setOnClickListener(mHomepageListener);
}
}

private void setWindowDistance(float value, boolean doApply) {
Expand Down
Loading
Loading