Add support for single wallpaper collections

When a collection has only one wallpaper, jump directly into the
wallpaper preview instead of going into the category page.

Also make sure we don't show on-device collections that end-up empty
because they reference not-available live wallpapers only.

Video: https://drive.google.com/file/d/105OmKD3FAATSooAAhWyoPsmfbjUrCsYX/view?usp=sharing

Bug: 187107417
Test: manual
Change-Id: I3f3bb8fd40a89930f76777bc67782351e5b93c82
diff --git a/src/com/android/wallpaper/picker/CategorySelectorFragment.java b/src/com/android/wallpaper/picker/CategorySelectorFragment.java
index 4c04942..0455f47 100644
--- a/src/com/android/wallpaper/picker/CategorySelectorFragment.java
+++ b/src/com/android/wallpaper/picker/CategorySelectorFragment.java
@@ -15,6 +15,9 @@
  */
 package com.android.wallpaper.picker;
 
+import static com.android.wallpaper.picker.WallpaperPickerDelegate.PREVIEW_LIVE_WALLPAPER_REQUEST_CODE;
+import static com.android.wallpaper.picker.WallpaperPickerDelegate.PREVIEW_WALLPAPER_REQUEST_CODE;
+
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.Intent;
@@ -44,6 +47,8 @@
 import com.android.wallpaper.asset.Asset;
 import com.android.wallpaper.model.Category;
 import com.android.wallpaper.model.CategoryProvider;
+import com.android.wallpaper.model.LiveWallpaperInfo;
+import com.android.wallpaper.model.WallpaperInfo;
 import com.android.wallpaper.module.InjectorProvider;
 import com.android.wallpaper.module.UserEventLogger;
 import com.android.wallpaper.util.DeepLinkUtils;
@@ -289,8 +294,9 @@
 
         @Override
         public void onClick(View view) {
+            Activity activity = getActivity();
             final UserEventLogger eventLogger =
-                    InjectorProvider.getInjector().getUserEventLogger(getActivity());
+                    InjectorProvider.getInjector().getUserEventLogger(activity);
             eventLogger.logCategorySelected(mCategory.getCollectionId());
 
             if (mCategory.supportsCustomPhotos()) {
@@ -309,6 +315,20 @@
                 return;
             }
 
+            if (mCategory.isSingleWallpaperCategory()) {
+                WallpaperInfo wallpaper = mCategory.getSingleWallpaper();
+                // Log click on individual wallpaper
+                eventLogger.logIndividualWallpaperSelected(mCategory.getCollectionId());
+
+                InjectorProvider.getInjector().getWallpaperPersister(activity)
+                        .setWallpaperInfoInPreview(wallpaper);
+                wallpaper.showPreview(activity,
+                        new PreviewActivity.PreviewActivityIntentFactory(),
+                        wallpaper instanceof LiveWallpaperInfo ? PREVIEW_LIVE_WALLPAPER_REQUEST_CODE
+                                : PREVIEW_WALLPAPER_REQUEST_CODE);
+                return;
+            }
+
             getCategorySelectorFragmentHost().show(mCategory);
         }