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

Commit 02edf550 authored by bobyang's avatar bobyang
Browse files

Add PackThemeInteractor into the CustomizationOptionsViewModel.

Bug: 398982575
Flag: EXEMPT refactor
Test: Tested by building and installing picker on local, checking if the
entry shown as expected.

Change-Id: I5f5f415665730cf50b5a2779024f8383b23421f9
parent a1ecffd0
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wallpaper.customization.ui.binder

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
@@ -81,7 +82,7 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO
        navigateToMoreLockScreenSettingsActivity: () -> Unit,
        navigateToColorContrastSettingsActivity: () -> Unit,
        navigateToLockScreenNotificationsSettingsActivity: () -> Unit,
        navigateToPackThemeActivity: () -> Unit,
        navigateToPackThemeActivity: (Intent) -> Unit,
    ) {
        defaultCustomizationOptionsBinder.bind(
            view,
@@ -179,20 +180,19 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO

        var optionPackThemeIconHome: ImageView? = null
        var optionPackThemeIconLock: ImageView? = null

        var optionPackThemeHome: View? = null
        var optionPackThemeLock: View? = null
        if (BaseFlags.get().isPackThemeEnabled()) {
            val optionPackThemeHome =
            optionPackThemeHome =
                homeScreenCustomizationOptionEntries
                    .first { it.first == ThemePickerHomeCustomizationOption.PACK_THEME }
                    .second
            optionPackThemeHome.setOnClickListener { navigateToPackThemeActivity.invoke() }
            optionPackThemeIconHome = optionPackThemeHome.requireViewById(R.id.option_entry_icon)

            val optionPackThemeLock =
            optionPackThemeLock =
                lockScreenCustomizationOptionEntries
                    .first { it.first == ThemePickerHomeCustomizationOption.PACK_THEME }
                    .second
            optionPackThemeLock.setOnClickListener { navigateToPackThemeActivity.invoke() }
            optionPackThemeIconLock = optionPackThemeLock.requireViewById(R.id.option_entry_icon)
        }

@@ -367,6 +367,25 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO
                        }
                    }
                }

                if (BaseFlags.get().isPackThemeEnabled()) {
                    launch {
                        optionsViewModel.packThemeViewModel.startThemePackActivityIntent.collect {
                            intent ->
                            if (intent != null) {
                                optionPackThemeHome?.setOnClickListener {
                                    navigateToPackThemeActivity.invoke(intent)
                                }
                                optionPackThemeLock?.setOnClickListener {
                                    navigateToPackThemeActivity.invoke(intent)
                                }
                            } else {
                                optionPackThemeHome?.setOnClickListener(null)
                                optionPackThemeLock?.setOnClickListener(null)
                            }
                        }
                    }
                }
            }
        }

+42 −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.viewmodel

import android.content.ComponentName
import android.content.Intent
import com.android.wallpaper.picker.domain.interactor.PackThemeInteractor
import dagger.hilt.android.scopes.ViewModelScoped
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

@ViewModelScoped
class PackThemeViewModel @Inject constructor(private val interactor: PackThemeInteractor) {
    val startThemePackActivityIntent: Flow<Intent?> =
        interactor.packThemeData.map { data ->
            if (
                data.launchingPackageName.isNotEmpty() &&
                    data.launchingDetailActivityClass.isNotEmpty()
            ) {
                val componentName =
                    ComponentName(data.launchingPackageName, data.launchingDetailActivityClass)
                Intent().apply { component = componentName }
            } else {
                null
            }
        }
}
+1 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ constructor(
    val colorContrastSectionViewModel: ColorContrastSectionViewModel2,
    val darkModeViewModel: DarkModeViewModel,
    val themedIconViewModel: ThemedIconViewModel,
    val packThemeViewModel: PackThemeViewModel,
    @Assisted private val viewModelScope: CoroutineScope,
) : CustomizationOptionsViewModel {

+28 −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.picker.domain.interactor

import com.android.customization.picker.pack.data.PackThemeData
import kotlinx.coroutines.flow.Flow

/**
 * Classes that implement this interface implement the business logic in assembling pack theme
 * category model
 */
interface PackThemeInteractor {
    val packThemeData: Flow<PackThemeData>
}
+29 −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.picker.domain.interactor.implementations

import com.android.customization.picker.pack.data.PackThemeData
import com.android.wallpaper.picker.domain.interactor.PackThemeInteractor
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow

@Singleton
class ThemePickerPackThemeInteractor @Inject constructor() : PackThemeInteractor {
    override val packThemeData: Flow<PackThemeData> = emptyFlow()
}
Loading