Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
haanhvu committed Dec 4, 2024
1 parent 76b493b commit ccb8497
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ 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 @@ -148,12 +147,6 @@ public WindowViewModel(Application application) {
);
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 @@ -256,7 +249,7 @@ public void onChanged(ObservableBoolean o) {
@Override
public void onChanged(Spannable aUrl) {
String url = aUrl.toString();
if (isNativeContentVisible.getValue().get() && !isInNewTabPage.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) {
Expand Down Expand Up @@ -470,10 +463,10 @@ public MutableLiveData<String> getHint() {
}

private String getHintValue() {
if (isNativeContentVisible.getValue().get() && !isInNewTabPage.getValue().get()) {
if (isNativeContentVisible.getValue().get() && currentContentType.getValue() != Windows.ContentType.NEW_TAB) {
return getApplication().getString(R.string.url_library_title);

} else if (isInNewTabPage.getValue().get()) {
} else if (currentContentType.getValue() == Windows.ContentType.NEW_TAB) {
return getApplication().getString(R.string.url_new_tab_title);

} else {
Expand Down Expand Up @@ -627,10 +620,6 @@ 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 @@ -1027,7 +1027,7 @@ public void onLocationChange(@NonNull WSession session, @Nullable String url) {
updateTrackingProtection();
}

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

// Content delegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ private void hidePanel(boolean switchSurface) {
}

public void hideNewTab() {
if (mViewModel.getIsInNewTabPage().getValue().get()) {
if (mViewModel.getCurrentContentType().getValue() == Windows.ContentType.NEW_TAB) {
mViewModel.enableBackToNewTab(true);
hideNewTab(true);
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/navigation_bar_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<data>
<import type="android.view.View" />
<import type="com.igalia.wolvic.BuildConfig"/>
<import type="com.igalia.wolvic.ui.widgets.Windows.ContentType" />
<variable
name="viewmodel"
type="com.igalia.wolvic.ui.viewmodel.WindowViewModel" />
Expand Down Expand Up @@ -50,7 +51,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}"
android:enabled="@{viewmodel.currentContentType != ContentType.NEW_TAB}"
app:privateMode="@{viewmodel.isPrivateSession}" />

<ProgressBar
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/tray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@
<com.igalia.wolvic.ui.views.UIButton
android:id="@+id/libraryButton"
style="@style/trayButtonMiddleTheme"
android:tooltipText="@{viewmodel.isNativeContentVisible &amp;&amp; !viewmodel.isInNewTabPage? @string/close_library_tooltip : @string/open_library_tooltip}"
android:tooltipText="@{viewmodel.isNativeContentVisible &amp;&amp; viewmodel.currentContentType != ContentType.NEW_TAB? @string/close_library_tooltip : @string/open_library_tooltip}"
app:tooltipDensity="@dimen/tray_tooltip_density"
app:tooltipPosition="bottom"
app:tooltipLayout="@layout/tooltip_tray"
android:src="@drawable/ic_icon_library"
app:clipDrawable="@drawable/ic_icon_library_clip"
app:activeMode="@{viewmodel.isNativeContentVisible &amp;&amp; !viewmodel.isInNewTabPage}"/>
app:activeMode="@{viewmodel.isNativeContentVisible &amp;&amp; viewmodel.currentContentType != ContentType.NEW_TAB}"/>
<com.google.android.material.textview.MaterialTextView
android:layout_width="12dp"
android:layout_height="12dp"
Expand Down

0 comments on commit ccb8497

Please sign in to comment.