Skip to content

Commit

Permalink
Do not allow privatebrowsing page to be bookmarked (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Mar 1, 2019
1 parent 3db7004 commit c5fb399
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
Expand Down Expand Up @@ -71,6 +72,7 @@ public class NavigationURLBar extends FrameLayout {
private BookmarkViewModel mBookmarkModel;
private AudioEngine mAudio;
private boolean mIsBookmarkMode;
private boolean mBookmarkEnabled = true;

private Unit domainAutocompleteFilter(String text, InlineAutocompleteEditText view) {
if (view != null) {
Expand Down Expand Up @@ -187,10 +189,33 @@ public void setDelegate(NavigationURLBarDelegate delegate) {
}

public void setIsBookmarkMode(boolean isBookmarkMode) {
if (mIsBookmarkMode == isBookmarkMode) {
return;
}
mIsBookmarkMode = isBookmarkMode;
if (isBookmarkMode) {
mMicrophoneButton.setVisibility(GONE);
mBookmarkButton.setVisibility(GONE);
} else {
mMicrophoneButton.setVisibility(VISIBLE);
if (mBookmarkEnabled) {
mBookmarkButton.setVisibility(VISIBLE);
}
}
syncViews();
}

private void setBookmarkEnabled(boolean aEnabled) {
if (mBookmarkEnabled != aEnabled) {
mBookmarkEnabled = aEnabled;
mBookmarkButton.setVisibility(aEnabled ? View.VISIBLE : View.GONE);
ViewGroup.LayoutParams params = mMicrophoneButton.getLayoutParams();
params.width = (int) getResources().getDimension(aEnabled ? R.dimen.url_bar_item_width : R.dimen.url_bar_last_item_width);
mMicrophoneButton.setLayoutParams(params);
mMicrophoneButton.setBackgroundResource(aEnabled ? R.drawable.url_button : R.drawable.url_button_end);
}
}

private final NavigationBarCallback mNavigationBarCallback = new NavigationBarCallback() {
@Override
public void onBookmarkClick(Bookmark bookmark) {
Expand Down Expand Up @@ -266,6 +291,7 @@ else if (aURL.startsWith("data:") && SessionStore.get().isCurrentSessionPrivate(
mURL.setText(aURL);
}
}
setBookmarkEnabled(aURL.length() > 0 && !aURL.startsWith("about://"));
}

mURL.addTextChangedListener(mURLTextWatcher);
Expand Down Expand Up @@ -303,28 +329,18 @@ public void setIsLoading(boolean aIsLoading) {
}
}

public void setBookmarks(boolean enabled) {
if (enabled) {
mMicrophoneButton.setVisibility(GONE);
mBookmarkButton.setVisibility(GONE);

} else {
mMicrophoneButton.setVisibility(VISIBLE);
mBookmarkButton.setVisibility(VISIBLE);
}
}

public void showVoiceSearch(boolean enabled) {
if (enabled) {
if (mBookmarkEnabled) {
mMicrophoneButton.setBackgroundResource(R.drawable.url_button);
mMicrophoneButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_item_width);
}
mMicrophoneButton.setImageResource(R.drawable.ic_icon_microphone);
mMicrophoneButton.setBackgroundResource(R.drawable.url_button);
mMicrophoneButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_item_width);
mMicrophoneButton.setOnClickListener(mMicrophoneListener);

if (mIsBookmarkMode) {
mMicrophoneButton.setVisibility(GONE);

} else {
} else if (mBookmarkEnabled) {
mBookmarkButton.setVisibility(VISIBLE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,6 @@ public void OnItemDeleted(SuggestionsWidget.SuggestionItem item) {

@Override
public void onBookmarksShown() {
mURLBar.setBookmarks(true);
mURLBar.setURL("");
mURLBar.setHint(R.string.about_bookmarks);
mURLBar.setIsBookmarkMode(true);
Expand All @@ -973,7 +972,6 @@ public void onBookmarksShown() {
@Override
public void onBookmarksHidden() {
mURLBar.setIsBookmarkMode(false);
mURLBar.setBookmarks(false);
mURLBar.setURL(SessionStore.get().getCurrentUri());
mURLBar.setHint(R.string.search_placeholder);
}
Expand Down

0 comments on commit c5fb399

Please sign in to comment.