Add more actions to be supported by IndividualPickerFragment

Add two more actions to be supported by IndividualPickerFragment

Bug: 151286377
Bug: 151286784
Change-Id: If53505c0206e84b0c22ab45e25fd542f02fe24d9
diff --git a/res/layout/bottom_actions_layout.xml b/res/layout/bottom_actions_layout.xml
index 14bea38..cccc116 100644
--- a/res/layout/bottom_actions_layout.xml
+++ b/res/layout/bottom_actions_layout.xml
@@ -61,17 +61,26 @@
             android:layout_height="match_parent"
             android:src="@drawable/ic_rotation_gm2_24px"
             android:visibility="gone"
-            app:layout_constraintEnd_toStartOf="@id/action_information"
+            app:layout_constraintEnd_toStartOf="@id/action_delete"
             app:layout_constraintStart_toEndOf="@id/action_cancel" />
 
         <ImageView
+            android:id="@+id/action_delete"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:src="@drawable/ic_delete_24px"
+            android:visibility="gone"
+            app:layout_constraintEnd_toStartOf="@id/action_information"
+            app:layout_constraintStart_toEndOf="@id/action_rotation" />
+
+        <ImageView
             android:id="@+id/action_information"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:src="@drawable/ic_info_gm2_24px"
             android:visibility="gone"
             app:layout_constraintEnd_toStartOf="@id/action_edit"
-            app:layout_constraintStart_toEndOf="@id/action_rotation" />
+            app:layout_constraintStart_toEndOf="@id/action_delete" />
 
         <ImageView
             android:id="@+id/action_edit"
@@ -79,17 +88,34 @@
             android:layout_height="match_parent"
             android:src="@drawable/ic_mode_edit_gm2_24px"
             android:visibility="gone"
-            app:layout_constraintEnd_toStartOf="@id/action_apply"
+            app:layout_constraintEnd_toStartOf="@id/action_download"
             app:layout_constraintStart_toEndOf="@id/action_information" />
 
         <ImageView
+            android:id="@+id/action_download"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:src="@drawable/ic_file_download_gm2_24px"
+            android:visibility="gone"
+            app:layout_constraintEnd_toStartOf="@id/action_progress"
+            app:layout_constraintStart_toEndOf="@id/action_edit" />
+
+        <ProgressBar
+            android:id="@+id/action_progress"
+            android:layout_width="@dimen/bottom_action_icon_size"
+            android:layout_height="wrap_content"
+            android:visibility="gone"
+            app:layout_constraintEnd_toStartOf="@id/action_apply"
+            app:layout_constraintStart_toEndOf="@id/action_download" />
+
+        <ImageView
             android:id="@+id/action_apply"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:src="@drawable/ic_done_gm2_24px"
             android:visibility="gone"
             app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintStart_toEndOf="@id/action_edit" />
+            app:layout_constraintStart_toEndOf="@id/action_progress" />
 
     </androidx.constraintlayout.widget.ConstraintLayout>
 </LinearLayout>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index b43d350..6b0ff2a 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -212,6 +212,7 @@
     <dimen name="bottom_action_bar_padding_horizontal">16dp</dimen>
     <dimen name="bottom_action_bar_padding_vertical">20dp</dimen>
     <dimen name="bottom_action_bar_elevation">10dp</dimen>
+    <dimen name="bottom_action_icon_size">24dp</dimen>
 
     <dimen name="option_border_width">2dp</dimen>
     <dimen name="option_selected_border_width">3dp</dimen>
