Skip to content

Commit

Permalink
Unify url bar bubble notifications witch switch button
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Apr 1, 2020
1 parent 2c8e0e0 commit d54f7e2
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.audio.AudioEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,14 +969,14 @@ public void onWebXRButtonClicked() {
public void onTrackingButtonClicked() {
toggleQuickPermission(mBinding.navigationBarNavigation.urlBar.getTrackingButton(),
SitePermission.SITE_PERMISSION_TRACKING,
mViewModel.getIsTrackingEnabled().getValue().get());
!mViewModel.getIsTrackingEnabled().getValue().get());
}

@Override
public void onDrmButtonClicked() {
toggleQuickPermission(mBinding.navigationBarNavigation.urlBar.getTrackingButton(),
SitePermission.SITE_PERMISSION_DRM,
SettingsStore.getInstance(getContext()).isDrmContentPlaybackEnabled());
!SettingsStore.getInstance(getContext()).isDrmContentPlaybackEnabled());
}

// VoiceSearch Delegate
Expand Down Expand Up @@ -1244,11 +1244,11 @@ private void toggleQuickPermission(UIButton target, @SitePermission.Category int
public void onBlock() {
if (aCategory == SITE_PERMISSION_TRACKING) {
if (getSession() != null) {
mTrackingDelegate.remove(getSession());
mTrackingDelegate.add(getSession());
}

} else if (aCategory == SITE_PERMISSION_DRM) {
SettingsStore.getInstance(getContext()).setDrmContentPlaybackEnabled(true);
SettingsStore.getInstance(getContext()).setDrmContentPlaybackEnabled(false);

} else {
SessionStore.get().setPermissionAllowed(uri, aCategory, false);
Expand All @@ -1260,11 +1260,11 @@ public void onBlock() {
public void onAllow() {
if (aCategory == SITE_PERMISSION_TRACKING) {
if (getSession() != null) {
mTrackingDelegate.add(getSession());
mTrackingDelegate.remove(getSession());
}

} else if (aCategory == SITE_PERMISSION_DRM) {
SettingsStore.getInstance(getContext()).setDrmContentPlaybackEnabled(false);
SettingsStore.getInstance(getContext()).setDrmContentPlaybackEnabled(true);

} else {
SessionStore.get().setPermissionAllowed(uri, aCategory, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import android.content.res.Configuration;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CompoundButton;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.databinding.QuickPermissionDialogBinding;
import org.mozilla.vrbrowser.db.SitePermission;
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
Expand All @@ -24,7 +24,7 @@ public interface Delegate {

private Delegate mDelegate;
private String mDomain = "";
QuickPermissionDialogBinding mBinding;
private QuickPermissionDialogBinding mBinding;
private @SitePermission.Category int mCategory = SitePermission.SITE_PERMISSION_WEBXR;

public QuickPermissionWidget(Context aContext) {
Expand All @@ -35,24 +35,14 @@ public QuickPermissionWidget(Context aContext) {
private void initialize() {
LayoutInflater inflater = LayoutInflater.from(getContext());
mBinding = DataBindingUtil.inflate(inflater, R.layout.quick_permission_dialog, this, true);
mBinding.setBlockButtonVisible(false);
mBinding.allowButton.setOnClickListener(v -> {
if (mDelegate != null) {
mDelegate.onAllow();
}
});
mBinding.blockButton.setOnClickListener(v -> {
if (mDelegate != null) {
mDelegate.onBlock();
}
});
mBinding.setIsBlocked(false);
updateUI();
}

public void setData(String uri, int aCategory, boolean aBlocked) {
mCategory = aCategory;
mDomain = uri;
mBinding.setBlockButtonVisible(aBlocked);
mBinding.setIsBlocked(aBlocked);
updateUI();
}

Expand All @@ -61,32 +51,32 @@ public void updateUI() {
case SitePermission.SITE_PERMISSION_WEBXR: {
mBinding.message.setText(
getResources().getString(R.string.webxr_permission_dialog_message,
mBinding.getBlockButtonVisible() ?
mBinding.getIsBlocked() ?
getResources().getString(R.string.off).toUpperCase() :
getResources().getString(R.string.on).toUpperCase(),
getResources().getString(R.string.sumo_webxr_url)));
mBinding.allowButton.setText(R.string.permission_allow);
mBinding.blockButton.setText(R.string.pop_up_site_switch_block);
mBinding.setOnText(getResources().getString(R.string.webxr_dialog_button_allow));
mBinding.setOffText(getResources().getString(R.string.webxr_dialog_button_not_allow));
break;
}
case SitePermission.SITE_PERMISSION_TRACKING: {
mBinding.message.setText(
getResources().getString(R.string.tracking_dialog_message,
mBinding.getBlockButtonVisible() ?
getResources().getString(R.string.on).toUpperCase() :
getResources().getString(R.string.off).toUpperCase(),
mBinding.getIsBlocked() ?
getResources().getString(R.string.off).toUpperCase() :
getResources().getString(R.string.on).toUpperCase(),
getResources().getString(R.string.sumo_etp_url)));
mBinding.allowButton.setText(R.string.tracking_dialog_button_disable);
mBinding.blockButton.setText(R.string.tracking_dialog_button_enable);
mBinding.setOnText(getResources().getString(R.string.tracking_dialog_button_allow));
mBinding.setOffText(getResources().getString(R.string.tracking_dialog_button_not_allow));
break;
}
case SitePermission.SITE_PERMISSION_DRM: {
mBinding.message.setText(
getResources().getString(R.string.drm_dialog_message,
getResources().getString(R.string.app_name),
getResources().getString(R.string.sumo_drm_url)));
mBinding.allowButton.setText(R.string.drm_dialog_button_disable);
mBinding.blockButton.setText(R.string.drm_dialog_button_enable);
mBinding.setOnText(getResources().getString(R.string.drm_dialog_button_allow));
mBinding.setOffText(getResources().getString(R.string.drm_dialog_button_not_allow));
break;
}
}
Expand All @@ -96,6 +86,10 @@ public void updateUI() {
onDismiss();
});

mBinding.enableSwitch.setOnCheckedChangeListener (null);
mBinding.enableSwitch.setChecked(!mBinding.getIsBlocked());
mBinding.enableSwitch.setOnCheckedChangeListener(mSwitchListener);

mBinding.executePendingBindings();
}

Expand Down Expand Up @@ -140,7 +134,21 @@ public void hide(@HideFlags int aHideFlags) {
mWidgetManager.removeFocusChangeListener(this);
}

private CompoundButton.OnCheckedChangeListener mSwitchListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (mDelegate != null) {
if (isChecked) {
mDelegate.onAllow();
} else {
mDelegate.onBlock();
}
}
}
};

// WidgetManagerDelegate.FocusChangeListener

@Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
if (!ViewUtils.isEqualOrChildrenOf(this, newFocus)) {
Expand Down
76 changes: 30 additions & 46 deletions app/src/main/res/layout/quick_permission_dialog.xml
Original file line number Diff line number Diff line change
@@ -1,77 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="blockButtonVisible"
name="isBlocked"
type="Boolean" />
<variable
name="onText"
type="String" />
<variable
name="offText"
type="String" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_width="@dimen/quick_permission_width"
tools:layout_height="@dimen/quick_permission_height"
android:layout_width="@dimen/quick_permission_width"
android:layout_height="@dimen/quick_permission_height"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/selectionMenuContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="100"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_marginBottom="15dp"
android:background="@drawable/context_menu_background">
<org.mozilla.vrbrowser.ui.views.LinkTextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="20dp"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:layout_above="@id/enableSwitch"
android:gravity="center"
android:layout_marginTop="25dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:text="@string/webxr_permission_dialog_message"
android:textStyle="bold"
android:textColor="@color/fog"
android:textSize="@dimen/text_bigger_size" />

<Button
android:id="@+id/allowButton"
android:layout_width="156dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_below="@id/message"
android:background="@drawable/dialog_highlighted_button_background"
android:fontFamily="sans-serif"
android:scaleType="fitCenter"
android:textSize="@dimen/text_bigger_size"
android:text="@string/pop_up_site_switch_allow"
android:textColor="@drawable/dialog_button_text_color"
android:textStyle="bold"
visibleGone="@{blockButtonVisible}"/>

<Button
android:id="@+id/blockButton"
android:layout_width="156dp"
android:layout_height="50dp"
<Switch
android:id="@+id/enableSwitch"
style="@style/settingsSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_below="@id/message"
android:background="@drawable/dialog_highlighted_button_background"
android:fontFamily="sans-serif"
android:layout_marginTop="10dp"
android:layout_marginBottom="25dp"
android:scaleType="fitCenter"
android:textSize="@dimen/text_bigger_size"
android:text="@string/pop_up_site_switch_block"
android:textColor="@drawable/dialog_button_text_color"
android:textStyle="bold"
visibleGone="@{!blockButtonVisible}"/>
android:switchPadding="5dp"
android:scaleX="1.5"
android:scaleY="1.5"
android:text="@{isBlocked ? offText : onText}" />
</RelativeLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="-1dp">
android:layout_marginTop="-16dp">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="30dp"
android:layout_height="15dp"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@

<!-- Quick Permission -->
<dimen name="quick_permission_width">420dp</dimen>
<dimen name="quick_permission_height">260dp</dimen>
<dimen name="quick_permission_height">220dp</dimen>

<!-- Hamburger Menu -->
<dimen name="hamburger_menu_width">300dp</dimen>
Expand Down
28 changes: 17 additions & 11 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1467,23 +1467,29 @@ the Select` button. When clicked it closes all the previously selected tabs -->

<!-- This string is displayed in the title of the quick WebXR blocking dialog, accessed from the VR icon in the URL bar.
'%1$s' will be replaced at runtime with the app's name. -->
<string name="webxr_permission_dialog_message">WebXR is %1$s for this site. (&lt;a href="%2$s">Learn More&lt;/a>)</string>
<string name="webxr_permission_dialog_message">WebXR is %1$s for this site. &lt;a href="%2$s">Learn More&lt;/a></string>

<!-- This string is displayed in the enable button of the quick WebXR blocking dialog when it's in enabled state. It's accessed from the WebXR icon in the URL bar. -->
<string name="webxr_dialog_button_allow">Allow</string>

<!-- This string is displayed in the disable button of the quick WebXR blocking dialog when it's in disabled state. It's accessed from the WebXR icon in the URL bar. -->
<string name="webxr_dialog_button_not_allow">Don\'t Allow</string>

<!-- This string is displayed in the title of the quick Tracking Protection dialog, accessed from the Tracking Protection icon in the URL bar. -->
<string name="tracking_dialog_message">Enhanced Tracking Protection is %1$s for this site. (&lt;a href="%2$s">Learn More&lt;/a>)</string>
<string name="tracking_dialog_message">Enhanced Tracking Protection is %1$s for this site. &lt;a href="%2$s">Learn More&lt;/a></string>

<!-- This string is displayed in the enable button of the quick Tracking Protection dialog, accessed from the Tracking Protection icon in the URL bar. -->
<string name="tracking_dialog_button_enable">Enable</string>
<!-- This string is displayed in the enable button of the quick Tracking Protection dialog when it's in enabled state. It's accessed from the Tracking Protection icon in the URL bar. -->
<string name="tracking_dialog_button_allow">Allow</string>

<!-- This string is displayed in the disable button of the quick Tracking Protection dialog, accessed from the Tracking Protection icon in the URL bar. -->
<string name="tracking_dialog_button_disable">Disable</string>
<!-- This string is displayed in the disable button of the quick Tracking Protection dialog when it's in disabled state. It's accessed from the Tracking Protection icon in the URL bar. -->
<string name="tracking_dialog_button_not_allow">Don\'t Allow</string>

<!-- This string is displayed in the title of the quick DRM dialog, accessed from the DRM icon in the URL bar. -->
<string name="drm_dialog_message">Some audio or video on this site uses DRM software, which may limit what %1$s can let you do with it (&lt;a href="%2$s">Learn More&lt;/a>)</string>
<string name="drm_dialog_message">Some audio or video on this site uses DRM software, which may limit what %1$s can let you do with it. &lt;a href="%2$s">Learn More&lt;/a></string>

<!-- This string is displayed in the enable button of the quick DRM dialog, accessed from the DRM icon in the URL bar. -->
<string name="drm_dialog_button_enable">Enable</string>
<!-- This string is displayed in the switch button of the quick DRM dialog when it's in enabled state. It's accessed from the DRM icon in the URL bar. -->
<string name="drm_dialog_button_allow">Allow</string>

<!-- This string is displayed in the disable button of the quick DRM dialog, accessed from the DRM icon in the URL bar. -->
<string name="drm_dialog_button_disable">Disable</string>
<!-- This string is displayed in the switch button of the quick DRM dialog when it's in disabled state. It's accessed from the DRM icon in the URL bar. -->
<string name="drm_dialog_button_not_allow">Don\'t Allow</string>
</resources>

0 comments on commit d54f7e2

Please sign in to comment.