Skip to content

Commit

Permalink
Fixes #2750 Fixes #2733 Update the bookmark button state after a new …
Browse files Browse the repository at this point in the history
…url is loaded (#2754)

* Update the bookmark button state after a new url is loaded

* Make url empty the default
  • Loading branch information
keianhzo committed Feb 10, 2020
1 parent fb42825 commit 3949e4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.VRBrowserApplication;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.ui.widgets.Windows;
import org.mozilla.vrbrowser.utils.ServoUtils;
import org.mozilla.vrbrowser.utils.StringUtils;
import org.mozilla.vrbrowser.utils.UrlUtils;

import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -129,7 +127,7 @@ public WindowViewModel(Application application) {
isMicrophoneEnabled = new MutableLiveData<>(new ObservableBoolean(true));
isBookmarked = new MutableLiveData<>(new ObservableBoolean(false));
isFocused = new MutableLiveData<>(new ObservableBoolean(false));
isUrlEmpty = new MutableLiveData<>(new ObservableBoolean(false));
isUrlEmpty = new MutableLiveData<>(new ObservableBoolean(true));
isPopUpAvailable = new MutableLiveData<>(new ObservableBoolean(false));
canGoForward = new MutableLiveData<>(new ObservableBoolean(false));
canGoBack = new MutableLiveData<>(new ObservableBoolean(false));
Expand Down Expand Up @@ -323,9 +321,7 @@ public MutableLiveData<Spannable> getUrl() {
}

public void setUrl(@Nullable String url) {
if (url != null) {
this.url.setValue(new SpannableString(url));
}
setUrl(new SpannableString(url));
}

public void setUrl(@Nullable Spannable url) {
Expand All @@ -339,16 +335,6 @@ public void setUrl(@Nullable Spannable url) {
return;
}

if (StringUtils.isEmpty(aURL)) {
setIsBookmarked(false);

} else {
SessionStore.get().getBookmarkStore().isBookmarked(aURL).thenAcceptAsync(this::setIsBookmarked, mUIThreadExecutor).exceptionally(throwable -> {
throwable.printStackTrace();
return null;
});
}

int index = -1;
try {
aURL = URLDecoder.decode(aURL, "UTF-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.mozilla.vrbrowser.ui.widgets.dialogs.SelectionActionWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.ContextMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.LibraryMenuWidget;
import org.mozilla.vrbrowser.utils.StringUtils;
import org.mozilla.vrbrowser.utils.ViewUtils;

import java.util.Arrays;
Expand Down Expand Up @@ -1583,6 +1584,16 @@ public void captureImage() {
@Override
public void onLocationChange(@NonNull GeckoSession session, @Nullable String url) {
mViewModel.setUrl(url);

if (StringUtils.isEmpty(url)) {
mViewModel.setIsBookmarked(false);

} else {
SessionStore.get().getBookmarkStore().isBookmarked(url).thenAcceptAsync(aBoolean -> mViewModel.setIsBookmarked(aBoolean), mUIThreadExecutor).exceptionally(throwable -> {
throwable.printStackTrace();
return null;
});
}
}

@Override
Expand Down

0 comments on commit 3949e4c

Please sign in to comment.