Commit 83119f03 authored by Kyle Milka's avatar Kyle Milka Committed by Commit Bot

[Sharing Hub] Add educational panel for STTS

If STTS is not available (sync not enabled or no target devices
available) display a prompt to educated users to sign in.

Bug: 1009124
Change-Id: I357763f51fafcfded316fb8ecfb954470ea527e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067798
Commit-Queue: Kyle Milka <kmilka@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarJeffrey Cohen <jeffreycohen@chromium.org>
Reviewed-by: default avatarTanya Gupta <tgupta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745165}
parent 021a7cb2
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<!-- Container for sign in prompt if Sync is disable or no devices are available -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/min_touch_target_size"
android:orientation="vertical"
android:paddingBottom="32dp">
<ImageView
android:id="@+id/empty_state_image"
android:layout_height="wrap_content"
android:layout_width ="match_parent"
android:contentDescription="@string/sharing_hub_no_devices_available_text"
app:srcCompat="@drawable/shared_clipboard_zero_state"/>
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/min_touch_target_size"
android:gravity="center"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:paddingTop="16dp"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.BlackToolbarTitle"
android:text="@string/sharing_no_devices_available_title"/>
<TextView
android:id='@+id/enable_sync_text_field'
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:paddingTop="16dp"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.TextLarge.Secondary"
android:text="@string/sharing_hub_sync_disabled_text"/>
<org.chromium.ui.widget.ButtonCompat
android:id="@+id/chrome_settings"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:text="@string/sharing_chrome_settings"
android:visibility="gone"
style="@style/FilledButton"/>
</LinearLayout>
...@@ -14,18 +14,28 @@ import android.widget.AdapterView.OnItemClickListener; ...@@ -14,18 +14,28 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import org.chromium.base.ContextUtils;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.send_tab_to_self.SendTabToSelfMetrics.SendTabToSelfShareClickResult; import org.chromium.chrome.browser.send_tab_to_self.SendTabToSelfMetrics.SendTabToSelfShareClickResult;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.components.sync.AndroidSyncSettings;
import org.chromium.content_public.browser.NavigationEntry; import org.chromium.content_public.browser.NavigationEntry;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.widget.ButtonCompat;
import org.chromium.ui.widget.Toast; import org.chromium.ui.widget.Toast;
import java.util.ArrayList;
import java.util.List;
/** /**
* Bottom sheet content to display a list of devices a user can send a tab to after they have * Bottom sheet content to display a list of devices a user can send a tab to after they have
* chosen to share it with themselves through the SendTabToSelfFeature. * chosen to share it with themselves through the SendTabToSelfFeature. If sync is disabled
* or no target devices are available an prompt will be shown indicating to the user that
* they must sign in to use the feature.
*/ */
public class DevicePickerBottomSheetContent implements BottomSheetContent, OnItemClickListener { public class DevicePickerBottomSheetContent implements BottomSheetContent, OnItemClickListener {
private final Context mContext; private final Context mContext;
...@@ -35,14 +45,16 @@ public class DevicePickerBottomSheetContent implements BottomSheetContent, OnIte ...@@ -35,14 +45,16 @@ public class DevicePickerBottomSheetContent implements BottomSheetContent, OnIte
private final DevicePickerBottomSheetAdapter mAdapter; private final DevicePickerBottomSheetAdapter mAdapter;
private final NavigationEntry mEntry; private final NavigationEntry mEntry;
private final Profile mProfile; private final Profile mProfile;
private final WebContents mWebContents;
public DevicePickerBottomSheetContent( public DevicePickerBottomSheetContent(Context context, NavigationEntry entry,
Context context, NavigationEntry entry, BottomSheetController controller) { BottomSheetController controller, WebContents webContents) {
mContext = context; mContext = context;
mController = controller; mController = controller;
mProfile = Profile.getLastUsedRegularProfile(); mProfile = Profile.getLastUsedRegularProfile();
mAdapter = new DevicePickerBottomSheetAdapter(mProfile); mAdapter = new DevicePickerBottomSheetAdapter(mProfile);
mEntry = entry; mEntry = entry;
mWebContents = webContents;
createToolbarView(); createToolbarView();
createContentView(); createContentView();
...@@ -63,12 +75,36 @@ public class DevicePickerBottomSheetContent implements BottomSheetContent, OnIte ...@@ -63,12 +75,36 @@ public class DevicePickerBottomSheetContent implements BottomSheetContent, OnIte
} }
private void createContentView() { private void createContentView() {
mContentView = (ViewGroup) LayoutInflater.from(mContext).inflate( List<TargetDeviceInfo> targetDeviceList = new ArrayList<TargetDeviceInfo>();
R.layout.send_tab_to_self_device_picker_list, null); SendTabToSelfAndroidBridgeJni.get().getAllTargetDeviceInfos(mProfile, targetDeviceList);
ListView listView = mContentView.findViewById(R.id.device_picker_list);
if (!AndroidSyncSettings.get().isChromeSyncEnabled()) {
listView.setAdapter(mAdapter); mContentView = (ViewGroup) LayoutInflater.from(mContext).inflate(
listView.setOnItemClickListener(this); R.layout.send_tab_to_self_feature_unavailable_prompt, null);
mToolbarView.setVisibility(View.GONE);
enableSettingsButton();
} else if (targetDeviceList.isEmpty()) {
mContentView = (ViewGroup) LayoutInflater.from(mContext).inflate(
R.layout.send_tab_to_self_feature_unavailable_prompt, null);
mToolbarView.setVisibility(View.GONE);
TextView textView = mContentView.findViewById(R.id.enable_sync_text_field);
textView.setText(mContext.getResources().getString(
R.string.sharing_hub_no_devices_available_text));
} else {
mContentView = (ViewGroup) LayoutInflater.from(mContext).inflate(
R.layout.send_tab_to_self_device_picker_list, null);
ListView listView = mContentView.findViewById(R.id.device_picker_list);
listView.setAdapter(mAdapter);
listView.setOnItemClickListener(this);
}
}
private void enableSettingsButton() {
ButtonCompat chromeSettingsButton = mContentView.findViewById(R.id.chrome_settings);
chromeSettingsButton.setVisibility(View.VISIBLE);
chromeSettingsButton.setOnClickListener(view -> {
SettingsLauncher.getInstance().launchSettingsPage(ContextUtils.getApplicationContext());
});
} }
@Override @Override
......
...@@ -15,6 +15,7 @@ import org.chromium.chrome.browser.tab.Tab; ...@@ -15,6 +15,7 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.content_public.browser.NavigationEntry; import org.chromium.content_public.browser.NavigationEntry;
import org.chromium.content_public.browser.WebContents;
/** /**
* A simple activity that allows Chrome to expose send tab to self as an option in the share menu. * A simple activity that allows Chrome to expose send tab to self as an option in the share menu.
...@@ -27,29 +28,31 @@ public class SendTabToSelfShareActivity extends ShareActivity { ...@@ -27,29 +28,31 @@ public class SendTabToSelfShareActivity extends ShareActivity {
Tab tab = triggeringActivity.getActivityTabProvider().get(); Tab tab = triggeringActivity.getActivityTabProvider().get();
if (tab == null) return; if (tab == null) return;
NavigationEntry entry = tab.getWebContents().getNavigationController().getVisibleEntry(); NavigationEntry entry = tab.getWebContents().getNavigationController().getVisibleEntry();
actionHandler(triggeringActivity, entry, triggeringActivity.getBottomSheetController()); actionHandler(triggeringActivity, entry, triggeringActivity.getBottomSheetController(),
tab.getWebContents());
} }
public static void actionHandler( public static void actionHandler(Context context, NavigationEntry entry,
Context context, NavigationEntry entry, BottomSheetController controller) { BottomSheetController controller, WebContents webContents) {
if (entry == null || controller == null) { if (entry == null || controller == null) {
return; return;
} }
SendTabToSelfShareClickResult.recordClickResult( SendTabToSelfShareClickResult.recordClickResult(
SendTabToSelfShareClickResult.ClickType.SHOW_DEVICE_LIST); SendTabToSelfShareClickResult.ClickType.SHOW_DEVICE_LIST);
controller.requestShowContent(createBottomSheetContent(context, entry, controller), true); controller.requestShowContent(
createBottomSheetContent(context, entry, controller, webContents), true);
// TODO(crbug.com/968246): Remove the need to call this explicitly and instead have it // TODO(crbug.com/968246): Remove the need to call this explicitly and instead have it
// automatically show since PeekStateEnabled is set to false. // automatically show since PeekStateEnabled is set to false.
controller.expandSheet(); controller.expandSheet();
} }
static BottomSheetContent createBottomSheetContent( static BottomSheetContent createBottomSheetContent(Context context, NavigationEntry entry,
Context context, NavigationEntry entry, BottomSheetController controller) { BottomSheetController controller, WebContents webContents) {
if (sBottomSheetContentForTesting != null) { if (sBottomSheetContentForTesting != null) {
return sBottomSheetContentForTesting; return sBottomSheetContentForTesting;
} }
return new DevicePickerBottomSheetContent(context, entry, controller); return new DevicePickerBottomSheetContent(context, entry, controller, webContents);
} }
public static boolean featureIsAvailable(Tab currentTab) { public static boolean featureIsAvailable(Tab currentTab) {
......
...@@ -127,7 +127,8 @@ public class ShareSheetCoordinator { ...@@ -127,7 +127,8 @@ public class ShareSheetCoordinator {
.getWebContents() .getWebContents()
.getNavigationController() .getNavigationController()
.getVisibleEntry(), .getVisibleEntry(),
mBottomSheetController); mBottomSheetController,
mActivityTabProvider.get().getWebContents());
}, },
/*isFirstParty=*/true); /*isFirstParty=*/true);
models.add(sttsPropertyModel); models.add(sttsPropertyModel);
......
...@@ -3755,6 +3755,14 @@ Only you can see what your camera is looking at. The site can't see your camera' ...@@ -3755,6 +3755,14 @@ Only you can see what your camera is looking at. The site can't see your camera'
Go to Chrome settings Go to Chrome settings
</message> </message>
<!-- Sharing Hub -->
<message name="IDS_SHARING_HUB_NO_DEVICES_AVAILABLE_TEXT" desc="Text to show when no device targets are available for sharing.">
To share this page to another device, turn on sync in Chrome settings on the other device
</message>
<message name="IDS_SHARING_HUB_SYNC_DISABLED_TEXT" desc="Text to show when sync is disabled on the current device.">
To share this page to another device, turn on sync in Chrome settings
</message>
<!-- ClickToCall --> <!-- ClickToCall -->
<message name="IDS_CLICK_TO_CALL_NOTIFICATION_TEXT" desc="Text displayed in a click to call notification to call on a number."> <message name="IDS_CLICK_TO_CALL_NOTIFICATION_TEXT" desc="Text displayed in a click to call notification to call on a number.">
Tap to make call Tap to make call
......
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