OSDN Git Service

Add estimate time under support options.
authorFan Zhang <zhfan@google.com>
Tue, 3 May 2016 00:25:05 +0000 (17:25 -0700)
committerFan Zhang <zhfan@google.com>
Thu, 5 May 2016 18:06:08 +0000 (11:06 -0700)
Bug: 28141203

- SupportFeatureProvider will provide a localized estimate string.
- Use a builder pattern to instantiate SupportData to avoid increasing
  constructor args.

Change-Id: I92e90cd57b4ef4e1d921f403801cfd5984ef6a3b

res/layout/support_escalation_options.xml
res/values/strings.xml
src/com/android/settings/dashboard/SupportItemAdapter.java
src/com/android/settings/overlay/SupportFeatureProvider.java

index bedb447..69c49dc 100644 (file)
     android:layout_height="wrap_content"
     android:background="@color/support_escalation_background"
     android:gravity="center_horizontal"
-    android:orientation="horizontal"
     android:paddingStart="56dp"
-    android:paddingEnd="56dp">
-    <Button
-        android:id="@android:id/text1"
-        style="@style/SupportPrimaryButton"
+    android:paddingEnd="56dp"
+    android:paddingBottom="8dp">
+    <LinearLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_margin="8dp"/>
-    <Button
-        android:id="@android:id/text2"
-        style="@style/SupportPrimaryButton"
+        android:layout_marginStart="8dp"
+        android:layout_marginEnd="8dp"
+        android:gravity="center_horizontal"
+        android:orientation="vertical">
+        <Button
+            android:id="@android:id/text1"
+            style="@style/SupportPrimaryButton"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_margin="8dp"/>
+        <TextView
+            android:id="@+id/summary1"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="@style/TextAppearance.Small"
+            android:textColor="?android:attr/textColorSecondary"/>
+    </LinearLayout>
+    <LinearLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_margin="8dp"/>
+        android:layout_marginStart="8dp"
+        android:layout_marginEnd="8dp"
+        android:gravity="center_horizontal"
+        android:orientation="vertical">
+        <Button
+            android:id="@android:id/text2"
+            style="@style/SupportPrimaryButton"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_margin="8dp"/>
+        <TextView
+            android:id="@+id/summary2"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="@style/TextAppearance.Small"
+            android:textColor="?android:attr/textColorSecondary"/>
+    </LinearLayout>
 </LinearLayout>
index 7b7f996..31a1a27 100644 (file)
     <!-- [CHAR LIMIT=NONE] The preference summary for enabling cross-profile remote contact search -->
     <string name="managed_profile_contact_search_summary">Allow contact searches by your organization to identify callers and contacts</string>
 
+    <!-- Time in hours -->
+    <plurals name="hours">
+        <item quantity="one">1 hour</item>
+        <item quantity="other"><xliff:g id="number" example="7">%s</xliff:g> hours</item>
+    </plurals>
+
+    <!-- Time in minutes -->
+    <plurals name="minutes">
+        <item quantity="one">1 minute</item>
+        <item quantity="other"><xliff:g id="number" example="7">%s</xliff:g> minutes</item>
+    </plurals>
+
+    <!-- Time in seconds -->
+    <plurals name="seconds">
+        <item quantity="one">1 second</item>
+        <item quantity="other"><xliff:g id="number" example="7">%s</xliff:g> seconds</item>
+    </plurals>
+
+    <!-- Estimated wait time range for real time supports -->
+    <string name="support_estimated_wait_time">~<xliff:g id="ESTIMATE" example="2 minutes">%1$s</xliff:g> wait</string>
+
 </resources>
