Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
haanhvu committed Oct 22, 2024
1 parent 21677ca commit ec74612
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,13 @@ private void updateUI() {

mBinding.navigationBarNavigation.homeButton.setOnClickListener(v -> {
v.requestFocusFromTouch();
getSession().loadUri(getSession().getHomeUri());
String homeUri = getSession().getHomeUri();
if (homeUri != "") {
getSession().loadUri(homeUri);
} else {
mAttachedWindow.showPanel(Windows.BOOKMARKS);
}

if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,13 @@ public void loadHome() {
mSession.loadPrivateBrowsingPage();

} else {
mSession.loadUri(SettingsStore.getInstance(getContext()).getHomepage());
if (mSession.getHomeUri() == "") {
Log.e(LOGTAG, "Empty home URI in WindowWidget => Show bookmarks");
showPanel(Windows.BOOKMARKS);
} else {
Log.e(LOGTAG, "Non-empty home URI in WindowWidget => Load homepage");
mSession.loadUri(SettingsStore.getInstance(getContext()).getHomepage());
}
}
}

Expand Down Expand Up @@ -523,15 +529,18 @@ public void showPanel(@Windows.PanelType int panelType) {
showPanel(panelType, true);
}

private void showPanel(@Windows.PanelType int panelType, boolean switchSurface) {
public void showPanel(@Windows.PanelType int panelType, boolean switchSurface) {
if (mLibrary != null) {
Log.e(LOGTAG, "mLibrary is not null => Function USED");
if (mView == null) {
Log.e(LOGTAG, "mView is null => First case");
setView(mLibrary, switchSurface);
mLibrary.selectPanel(panelType);
mLibrary.onShow();
mViewModel.setIsFindInPage(false);
mViewModel.setIsPanelVisible(true);
if (mRestoreFirstPaint == null && !isFirstPaintReady() && (mFirstDrawCallback != null) && (mSurface != null)) {
//if (mRestoreFirstPaint == null && !isFirstPaintReady() && (mFirstDrawCallback != null) && (mSurface != null)) {
Log.e(LOGTAG, "if is executed");
final Runnable firstDrawCallback = mFirstDrawCallback;
onFirstContentfulPaint(mSession.getWSession());
mRestoreFirstPaint = () -> {
Expand All @@ -541,11 +550,18 @@ private void showPanel(@Windows.PanelType int panelType, boolean switchSurface)
mWidgetManager.updateWidget(WindowWidget.this);
}
};
}
//} else {
//Log.e(LOGTAG, "if is not executed");
//}

} else if (mView == mLibrary) {
Log.e(LOGTAG, "mView == mLibrary => Second case");
mLibrary.selectPanel(panelType);
} else {
Log.e(LOGTAG, "mView is other case => Function NOT USED");
}
} else {
Log.e(LOGTAG, "mLibrary is null => Function NOT USED");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,13 @@ public void addTab(@NonNull WindowWidget targetWindow, @Nullable String aUri) {
setFirstPaint(targetWindow, session);
targetWindow.setSession(session, WindowWidget.DEACTIVATE_CURRENT_SESSION);
if (aUri == null || aUri.isEmpty()) {
session.loadHomePage();
if (session.getHomeUri() == "") {
Log.e(LOGTAG, "Empty home URI in Windows => Show bookmarks");
targetWindow.showPanel(Windows.BOOKMARKS);
} else {
Log.e(LOGTAG, "Non-empty home URI in Windows => Load homepage");
session.loadHomePage();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ protected void updateUI() {
mBinding.msaaRadio.setOnCheckedChangeListener(mMSSAChangeListener);
setMSAAMode(mBinding.msaaRadio.getIdForValue(msaaLevel), false);

int homepageId = getHomepageId();
mBinding.homepage.setOnCheckedChangeListener(mHomepageChangeListener);
setHomepage(homepageId, false);

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

Expand Down Expand Up @@ -165,6 +169,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 +257,10 @@ public boolean isEditing() {
restart = true;
}

if (mBinding.homepage.getCheckedRadioButtonId() != 0) {
setHomepage(0, 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 +386,43 @@ 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 (doApply) {
if (checkedId == 0) {
mBinding.homepageEdit.setVisibility(View.GONE);
SettingsStore.getInstance(getContext()).setHomepage(mDefaultHomepageUrl);
} else if (checkedId == 1) {
mBinding.homepageEdit.setVisibility(View.GONE);
SettingsStore.getInstance(getContext()).setHomepage("");
} else if (checkedId == 2) {
mBinding.homepageEdit.setVisibility(View.VISIBLE);
}
//}
}

private int getHomepageId() {
String homepage = SettingsStore.getInstance(getContext()).getHomepage();

if (homepage == mDefaultHomepageUrl) {
return 0;
} else if (homepage == "New Tab") {
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
11 changes: 9 additions & 2 deletions app/src/main/res/layout/options_display.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,22 @@
app:options="@array/developer_options_msaa"
app:values="@array/developer_options_msaa_mode_values" />

<com.igalia.wolvic.ui.views.settings.RadioGroupSetting
android:id="@+id/homepage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/developer_options_homepage"
app:options="@array/developer_options_homepage" />

<com.igalia.wolvic.ui.views.settings.SingleEditSetting
android:id="@+id/homepage_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:width="300dp"
android:inputType="textWebEmailAddress"
app:description="@string/developer_options_homepage"
app:hintTextColor="@color/iron_blur"
app:highlightedTextColor="@color/fog" />
app:highlightedTextColor="@color/fog"
android:visibility="gone" />

<com.igalia.wolvic.ui.views.settings.SingleEditSetting
android:id="@+id/density_edit"
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values/options_values.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@
<item>2</item>
</integer-array>

<!-- Homepage Setting Options -->
<string-array name="developer_options_homepage" translatable="false">
<item>@string/developer_options_homepage_wolvic</item>
<item>@string/developer_options_homepage_new_tab</item>
<item>@string/developer_options_homepage_other</item>
</string-array>

<!-- Tracking Options -->
<string-array name="privacy_options_tracking" translatable="false">
<item>@string/privacy_options_tracking_etp</item>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,12 @@
<!-- This string is used to label the MSAA radio button that enables two times MSAA in Immersive Mode. -->
<string name="developer_options_msaa_4">4x</string>

<string name="developer_options_homepage_wolvic">Wolvic</string>

<string name="developer_options_homepage_new_tab">New tab</string>

<string name="developer_options_homepage_other">Other</string>

<!-- This string is used to label a set of radio buttons that allow the user to change the
User-Agent (UA) string of the browser. -->
<string name="developer_options_ua_mode">User-Agent Mode</string>
Expand Down

0 comments on commit ec74612

Please sign in to comment.