Merge d7b211e519969461139d5faed47d5922eab50ef2 on remote branch

Change-Id: Ia07880caba60beb8711ee03a60d58ec7669b183a
diff --git a/res/values-af/strings.xml b/res/values-af/strings.xml
index e91262c..c381330 100644
--- a/res/values-af/strings.xml
+++ b/res/values-af/strings.xml
@@ -56,9 +56,9 @@
     <string name="wallpaper_disabled_by_administrator_message" msgid="1551430406714747884">"Jou toesteladministrateur het die stel van \'n muurpapier gedeaktiveer"</string>
     <string name="wallpaper_set_successfully_message" msgid="2958998799111688578">"Muurpapier is suksesvol gestel"</string>
     <string name="wallpapers_unavailable_offline_message" msgid="8136405438621689532">"Jy moet \'n internetverbinding hê om muurpapiere te bekyk. Koppel en probeer weer."</string>
-    <string name="currently_set_home_wallpaper_thumbnail" msgid="4022381436821898917">"Kleinkiekie van die muurpapier wat tans op die tuisskerm gestel is"</string>
-    <string name="currently_set_lock_wallpaper_thumbnail" msgid="2094209303934569997">"Kleinkiekie van die muurpapier wat tans op die sluitskerm gestel is"</string>
-    <string name="currently_set_wallpaper_thumbnail" msgid="8651887838745545107">"Kleinkiekie van die muurpapier wat tans gestel is"</string>
+    <string name="currently_set_home_wallpaper_thumbnail" msgid="4022381436821898917">"Miniprent van die muurpapier wat tans op die tuisskerm gestel is"</string>
+    <string name="currently_set_lock_wallpaper_thumbnail" msgid="2094209303934569997">"Miniprent van die muurpapier wat tans op die sluitskerm gestel is"</string>
+    <string name="currently_set_wallpaper_thumbnail" msgid="8651887838745545107">"Miniprent van die muurpapier wat tans gestel is"</string>
     <string name="wallpaper_thumbnail" msgid="569931475923605974">"Muurpapierkleinkiekie"</string>
     <string name="explore_home_screen" msgid="8756346794535765482">"Verken tuisskermmuurpapier"</string>
     <string name="explore_lock_screen" msgid="268938342103703665">"Verken sluitskermmuurpapier"</string>
diff --git a/res/values-ta/strings.xml b/res/values-ta/strings.xml
index 58624eb..9c62a1b 100644
--- a/res/values-ta/strings.xml
+++ b/res/values-ta/strings.xml
@@ -56,10 +56,10 @@
     <string name="wallpaper_disabled_by_administrator_message" msgid="1551430406714747884">"வால்பேப்பர் அமைவைச் சாதன நிர்வாகி முடக்கியுள்ளார்"</string>
     <string name="wallpaper_set_successfully_message" msgid="2958998799111688578">"வால்பேப்பர் அமைக்கப்பட்டது"</string>
     <string name="wallpapers_unavailable_offline_message" msgid="8136405438621689532">"வால்பேப்பர்களைப் பார்க்க, இணைய இணைப்புத் தேவை. இணையத்துடன் இணைத்து, மீண்டும் முயலவும்."</string>
