Theme picker polish fixes.

- Do not show Previous on first custom screen
- Show a toast instead of exiting the activity when
applying the clock
- Mutate drawables in custom theme icon preview thumbnails

Fixes: 132282403
Fixes: 132282415
Test: visual
Change-Id: If230c5c95ba92b787b9e6580261b0a662c159549
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a97e26d..8f1ecdd 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -105,6 +105,9 @@
     <!-- Message shown when a theme has been applied successfully in the system [CHAR LIMIT=NONE] -->
     <string name="applied_theme_msg">Style applied</string>
 
+    <!-- Message shown when a clock has been applied successfully in the system [CHAR LIMIT=NONE] -->
+    <string name="applied_clock_msg">Clock applied</string>
+
     <!-- Message shown when a theme couldn't be applied in the system because of an error
         [CHAR LIMIT=NONE] -->
     <string name="apply_theme_error_msg">There was a problem applying the style</string>
diff --git a/src/com/android/customization/model/theme/custom/ThemeComponentOption.java b/src/com/android/customization/model/theme/custom/ThemeComponentOption.java
index fa45931..2dc163e 100644
--- a/src/com/android/customization/model/theme/custom/ThemeComponentOption.java
+++ b/src/com/android/customization/model/theme/custom/ThemeComponentOption.java
@@ -150,7 +150,8 @@
         @Override
         public void bindThumbnailTile(View view) {
             Resources res = view.getContext().getResources();
-            Drawable icon = mIcons.get(THUMBNAIL_ICON_POSITION).mutate();
+            Drawable icon = mIcons.get(THUMBNAIL_ICON_POSITION)
+                    .getConstantState().newDrawable().mutate();
             icon.setTint(res.getColor(R.color.icon_thumbnail_color, null));
             ((ImageView) view.findViewById(R.id.option_icon)).setImageDrawable(
                     icon);
diff --git a/src/com/android/customization/picker/clock/ClockFragment.java b/src/com/android/customization/picker/clock/ClockFragment.java
index 73a8af4..c3e1c97 100644
--- a/src/com/android/customization/picker/clock/ClockFragment.java
+++ b/src/com/android/customization/picker/clock/ClockFragment.java
@@ -22,6 +22,7 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ImageView;
+import android.widget.Toast;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
@@ -87,7 +88,9 @@
             mClockManager.apply(mSelectedOption, new Callback() {
                 @Override
                 public void onSuccess() {
-                    getActivity().finish();
+                    mOptionsController.setAppliedOption(mSelectedOption);
+                    Toast.makeText(getContext(), R.string.applied_clock_msg,
+                            Toast.LENGTH_SHORT).show();
                 }
 
                 @Override
diff --git a/src/com/android/customization/picker/theme/CustomThemeActivity.java b/src/com/android/customization/picker/theme/CustomThemeActivity.java
index 1e8af0a..8cccd54 100644
--- a/src/com/android/customization/picker/theme/CustomThemeActivity.java
+++ b/src/com/android/customization/picker/theme/CustomThemeActivity.java
@@ -19,6 +19,7 @@
 import android.content.Intent;
 import android.os.Bundle;
 import android.util.Log;
+import android.view.View;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -152,7 +153,7 @@
         }
         fragmentTransaction.commit();
         fragmentManager.executePendingTransactions();
-        updateApplyButtonLabel();
+        updateNavigationButtonLabels();
     }
 
     private void initSteps(int currentStep) {
@@ -245,10 +246,11 @@
     @Override
     public void setCurrentStep(int i) {
         mCurrentStep = i;
-        updateApplyButtonLabel();
+        updateNavigationButtonLabels();
     }
 
-    private void updateApplyButtonLabel() {
+    private void updateNavigationButtonLabels() {
+        mPreviousButton.setVisibility(mCurrentStep == 0 ? View.INVISIBLE : View.VISIBLE);
         mNextButton.setText((mCurrentStep < mSteps.size() -1) ? R.string.custom_theme_next
                 : R.string.apply_btn);
     }
diff --git a/src/com/android/customization/widget/OptionSelectorController.java b/src/com/android/customization/widget/OptionSelectorController.java
index 06b1e0c..de2f09c 100644
--- a/src/com/android/customization/widget/OptionSelectorController.java
+++ b/src/com/android/customization/widget/OptionSelectorController.java
@@ -111,7 +111,12 @@
         if (!mOptions.contains(option)) {
             throw new IllegalArgumentException("Invalid option");
         }
+        CustomizationOption lastAppliedOption = mAppliedOption;
         mAppliedOption = option;
+        mAdapter.notifyItemChanged(mOptions.indexOf(option));
+        if (lastAppliedOption != null) {
+            mAdapter.notifyItemChanged(mOptions.indexOf(lastAppliedOption));
+        }
     }
 
     private void updateActivatedStatus(CustomizationOption option, boolean isActivated) {