Loading src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt +36 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.wallpaper.customization.ui.binder import android.app.Activity import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.graphics.drawable.AdaptiveIconDrawable import android.provider.Settings import android.view.View Loading Loading @@ -70,8 +71,11 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.google.android.material.snackbar.Snackbar import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.DisposableHandle import kotlinx.coroutines.Job import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.combine import kotlinx.coroutines.launch Loading Loading @@ -273,6 +277,8 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO .first { it.first == ThemePickerHomeCustomizationOption.COLOR_CONTRAST } .second optionColorContrast.setOnClickListener { navigateToColorContrastSettingsActivity.invoke() } val backgroundScope = CoroutineScope(Dispatchers.IO + Job() + CoroutineName(BACKGROUND_CONTEXT)) ColorUpdateBinder.bind( setColor = { color -> Loading Loading @@ -530,10 +536,30 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO intent -> if (intent != null) { optionPackThemeHome?.setOnClickListener { backgroundScope.launch { if (isActivityAvailable(view.context, intent)) { navigateToPackThemeActivity.invoke(intent) } else { showNoPackThemeIntentErrorMessage( lifecycleOwner, view, optionsViewModel, ) } } } optionPackThemeLock?.setOnClickListener { backgroundScope.launch { if (isActivityAvailable(view.context, intent)) { navigateToPackThemeActivity.invoke(intent) } else { showNoPackThemeIntentErrorMessage( lifecycleOwner, view, optionsViewModel, ) } } } } else { optionPackThemeHome?.setOnClickListener({ Loading Loading @@ -631,6 +657,13 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO // Track the current show clock flag. If it turns from false to true, animate fade-in. private var isClockCurrentlyShown: Boolean? = null private suspend fun isActivityAvailable(context: Context, intent: Intent): Boolean { val packageManager: PackageManager = context.packageManager val activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY) return activities.isNotEmpty() } private fun showNoPackThemeIntentErrorMessage( lifecycleOwner: LifecycleOwner, view: View, Loading Loading @@ -786,5 +819,6 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO companion object { private const val THUMBNAIL_CORNER_RADIUS = 18 private const val BACKGROUND_CONTEXT = "backgroundContext" } } src/com/android/wallpaper/customization/ui/binder/ThemePickerSuggestedEntryBinder.kt +49 −1 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package com.android.wallpaper.customization.ui.binder import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.view.View import android.widget.Toast import androidx.core.graphics.drawable.DrawableCompat import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner Loading @@ -31,6 +34,10 @@ import com.android.wallpaper.picker.customization.ui.viewmodel.ColorUpdateViewMo import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationPickerViewModel2 import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch @Singleton Loading @@ -49,6 +56,8 @@ class ThemePickerSuggestedEntryBinder @Inject constructor() : PackThemeSuggested val optionsViewModel = viewModel.customizationOptionsViewModel as ThemePickerCustomizationOptionsViewModel val backgroundScope = CoroutineScope(Dispatchers.IO + Job() + CoroutineName(BACKGROUND_CONTEXT)) lifecycleOwner.lifecycleScope.launch { lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { launch { Loading @@ -56,7 +65,17 @@ class ThemePickerSuggestedEntryBinder @Inject constructor() : PackThemeSuggested .collect { intent -> if (intent != null) { view.suggestedChip.setOnClickListener { backgroundScope.launch { if (isActivityAvailable(view.context, intent)) { navigateToPackThemeActivity.invoke(intent) } else { showNoPackThemeIntentErrorMessage( lifecycleOwner, view, optionsViewModel, ) } } } } else { view.suggestedChip.setOnClickListener { null } Loading @@ -68,6 +87,9 @@ class ThemePickerSuggestedEntryBinder @Inject constructor() : PackThemeSuggested if (packThemeData.suggestedChipThemePackInfo.title.isNotEmpty()) { view.visibility = View.VISIBLE view.hideSuggestedChip = false } else { view.visibility = View.GONE view.hideSuggestedChip = true } view.suggestedChipText.text = packThemeData.suggestedChipThemePackInfo.title } Loading @@ -94,4 +116,30 @@ class ThemePickerSuggestedEntryBinder @Inject constructor() : PackThemeSuggested lifecycleOwner = lifecycleOwner, ) } private suspend fun isActivityAvailable(context: Context, intent: Intent): Boolean { val packageManager: PackageManager = context.packageManager val activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY) return activities.isNotEmpty() } private fun showNoPackThemeIntentErrorMessage( lifecycleOwner: LifecycleOwner, view: View, optionsViewModel: ThemePickerCustomizationOptionsViewModel, ) { lifecycleOwner.lifecycleScope.launch { Toast.makeText( view.context, optionsViewModel.packThemeViewModel.noAppErrorMessage, Toast.LENGTH_SHORT, ) .show() } } companion object { private const val BACKGROUND_CONTEXT = "backgroundContext" } } Loading
src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt +36 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.wallpaper.customization.ui.binder import android.app.Activity import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.graphics.drawable.AdaptiveIconDrawable import android.provider.Settings import android.view.View Loading Loading @@ -70,8 +71,11 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.google.android.material.snackbar.Snackbar import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.DisposableHandle import kotlinx.coroutines.Job import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.combine import kotlinx.coroutines.launch Loading Loading @@ -273,6 +277,8 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO .first { it.first == ThemePickerHomeCustomizationOption.COLOR_CONTRAST } .second optionColorContrast.setOnClickListener { navigateToColorContrastSettingsActivity.invoke() } val backgroundScope = CoroutineScope(Dispatchers.IO + Job() + CoroutineName(BACKGROUND_CONTEXT)) ColorUpdateBinder.bind( setColor = { color -> Loading Loading @@ -530,10 +536,30 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO intent -> if (intent != null) { optionPackThemeHome?.setOnClickListener { backgroundScope.launch { if (isActivityAvailable(view.context, intent)) { navigateToPackThemeActivity.invoke(intent) } else { showNoPackThemeIntentErrorMessage( lifecycleOwner, view, optionsViewModel, ) } } } optionPackThemeLock?.setOnClickListener { backgroundScope.launch { if (isActivityAvailable(view.context, intent)) { navigateToPackThemeActivity.invoke(intent) } else { showNoPackThemeIntentErrorMessage( lifecycleOwner, view, optionsViewModel, ) } } } } else { optionPackThemeHome?.setOnClickListener({ Loading Loading @@ -631,6 +657,13 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO // Track the current show clock flag. If it turns from false to true, animate fade-in. private var isClockCurrentlyShown: Boolean? = null private suspend fun isActivityAvailable(context: Context, intent: Intent): Boolean { val packageManager: PackageManager = context.packageManager val activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY) return activities.isNotEmpty() } private fun showNoPackThemeIntentErrorMessage( lifecycleOwner: LifecycleOwner, view: View, Loading Loading @@ -786,5 +819,6 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO companion object { private const val THUMBNAIL_CORNER_RADIUS = 18 private const val BACKGROUND_CONTEXT = "backgroundContext" } }
src/com/android/wallpaper/customization/ui/binder/ThemePickerSuggestedEntryBinder.kt +49 −1 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package com.android.wallpaper.customization.ui.binder import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.view.View import android.widget.Toast import androidx.core.graphics.drawable.DrawableCompat import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner Loading @@ -31,6 +34,10 @@ import com.android.wallpaper.picker.customization.ui.viewmodel.ColorUpdateViewMo import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationPickerViewModel2 import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch @Singleton Loading @@ -49,6 +56,8 @@ class ThemePickerSuggestedEntryBinder @Inject constructor() : PackThemeSuggested val optionsViewModel = viewModel.customizationOptionsViewModel as ThemePickerCustomizationOptionsViewModel val backgroundScope = CoroutineScope(Dispatchers.IO + Job() + CoroutineName(BACKGROUND_CONTEXT)) lifecycleOwner.lifecycleScope.launch { lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { launch { Loading @@ -56,7 +65,17 @@ class ThemePickerSuggestedEntryBinder @Inject constructor() : PackThemeSuggested .collect { intent -> if (intent != null) { view.suggestedChip.setOnClickListener { backgroundScope.launch { if (isActivityAvailable(view.context, intent)) { navigateToPackThemeActivity.invoke(intent) } else { showNoPackThemeIntentErrorMessage( lifecycleOwner, view, optionsViewModel, ) } } } } else { view.suggestedChip.setOnClickListener { null } Loading @@ -68,6 +87,9 @@ class ThemePickerSuggestedEntryBinder @Inject constructor() : PackThemeSuggested if (packThemeData.suggestedChipThemePackInfo.title.isNotEmpty()) { view.visibility = View.VISIBLE view.hideSuggestedChip = false } else { view.visibility = View.GONE view.hideSuggestedChip = true } view.suggestedChipText.text = packThemeData.suggestedChipThemePackInfo.title } Loading @@ -94,4 +116,30 @@ class ThemePickerSuggestedEntryBinder @Inject constructor() : PackThemeSuggested lifecycleOwner = lifecycleOwner, ) } private suspend fun isActivityAvailable(context: Context, intent: Intent): Boolean { val packageManager: PackageManager = context.packageManager val activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY) return activities.isNotEmpty() } private fun showNoPackThemeIntentErrorMessage( lifecycleOwner: LifecycleOwner, view: View, optionsViewModel: ThemePickerCustomizationOptionsViewModel, ) { lifecycleOwner.lifecycleScope.launch { Toast.makeText( view.context, optionsViewModel.packThemeViewModel.noAppErrorMessage, Toast.LENGTH_SHORT, ) .show() } } companion object { private const val BACKGROUND_CONTEXT = "backgroundContext" } }