-    <string name="currently_set_home_wallpaper_thumbnail" msgid="4022381436821898917">"தற்போது அமைக்கப்பட்டுள்ள முகப்புத் திரை வால்பேப்பரின் சிறு படம்"</string>
-    <string name="currently_set_lock_wallpaper_thumbnail" msgid="2094209303934569997">"தற்போது அமைக்கப்பட்டுள்ள பூட்டுத் திரை வால்பேப்பரின் சிறு படம்"</string>
-    <string name="currently_set_wallpaper_thumbnail" msgid="8651887838745545107">"தற்போது அமைக்கப்பட்டுள்ள வால்பேப்பரின் சிறு படம்"</string>
-    <string name="wallpaper_thumbnail" msgid="569931475923605974">"வால்பேப்பரின் சிறு படம்"</string>
+    <string name="currently_set_home_wallpaper_thumbnail" msgid="4022381436821898917">"தற்போது அமைக்கப்பட்டுள்ள முகப்புத் திரை வால்பேப்பரின் சிறுபடம்"</string>
+    <string name="currently_set_lock_wallpaper_thumbnail" msgid="2094209303934569997">"தற்போது அமைக்கப்பட்டுள்ள பூட்டுத் திரை வால்பேப்பரின் சிறுபடம்"</string>
+    <string name="currently_set_wallpaper_thumbnail" msgid="8651887838745545107">"தற்போது அமைக்கப்பட்டுள்ள வால்பேப்பரின் சிறுபடம்"</string>
+    <string name="wallpaper_thumbnail" msgid="569931475923605974">"வால்பேப்பரின் சிறுபடம்"</string>
     <string name="explore_home_screen" msgid="8756346794535765482">"முகப்புத் திரை வால்பேப்பர் பற்றி மேலும் அறிவதற்கான பட்டன்"</string>
     <string name="explore_lock_screen" msgid="268938342103703665">"பூட்டுத் திரை வால்பேப்பர் பற்றி மேலும் அறிவதற்கான பட்டன்"</string>
     <string name="refresh_daily_wallpaper_home_content_description" msgid="2770445044556164259">"முகப்புத் திரையில் தினசரி வால்பேப்பரைப் புதுப்பிக்கும் பட்டன்"</string>
diff --git a/res/values-te/strings.xml b/res/values-te/strings.xml
index ed8bc4e..8d2a8b6 100644
--- a/res/values-te/strings.xml
+++ b/res/values-te/strings.xml
@@ -56,10 +56,10 @@
     <string name="wallpaper_disabled_by_administrator_message" msgid="1551430406714747884">"మీ పరికర నిర్వాహకులు వాల్‌పేపర్‌ను సెట్ చేయడం నిలిపివేసారు"</string>
     <string name="wallpaper_set_successfully_message" msgid="2958998799111688578">"వాల్‌పేపర్ విజయవంతంగా సెట్ చేయబడింది"</string>
     <string name="wallpapers_unavailable_offline_message" msgid="8136405438621689532">"వాల్‌పేపర్‌లను చూడాలంటే మీరు ఇంటర్నెట్ కనెక్షన్‌ని కలిగి ఉండాలి. దయచేసి కనెక్ట్ చేసి, మళ్లీ ప్రయత్నించండి."</string>
-    <string name="currently_set_home_wallpaper_thumbnail" msgid="4022381436821898917">"ప్రస్తుతం సెట్ చేసిన హోమ్ స్క్రీన్ వాల్‌పేపర్ సూక్ష్మచిత్రం"</string>
-    <string name="currently_set_lock_wallpaper_thumbnail" msgid="2094209303934569997">"ప్రస్తుతం సెట్ చేసిన లాక్ స్క్రీన్ వాల్‌పేపర్ సూక్ష్మచిత్రం"</string>
-    <string name="currently_set_wallpaper_thumbnail" msgid="8651887838745545107">"ప్రస్తుతం సెట్ చేసిన వాల్‌పేపర్ సూక్ష్మచిత్రం"</string>
-    <string name="wallpaper_thumbnail" msgid="569931475923605974">"వాల్‌పేపర్ సూక్ష్మచిత్రం"</string>
+    <string name="currently_set_home_wallpaper_thumbnail" msgid="4022381436821898917">"ప్రస్తుతం సెట్ చేసిన హోమ్ స్క్రీన్ వాల్‌పేపర్ థంబ్‌నెయిల్‌"</string>
+    <string name="currently_set_lock_wallpaper_thumbnail" msgid="2094209303934569997">"ప్రస్తుతం సెట్ చేసిన లాక్ స్క్రీన్ వాల్‌పేపర్ థంబ్‌నెయిల్‌"</string>
+    <string name="currently_set_wallpaper_thumbnail" msgid="8651887838745545107">"ప్రస్తుతం సెట్ చేసిన వాల్‌పేపర్ థంబ్‌నెయిల్‌"</string>
+    <string name="wallpaper_thumbnail" msgid="569931475923605974">"వాల్‌పేపర్ థంబ్‌నెయిల్‌"</string>
     <string name="explore_home_screen" msgid="8756346794535765482">"హోమ్ స్క్రీన్ వాల్‌పేపర్‌ను అన్వేషిస్తుంది"</string>
     <string name="explore_lock_screen" msgid="268938342103703665">"లాక్ స్క్రీన్ వాల్‌పేపర్‌ను అన్వేషిస్తుంది"</string>
     <string name="refresh_daily_wallpaper_home_content_description" msgid="2770445044556164259">"రోజువారీ హోమ్ స్క్రీన్ వాల్‌పేపర్‌ను రిఫ్రెష్ చేస్తుంది"</string>
