Skip to content

Commit

Permalink
Fix bug in going forward from new tab and disable refreshing in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
haanhvu committed Dec 4, 2024
1 parent d89daeb commit 7ece1bd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 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 @@ -55,6 +56,7 @@ public class WindowViewModel extends AndroidViewModel {
private MutableLiveData<Windows.ContentType> currentContentType;
public MutableLiveData<Windows.ContentType> lastContentType;
private MediatorLiveData<ObservableBoolean> isNativeContentVisible;
private MediatorLiveData<ObservableBoolean> isInNewTabPage;
private MutableLiveData<ObservableBoolean> backToNewTabEnabled;
private MutableLiveData<ObservableBoolean> isLoading;
private MutableLiveData<ObservableBoolean> isMicrophoneEnabled;
Expand Down Expand Up @@ -95,6 +97,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 @@ -138,11 +141,19 @@ public WindowViewModel(Application application) {

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(currentContentType.getValue() != Windows.ContentType.WEB_CONTENT));

isInNewTabPage = new MediatorLiveData<>();
isInNewTabPage.addSource(currentContentType, contentType ->
isInNewTabPage.setValue(new ObservableBoolean(contentType == Windows.ContentType.NEW_TAB))
);
isInNewTabPage.setValue(new ObservableBoolean(currentContentType.getValue() == Windows.ContentType.NEW_TAB));

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

isLoading = new MutableLiveData<>(new ObservableBoolean(false));
Expand Down Expand Up @@ -345,6 +356,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 Down Expand Up @@ -384,10 +396,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 @@ -431,9 +451,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 Down Expand Up @@ -601,6 +627,10 @@ public MutableLiveData<ObservableBoolean> getIsNativeContentVisible() {
return isNativeContentVisible;
}

public MutableLiveData<ObservableBoolean> getIsInNewTabPage() {
return isInNewTabPage;
}

public void enableBackToNewTab(boolean backToNewTabEnabled) {
this.backToNewTabEnabled.postValue(new ObservableBoolean(backToNewTabEnabled));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@ private void updateUI() {
mBinding.navigationBarNavigation.forwardButton.setOnClickListener(v -> {
v.requestFocusFromTouch();
if (mViewModel.getCanGoForwardFromNewTab().getValue().get()) {
getSession().loadUri(mAttachedWindow.uriForwardFromNewTab);
getSession().loadUri(mViewModel.getUrlForwardFromNewTab().getValue().toString());
mViewModel.setCanGoForwardFromNewTab(false);
} else {
getSession().goForward();
}
getSession().goForward();
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
Expand Down Expand Up @@ -1026,7 +1027,7 @@ public void onLocationChange(@NonNull WSession session, @Nullable String url) {
updateTrackingProtection();
}

mBinding.navigationBarNavigation.reloadButton.setEnabled(!UrlUtils.isPrivateAboutPage(getContext(), url));
mBinding.navigationBarNavigation.reloadButton.setEnabled(!mViewModel.getIsInNewTabPage().getValue().get() && !UrlUtils.isPrivateAboutPage(getContext(), url));
}

// Content delegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public class WindowWidget extends UIWidget implements SessionChangeListener,
private SharedPreferences mPrefs;
private DownloadsManager mDownloadsManager;
private float mBrowserDensity;
public String uriForwardFromNewTab;

public interface WindowListener {
default void onFocusRequest(@NonNull WindowWidget aWindow) {}
Expand Down Expand Up @@ -2080,9 +2079,6 @@ WResult<WAllowOrDeny> onLoadRequest(WSession aSession, @NonNull LoadRequest aReq
hideNewTab();
mViewModel.setCurrentContentType(Windows.ContentType.WEB_CONTENT);
mViewModel.setUrl(uri.toString());
if (mViewModel.lastContentType.getValue() == Windows.ContentType.NEW_TAB) {
uriForwardFromNewTab = uri.toString();
}
}

if ("file".equalsIgnoreCase(uri.getScheme())) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/navigation_bar_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
style="?attr/navigationBarButtonStyle"
android:src="@{viewmodel.isLoading ? @drawable/ic_icon_exit : @drawable/ic_icon_reload}"
android:tooltipText="@{viewmodel.isLoading ? @string/stop_tooltip : @string/refresh_tooltip}"
android:enabled="@{!viewmodel.isInNewTabPage}"
app:privateMode="@{viewmodel.isPrivateSession}" />

<ProgressBar
Expand Down

0 comments on commit 7ece1bd

Please sign in to comment.