diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/viewmodel/WindowViewModel.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/viewmodel/WindowViewModel.java index 42bb23fa0..db143fdd0 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/viewmodel/WindowViewModel.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/viewmodel/WindowViewModel.java @@ -15,6 +15,7 @@ import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.Observer; +import org.mozilla.geckoview.ContentBlocking; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.browser.SettingsStore; import org.mozilla.vrbrowser.ui.widgets.Windows; @@ -67,6 +68,8 @@ public class WindowViewModel extends AndroidViewModel { private MutableLiveData isWebXRBlocked; private MutableLiveData isTrackingEnabled; private MutableLiveData isDrmUsed; + private MediatorLiveData isUrlBarButtonsVisible; + private MediatorLiveData isUrlBarIconsVisible; public WindowViewModel(Application application) { super(application); @@ -162,6 +165,15 @@ public WindowViewModel(Application application) { isTrackingEnabled = new MutableLiveData<>(new ObservableBoolean(true)); isDrmUsed = new MutableLiveData<>(new ObservableBoolean(false)); + + isUrlBarButtonsVisible = new MediatorLiveData<>(); + isUrlBarButtonsVisible.addSource(url, mIsUrlBarButtonsVisibleObserver); + isUrlBarButtonsVisible.setValue(new ObservableBoolean(false)); + + isUrlBarIconsVisible = new MediatorLiveData<>(); + isUrlBarIconsVisible.addSource(isLoading, mIsUrlBarIconsVisibleObserver); + isUrlBarIconsVisible.addSource(isInsecureVisible, mIsUrlBarIconsVisibleObserver); + isUrlBarIconsVisible.setValue(new ObservableBoolean(false)); } private Observer mIsTopBarVisibleObserver = new Observer() { @@ -297,6 +309,34 @@ public void onChanged(Spannable aUrl) { } }; + private Observer mIsUrlBarButtonsVisibleObserver = new Observer() { + @Override + public void onChanged(Spannable aUrl) { + isUrlBarButtonsVisible.postValue(new ObservableBoolean( + !isFocused.getValue().get() && + !isLibraryVisible.getValue().get() && + !UrlUtils.isContentFeed(getApplication(), aUrl.toString()) && + !UrlUtils.isFileUri(aUrl.toString()) && + ( + (SettingsStore.getInstance(getApplication()).getTrackingProtectionLevel() != ContentBlocking.EtpLevel.NONE) || + isPopUpAvailable.getValue().get() || + isDrmUsed.getValue().get() || + isWebXRUsed.getValue().get() + ) + )); + } + }; + + private Observer mIsUrlBarIconsVisibleObserver = new Observer() { + @Override + public void onChanged(ObservableBoolean o) { + isUrlBarIconsVisible.postValue(new ObservableBoolean( + isLoading.getValue().get() || + isInsecureVisible.getValue().get() + )); + } + }; + public void refresh() { url.postValue(url.getValue()); hint.postValue(getHintValue()); @@ -730,4 +770,14 @@ public MutableLiveData getIsDrmUsed() { public void setIsDrmUsed(boolean isEnabled) { this.isDrmUsed.postValue(new ObservableBoolean(isEnabled)); } + + @NonNull + public MutableLiveData getIsUrlBarButtonsVisible() { + return isUrlBarButtonsVisible; + } + + @NonNull + public MutableLiveData getIsUrlBarIconsVisible() { + return isUrlBarIconsVisible; + } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/utils/UrlUtils.java b/app/src/common/shared/org/mozilla/vrbrowser/utils/UrlUtils.java index 627bc522b..6010f4439 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/utils/UrlUtils.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/utils/UrlUtils.java @@ -15,6 +15,7 @@ import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.browser.SettingsStore; +import java.io.File; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; @@ -124,16 +125,22 @@ public static String titleBarUrl(@Nullable String aUri) { } if (URLUtil.isValidUrl(aUri)) { - try { - URI uri = URI.create(aUri); - URL url = new URL( - uri.getScheme() != null ? uri.getScheme() : "", - uri.getAuthority() != null ? uri.getAuthority() : "", - ""); - return url.toString(); - - } catch (MalformedURLException | IllegalArgumentException e) { - return ""; + if (UrlUtils.isFileUri(aUri)) { + File file = new File(aUri); + return file.getName(); + + } else { + try { + URI uri = URI.create(aUri); + URL url = new URL( + uri.getScheme() != null ? uri.getScheme() : "", + uri.getAuthority() != null ? uri.getAuthority() : "", + ""); + return url.toString(); + + } catch (MalformedURLException | IllegalArgumentException e) { + return ""; + } } } else { diff --git a/app/src/main/res/layout/navigation_url.xml b/app/src/main/res/layout/navigation_url.xml index d01a7c696..358716810 100644 --- a/app/src/main/res/layout/navigation_url.xml +++ b/app/src/main/res/layout/navigation_url.xml @@ -41,7 +41,7 @@ android:layout_marginStart="2dp" android:addStatesFromChildren="true" android:orientation="horizontal" - app:visibleGone="@{!viewmodel.isLibraryVisible && !UrlUtils.isContentFeed(context, viewmodel.url.toString())}"> + app:visibleGone="@{!viewmodel.isFocused && viewmodel.isUrlBarButtonsVisible}"> - + app:visibleGone="@{!viewmodel.isUrlBarIconsVisible}"/> + app:visibleGone="@{!viewmodel.isUrlBarButtonsVisible || viewmodel.isFocused}"/> + app:visibleGone="@{viewmodel.isUrlBarIconsVisible && !viewmodel.isFocused}">