diff --git a/res/values-zh-rHK/strings.xml b/res/values-zh-rHK/strings.xml
index 94f4912..27930bf 100644
--- a/res/values-zh-rHK/strings.xml
+++ b/res/values-zh-rHK/strings.xml
@@ -32,10 +32,10 @@
     <string name="home_screen_message" msgid="106444102822522813">"主畫面"</string>
     <string name="lock_screen_message" msgid="1534506081955058013">"上鎖畫面"</string>
     <string name="home_and_lock_short_label" msgid="2937922943541927983">"主畫面及上鎖畫面"</string>
-    <string name="set_wallpaper_dialog_message" msgid="2110475703996853076">"設定以下畫面的桌布:"</string>
+    <string name="set_wallpaper_dialog_message" msgid="2110475703996853076">"設定桌布"</string>
     <string name="set_wallpaper_home_screen_destination" msgid="7315594722013109354">"主畫面"</string>
     <string name="set_wallpaper_lock_screen_destination" msgid="6224685559375417945">"上鎖畫面"</string>
-    <string name="set_wallpaper_both_destination" msgid="233216830256235288">"主畫面和螢幕鎖定畫面"</string>
+    <string name="set_wallpaper_both_destination" msgid="233216830256235288">"主畫面和上鎖畫面"</string>
     <string name="no_backup_image_wallpaper_label" msgid="6316627676107284851">"正在輪替顯示圖片桌布"</string>
     <string name="permission_needed_explanation" msgid="139166837541426823">"如要在此顯示目前的桌布,「<xliff:g id="APP_NAME">%1$s</xliff:g>」需要存取您裝置的儲存空間。"</string>
     <string name="permission_needed_explanation_go_to_settings" msgid="3923551582092599609">"如要在此顯示目前的桌布,「桌布」需要存取您裝置的儲存空間。\n\n如要變更此設定,請前往「桌布」應用程式資訊的「權限」部分。"</string>
diff --git a/src/com/android/wallpaper/model/SetWallpaperViewModel.java b/src/com/android/wallpaper/model/SetWallpaperViewModel.java
new file mode 100644
index 0000000..efd55d3
--- /dev/null
+++ b/src/com/android/wallpaper/model/SetWallpaperViewModel.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.wallpaper.model;
+
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.lifecycle.LiveData;
+import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.ViewModel;
+import androidx.lifecycle.ViewModelProvider;
+
+import com.android.wallpaper.module.WallpaperPersister.Destination;
+import com.android.wallpaper.module.WallpaperPersister.SetWallpaperCallback;
+
+/**
+ * {@link ViewModel} class that keeps track of the status of the "Set wallpaper" operation.
+ */
+public class SetWallpaperViewModel extends ViewModel {
+
+    private static final String TAG = "SetWallpaperViewModel";
+
+    public enum SetWallpaperStatus {
+        UNKNOWN, PENDING, SUCCESS, ERROR
+    }
+
+    /**
+     * @return a {@link SetWallpaperCallback} to set as listener for
+     * {@link WallpaperSetter#setCurrentWallpaper} that will update the
+     * {@link SetWallpaperViewModel} obtained from the given provider.
+     */
+    public static SetWallpaperCallback getCallback(@NonNull ViewModelProvider provider) {
+        SetWallpaperViewModel viewModel = provider.get(SetWallpaperViewModel.class);
+        return new SetWallpaperCallback() {
+            @Override
+            public void onSuccess(WallpaperInfo wallpaperInfo) {
+                Log.d(TAG, "SetWallpaperCallback success");
+                viewModel.mStatus.setValue(SetWallpaperStatus.SUCCESS);
+            }
+
+            @Override
+            public void onError(@Nullable Throwable throwable) {
+                Log.w(TAG, "SetWallpaperCallback error", throwable);
+                viewModel.mStatus.setValue(SetWallpaperStatus.ERROR);
+            }
+        };
+    }
+
+    private final MutableLiveData<SetWallpaperStatus> mStatus = new MutableLiveData<>();
+
+    @Destination
+    private int mDestination;
+
+    public SetWallpaperViewModel() {
+        mStatus.setValue(SetWallpaperStatus.UNKNOWN);
+    }
+
+    public LiveData<SetWallpaperStatus> getStatus() {
+        return mStatus;
+    }
+
+    public int getDestination() {
+        return mDestination;
+    }
+
+    public void setDestination(int destination) {
+        mDestination = destination;
+    }
+}
diff --git a/src/com/android/wallpaper/module/WallpaperSetter.java b/src/com/android/wallpaper/module/WallpaperSetter.java
index 9d5bb96..dbb6c76 100644
--- a/src/com/android/wallpaper/module/WallpaperSetter.java
+++ b/src/com/android/wallpaper/module/WallpaperSetter.java
@@ -21,6 +21,7 @@
 
 import com.android.wallpaper.R;
 import com.android.wallpaper.asset.Asset;
