Skip to content

Commit

Permalink
Show clear button when there is text in the url bar (#2740)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Feb 5, 2020
1 parent 6aeaf88 commit f9bc1c2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
Expand Up @@ -55,7 +55,6 @@ public class WindowViewModel extends AndroidViewModel {
private MutableLiveData<ObservableBoolean> isMicrophoneEnabled;
private MutableLiveData<ObservableBoolean> isBookmarked;
private MutableLiveData<ObservableBoolean> isFocused;
private MutableLiveData<ObservableBoolean> isSpecialUrl;
private MutableLiveData<ObservableBoolean> isUrlEmpty;
private MutableLiveData<ObservableBoolean> isPopUpAvailable;
private MutableLiveData<ObservableBoolean> canGoForward;
Expand Down Expand Up @@ -130,7 +129,6 @@ public WindowViewModel(Application application) {
isMicrophoneEnabled = new MutableLiveData<>(new ObservableBoolean(true));
isBookmarked = new MutableLiveData<>(new ObservableBoolean(false));
isFocused = new MutableLiveData<>(new ObservableBoolean(false));
isSpecialUrl = new MutableLiveData<>(new ObservableBoolean(false));
isUrlEmpty = new MutableLiveData<>(new ObservableBoolean(false));
isPopUpAvailable = new MutableLiveData<>(new ObservableBoolean(false));
canGoForward = new MutableLiveData<>(new ObservableBoolean(false));
Expand Down Expand Up @@ -306,7 +304,6 @@ public void refresh() {
isMicrophoneEnabled.postValue(isMicrophoneEnabled.getValue());
isBookmarked.postValue(isBookmarked.getValue());
isFocused.postValue(isFocused.getValue());
isSpecialUrl.postValue(isSpecialUrl.getValue());
isUrlEmpty.postValue(isUrlEmpty.getValue());
isPopUpAvailable.postValue(isPopUpAvailable.getValue());
canGoForward.postValue(canGoForward.getValue());
Expand Down Expand Up @@ -393,8 +390,6 @@ public void setUrl(@Nullable Spannable url) {
}
}

setIsSpecialUrl(aURL.isEmpty());

this.url.setValue(url);
}

Expand Down Expand Up @@ -560,15 +555,6 @@ public void setIsFocused(boolean isFocused) {
this.isFocused.postValue(new ObservableBoolean(isFocused));
}

@NonNull
public MutableLiveData<ObservableBoolean> getIsSpecialUrl() {
return isSpecialUrl;
}

public void setIsSpecialUrl(boolean isSpecialUrl) {
this.isSpecialUrl.postValue(new ObservableBoolean(isSpecialUrl));
}

@NonNull
public MutableLiveData<ObservableBoolean> getIsUrlEmpty() {
return isUrlEmpty;
Expand Down
Expand Up @@ -136,9 +136,8 @@ private void initialize(Context aContext) {
});

mBinding.urlEditText.setOnFocusChangeListener((view, focused) -> {
boolean isUrlEmpty = mBinding.urlEditText.getText().length() == 0;
mViewModel.setIsFocused(focused);
mViewModel.setIsUrlEmpty(isUrlEmpty);
mViewModel.setIsUrlEmpty(mBinding.urlEditText.getText().toString().isEmpty());
if (!focused) {
hideSelectionMenu();
} else {
Expand Down Expand Up @@ -430,9 +429,7 @@ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
String aURL = mBinding.urlEditText.getText().toString();
boolean empty = aURL.length() == 0 || aURL.startsWith("about://");
mViewModel.setIsUrlEmpty(empty);
mViewModel.setIsUrlEmpty(mBinding.urlEditText.getText().toString().isEmpty());
}

@Override
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/res/layout/navigation_url.xml
Expand Up @@ -40,8 +40,8 @@
<org.mozilla.vrbrowser.ui.views.UIButton
android:id="@+id/microphoneButton"
style="@style/urlBarIconTheme"
android:layout_width="@{(viewmodel.isLibraryVisible || viewmodel.isSpecialUrl) ? @dimen/url_bar_last_item_width : @dimen/url_bar_item_width}"
android:background="@{(viewmodel.isLibraryVisible || viewmodel.isSpecialUrl) ? (viewmodel.isPrivateSession ? @drawable/url_button_end_private : @drawable/url_button_end) : (viewmodel.isPrivateSession ? @drawable/url_button_private : @drawable/url_button)}"
android:layout_width="@{(viewmodel.isLibraryVisible || viewmodel.isUrlEmpty) ? @dimen/url_bar_last_item_width : @dimen/url_bar_item_width}"
android:background="@{(viewmodel.isLibraryVisible || viewmodel.isUrlEmpty) ? (viewmodel.isPrivateSession ? @drawable/url_button_end_private : @drawable/url_button_end) : (viewmodel.isPrivateSession ? @drawable/url_button_private : @drawable/url_button)}"
android:src="@drawable/ic_icon_microphone"
android:tint="@color/fog"
android:tooltipText="@string/voice_search_tooltip"
Expand All @@ -53,7 +53,7 @@
android:src="@{viewmodel.isBookmarked ? @drawable/ic_icon_bookmarked_active : @drawable/ic_icon_bookmarked}"
android:tint="@color/fog"
android:tooltipText="@string/bookmark_tooltip"
app:visibleGone="@{!(viewmodel.isLibraryVisible || viewmodel.isSpecialUrl) &amp;&amp; !viewmodel.isFocused}"
app:visibleGone="@{!(viewmodel.isLibraryVisible || viewmodel.isUrlEmpty) &amp;&amp; !viewmodel.isFocused}"
tools:src="@drawable/ic_icon_bookmarked" />

<org.mozilla.vrbrowser.ui.views.UIButton
Expand All @@ -62,7 +62,7 @@
android:src="@drawable/ic_icon_clear"
android:tint="@color/fog"
android:tooltipText="@string/clear_tooltip"
app:visibleGone="@{!viewmodel.isMicrophoneEnabled &amp;&amp; viewmodel.isFocused &amp;&amp; (urlEditText.text.length > 0)}" />
app:visibleGone="@{viewmodel.isFocused &amp;&amp; !viewmodel.isUrlEmpty}" />
</LinearLayout>

<RelativeLayout
Expand Down Expand Up @@ -106,7 +106,8 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toEndOf="@id/startButtonsLayout"
android:layout_centerVertical="true">
android:layout_centerVertical="true"
app:visibleGone="@{!viewmodel.isFocused}">
<ImageView
android:id="@+id/loadingView"
android:layout_width="24dp"
Expand All @@ -121,7 +122,7 @@
android:layout_height="24dp"
android:contentDescription="SSL icon"
android:src="@drawable/ic_icon_security_state_insecure"
app:visibleGone="@{viewmodel.isInsecureVisible &amp;&amp; (urlEditText.length() != 0)}" />
app:visibleGone="@{viewmodel.isInsecureVisible}" />
</LinearLayout>

</RelativeLayout>
Expand Down

0 comments on commit f9bc1c2

Please sign in to comment.