Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c328b3ac authored by George Lin's avatar George Lin
Browse files

Move customization options to proper projects (3/3)

Move the customization options to correspondent projects, so that
WallpaperPicker2 only has wallpaper customization
ThemePicker has clock, color, customiztion etc.
WallpaperPickerGoogle has all customization options

Test: Manually tested it works as expected
Bug: 343300705
Flag: com.android.wallpaper.new_picker_ui_flag
Change-Id: I5f68b6afe3e3e99aea21c5866fbe187db7e1431a
parent 8f47d2dc
Loading
Loading
Loading
Loading
+67 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.customization.ui.binder

import android.view.View
import android.widget.TextView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.android.wallpaper.R
import com.android.wallpaper.customization.ui.viewmodel.ThemePickerCustomizationOptionsViewModel
import com.android.wallpaper.picker.customization.ui.binder.CustomizationOptionsBinder
import com.android.wallpaper.picker.customization.ui.binder.DefaultCustomizationOptionsBinder
import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationOptionsViewModel
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.launch

@Singleton
class ThemePickerCustomizationOptionsBinder
@Inject
constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationOptionsBinder) :
    CustomizationOptionsBinder {

    override fun bind(
        view: View,
        viewModel: CustomizationOptionsViewModel,
        lifecycleOwner: LifecycleOwner
    ) {
        defaultCustomizationOptionsBinder.bind(view, viewModel, lifecycleOwner)

        val optionClock = view.requireViewById<TextView>(R.id.option_clock)
        val optionShortcut = view.requireViewById<TextView>(R.id.option_shortcut)
        viewModel as ThemePickerCustomizationOptionsViewModel

        lifecycleOwner.lifecycleScope.launch {
            lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                launch {
                    viewModel.onCustomizeClockClicked.collect {
                        optionClock.setOnClickListener { _ -> it?.invoke() }
                    }
                }

                launch {
                    viewModel.onCustomizeShortcutClicked.collect {
                        optionShortcut.setOnClickListener { _ -> it?.invoke() }
                    }
                }
            }
        }
    }
}
+98 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.customization.ui.util

import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import com.android.wallpaper.R
import com.android.wallpaper.picker.customization.ui.util.CustomizationOptionUtil
import com.android.wallpaper.picker.customization.ui.util.DefaultCustomizationOptionUtil
import dagger.hilt.android.scopes.ActivityScoped
import javax.inject.Inject

@ActivityScoped
class ThemePickerCustomizationOptionUtil
@Inject
constructor(private val defaultCustomizationOptionUtil: DefaultCustomizationOptionUtil) :
    CustomizationOptionUtil {

    enum class ThemePickerLockCustomizationOption : CustomizationOptionUtil.CustomizationOption {
        CLOCK,
        SHORTCUTS,
        SHOW_NOTIFICATIONS,
        MORE_LOCK_SCREEN_SETTINGS,
    }

    enum class ThemePickerHomeCustomizationOption : CustomizationOptionUtil.CustomizationOption {
        COLORS,
        APP_GRID,
        APP_SHAPE,
        THEMED_ICONS,
    }

    private var viewMap: Map<CustomizationOptionUtil.CustomizationOption, View>? = null

    override fun initBottomSheetContent(
        bottomSheetContainer: FrameLayout,
        layoutInflater: LayoutInflater
    ) {
        defaultCustomizationOptionUtil.initBottomSheetContent(bottomSheetContainer, layoutInflater)
        viewMap = buildMap {
            put(
                ThemePickerLockCustomizationOption.CLOCK,
                createCustomizationPickerBottomSheetView(
                        ThemePickerLockCustomizationOption.CLOCK,
                        bottomSheetContainer,
                        layoutInflater,
                    )
                    .also { bottomSheetContainer.addView(it) }
            )
            put(
                ThemePickerLockCustomizationOption.SHORTCUTS,
                createCustomizationPickerBottomSheetView(
                        ThemePickerLockCustomizationOption.SHORTCUTS,
                        bottomSheetContainer,
                        layoutInflater,
                    )
                    .also { bottomSheetContainer.addView(it) }
            )
        }
    }

    override fun getBottomSheetContent(option: CustomizationOptionUtil.CustomizationOption): View? {
        return defaultCustomizationOptionUtil.getBottomSheetContent(option) ?: viewMap?.get(option)
    }

    override fun onDestroy() {
        viewMap = null
    }

    private fun createCustomizationPickerBottomSheetView(
        option: ThemePickerLockCustomizationOption,
        bottomSheetContainer: FrameLayout,
        layoutInflater: LayoutInflater,
    ): View =
        when (option) {
            ThemePickerLockCustomizationOption.CLOCK -> R.layout.bottom_sheet_clock
            ThemePickerLockCustomizationOption.SHORTCUTS -> R.layout.bottom_sheet_shortcut
            else ->
                throw IllegalStateException(
                    "Customization option $option does not have a bottom sheet view"
                )
        }.let { layoutInflater.inflate(it, bottomSheetContainer, false) }
}
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.customization.ui.viewmodel