+import com.android.wallpaper.asset.BuiltInWallpaperAsset;
 import com.android.wallpaper.model.LiveWallpaperInfo;
 import com.android.wallpaper.model.WallpaperInfo;
 import com.android.wallpaper.module.UserEventLogger.WallpaperSetFailureReason;
@@ -153,6 +154,7 @@
                                 if (event == Event.ON_DESTROY) {
                                     if (mProgressDialog != null) {
                                         mProgressDialog.dismiss();
+                                        mProgressDialog = null;
                                     }
                                 }
                             }
@@ -302,7 +304,9 @@
             SetWallpaperDialogFragment setWallpaperDialog = new SetWallpaperDialogFragment();
             setWallpaperDialog.setTitleResId(titleResId);
             setWallpaperDialog.setListener(listenerWrapper);
-            if (homeWallpaper instanceof LiveWallpaperInfo && lockWallpaper == null) {
+            boolean isBuiltIn = homeWallpaper.getAsset(activity) instanceof BuiltInWallpaperAsset;
+            if ((homeWallpaper instanceof LiveWallpaperInfo || isBuiltIn)
+                    && lockWallpaper == null) {
                 if (isLiveWallpaper) {
                     // If lock wallpaper is live and we're setting a live wallpaper, we can only
                     // set it to both, so bypass the dialog.
diff --git a/src/com/android/wallpaper/picker/ImagePreviewFragment.java b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
index c41d394..9a91b96 100755
--- a/src/com/android/wallpaper/picker/ImagePreviewFragment.java
+++ b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
@@ -60,11 +60,10 @@
 import com.android.wallpaper.R;
 import com.android.wallpaper.asset.Asset;
 import com.android.wallpaper.asset.CurrentWallpaperAssetVN;
-import com.android.wallpaper.model.WallpaperInfo;
+import com.android.wallpaper.model.SetWallpaperViewModel;
 import com.android.wallpaper.module.BitmapCropper;
 import com.android.wallpaper.module.InjectorProvider;
 import com.android.wallpaper.module.WallpaperPersister.Destination;
-import com.android.wallpaper.module.WallpaperPersister.SetWallpaperCallback;
 import com.android.wallpaper.util.FullScreenAnimation;
 import com.android.wallpaper.util.ResourceUtils;
 import com.android.wallpaper.util.ScreenSizeCalculator;
@@ -111,6 +110,7 @@
     private TouchForwardingLayout mTouchForwardingLayout;
     private ConstraintLayout mContainer;
     private SurfaceView mWallpaperSurface;
+    private boolean mIsSurfaceCreated = false;
 
     protected SurfaceView mWorkspaceSurface;
     protected WorkspaceSurfaceHolderCallback mWorkspaceSurfaceCallback;
@@ -480,17 +480,7 @@
     protected void setCurrentWallpaper(@Destination int destination) {
         mWallpaperSetter.setCurrentWallpaper(getActivity(), mWallpaper, mWallpaperAsset,
                 destination, mFullResImageView.getScale(), calculateCropRect(getContext()),
-                new SetWallpaperCallback() {
-                    @Override
-                    public void onSuccess(WallpaperInfo wallpaperInfo) {
-                        finishActivity(/* success= */ true);
-                    }
-
-                    @Override
-                    public void onError(@Nullable Throwable throwable) {
-                        showSetWallpaperErrorDialog(destination);
-                    }
-                });
+                SetWallpaperViewModel.getCallback(mViewModelProvider));
     }
 
     private void renderWorkspaceSurface() {
@@ -566,17 +556,22 @@
                 // Load a low-res placeholder image if there's a thumbnail available from the asset
                 // that can be shown to the user more quickly than the full-sized image.
                 Activity activity = requireActivity();
+                // Change to background color if colorValue is Color.TRANSPARENT
                 int placeHolderColor = ResourceUtils.getColorAttr(activity,
                         android.R.attr.colorBackground);
                 if (mPlaceholderColorFuture.isDone()) {
                     try {
-                        placeHolderColor = mWallpaper.computePlaceholderColor(context).get();
+                        int colorValue = mWallpaper.computePlaceholderColor(context).get();
+                        if (colorValue != Color.TRANSPARENT) {
+                            placeHolderColor = colorValue;
+                        }
                     } catch (InterruptedException | ExecutionException e) {
                         // Do nothing
                     }
                 }
                 mWallpaperSurface.setResizeBackgroundColor(placeHolderColor);
                 mWallpaperSurface.setBackgroundColor(placeHolderColor);
+                mLowResImageView.setBackgroundColor(placeHolderColor);
 
                 mWallpaperAsset.loadLowResDrawable(activity, mLowResImageView, placeHolderColor,
                         mPreviewBitmapTransformation);
@@ -593,6 +588,9 @@
                 mHost.setView(wallpaperPreviewContainer, wallpaperPreviewContainer.getWidth(),
                         wallpaperPreviewContainer.getHeight());
                 mWallpaperSurface.setChildSurfacePackage(mHost.getSurfacePackage());
+                // After surface creating, update workspaceSurface.
+                mIsSurfaceCreated = true;
+                updateScreenPreview(mLastSelectedTabPositionOptional.orElse(0) == 0);
             }
         }
 
@@ -607,12 +605,15 @@
                 mHost.release();
                 mHost = null;
             }