diff --git a/src/com/android/wallpaper/picker/LivePreviewFragment.java b/src/com/android/wallpaper/picker/LivePreviewFragment.java
index 0a3003d..6e2c1ba 100644
--- a/src/com/android/wallpaper/picker/LivePreviewFragment.java
+++ b/src/com/android/wallpaper/picker/LivePreviewFragment.java
@@ -71,10 +71,10 @@
 public class LivePreviewFragment extends PreviewFragment implements
         WallpaperConnection.WallpaperConnectionListener {
 
-    private static final String TAG = "LivePreviewFragment";
+    public static final String EXTRA_LIVE_WALLPAPER_INFO = "android.live_wallpaper.info";
+    public static final String KEY_ACTION_DELETE_LIVE_WALLPAPER = "action_delete_live_wallpaper";
 
-    private static final String KEY_ACTION_DELETE_LIVE_WALLPAPER = "action_delete_live_wallpaper";
-    private static final String EXTRA_LIVE_WALLPAPER_INFO = "android.live_wallpaper.info";
+    private static final String TAG = "LivePreviewFragment";
 
     /**
      * Instance of {@link WallpaperConnection} used to bind to the live wallpaper service to show
diff --git a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
index a2b13a0..b48c9f7 100755
--- a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
+++ b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
@@ -114,6 +114,10 @@
      */
     static final int SPECIAL_FIXED_TILE_ADAPTER_POSITION = 0;
     static final String ARG_CATEGORY_COLLECTION_ID = "category_collection_id";
+    /**
+     * A temporary flag to hide the bottom action bar feature.
+     */
+    static final boolean TEMP_BOTTOM_ACTION_BAR_FEATURE = false;
 
     private static final String TAG = "IndividualPickerFrgmnt";
     private static final int UNUSED_REQUEST_CODE = 1;
@@ -126,11 +130,6 @@
     private static final String KEY_NIGHT_MODE = "IndividualPickerFragment.NIGHT_MODE";
 
     /**
-     * A temporary flag to hide the bottom action bar feature.
-     */
-    private static final boolean TEMP_BOTTOM_ACTION_BAR_FEATURE = false;
-
-    /**
      * An interface for updating the thumbnail with the specific wallpaper.
      */
     public interface ThumbnailUpdater {
@@ -209,6 +208,8 @@
         }
     };
     PackageStatusNotifier.Listener mAppStatusListener;
+    BottomActionBar mBottomActionBar;
+    @Nullable WallpaperInfo mSelectedWallpaperInfo;
 
     private ProgressDialog mProgressDialog;
     private boolean mTestingMode;
@@ -252,10 +253,8 @@
         }
     };
 
-    private BottomActionBar mBottomActionBar;
     private WallpaperSetter mWallpaperSetter;
     private WallpaperPersister mWallpaperPersister;
-    @Nullable private WallpaperInfo mSelectedWallpaperInfo;
     private WallpaperInfo mAppliedWallpaperInfo;
     private WallpaperManager mWallpaperManager;
     private int mWallpaperDestination;
@@ -452,33 +451,7 @@
         maybeSetUpImageGrid();
 
         setUpBottomSheet();
-
-        if (TEMP_BOTTOM_ACTION_BAR_FEATURE) {
-            mBottomActionBar = getActivity().findViewById(R.id.bottom_actionbar);
-
-            mBottomActionBar.setActionClickListener(CANCEL, unused -> {
-                if (mSelectedWallpaperInfo != null) {
-                    onWallpaperSelected(null, 0);
-                    return;
-                }
-                getActivity().onBackPressed();
-            });
-            mBottomActionBar.setActionClickListener(ROTATION, unused -> {
-                DialogFragment startRotationDialogFragment = new StartRotationDialogFragment();
-                startRotationDialogFragment.setTargetFragment(
-                        IndividualPickerFragment.this, UNUSED_REQUEST_CODE);
-                startRotationDialogFragment.show(getFragmentManager(), TAG_START_ROTATION_DIALOG);
-            });
-            mBottomActionBar.setActionClickListener(APPLY, unused -> {
-                mBottomActionBar.disableActions();
-                mWallpaperSetter.requestDestination(getActivity(), getFragmentManager(), this,
-                        mSelectedWallpaperInfo instanceof LiveWallpaperInfo);
-            });
-
-            mBottomActionBar.show();
-            mBottomActionBar.showActionsOnly(
-                    isRotationEnabled() ? EnumSet.of(CANCEL, ROTATION) : EnumSet.of(CANCEL));
-        }
+        setupBottomActionBar();
 
         return view;
     }
@@ -565,6 +538,35 @@
         });
     }
 
