Merge "Make fragment the owner of the view model" into udc-dev
diff --git a/src/com/android/customization/module/ThemePickerInjector.kt b/src/com/android/customization/module/ThemePickerInjector.kt
index 050c7b2..e716406 100644
--- a/src/com/android/customization/module/ThemePickerInjector.kt
+++ b/src/com/android/customization/module/ThemePickerInjector.kt
@@ -80,11 +80,8 @@
import com.android.wallpaper.picker.customization.data.repository.WallpaperRepository
import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInteractor
import com.android.wallpaper.picker.undo.domain.interactor.SnapshotRestorer
-import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.GlobalScope
-@OptIn(DelicateCoroutinesApi::class)
open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInjector {
private var customizationSections: CustomizationSections? = null
private var userEventLogger: UserEventLogger? = null
@@ -231,7 +228,7 @@
?: WallpaperInteractor(
repository =
WallpaperRepository(
- scope = GlobalScope,
+ scope = getApplicationCoroutineScope(),
client = WallpaperClientImpl(context = context),
wallpaperPreferences = getPreferences(context = context),
backgroundDispatcher = Dispatchers.IO,
@@ -292,7 +289,7 @@
}
}
- protected fun getKeyguardQuickAffordancePickerProviderClient(
+ private fun getKeyguardQuickAffordancePickerProviderClient(
context: Context
): CustomizationProviderClient {
return customizationProviderClient
@@ -327,7 +324,7 @@
return clockRegistry
?: ClockRegistryProvider(
context = context,
- coroutineScope = GlobalScope,
+ coroutineScope = getApplicationCoroutineScope(),
mainDispatcher = Dispatchers.Main,
backgroundDispatcher = Dispatchers.IO,
)
@@ -343,7 +340,7 @@
ClockPickerRepositoryImpl(
secureSettingsRepository = getSecureSettingsRepository(context),
registry = getClockRegistry(context),
- scope = GlobalScope,
+ scope = getApplicationCoroutineScope(),
),
)
.also { clockPickerInteractor = it }
@@ -370,14 +367,14 @@
?: ClockViewFactory(activity, getClockRegistry(activity)).also { clockViewFactory = it }
}
- protected fun getNotificationsInteractor(
+ private fun getNotificationsInteractor(
context: Context,
): NotificationsInteractor {
return notificationsInteractor
?: NotificationsInteractor(
repository =
NotificationsRepository(
- scope = GlobalScope,
+ scope = getApplicationCoroutineScope(),
backgroundDispatcher = Dispatchers.IO,
secureSettingsRepository = getSecureSettingsRepository(context),
),
@@ -505,10 +502,10 @@
): GridInteractor {
return gridInteractor
?: GridInteractor(
- applicationScope = GlobalScope,
+ applicationScope = getApplicationCoroutineScope(),
repository =
GridRepositoryImpl(
- applicationScope = GlobalScope,
+ applicationScope = getApplicationCoroutineScope(),
manager = GridOptionsManager.getInstance(context),
backgroundDispatcher = Dispatchers.IO,
),
diff --git a/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt b/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
index 7bdd4fc..f455600 100644
--- a/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
+++ b/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
@@ -106,9 +106,7 @@
LifecycleEventObserver { source, event ->
when (event) {
Lifecycle.Event.ON_RESUME -> {
- clockViewFactory.registerTimeTicker(source) {
- !carouselView.isCarouselInTransition
- }
+ clockViewFactory.registerTimeTicker(source)
}
Lifecycle.Event.ON_PAUSE -> {
clockViewFactory.unregisterTimeTicker(source)
diff --git a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
index 059e498..3cf5471 100644
--- a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
+++ b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
@@ -36,8 +36,6 @@
attrs,
) {
- var isCarouselInTransition = false
-
val carousel: Carousel
private val motionLayout: MotionLayout
private lateinit var adapter: ClockCarouselAdapter
@@ -72,7 +70,6 @@
startId: Int,
endId: Int
) {
- isCarouselInTransition = true
val scalingDownClockId = adapter.clockIds[carousel.currentIndex]
val scalingUpIdx =
if (endId == R.id.next) (carousel.currentIndex + 1) % adapter.count()
@@ -125,7 +122,6 @@
}
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
- isCarouselInTransition = false
setCardAnimationState(currentId == R.id.start)
}
@@ -197,8 +193,6 @@
clockHostView.removeAllViews()
val clockView = onGetClockController(clockIds[index]).largeClock.view
- // Making sure the large clock tick to the correct time
- onGetClockController(clockIds[index]).largeClock.events.onTimeTick()
// The clock view might still be attached to an existing parent. Detach before adding to
// another parent.
(clockView.parent as? ViewGroup)?.removeView(clockView)
diff --git a/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt b/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt
index cf154d5..3c7bab1 100644
--- a/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt
+++ b/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt
@@ -67,21 +67,13 @@
}
fun registerTimeTicker(owner: LifecycleOwner) {
- registerTimeTicker(owner, null)
- }
-
- fun registerTimeTicker(owner: LifecycleOwner, shouldTimeTick: (() -> Boolean)?) {
val hashCode = owner.hashCode()
if (timeTickListeners.keys.contains(hashCode)) {
return
}
timeTickListeners[hashCode] =
- TimeTicker.registerNewReceiver(activity.applicationContext) {
- if (shouldTimeTick == null || shouldTimeTick()) {
- onTimeTick()
- }
- }
+ TimeTicker.registerNewReceiver(activity.applicationContext) { onTimeTick() }
}
private fun onTimeTick() {
diff --git a/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt b/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt
index 3dba27e..3eadec5 100644
--- a/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt
+++ b/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt
@@ -92,6 +92,22 @@
launch {
viewModel.colorOptions.collect { colorOptions ->
colorOptionAdapter.setItems(colorOptions)
+ // the same recycler view is used for different color types tabs
+ // the scroll state of each tab should be independent of others
+ var indexToFocus = 0
+ colorOptions.forEachIndexed { index, colorOption ->
+ if (colorOption.isSelected.value) {
+ indexToFocus = index
+ }
+ }
+ val linearLayoutManager =
+ object : LinearLayoutManager(view.context, HORIZONTAL, false) {
+ override fun onLayoutCompleted(state: RecyclerView.State?) {
+ super.onLayoutCompleted(state)
+ scrollToPosition(indexToFocus)
+ }
+ }
+ colorOptionContainerView.layoutManager = linearLayoutManager
}
}
}
diff --git a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
index 029d76e..0a52e8f 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
@@ -64,7 +64,7 @@
private val quickAffordanceInteractor: KeyguardQuickAffordancePickerInteractor,
private val wallpaperInteractor: WallpaperInteractor,
private val wallpaperInfoFactory: CurrentWallpaperInfoFactory,
- activityStarter: (Intent) -> Unit,
+ private val activityStarter: (Intent) -> Unit,
) : ViewModel() {
@SuppressLint("StaticFieldLeak") private val applicationContext = context.applicationContext
@@ -361,7 +361,7 @@
style = ButtonStyle.Primary,
onClicked = {
actionComponentName.toIntent()?.let { intent ->
- applicationContext.startActivity(intent)
+ activityStarter(intent)
}
}
),
diff --git a/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt b/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
index 155b912..1b241ca 100644
--- a/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
+++ b/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
@@ -282,9 +282,14 @@
assertThat(dialog()?.buttons?.first()?.text)
.isEqualTo(Text.Loaded(enablementActionText))
+ // When the button is clicked, we expect an intent of the given enablement action
+ // component name is launched.
+ dialog()?.buttons?.first()?.onClicked?.invoke()
+ assertThat(latestStartedActivityIntent?.`package`).isEqualTo(packageName)
+ assertThat(latestStartedActivityIntent?.action).isEqualTo(action)
+
// Once we report that the dialog has been dismissed by the user, we expect there to be
- // no
- // dialog to be shown:
+ // no dialog to be shown:
underTest.onDialogDismissed()
assertThat(dialog()).isNull()
}