+            mIsSurfaceCreated = false;
         }
     }
 
     @Override
     protected void updateScreenPreview(boolean isHomeSelected) {
-        mWorkspaceSurface.setVisibility(isHomeSelected ? View.VISIBLE : View.INVISIBLE);
+        // Use View.GONE for WorkspaceSurface's visibility before its surface is created.
+        mWorkspaceSurface.setVisibility(isHomeSelected && mIsSurfaceCreated ? View.VISIBLE :
+                View.GONE);
 
         mLockPreviewContainer.setVisibility(isHomeSelected ? View.INVISIBLE : View.VISIBLE);
 
diff --git a/src/com/android/wallpaper/picker/LivePreviewFragment.java b/src/com/android/wallpaper/picker/LivePreviewFragment.java
index ec17767..b342e24 100644
--- a/src/com/android/wallpaper/picker/LivePreviewFragment.java
+++ b/src/com/android/wallpaper/picker/LivePreviewFragment.java
@@ -65,7 +65,7 @@
 
 import com.android.wallpaper.R;
 import com.android.wallpaper.compat.BuildCompat;
-import com.android.wallpaper.module.WallpaperPersister.SetWallpaperCallback;
+import com.android.wallpaper.model.SetWallpaperViewModel;
 import com.android.wallpaper.util.FullScreenAnimation;
 import com.android.wallpaper.util.ResourceUtils;
 import com.android.wallpaper.util.ScreenSizeCalculator;
@@ -444,17 +444,7 @@
     @Override
     protected void setCurrentWallpaper(int destination) {
         mWallpaperSetter.setCurrentWallpaper(getActivity(), mWallpaper, null,
-                destination, 0, null, new SetWallpaperCallback() {
-                    @Override
-                    public void onSuccess(com.android.wallpaper.model.WallpaperInfo wallpaperInfo) {
-                        finishActivity(/* success= */ true);
-                    }
-
-                    @Override
-                    public void onError(@Nullable Throwable throwable) {
-                        showSetWallpaperErrorDialog(destination);
-                    }
-                });
+                destination, 0, null, SetWallpaperViewModel.getCallback(mViewModelProvider));
     }
 
     @Nullable