+    void setupBottomActionBar() {
+        if (TEMP_BOTTOM_ACTION_BAR_FEATURE) {
+            mBottomActionBar = getActivity().findViewById(R.id.bottom_actionbar);
+
+            mBottomActionBar.setActionClickListener(CANCEL, unused -> {
+                if (mSelectedWallpaperInfo != null) {
+                    onWallpaperSelected(null, 0);
+                    return;
+                }
+                getActivity().onBackPressed();
+            });
+            mBottomActionBar.setActionClickListener(ROTATION, unused -> {
+                DialogFragment startRotationDialogFragment = new StartRotationDialogFragment();
+                startRotationDialogFragment.setTargetFragment(
+                        IndividualPickerFragment.this, UNUSED_REQUEST_CODE);
+                startRotationDialogFragment.show(getFragmentManager(), TAG_START_ROTATION_DIALOG);
+            });
+            mBottomActionBar.setActionClickListener(APPLY, unused -> {
+                mBottomActionBar.disableActions();
+                mWallpaperSetter.requestDestination(getActivity(), getFragmentManager(), this,
+                        mSelectedWallpaperInfo instanceof LiveWallpaperInfo);
+            });
+
+            mBottomActionBar.show();
+            mBottomActionBar.showActionsOnly(
+                    isRotationEnabled() ? EnumSet.of(CANCEL, ROTATION) : EnumSet.of(CANCEL));
+        }
+    }
+
     @Override
     public void onResume() {
         super.onResume();
@@ -897,7 +899,7 @@
         }
     }
 
-    private void updateBottomActions(boolean hasWallpaperSelected) {
+    void updateBottomActions(boolean hasWallpaperSelected) {
         mBottomActionBar.showActions(
                 hasWallpaperSelected ? EnumSet.of(APPLY, INFORMATION) : EnumSet.of(ROTATION));
         mBottomActionBar.hideActions(
@@ -927,7 +929,7 @@
         wallpaperDestinationCallback.onDestinationSet(destination);
     }
 
-    private void onWallpaperSelected(@Nullable WallpaperInfo newSelectedWallpaperInfo,
+    void onWallpaperSelected(@Nullable WallpaperInfo newSelectedWallpaperInfo,
                                      int position) {
         if (mSelectedWallpaperInfo == newSelectedWallpaperInfo) {
             return;
diff --git a/src/com/android/wallpaper/widget/BottomActionBar.java b/src/com/android/wallpaper/widget/BottomActionBar.java
index 77b1bba..626182c 100644
--- a/src/com/android/wallpaper/widget/BottomActionBar.java
+++ b/src/com/android/wallpaper/widget/BottomActionBar.java
@@ -44,9 +44,10 @@
 /** A {@code ViewGroup} which provides the specific actions for the user to interact with. */
 public class BottomActionBar extends FrameLayout {
 
+    // TODO(b/154299462): Separate downloadable related actions from WallpaperPicker.
     /** The action items in the bottom action bar. */
     public enum BottomAction {
-        CANCEL, ROTATION, INFORMATION, EDIT, APPLY,
+        CANCEL, ROTATION, DELETE, INFORMATION, EDIT, DOWNLOAD, PROGRESS, APPLY,
     }
 
     private final Map<BottomAction, View> mActionList = new EnumMap<>(BottomAction.class);
@@ -65,8 +66,11 @@
 
         mActionList.put(BottomAction.CANCEL, findViewById(R.id.action_cancel));
         mActionList.put(BottomAction.ROTATION, findViewById(R.id.action_rotation));
+        mActionList.put(BottomAction.DELETE, findViewById(R.id.action_delete));
         mActionList.put(BottomAction.INFORMATION, findViewById(R.id.action_information));
         mActionList.put(BottomAction.EDIT, findViewById(R.id.action_edit));
+        mActionList.put(BottomAction.DOWNLOAD, findViewById(R.id.action_download));
+        mActionList.put(BottomAction.PROGRESS, findViewById(R.id.action_progress));
         mActionList.put(BottomAction.APPLY, findViewById(R.id.action_apply));
 
         ViewGroup bottomSheet = findViewById(R.id.action_bottom_sheet);
@@ -219,6 +223,30 @@
         mActionList.forEach((bottomAction, view) -> view.setEnabled(enable));
     }
 
+    /**
+     * Enables specified actions' {@link View}.
+     *
+     * @param actions the specified actions to enable their views
+     */
+    public void enableActions(EnumSet<BottomAction> actions) {
+        enableActions(/* enable= */ true, actions);
+    }
+
+    /**
+     * Disables specified actions' {@link View}.
+     *
+     * @param actions the specified actions to disable their views
+     */
+    public void disableActions(EnumSet<BottomAction> actions) {
+        enableActions(/* enable= */ false, actions);
+    }
+
+    private void enableActions(boolean enable, EnumSet<BottomAction> actions) {
+        actions.forEach(bottomAction -> {
+            mActionList.get(bottomAction).setEnabled(enable);
+        });
+    }
+
     private void showActions(EnumSet<BottomAction> actions, boolean show) {
         actions.forEach(bottomAction ->
                 mActionList.get(bottomAction).setVisibility(show ? VISIBLE : GONE));