[TP] Refactor util function for instantiating preview fragment
Due to the refactor, we no longer have the newInstance function from
PreviewFragment. Thus we directly instantiate the fragment in the
injector.
Bug: 246968463
Test: manuel testing and it works as before
Change-Id: I223661e2068d6b1c0d32feb45dff8257c6acb6d5
diff --git a/src/com/android/customization/module/DefaultCustomizationInjector.java b/src/com/android/customization/module/DefaultCustomizationInjector.java
index 220c406..9afad41 100644
--- a/src/com/android/customization/module/DefaultCustomizationInjector.java
+++ b/src/com/android/customization/module/DefaultCustomizationInjector.java
@@ -15,9 +15,16 @@
*/
package com.android.customization.module;
+import static com.android.wallpaper.picker.PreviewFragment.ARG_FULL_SCREEN;
+import static com.android.wallpaper.picker.PreviewFragment.ARG_PREVIEW_MODE;
+import static com.android.wallpaper.picker.PreviewFragment.ARG_TESTING_MODE_ENABLED;
+import static com.android.wallpaper.picker.PreviewFragment.ARG_VIEW_AS_HOME;
+import static com.android.wallpaper.picker.PreviewFragment.ARG_WALLPAPER;
+
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
+import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
@@ -26,6 +33,7 @@
import com.android.customization.model.theme.ThemeBundleProvider;
import com.android.customization.model.theme.ThemeManager;
import com.android.wallpaper.model.CategoryProvider;
+import com.android.wallpaper.model.LiveWallpaperInfo;
import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.module.BaseWallpaperInjector;
import com.android.wallpaper.module.CustomizationSections;
@@ -35,6 +43,8 @@
import com.android.wallpaper.module.WallpaperRotationRefresher;
import com.android.wallpaper.monitor.PerformanceMonitor;
import com.android.wallpaper.picker.CustomizationPickerActivity;
+import com.android.wallpaper.picker.ImagePreviewFragment;
+import com.android.wallpaper.picker.LivePreviewFragment;
import com.android.wallpaper.picker.PreviewFragment;
public class DefaultCustomizationInjector extends BaseWallpaperInjector
@@ -97,8 +107,16 @@
boolean viewAsHome,
boolean viewFullScreen,
boolean testingModeEnabled) {
- return PreviewFragment.newInstance(wallpaperInfo, mode, viewAsHome, viewFullScreen,
- testingModeEnabled);
+ Bundle args = new Bundle();
+ args.putParcelable(ARG_WALLPAPER, wallpaperInfo);
+ args.putInt(ARG_PREVIEW_MODE, mode);
+ args.putBoolean(ARG_VIEW_AS_HOME, viewAsHome);
+ args.putBoolean(ARG_FULL_SCREEN, viewFullScreen);
+ args.putBoolean(ARG_TESTING_MODE_ENABLED, testingModeEnabled);
+ PreviewFragment fragment = wallpaperInfo instanceof LiveWallpaperInfo
+ ? new LivePreviewFragment() : new ImagePreviewFragment();
+ fragment.setArguments(args);
+ return fragment;
}
@Override
diff --git a/src_override/com/android/wallpaper/module/WallpapersInjector.java b/src_override/com/android/wallpaper/module/WallpapersInjector.java
index 9f8fe9c..e582fe4 100755
--- a/src_override/com/android/wallpaper/module/WallpapersInjector.java
+++ b/src_override/com/android/wallpaper/module/WallpapersInjector.java
@@ -15,17 +15,27 @@
*/
package com.android.wallpaper.module;
+import static com.android.wallpaper.picker.PreviewFragment.ARG_FULL_SCREEN;
+import static com.android.wallpaper.picker.PreviewFragment.ARG_PREVIEW_MODE;
+import static com.android.wallpaper.picker.PreviewFragment.ARG_TESTING_MODE_ENABLED;
+import static com.android.wallpaper.picker.PreviewFragment.ARG_VIEW_AS_HOME;
+import static com.android.wallpaper.picker.PreviewFragment.ARG_WALLPAPER;
+
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
+import android.os.Bundle;
import androidx.fragment.app.Fragment;
import com.android.wallpaper.model.CategoryProvider;
+import com.android.wallpaper.model.LiveWallpaperInfo;
import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.monitor.PerformanceMonitor;
import com.android.wallpaper.picker.CustomizationPickerActivity;
import com.android.wallpaper.picker.ImagePreviewFragment;
+import com.android.wallpaper.picker.LivePreviewFragment;
+import com.android.wallpaper.picker.PreviewFragment;
/**
* A concrete, real implementation of the dependency provider.
@@ -74,8 +84,16 @@
boolean viewAsHome,
boolean viewFullScreen,
boolean testingModeEnabled) {
- return ImagePreviewFragment.newInstance(wallpaperInfo, mode, viewAsHome, viewFullScreen,
- testingModeEnabled);
+ Bundle args = new Bundle();
+ args.putParcelable(ARG_WALLPAPER, wallpaperInfo);
+ args.putInt(ARG_PREVIEW_MODE, mode);
+ args.putBoolean(ARG_VIEW_AS_HOME, viewAsHome);
+ args.putBoolean(ARG_FULL_SCREEN, viewFullScreen);
+ args.putBoolean(ARG_TESTING_MODE_ENABLED, testingModeEnabled);
+ PreviewFragment fragment = wallpaperInfo instanceof LiveWallpaperInfo
+ ? new LivePreviewFragment() : new ImagePreviewFragment();
+ fragment.setArguments(args);
+ return fragment;
}
@Override