Merge "VideoCalling UI adds the init value" into main

This commit is contained in:
SongFerng Wang
2024-10-04 04:55:46 +00:00
committed by Android (Google) Code Review
2 changed files with 57 additions and 8 deletions

View File

@@ -44,12 +44,12 @@ constructor(
context: Context, context: Context,
key: String, key: String,
private val callStateRepository: CallStateRepository = CallStateRepository(context), private val callStateRepository: CallStateRepository = CallStateRepository(context),
private val videoCallingRepository: VideoCallingRepository = VideoCallingRepository(context),
) : TogglePreferenceController(context, key), On4gLteUpdateListener { ) : TogglePreferenceController(context, key), On4gLteUpdateListener {
private var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID private var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID
private var preference: TwoStatePreference? = null private var preference: TwoStatePreference? = null
private var callingPreferenceCategoryController: CallingPreferenceCategoryController? = null private var callingPreferenceCategoryController: CallingPreferenceCategoryController? = null
private val repository = VideoCallingRepository(context)
private var videoCallEditable = false private var videoCallEditable = false
private var isInCall = false private var isInCall = false
@@ -71,11 +71,15 @@ constructor(
override fun displayPreference(screen: PreferenceScreen) { override fun displayPreference(screen: PreferenceScreen) {
super.displayPreference(screen) super.displayPreference(screen)
preference = screen.findPreference(preferenceKey) preference = screen.findPreference(preferenceKey)
Log.d(TAG, "init ui")
preference?.isVisible = false
callingPreferenceCategoryController?.updateChildVisible(preferenceKey, false)
} }
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) { override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
repository.isVideoCallReadyFlow(subId).collectLatestWithLifecycle(viewLifecycleOwner) { videoCallingRepository.isVideoCallReadyFlow(subId)
isReady -> .collectLatestWithLifecycle(viewLifecycleOwner) { isReady ->
Log.d(TAG, "isVideoCallReadyFlow: update visible")
preference?.isVisible = isReady preference?.isVisible = isReady
callingPreferenceCategoryController?.updateChildVisible(preferenceKey, isReady) callingPreferenceCategoryController?.updateChildVisible(preferenceKey, isReady)
} }
@@ -129,10 +133,10 @@ constructor(
class VideoCallingSearchItem(private val context: Context) : class VideoCallingSearchItem(private val context: Context) :
MobileNetworkSettingsSearchItem { MobileNetworkSettingsSearchItem {
private val repository = VideoCallingRepository(context) private val videoCallingRepository = VideoCallingRepository(context)
private fun isAvailable(subId: Int): Boolean = runBlocking { private fun isAvailable(subId: Int): Boolean = runBlocking {
repository.isVideoCallReadyFlow(subId).first() videoCallingRepository.isVideoCallReadyFlow(subId).first()
} }
override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? { override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? {

View File

@@ -47,6 +47,8 @@ class VideoCallingPreferenceControllerTest {
private val context: Context = ApplicationProvider.getApplicationContext() private val context: Context = ApplicationProvider.getApplicationContext()
private val mockCallStateRepository = mock<CallStateRepository> {} private val mockCallStateRepository = mock<CallStateRepository> {}
private val mockVideoCallingRepository = mock<VideoCallingRepository> {}
private var controller = private var controller =
spy( spy(
@@ -54,6 +56,7 @@ class VideoCallingPreferenceControllerTest {
context = context, context = context,
key = TEST_KEY, key = TEST_KEY,
callStateRepository = mockCallStateRepository, callStateRepository = mockCallStateRepository,
videoCallingRepository = mockVideoCallingRepository
) )
) { ) {
on { queryImsState(SUB_ID) } doReturn mockVtQueryImsState on { queryImsState(SUB_ID) } doReturn mockVtQueryImsState
@@ -70,6 +73,42 @@ class VideoCallingPreferenceControllerTest {
controller.displayPreference(preferenceScreen) controller.displayPreference(preferenceScreen)
} }
@Test
fun displayPreference_uiInitState_isHidden() {
assertThat(preference.isVisible).isFalse()
}
@Test
fun onViewCreated_videoCallIsNotReady_isHidden() = runBlocking {
mockVideoCallingRepository.stub {
on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(false)
}
mockCallStateRepository.stub {
on { callStateFlow(SUB_ID) } doReturn flowOf(TelephonyManager.CALL_STATE_IDLE)
}
controller.onViewCreated(TestLifecycleOwner())
delay(100)
assertThat(preference.isVisible).isFalse()
}
@Test
fun onViewCreated_videoCallIsNotReady_isShown() = runBlocking {
mockVideoCallingRepository.stub {
on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(true)
}
mockCallStateRepository.stub {
on { callStateFlow(SUB_ID) } doReturn flowOf(TelephonyManager.CALL_STATE_IDLE)
}
controller.onViewCreated(TestLifecycleOwner())
delay(100)
assertThat(preference.isVisible).isTrue()
}
@Test @Test
fun updateState_4gLteOff_disabledAndUnchecked() { fun updateState_4gLteOff_disabledAndUnchecked() {
mockQueryVoLteState.stub { on { isEnabledByUser } doReturn false } mockQueryVoLteState.stub { on { isEnabledByUser } doReturn false }
@@ -82,6 +121,9 @@ class VideoCallingPreferenceControllerTest {
@Test @Test
fun updateState_4gLteOnWithoutCall_enabledAndChecked() = runBlocking { fun updateState_4gLteOnWithoutCall_enabledAndChecked() = runBlocking {
mockVideoCallingRepository.stub {
on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(true)
}
mockVtQueryImsState.stub { mockVtQueryImsState.stub {
on { isEnabledByUser } doReturn true on { isEnabledByUser } doReturn true
on { isAllowUserControl } doReturn true on { isAllowUserControl } doReturn true
@@ -101,6 +143,9 @@ class VideoCallingPreferenceControllerTest {
@Test @Test
fun updateState_4gLteOnWithCall_disabledAndChecked() = runBlocking { fun updateState_4gLteOnWithCall_disabledAndChecked() = runBlocking {
mockVideoCallingRepository.stub {
on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(true)
}
mockVtQueryImsState.stub { mockVtQueryImsState.stub {
on { isEnabledByUser } doReturn true on { isEnabledByUser } doReturn true
on { isAllowUserControl } doReturn true on { isAllowUserControl } doReturn true