import com.android.wallpaper.customization.ui.util.ThemePickerCustomizationOptionUtil
import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationOptionsViewModel
import com.android.wallpaper.picker.customization.ui.viewmodel.DefaultCustomizationOptionsViewModel
import dagger.hilt.android.scopes.ViewModelScoped
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

@ViewModelScoped
class ThemePickerCustomizationOptionsViewModel
@Inject
constructor(
    private val defaultCustomizationOptionsViewModel: DefaultCustomizationOptionsViewModel
) : CustomizationOptionsViewModel {

    override val selectedOption = defaultCustomizationOptionsViewModel.selectedOption

    override fun deselectOption(): Boolean = defaultCustomizationOptionsViewModel.deselectOption()

    val onCustomizeClockClicked: Flow<(() -> Unit)?> =
        selectedOption.map {
            if (it == null) {
                {
                    defaultCustomizationOptionsViewModel.selectOption(
                        ThemePickerCustomizationOptionUtil.ThemePickerLockCustomizationOption.CLOCK
                    )
                }
            } else {
                null
            }
        }

    val onCustomizeShortcutClicked: Flow<(() -> Unit)?> =
        selectedOption.map {
            if (it == null) {
                {
                    defaultCustomizationOptionsViewModel.selectOption(
                        ThemePickerCustomizationOptionUtil.ThemePickerLockCustomizationOption
                            .SHORTCUTS
                    )
                }
            } else {
                null
            }
        }
}
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.modules

import com.android.wallpaper.customization.ui.util.ThemePickerCustomizationOptionUtil
import com.android.wallpaper.picker.customization.ui.util.CustomizationOptionUtil
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityComponent
import dagger.hilt.android.scopes.ActivityScoped

@Module
@InstallIn(ActivityComponent::class)
abstract class ThemePickerActivityModule {

    @Binds
    @ActivityScoped
    abstract fun bindCustomizationOptionUtil(
        impl: ThemePickerCustomizationOptionUtil
    ): CustomizationOptionUtil
}
+8 −0
Original line number Diff line number Diff line
@@ -23,10 +23,12 @@ import com.android.customization.module.DefaultCustomizationPreferences
import com.android.customization.module.ThemePickerInjector
import com.android.customization.module.logging.ThemesUserEventLogger
import com.android.customization.module.logging.ThemesUserEventLoggerImpl
import com.android.wallpaper.customization.ui.binder.ThemePickerCustomizationOptionsBinder
import com.android.wallpaper.module.DefaultPartnerProvider
import com.android.wallpaper.module.PartnerProvider
import com.android.wallpaper.module.WallpaperPreferences
import com.android.wallpaper.module.logging.UserEventLogger
import com.android.wallpaper.picker.customization.ui.binder.CustomizationOptionsBinder
import com.android.wallpaper.picker.preview.data.util.DefaultLiveWallpaperDownloader
import com.android.wallpaper.picker.preview.data.util.LiveWallpaperDownloader
import com.android.wallpaper.picker.preview.ui.util.DefaultImageEffectDialogUtil
@@ -76,6 +78,12 @@ abstract class ThemePickerAppModule {
        impl: DefaultImageEffectDialogUtil
    ): ImageEffectDialogUtil

    @Binds
    @Singleton
    abstract fun bindCustomizationOptionsBinder(
        impl: ThemePickerCustomizationOptionsBinder
    ): CustomizationOptionsBinder

    companion object {
        @Provides
        @Singleton
Loading