index beef92e..4b1d318 100644 (file)
@@ -146,41 +146,53 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
 
     private void addEscalationCards() {
         if (mHasInternet) {
-            mSupportData.add(new SupportData(TYPE_TITLE, 0 /* icon */,
-                    R.string.support_escalation_title, R.string.support_escalation_summary,
-                    null /* intent */));
+            mSupportData.add(new SupportData.Builder(TYPE_TITLE)
+                    .setText1(R.string.support_escalation_title)
+                    .setText2(R.string.support_escalation_summary)
+                    .build());
         } else {
-            mSupportData.add(new SupportData(TYPE_TITLE, 0 /* icon */,
-                    R.string.support_offline_title, R.string.support_offline_summary,
-                    null /* intent */));
+            mSupportData.add(new SupportData.Builder(TYPE_TITLE)
+                    .setText1(R.string.support_offline_title)
+                    .setText2(R.string.support_offline_summary)
+                    .build());
         }
-        final int phoneSupportText = mSupportFeatureProvider.isSupportTypeEnabled(mActivity, PHONE)
-                ? R.string.support_escalation_by_phone : 0;
-        final int chatSupportText = mSupportFeatureProvider.isSupportTypeEnabled(mActivity, CHAT)
-                ? R.string.support_escalation_by_chat : 0;
-        mSupportData.add(new SupportData(TYPE_ESCALATION_OPTIONS, 0 /* icon */,
-                phoneSupportText, chatSupportText, null /* intent */));
+        final SupportData.Builder builder = new SupportData.Builder(TYPE_ESCALATION_OPTIONS);
+        if (mSupportFeatureProvider.isSupportTypeEnabled(mActivity, PHONE)) {
+            builder.setText1(R.string.support_escalation_by_phone);
+            builder.setSummary1(mSupportFeatureProvider.getEstimatedWaitTime(mActivity, PHONE));
+        }
+        if (mSupportFeatureProvider.isSupportTypeEnabled(mActivity, CHAT)) {
+            builder.setText2(R.string.support_escalation_by_chat);
+            builder.setSummary2(mSupportFeatureProvider.getEstimatedWaitTime(mActivity, CHAT));
+        }
+        mSupportData.add(builder.build());
     }
 
     private void addSignInPromo() {
-        mSupportData.add(new SupportData(TYPE_TITLE, 0 /* icon */,
-                R.string.support_sign_in_required_title, R.string.support_sign_in_required_summary,
-                null /* intent */));
-        mSupportData.add(new SupportData(TYPE_SIGN_IN_BUTTON, 0 /* icon */,
-                R.string.support_sign_in_button_text, R.string.support_sign_in_required_help,
-                null /* intent */));
-
+        mSupportData.add(new SupportData.Builder(TYPE_TITLE)
+                .setText1(R.string.support_sign_in_required_title)
+                .setText2(R.string.support_sign_in_required_summary)
+                .build());
+        mSupportData.add(new SupportData.Builder(TYPE_SIGN_IN_BUTTON)
+                .setText1(R.string.support_sign_in_button_text)
+                .setText2(R.string.support_sign_in_required_help)
+                .build());
     }
 
     private void addMoreHelpItems() {
-        mSupportData.add(new SupportData(TYPE_SUBTITLE, 0 /* icon */,
-                R.string.support_more_help_title, 0 /* summary */, null /* intent */));
-        mSupportData.add(new SupportData(TYPE_SUPPORT_TILE, R.drawable.ic_forum_24dp,
-                R.string.support_forum_title, 0 /* summary */,
-                mSupportFeatureProvider.getForumIntent()));
-        mSupportData.add(new SupportData(TYPE_SUPPORT_TILE, R.drawable.ic_help_24dp,
-                R.string.help_feedback_label, 0 /* summary */,
-                mSupportFeatureProvider.getHelpIntent(mActivity)));
+        mSupportData.add(new SupportData.Builder(TYPE_SUBTITLE)
+                .setText1(R.string.support_more_help_title)
+                .build());
+        mSupportData.add(new SupportData.Builder(TYPE_SUPPORT_TILE)
+                .setIcon(R.drawable.ic_forum_24dp)
+                .setText1(R.string.support_forum_title)
+                .setIntent(mSupportFeatureProvider.getForumIntent())
+                .build());
+        mSupportData.add(new SupportData.Builder(TYPE_SUPPORT_TILE)
+                .setIcon(R.drawable.ic_help_24dp)
+                .setText1(R.string.help_feedback_label)
+                .setIntent(mSupportFeatureProvider.getHelpIntent(mActivity))
+                .build());
     }
 
     private void bindEscalationOptions(ViewHolder holder, SupportData data) {
@@ -200,6 +212,14 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
             holder.text2View.setEnabled(mHasInternet);
             holder.text2View.setVisibility(View.VISIBLE);
         }
