8000 Use the native New Tab by default by felipeerias · Pull Request #1830 · Igalia/wolvic · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use the native New Tab by default #1830

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ def isWebKitAvailable = {
def GECKO_RELEASE_VERSION_NAME = '1.8.1'
def CHROMIUM_RELEASE_VERSION_NAME = '1.2.1'

// Homepage and new tab URLs. HOMEPAGE_URL points at a website
// and NEW_TAB_DEFAULT_URL determines the default content of a new tab.
def localNewTabUrl = "about://newtab"
def homepageDefaultUrl = "https://wolvic.com/start"
def homepageChinaUrl = "https://wolvic.com/zh/start/index.html"
def homepageChinaHvgUrl = "https://wolvic.com/zh/start/hvg.html"
def homepageChinaPicoUrl = "https://wolvic.com/zh/start/pico.html"
def homepageChinaPfdmUrl = "https://wolvic.com/zh/start/pfdm.html"

android {
namespace 'com.igalia.wolvic'
compileSdkVersion 35
Expand Down Expand Up @@ -131,7 +140,8 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resValue 'string', 'app_name', 'Wolvic'
resValue 'string', 'HOMEPAGE_URL', "https://wolvic.com/start"
resValue 'string', 'HOMEPAGE_URL', homepageDefaultUrl
resValue 'string', 'NEW_TAB_DEFAULT_URL', localNewTabUrl
externalNativeBuild {
cmake {
cppFlags "-std=c++14 -fexceptions -frtti -Werror" +
Expand Down Expand Up @@ -759,16 +769,20 @@ android.applicationVariants.configureEach { variant ->
// HVR packages for mainland china must only use HVR speech recognition system.
if (store == "mainlandChina") {
if (platform.toLowerCase().startsWith('hvr')) {
variant.resValue 'string', 'HOMEPAGE_URL', '"https://wolvic.com/zh/start/index.html"'
variant.resValue 'string', 'HOMEPAGE_URL', homepageChinaUrl
variant.resValue 'string', 'NEW_TAB_DEFAULT_URL', homepageChinaUrl
variant.buildConfigField "String[]", "SPEECH_SERVICES", "{ com.igalia.wolvic.speech.SpeechServices.HUAWEI_ASR }"
} else if (platform.toLowerCase().startsWith('visionglass')) {
variant.resValue 'string', 'HOMEPAGE_URL', '"https://wolvic.com/zh/start/hvg.html"'
variant.resValue 'string', 'HOMEPAGE_URL', homepageChinaHvgUrl
variant.resValue 'string', 'NEW_TAB_DEFAULT_URL', homepageChinaHvgUrl
variant.buildConfigField "String[]", "SPEECH_SERVICES", "{ com.igalia.wolvic.speech.SpeechServices.HUAWEI_ASR }"
} else if (platform.toLowerCase().startsWith('picoxr')) {
variant.resValue 'string', 'HOMEPAGE_URL', '"https://wolvic.com/zh/start/pico.html"'
variant.resValue 'string', 'HOMEPAGE_URL', homepageChinaPicoUrl
variant.resValue 'string', 'NEW_TAB_DEFAULT_URL', homepageChinaPicoUrl
variant.buildConfigField "String[]", "SPEECH_SERVICES", "{ com.igalia.wolvic.speech.SpeechServices.MEETKAI }"
} else if (platform.toLowerCase().startsWith('pfdmxr')) {
variant.resValue 'string', 'HOMEPAGE_URL', '"https://wolvic.com/zh/start/pfdm.html"'
variant.resValue 'string', 'HOMEPAGE_URL', homepageChinaPfdmUrl
variant.resValue 'string', 'NEW_TAB_DEFAULT_URL', homepageChinaPfdmUrl
variant.buildConfigField "String[]", "SPEECH_SERVICES", "{ com.igalia.wolvic.speech.SpeechServices.MEETKAI }"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public void setInputMode(int aTouchMode) {
public String getHomepage() {
return mPrefs.getString(
mContext.getString(R.string.settings_key_homepage),
mContext.getString(R.string.HOMEPAGE_URL));
mContext.getString(R.string.NEW_TAB_DEFAULT_URL));
}

public void setHomepage(String aHomepage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.IntDef;
import androidx.databinding.DataBindingUtil;

import com.igalia.wolvic.R;
Expand All @@ -21,16 +22,23 @@
import com.igalia.wolvic.ui.widgets.WidgetPlacement;
import com.igalia.wolvic.utils.UrlUtils;

import java.util.Objects;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

class DisplayOptionsView extends SettingsView {

private OptionsDisplayBinding mBinding;
private String mDefaultHomepageUrl;

@IntDef(value = {CHOICE_NEW_TAB, CHOICE_HOMEPAGE_URL, CHOICE_CUSTOM})
public @interface HomepageChoiceValues {
}

public static final int CHOICE_NEW_TAB = 0;
public static final int CHOICE_HOMEPAGE_URL = 1;
public static final int CHOICE_CUSTOM = 2;

public DisplayOptionsView(Context aContext, WidgetManagerDelegate aWidgetManager) {
super(aContext, aWidgetManager);
initialize(aContext);
Expand Down Expand Up @@ -83,9 +91,10 @@ protected void updateUI() {
SettingsStore.WindowSizePreset windowSizePreset = SettingsStore.WindowSizePreset.fromValues(windowWidth, windowHeight);
setWindowsSizePreset(windowSizePreset.ordinal(), false);

int homepageId = getHomepageId(SettingsStore.getInstance(getContext()).getHomepage());
mDefaultHomepageUrl = getContext().getString(R.string.HOMEPAGE_URL);
@HomepageChoiceValues int initialHomepageChoice = getHomepageChoice(SettingsStore.getInstance(getContext()).getHomepage());
mBinding.homepage.setOnCheckedChangeListener(mHomepageChangeListener);
setHomepage(homepageId, false);
setHomepageChoice(initialHomepageChoice, false);

mBinding.autoplaySwitch.setOnCheckedChangeListener(mAutoplayListener);
setAutoplay(SettingsStore.getInstance(getContext()).isAutoplayEnabled(), false);
Expand All @@ -112,13 +121,12 @@ protected void updateUI() {
mBinding.tabsLocationRadio.setOnCheckedChangeListener(mTabsLocationChangeListener);
setTabsLocation(mBinding.tabsLocationRadio.getIdForValue(tabsLocation), false);

mDefaultHomepageUrl = getContext().getString(R.string.HOMEPAGE_URL);

mBinding.homepageEdit.setHint1(getContext().getString(R.string.homepage_hint, getContext().getString(R.string.app_name)));
mBinding.homepageEdit.setDefaultFirstValue(mDefaultHomepageUrl);
// For clarity, we use the current homepage for the edit field.
mBinding.homepageEdit.setHint1(SettingsStore.getInstance(getContext()).getHomepage());
mBinding.homepageEdit.setDefaultFirstValue(SettingsStore.getInstance(getContext()).getHomepage());
mBinding.homepageEdit.setFirstText(SettingsStore.getInstance(getContext()).getHomepage());
mBinding.homepageEdit.setOnSaveClickedListener(mHomepageListener);
setHomepage(SettingsStore.getInstance(getContext()).getHomepage());
setHomepageValue(SettingsStore.getInstance(getContext()).getHomepage());

mBinding.densityEdit.setHint1(String.valueOf(SettingsStore.DISPLAY_DENSITY_DEFAULT));
mBinding.densityEdit.setDefaultFirstValue(String.valueOf(SettingsStore.DISPLAY_DENSITY_DEFAULT));
Expand Down Expand Up @@ -182,7 +190,7 @@ public boolean isEditing() {
};

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

private SwitchSetting.OnCheckedChangeListener mAutoplayListener = (compoundButton, enabled, apply) -> {
Expand Down Expand Up @@ -211,10 +219,11 @@ public boolean isEditing() {

private OnClickListener mHomepageListener = (view) -> {
if (!mBinding.homepageEdit.getFirstText().isEmpty()) {
setHomepage(mBinding.homepageEdit.getFirstText());
setHomepageValue(mBinding.homepageEdit.getFirstText());

} else {
setHomepage(mDefaultHomepageUrl);
// Reset the edit field to the current value.
setHomepageValue(SettingsStore.getInstance(getContext()).getHomepage());
}
};

Expand Down Expand Up @@ -275,10 +284,10 @@ public boolean isEditing() {
if (mBinding.windowsSize.getCheckedRadioButtonId() != SettingsStore.WINDOW_SIZE_PRESET_DEFAULT.ordinal()) {
setWindowsSizePreset(SettingsStore.WINDOW_SIZE_PRESET_DEFAULT.ordinal(), true);
}
int defaultHomepageId = getHomepageId(mDefaultHomepageUrl);

@HomepageChoiceValues int defaultHomepageId = getHomepageChoice(mDefaultHomepageUrl);
if (mBinding.homepage.getCheckedRadioButtonId() != defaultHomepageId) {
setHomepage(defaultHomepageId, true);
setHomepageChoice(defaultHomepageId, true);
}

float prevDensity = SettingsStore.getInstance(getContext()).getDisplayDensity();
Expand All @@ -287,7 +296,7 @@ public boolean isEditing() {
restart = restart | setDisplayDpi(SettingsStore.DISPLAY_DPI_DEFAULT);


setHomepage(mDefaultHomepageUrl);
setHomepageValue(mDefaultHomepageUrl);
setAutoplay(SettingsStore.AUTOPLAY_ENABLED, true);
setCurvedDisplay(false, true);
setHeadLock(SettingsStore.HEAD_LOCK_DEFAULT, true);
Expand Down Expand Up @@ -391,39 +400,40 @@ private void setTabsLocation(int checkedId, boolean doApply) {
}
}

private void setHomepage(int checkedId, boolean doApply) {
private void setHomepageChoice(@HomepageChoiceValues 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);
mBinding.homepageEdit.setVisibility(checkedId == CHOICE_CUSTOM ? View.VISIBLE : View.GONE);

if (doApply && checkedId != CHOICE_CUSTOM) {
if (checkedId == CHOICE_NEW_TAB) {
setHomepageValue(UrlUtils.ABOUT_NEWTAB);
} else if (checkedId == CHOICE_HOMEPAGE_URL) {
setHomepageValue(mDefaultHomepageUrl);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a fallback in case none of the conditional clauses is satisfied ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, the value comes from a group of three radio buttons so it can only take the values 0, 1, and 2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then perhaps it'd be clearer to use a switch and an assert to ensure no mismatch is possible.

}

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

private void setHomepage(String newHomepage) {
if (mBinding.homepageEdit.getVisibility() != VISIBLE) {
return;
}
private void setHomepageValue(String newHomepage) {
mBinding.homepageEdit.setOnSaveClickedListener(null);
mBinding.homepageEdit.setHint1(newHomepage);
mBinding.homepageEdit.setDefaultFirstValue(newHomepage);
mBinding.homepageEdit.setFirstText(newHomepage);

SettingsStore.getInstance(getContext()).setHomepage(newHomepage);

mBinding.homepageEdit.setOnSaveClickedListener(mHomepageListener);
}

Expand Down
Loading
0