diff --git a/src/com/android/wallpaper/picker/PreviewFragment.java b/src/com/android/wallpaper/picker/PreviewFragment.java
index 74bdd6f..172bacd 100755
--- a/src/com/android/wallpaper/picker/PreviewFragment.java
+++ b/src/com/android/wallpaper/picker/PreviewFragment.java
@@ -23,6 +23,7 @@
 import android.content.Intent;
 import android.content.res.Resources.NotFoundException;
 import android.os.Bundle;
+import android.os.Handler;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.SurfaceView;
@@ -39,9 +40,11 @@
 import androidx.annotation.LayoutRes;
 import androidx.annotation.Nullable;
 import androidx.fragment.app.FragmentActivity;
+import androidx.lifecycle.ViewModelProvider;
 
 import com.android.wallpaper.R;
 import com.android.wallpaper.model.LiveWallpaperInfo;
+import com.android.wallpaper.model.SetWallpaperViewModel;
 import com.android.wallpaper.model.WallpaperInfo;
 import com.android.wallpaper.module.Injector;
 import com.android.wallpaper.module.InjectorProvider;
@@ -80,7 +83,6 @@
      * wallpaper with pan and crop position to the device.
      */
     static final int MODE_CROP_AND_SET_WALLPAPER = 1;
-    private Optional<Integer> mLastSelectedTabPositionOptional = Optional.empty();
 
     /**
      * Possible preview modes for the fragment.
@@ -139,6 +141,9 @@
     @PreviewMode protected int mPreviewMode;
     protected boolean mViewAsHome;
 
+    protected SetWallpaperViewModel mSetWallpaperViewModel;
+    protected ViewModelProvider mViewModelProvider;
+    protected Optional<Integer> mLastSelectedTabPositionOptional = Optional.empty();
     private OnBackPressedCallback mOnBackPressedCallback;
 
     /**
@@ -166,6 +171,9 @@
         mWallpaperSetter = new WallpaperSetter(injector.getWallpaperPersister(appContext),
                 injector.getPreferences(appContext), mUserEventLogger, mTestingModeEnabled);
 
+        mViewModelProvider = new ViewModelProvider(requireActivity());
+        mSetWallpaperViewModel = mViewModelProvider.get(SetWallpaperViewModel.class);
+
         Activity activity = getActivity();
         List<String> attributions = getAttributions(activity);
         if (attributions.size() > 0 && attributions.get(0) != null) {
@@ -284,12 +292,28 @@
                     requireFragmentManager(), TAG_SET_WALLPAPER_ERROR_DIALOG_FRAGMENT);
             mStagedSetWallpaperErrorDialogFragment = null;
         }
+
+        mSetWallpaperViewModel.getStatus().observe(requireActivity(), setWallpaperStatus -> {
+            switch (setWallpaperStatus) {
+                case SUCCESS:
+                    // Give a few millis before finishing to allow for the dialog dismiss
+                    // and animations to finish
+                    Handler.getMain().postDelayed(() -> finishActivity(true), 300);
+                    break;
+                case ERROR:
+                    showSetWallpaperErrorDialog(mSetWallpaperViewModel.getDestination());
+                    break;
+                default:
+                    // Do nothing in this case, either status is pending, or unknown
+            }
+        });
     }
 
     protected abstract boolean isLoaded();
 
     @Override
     public void onSet(int destination) {
+        mSetWallpaperViewModel.setDestination(destination);
         setCurrentWallpaper(destination);
     }
 
@@ -300,6 +324,7 @@
 
     @Override
     public void onClickTryAgain(@Destination int wallpaperDestination) {
+        mSetWallpaperViewModel.setDestination(wallpaperDestination);
         setCurrentWallpaper(wallpaperDestination);
     }
 
@@ -375,8 +400,8 @@
             }
             activity.setResult(Activity.RESULT_OK);
         }
-        activity.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
         activity.finish();
+        activity.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
     }
 
     protected void showSetWallpaperErrorDialog(@Destination int wallpaperDestination) {