+        if (holder.summary1View != null) {
+            holder.summary1View.setText(data.summary1);
+            holder.summary1View.setVisibility(mHasInternet ? View.VISIBLE : View.GONE);
+        }
+        if (holder.summary2View != null) {
+            holder.summary2View.setText(data.summary2);
+            holder.summary2View.setVisibility(mHasInternet ? View.VISIBLE : View.GONE);
+        }
     }
 
     private void bindSignInPromoTile(ViewHolder holder, SupportData data) {
@@ -255,12 +275,16 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
         final ImageView iconView;
         final TextView text1View;
         final TextView text2View;
+        final TextView summary1View;
+        final TextView summary2View;
 
         ViewHolder(View itemView) {
             super(itemView);
             iconView = (ImageView) itemView.findViewById(android.R.id.icon);
             text1View = (TextView) itemView.findViewById(android.R.id.text1);
             text2View = (TextView) itemView.findViewById(android.R.id.text2);
+            summary1View = (TextView) itemView.findViewById(R.id.summary1);
+            summary2View = (TextView) itemView.findViewById(R.id.summary2);
         }
     }
 
@@ -278,14 +302,65 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
         final int text1;
         @StringRes
         final int text2;
+        final String summary1;
+        final String summary2;
+
+        private SupportData(Builder builder) {
+            this.type = builder.mType;
+            this.icon = builder.mIcon;
+            this.text1 = builder.mText1;
+            this.text2 = builder.mText2;
+            this.summary1 = builder.mSummary1;
+            this.summary2 = builder.mSummary2;
+            this.intent = builder.mIntent;
+        }
+
+        static final class Builder {
+            @LayoutRes private final int mType;
+            @DrawableRes private int mIcon;
+            @StringRes private int mText1;
+            @StringRes private int mText2;
+            private String mSummary1;
+            private String mSummary2;
+            private Intent mIntent;
+
+            Builder(@LayoutRes int type) {
+                mType = type;
+            }
+
+            Builder setIcon(@DrawableRes int icon) {
+                mIcon = icon;
+                return this;
+            }
 
-        SupportData(@LayoutRes int type, @DrawableRes int icon, @StringRes int text1,
-                @StringRes int text2, Intent intent) {
-            this.type = type;
-            this.icon = icon;
-            this.text1 = text1;
-            this.text2 = text2;
-            this.intent = intent;
+            Builder setText1(@StringRes int text1) {
+                mText1 = text1;
+                return this;
+            }
+
+            Builder setSummary1(String summary1) {
+                mSummary1 = summary1;
+                return this;
+            }
+
+            Builder setText2(@StringRes int text2) {
+                mText2 = text2;
+                return this;
+            }
+
+            Builder setSummary2(String summary2) {
+                mSummary2 = summary2;
+                return this;
+            }
+
+            Builder setIntent(Intent intent) {
+                mIntent = intent;
+                return this;
+            }
+
+            SupportData build() {
+                return new SupportData(this);
+            }
         }
     }
 }
index bd4352a..bf31f7f 100644 (file)
@@ -53,6 +53,11 @@ public interface SupportFeatureProvider {
     boolean isSupportTypeEnabled(Context context, @SupportType int type);
 
     /**
+     * Returns a localized string indicating estimated wait time for a support time.
+     */
+    String getEstimatedWaitTime(Context context, @SupportType int type);
+
+    /**
      * Returns an {@link Account} that's eligible for support options.
      */
     Account getSupportEligibleAccount(Context context);
@@ -61,7 +66,7 @@ public interface SupportFeatureProvider {
      * Returns an {@link Intent} that opens email support for specified account.
      *
      * @param context A UI Context
-     * @param account A account returned by {@link #getSupportEligibleAccounts}
+     * @param account A account returned by {@link #getSupportEligibleAccount}
      * @param type The type of support account needs.
      */
     Intent getSupportIntent(Context context, Account account, @SupportType int type);