Commit 1b031044 authored by Gordon Seto's avatar Gordon Seto Committed by Chromium LUCI CQ

[Nearby] Add high visibility toggle to Nearby Share Settings.

Add switch to toggle high visibility mode in nearby_share_subpage.

Screenshots:
https://screenshot.googleplex.com/7gpoKJmsBx7GW9c.png
https://screenshot.googleplex.com/Ak79VN82QFsGSkK.png
https://screenshot.googleplex.com/6aVSR3FqyfvMRz6.png

Fixed: 1154830
Change-Id: I2c59c8cb5a90ee7469eddfe04d691280044967d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2584355
Commit-Queue: Gordon Seto <gordonseto@google.com>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836371}
parent 15d3477f
...@@ -168,6 +168,18 @@ ...@@ -168,6 +168,18 @@
<message name="IDS_SETTINGS_NEARBY_SHARE_DESCRIPTION" desc="A description of nearby share that helps users understand what the feature is used for."> <message name="IDS_SETTINGS_NEARBY_SHARE_DESCRIPTION" desc="A description of nearby share that helps users understand what the feature is used for.">
Share files with people around you. <ph name="LINK_BEGIN">&lt;a&gt;</ph>Learn more<ph name="LINK_END">&lt;/a&gt;</ph> Share files with people around you. <ph name="LINK_BEGIN">&lt;a&gt;</ph>Learn more<ph name="LINK_END">&lt;/a&gt;</ph>
</message> </message>
<message name="IDS_SETTINGS_NEARBY_SHARE_HIGH_VISIBILITY_TITLE" desc="Label for the switch that toggles whether the device is visible to all devices around it for the Nearby Share feature.">
Visible to everyone
</message>
<message name="IDS_SETTINGS_NEARBY_SHARE_HIGH_VISIBILITY_ON" desc="Subtitle shown indicating that the device is visible to all devices around it for the Nearby Share feature and the nearest number of whole minutes it is on until it is turned off.">
On, <ph name="MINUTES">$1<ex>5</ex></ph> min
</message>
<message name="IDS_SETTINGS_NEARBY_SHARE_HIGH_VISIBILITY_OFF" desc="Label for the switch that toggles whether the device is visible to all devices around it for the Nearby Share feature.">
Off. <ph name="LINK_BEGIN">&lt;a&gt;</ph>Learn more<ph name="LINK_END">&lt;/a&gt;</ph>
</message>
<message name="IDS_SETTINGS_NEARBY_SHARE_HIGH_VISIBILITY_TOOLTIP" desc="Text for tooltip that explains that turning on high visibility mode will allow the device to visible to all devices around it for the Nearby Share feature for 5 minutes.">
Your Chromebook will be visible to everyone nearby for 5 min
</message>
<!-- Personalization Options SubPage (strings used by the <settings-personalization-options> element) --> <!-- Personalization Options SubPage (strings used by the <settings-personalization-options> element) -->
<message name="IDS_SETTINGS_ENABLE_URL_KEYED_ANONYMIZED_DATA_COLLECTION" desc="The label of the checkbox to enable/disable url keyed anonymized data collection."> <message name="IDS_SETTINGS_ENABLE_URL_KEYED_ANONYMIZED_DATA_COLLECTION" desc="The label of the checkbox to enable/disable url keyed anonymized data collection.">
......
b9d454839a1ab43e3efab0e51530ba2ec97c3e11
\ No newline at end of file
c39ed74cee607de5cd5a660fbf63e37c4bd8e8f8
\ No newline at end of file
b9d454839a1ab43e3efab0e51530ba2ec97c3e11
\ No newline at end of file
d536eab0387d1efcaf4c1867bc0025944251dccb
\ No newline at end of file
...@@ -109,6 +109,7 @@ js_library("nearby_share_subpage") { ...@@ -109,6 +109,7 @@ js_library("nearby_share_subpage") {
":nearby_share_data_usage_dialog", ":nearby_share_data_usage_dialog",
":nearby_share_device_name_dialog", ":nearby_share_device_name_dialog",
":nearby_share_receive_dialog", ":nearby_share_receive_dialog",
":nearby_share_receive_manager",
":types", ":types",
"..:deep_linking_behavior", "..:deep_linking_behavior",
"..:os_route", "..:os_route",
...@@ -265,6 +266,7 @@ js_library("nearby_share_subpage.m") { ...@@ -265,6 +266,7 @@ js_library("nearby_share_subpage.m") {
":nearby_share_data_usage_dialog.m", ":nearby_share_data_usage_dialog.m",
":nearby_share_device_name_dialog.m", ":nearby_share_device_name_dialog.m",
":nearby_share_receive_dialog.m", ":nearby_share_receive_dialog.m",
":nearby_share_receive_manager.m",
":types.m", ":types.m",
"..:deep_linking_behavior.m", "..:deep_linking_behavior.m",
"..:os_route.m", "..:os_route.m",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<link rel="import" href="nearby_share_device_name_dialog.html"> <link rel="import" href="nearby_share_device_name_dialog.html">
<link rel="import" href="nearby_share_data_usage_dialog.html"> <link rel="import" href="nearby_share_data_usage_dialog.html">
<link rel="import" href="nearby_share_receive_dialog.html"> <link rel="import" href="nearby_share_receive_dialog.html">
<link rel="import" href="nearby_share_receive_manager.html">
<link rel="import" href="types.html"> <link rel="import" href="types.html">
<dom-module id="settings-nearby-share-subpage"> <dom-module id="settings-nearby-share-subpage">
...@@ -40,6 +41,24 @@ ...@@ -40,6 +41,24 @@
font-size: 13px; font-size: 13px;
line-height: 20px; line-height: 20px;
} }
#highVisibilityContainer {
border-top: none;
padding: 0 var(--cr-section-padding) 0 60px;
}
.separator {
margin: 0;
}
#highVisibilityHelpIcon {
margin-inline-end: var(--cr-section-padding);
}
#highVisibilityContainer cr-toggle {
margin-inline-start: var(--cr-section-padding);
padding-inline-end: var(--cr-section-padding);
}
</style> </style>
<div id="toggleRow" class="cr-row first" on-click="onEnableTap_" actionable> <div id="toggleRow" class="cr-row first" on-click="onEnableTap_" actionable>
<div id="onOff" class="flex cr-padded-text" <div id="onOff" class="flex cr-padded-text"
...@@ -97,6 +116,41 @@ ...@@ -97,6 +116,41 @@
$i18n{nearbyShareEditVisibility} $i18n{nearbyShareEditVisibility}
</cr-button> </cr-button>
</div> </div>
<div id="highVisibilityContainer" class="settings-box two-line">
<div class="start">
<div id="highVisibilityTitle"
role="heading" aria-hidden="true">
$i18n{nearbyShareHighVisibilityTitle}
</div>
<div id="highVisibilitySubtitle"
class="secondary" aria-hidden="true">
<!-- TODO(vecore) add correct help link -->
<settings-localized-link id="highVisibilityOff"
localized-string="[[getHighVisibilityToggleText_(inHighVisibility_)]]"
link-url="https://google.com">
</settings-localized-link>
</div>
</div>
<iron-icon tabindex="0" id="highVisibilityHelpIcon"
icon="cr:help-outline"
aria-labelledby="highVisibilityTitle tooltip">
</iron-icon>
<paper-tooltip id="tooltip"
for="highVisibilityHelpIcon"
position="bottom"
aria-hidden="true"
fit-to-visible-bounds>
$i18n{nearbyShareHighVisibilityTooltip}
</paper-tooltip>
<div class="separator"></div>
<cr-toggle
id="highVisibilityToggle"
checked="{{inHighVisibility_}}"
aria-labelledby="highVisibilityTitle"
aria-describedby="highVisibilitySubtitle"
on-change="onInHighVisibilityToggledByUser_">
</cr-toggle>
</div>
<template is="dom-if" if="[[showVisibilityDialog_]]" restamp> <template is="dom-if" if="[[showVisibilityDialog_]]" restamp>
<nearby-share-contact-visibility-dialog settings="{{settings}}" <nearby-share-contact-visibility-dialog settings="{{settings}}"
id="visibilityDialog" on-close="onVisibilityDialogClose_"> id="visibilityDialog" on-close="onVisibilityDialogClose_">
......
...@@ -65,6 +65,12 @@ Polymer({ ...@@ -65,6 +65,12 @@ Polymer({
value: () => loadTimeData.getString('nearbyShareManageContactsUrl') value: () => loadTimeData.getString('nearbyShareManageContactsUrl')
}, },
/** @private {boolean} */
inHighVisibility_: {
type: Boolean,
value: false,
},
/** /**
* Used by DeepLinkingBehavior to focus this page's deep links. * Used by DeepLinkingBehavior to focus this page's deep links.
* @type {!Set<!chromeos.settings.mojom.Setting>} * @type {!Set<!chromeos.settings.mojom.Setting>}
...@@ -77,6 +83,12 @@ Polymer({ ...@@ -77,6 +83,12 @@ Polymer({
}, },
}, },
/** @private {?nearbyShare.mojom.ReceiveManagerInterface} */
receiveManager_: null,
/** @private {?nearbyShare.mojom.ReceiveObserverReceiver} */
receiveObserver_: null,
attached() { attached() {
// TODO(b/166779043): Check whether the Account Manager is enabled and fall // TODO(b/166779043): Check whether the Account Manager is enabled and fall
// back to profile name, or just hide the row. This is not urgent because // back to profile name, or just hide the row. This is not urgent because
...@@ -91,6 +103,9 @@ Polymer({ ...@@ -91,6 +103,9 @@ Polymer({
this.profileName_ = accounts[0].fullName; this.profileName_ = accounts[0].fullName;
this.profileLabel_ = accounts[0].email; this.profileLabel_ = accounts[0].email;
}); });
this.receiveManager_ = nearby_share.getReceiveManager();
this.receiveObserver_ = nearby_share.observeReceiveManager(
/** @type {!nearbyShare.mojom.ReceiveObserverInterface} */ (this));
}, },
/** /**
...@@ -171,6 +186,32 @@ Polymer({ ...@@ -171,6 +186,32 @@ Polymer({
return this.manageContactsUrl_.replace(/(^\w+:|^)\/\//, ''); return this.manageContactsUrl_.replace(/(^\w+:|^)\/\//, '');
}, },
/**
* Mojo callback when high visibility changes.
* @param {boolean} inHighVisibility
*/
onHighVisibilityChanged(inHighVisibility) {
this.inHighVisibility_ = inHighVisibility;
},
/**
* Mojo callback when transfer status changes.
* @param {!nearbyShare.mojom.ShareTarget} shareTarget
* @param {!nearbyShare.mojom.TransferMetadata} metadata
*/
onTransferUpdate(shareTarget, metadata) {
// Note: Intentionally left empty.
},
/** @private */
onInHighVisibilityToggledByUser_() {
if (this.inHighVisibility_) {
this.receiveManager_.registerForegroundReceiveSurface();
} else {
this.receiveManager_.unregisterForegroundReceiveSurface();
}
},
/** /**
* @param {boolean} state boolean state that determines which string to show * @param {boolean} state boolean state that determines which string to show
* @param {string} onstr string to show when state is true * @param {string} onstr string to show when state is true
...@@ -231,6 +272,16 @@ Polymer({ ...@@ -231,6 +272,16 @@ Polymer({
} }
}, },
/**
* @param {boolean} inHighVisibility
*/
getHighVisibilityToggleText_(inHighVisibility) {
// TODO(crbug.com/1154830): Add logic to show how much time the user
// actually has left.
return inHighVisibility ? this.i18n('nearbyShareHighVisibilityOn', 5) :
this.i18nAdvanced('nearbyShareHighVisibilityOff');
},
/** /**
* @param {string} dataUsageValue enum value of data usage setting. * @param {string} dataUsageValue enum value of data usage setting.
* @return {string} localized string * @return {string} localized string
......
...@@ -289,7 +289,15 @@ void AddNearbyShareData(content::WebUIDataSource* html_source) { ...@@ -289,7 +289,15 @@ void AddNearbyShareData(content::WebUIDataSource* html_source) {
{"nearbyShareEditVisibility", IDS_SETTINGS_NEARBY_SHARE_EDIT_VISIBILITY}, {"nearbyShareEditVisibility", IDS_SETTINGS_NEARBY_SHARE_EDIT_VISIBILITY},
{"nearbyShareVisibilityDialogTitle", {"nearbyShareVisibilityDialogTitle",
IDS_SETTINGS_NEARBY_SHARE_VISIBILITY_DIALOG_TITLE}, IDS_SETTINGS_NEARBY_SHARE_VISIBILITY_DIALOG_TITLE},
{"nearbyShareDescription", IDS_SETTINGS_NEARBY_SHARE_DESCRIPTION}}; {"nearbyShareDescription", IDS_SETTINGS_NEARBY_SHARE_DESCRIPTION},
{"nearbyShareHighVisibilityTitle",
IDS_SETTINGS_NEARBY_SHARE_HIGH_VISIBILITY_TITLE},
{"nearbyShareHighVisibilityOn",
IDS_SETTINGS_NEARBY_SHARE_HIGH_VISIBILITY_ON},
{"nearbyShareHighVisibilityOff",
IDS_SETTINGS_NEARBY_SHARE_HIGH_VISIBILITY_OFF},
{"nearbyShareHighVisibilityTooltip",
IDS_SETTINGS_NEARBY_SHARE_HIGH_VISIBILITY_TOOLTIP}};
AddLocalizedStringsBulk(html_source, kLocalizedStrings); AddLocalizedStringsBulk(html_source, kLocalizedStrings);
......
...@@ -110,6 +110,23 @@ cr.define('nearby_share', function() { ...@@ -110,6 +110,23 @@ cr.define('nearby_share', function() {
this.methodCalled('reject', shareTargetId); this.methodCalled('reject', shareTargetId);
return {success: this.nextResult_}; return {success: this.nextResult_};
} }
/**
* @return {boolean}
*/
getInHighVisibilityForTest() {
return this.inHighVisibility_;
}
/**
* @param {boolean} inHighVisibility
*/
setInHighVisibilityForTest(inHighVisibility) {
this.inHighVisibility_ = inHighVisibility;
if (this.observer_) {
this.observer_.onHighVisibilityChanged(inHighVisibility);
}
}
} }
// #cr_define_end // #cr_define_end
......
...@@ -214,6 +214,27 @@ suite('NearbyShare', function() { ...@@ -214,6 +214,27 @@ suite('NearbyShare', function() {
dialog.$$('.action-button').click(); dialog.$$('.action-button').click();
}); });
test('toggle high visibility from UI', function() {
subpage.$$('#highVisibilityToggle').click();
Polymer.dom.flush();
assertTrue(fakeReceiveManager.getInHighVisibilityForTest());
subpage.$$('#highVisibilityToggle').click();
Polymer.dom.flush();
assertFalse(fakeReceiveManager.getInHighVisibilityForTest());
});
test('high visibility UI updates from high visibility changes', function() {
const highVisibilityToggle = subpage.$$('#highVisibilityToggle');
assertFalse(highVisibilityToggle.checked);
fakeReceiveManager.setInHighVisibilityForTest(true);
assertTrue(highVisibilityToggle.checked);
fakeReceiveManager.setInHighVisibilityForTest(false);
assertFalse(highVisibilityToggle.checked);
});
test('GAIA email, account manager enabled', async () => { test('GAIA email, account manager enabled', async () => {
await accountManagerBrowserProxy.whenCalled('getAccounts'); await accountManagerBrowserProxy.whenCalled('getAccounts');
Polymer.dom.flush(); Polymer.dom.flush();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment