ThemePickerLeaf: Implement custom CustomizationSections

Change-Id: Ic912ac0f6a509d1f308bd91f76ef7a809079bf3b
diff --git a/Android.bp b/Android.bp
index cd949c3..57ddbe3 100644
--- a/Android.bp
+++ b/Android.bp
@@ -15,6 +15,14 @@
  */
 
 filegroup {
+    name: "ThemePickerLeaf_srcs",
+    srcs: [
+        "src/**/*.java",
+        "src/**/*.kt",
+    ],
+}
+
+filegroup {
     name: "ThemePickerLeaf_Manifest",
     srcs: [
         "AndroidManifest.xml",
@@ -50,6 +58,7 @@
     srcs: [
         ":WallpaperPicker2_srcs",
         ":ThemePicker_srcs",
+        ":ThemePickerLeaf_srcs",
     ],
     static_libs: [
         "ThemePickerLeaf-core",
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 6e94108..589b03d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -28,4 +28,9 @@
 
     <uses-permission android:name="com.android.launcher3.permission.READ_SETTINGS" />
     <uses-permission android:name="com.android.launcher3.permission.WRITE_SETTINGS" />
+
+    <application
+        tools:replace="android:name"
+        android:name="org.leafos.customization.picker.LeafCustomizationPickerApplication">
+    </application>
 </manifest>
diff --git a/src/org/leafos/customization/module/LeafCustomizationSections.java b/src/org/leafos/customization/module/LeafCustomizationSections.java
new file mode 100644
index 0000000..dcc2a3b
--- /dev/null
+++ b/src/org/leafos/customization/module/LeafCustomizationSections.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2023 The LeafOS 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 org.leafos.customization.module;
+
+import android.os.Bundle;
+
+import androidx.annotation.Nullable;
+import androidx.fragment.app.FragmentActivity;
+import androidx.lifecycle.LifecycleOwner;
+
+import com.android.wallpaper.model.CustomizationSectionController;
+import com.android.wallpaper.model.CustomizationSectionController.CustomizationSectionNavigationController;
+import com.android.wallpaper.model.PermissionRequester;
+import com.android.wallpaper.model.WallpaperColorsViewModel;
+import com.android.wallpaper.model.WallpaperPreviewNavigator;
+import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
+import com.android.wallpaper.module.CustomizationSections;
+import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInteractor;
+import com.android.wallpaper.picker.customization.ui.viewmodel.WallpaperQuickSwitchViewModel;
+import com.android.wallpaper.util.DisplayUtils;
+
+import java.util.List;
+
+public class LeafCustomizationSections implements CustomizationSections {
+    private CustomizationSections mDefaultCustomizationSections;
+
+    public LeafCustomizationSections(CustomizationSections defaultCustomizationSections) {
+        mDefaultCustomizationSections = defaultCustomizationSections;
+    }
+
+    @Override
+    public List<CustomizationSectionController<?>> getRevampedUISectionControllersForScreen(
+            Screen screen,
+            FragmentActivity activity,
+            LifecycleOwner lifecycleOwner,
+            WallpaperColorsViewModel wallpaperColorsViewModel,
+            PermissionRequester permissionRequester,
+            WallpaperPreviewNavigator wallpaperPreviewNavigator,
+            CustomizationSectionNavigationController sectionNavigationController,
+            @Nullable Bundle savedInstanceState,
+            CurrentWallpaperInfoFactory wallpaperInfoFactory,
+            DisplayUtils displayUtils,
+            WallpaperQuickSwitchViewModel wallpaperQuickSwitchViewModel,
+            WallpaperInteractor wallpaperInteractor) {
+        List<CustomizationSectionController<?>> sections = mDefaultCustomizationSections
+                .getRevampedUISectionControllersForScreen(screen, activity, lifecycleOwner,
+                        wallpaperColorsViewModel, permissionRequester, wallpaperPreviewNavigator,
+                        sectionNavigationController, savedInstanceState, wallpaperInfoFactory,
+                        displayUtils, wallpaperQuickSwitchViewModel,
+                        wallpaperInteractor);
+        return sections;
+    }
+
+    @Override
+    public List<CustomizationSectionController<?>> getAllSectionControllers(
+            FragmentActivity activity,
+            LifecycleOwner lifecycleOwner,
+            WallpaperColorsViewModel wallpaperColorsViewModel,
+            PermissionRequester permissionRequester,
+            WallpaperPreviewNavigator wallpaperPreviewNavigator,
+            CustomizationSectionNavigationController sectionNavigationController,
+            @Nullable Bundle savedInstanceState,
+            DisplayUtils displayUtils) {
+        List<CustomizationSectionController<?>> sections = mDefaultCustomizationSections
+                .getAllSectionControllers(
+                        activity, lifecycleOwner, wallpaperColorsViewModel, permissionRequester,
+                        wallpaperPreviewNavigator, sectionNavigationController, savedInstanceState,
+                        displayUtils);
+        return sections;
+    }
+}
diff --git a/src/org/leafos/customization/module/LeafThemePickerInjector.java b/src/org/leafos/customization/module/LeafThemePickerInjector.java
new file mode 100644
index 0000000..d7f71dc
--- /dev/null
+++ b/src/org/leafos/customization/module/LeafThemePickerInjector.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2023 The LeafOS 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 org.leafos.customization.module;
+
+import androidx.activity.ComponentActivity;
+
+import com.android.customization.module.ThemePickerInjector;
+import com.android.wallpaper.module.CustomizationSections;
+
+public class LeafThemePickerInjector extends ThemePickerInjector {
+    private CustomizationSections mCustomizationSections;
+
+    @Override
+    public CustomizationSections getCustomizationSections(ComponentActivity activity) {
+        if (mCustomizationSections == null) {
+            mCustomizationSections = new LeafCustomizationSections(
+                    super.getCustomizationSections(activity));
+        }
+        return mCustomizationSections;
+    }
+}
diff --git a/src/org/leafos/customization/picker/LeafCustomizationPickerApplication.java b/src/org/leafos/customization/picker/LeafCustomizationPickerApplication.java
new file mode 100644
index 0000000..8970ddf
--- /dev/null
+++ b/src/org/leafos/customization/picker/LeafCustomizationPickerApplication.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2023 The LeafOS 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 org.leafos.customization.picker;
+
+import com.android.customization.picker.CustomizationPickerApplication;
+import com.android.wallpaper.module.InjectorProvider;
+
+import org.leafos.customization.module.LeafThemePickerInjector;
+
+public class LeafCustomizationPickerApplication extends CustomizationPickerApplication {
+    @Override
+    public void onCreate() {
+        super.onCreate();
+
+        InjectorProvider.setInjector(new LeafThemePickerInjector());
+    }
+}