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

Commit 2658cb66 authored by Bob Yang's avatar Bob Yang Committed by Android (Google) Code Review
Browse files

Merge "Show title and add click event for the suggested button" into main

parents 11e7da85 629c12b6
Loading
Loading
Loading
Loading
+92 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.content.Intent
import androidx.core.graphics.drawable.DrawableCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.android.wallpaper.customization.ui.viewmodel.ThemePickerCustomizationOptionsViewModel
import com.android.wallpaper.picker.customization.ui.binder.ColorUpdateBinder
import com.android.wallpaper.picker.customization.ui.binder.PackThemeSuggestedEntryBinder
import com.android.wallpaper.picker.customization.ui.view.PackThemeSuggestedChip
import com.android.wallpaper.picker.customization.ui.viewmodel.ColorUpdateViewModel
import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationPickerViewModel2
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.launch

@Singleton
class ThemePickerSuggestedEntryBinder @Inject constructor() : PackThemeSuggestedEntryBinder {
    override fun bind(
        view: PackThemeSuggestedChip,
        viewModel: CustomizationPickerViewModel2,
        colorUpdateViewModel: ColorUpdateViewModel,
        lifecycleOwner: LifecycleOwner,
        navigateToPackThemeActivity: (Intent) -> Unit,
    ) {
        val isOnMainScreen = {
            viewModel.customizationOptionsViewModel.selectedOption.value == null
        }

        val optionsViewModel =
            viewModel.customizationOptionsViewModel as ThemePickerCustomizationOptionsViewModel

        lifecycleOwner.lifecycleScope.launch {
            lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                launch {
                    optionsViewModel.packThemeViewModel.startSuggestedThemePackActivityIntent
                        .collect { intent ->
                            if (intent != null) {
                                view.suggestedChip.setOnClickListener {
                                    navigateToPackThemeActivity.invoke(intent)
                                }
                            } else {
                                view.suggestedChip.setOnClickListener { null }
                            }
                        }
                }
                launch {
                    optionsViewModel.packThemeViewModel.packThemeData.collect { packThemeData ->
                        view.suggestedChipText.text = packThemeData.suggestedChipThemePackInfo.title
                    }
                }
            }
        }

        ColorUpdateBinder.bind(
            setColor = { color ->
                DrawableCompat.setTint(DrawableCompat.wrap(view.suggestedChip.background), color)
            },
            color = colorUpdateViewModel.colorSecondaryContainer,
            shouldAnimate = isOnMainScreen,
            lifecycleOwner = lifecycleOwner,
        )
        ColorUpdateBinder.bind(
            setColor = { color ->
                DrawableCompat.setTint(DrawableCompat.wrap(view.cancelButton.background), color)
                DrawableCompat.setTint(DrawableCompat.wrap(view.icon.background), color)
                view.suggestedChipText.setTextColor(color)
            },
            color = colorUpdateViewModel.colorOnPrimaryContainer,
            shouldAnimate = isOnMainScreen,
            lifecycleOwner = lifecycleOwner,
        )
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -40,5 +40,25 @@ class PackThemeViewModel @Inject constructor(private val interactor: PackThemeIn
                null
            }
        }
    val startSuggestedThemePackActivityIntent: Flow<Intent?> =
        interactor.packThemeData.map { data ->
            if (
                data.launchingPackageName.isNotEmpty() &&
                    data.launchingDetailActivityClass.isNotEmpty()
            ) {
                val componentName =
                    ComponentName(data.launchingPackageName, data.launchingDetailActivityClass)
                Intent().apply {
                    component = componentName
                    putExtra(THEME_ID, data.suggestedChipThemePackInfo.themeId)
                }
            } else {
                null
            }
        }
    val packThemeData: Flow<PackThemeData> = interactor.packThemeData

    private companion object {
        const val THEME_ID = "themeId"
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -70,6 +70,8 @@ import com.android.wallpaper.picker.category.wrapper.WallpaperCategoryWrapper
import com.android.wallpaper.picker.common.preview.ui.binder.ThemePickerWorkspaceCallbackBinder
import com.android.wallpaper.picker.common.preview.ui.binder.WorkspaceCallbackBinder
import com.android.wallpaper.picker.customization.ui.binder.CustomizationOptionsBinder
import com.android.wallpaper.picker.customization.ui.binder.DefaultPackThemeSuggestedEntryBinder
import com.android.wallpaper.picker.customization.ui.binder.PackThemeSuggestedEntryBinder
import com.android.wallpaper.picker.customization.ui.binder.ToolbarBinder
import com.android.wallpaper.picker.di.modules.BackgroundDispatcher
import com.android.wallpaper.picker.di.modules.MainDispatcher
@@ -115,6 +117,12 @@ abstract class ThemePickerAppModule {
    @Singleton
    abstract fun bindThemedIconRepository(impl: ThemedIconRepositoryImpl): ThemedIconRepository

    @Binds
    @Singleton
    abstract fun bindPackThemeSuggestedEntryBinder(
        impl: DefaultPackThemeSuggestedEntryBinder
    ): PackThemeSuggestedEntryBinder

    @Binds
    @Singleton
    abstract fun bindCreativeCategoryInteractor(
+8 −0
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ import com.android.wallpaper.picker.common.preview.ui.binder.ThemePickerWorkspac
import com.android.wallpaper.picker.common.preview.ui.binder.WorkspaceCallbackBinder
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.binder.DefaultPackThemeSuggestedEntryBinder
import com.android.wallpaper.picker.customization.ui.binder.PackThemeSuggestedEntryBinder
import com.android.wallpaper.picker.customization.ui.binder.ToolbarBinder
import com.android.wallpaper.picker.di.modules.BackgroundDispatcher
import com.android.wallpaper.picker.di.modules.MainDispatcher
@@ -116,6 +118,12 @@ abstract class ThemePickerTestModule {
    @Singleton
    abstract fun bindCustomizationInjector(impl: TestCustomizationInjector): CustomizationInjector

    @Binds
    @Singleton
    abstract fun bindPackThemeSuggestedEntryBinder(
        impl: DefaultPackThemeSuggestedEntryBinder
    ): PackThemeSuggestedEntryBinder

    @Binds
    @Singleton
    abstract fun bindCustomizationOptionsBinder(