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

Commit 53f2d39c authored by SongFerng Wang's avatar SongFerng Wang Committed by Android (Google) Code Review
Browse files

Merge "Fix the UI updatestate issue" into main

parents a4c6d835 ce5469f4
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ constructor(
    private var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID
    private var preference: TwoStatePreference? = null
    private var callingPreferenceCategoryController: CallingPreferenceCategoryController? = null

    private var isVisible = false
    private var videoCallEditable = false
    private var isInCall = false

@@ -66,21 +66,26 @@ constructor(
    }

    // Availability is controlled in onViewCreated() and VideoCallingSearchItem.
    override fun getAvailabilityStatus() = AVAILABLE
    override fun getAvailabilityStatus() = if (isVisible) AVAILABLE else CONDITIONALLY_UNAVAILABLE

    override fun displayPreference(screen: PreferenceScreen) {
        super.displayPreference(screen)
        preference = screen.findPreference(preferenceKey)
        Log.d(TAG, "init ui")
        preference?.isVisible = false
        callingPreferenceCategoryController?.updateChildVisible(preferenceKey, false)
        Log.d(
            TAG,
            "displayPreference: isVisible: $isVisible, videoCallEditable: $videoCallEditable"
        )
    }

    override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
        videoCallingRepository.isVideoCallReadyFlow(subId)
            .collectLatestWithLifecycle(viewLifecycleOwner) { isReady ->
                Log.d(TAG, "isVideoCallReadyFlow: update visible")
                preference?.isVisible = isReady
                Log.d(TAG, "isVideoCallReadyFlow: update visible: $isReady")
                isVisible = isReady
                preference?.let{
                    it.isVisible = isVisible
                    updateState(it)
                }
                callingPreferenceCategoryController?.updateChildVisible(preferenceKey, isReady)
            }
        callStateRepository.callStateFlow(subId).collectLatestWithLifecycle(viewLifecycleOwner) {
@@ -92,8 +97,10 @@ constructor(

    override fun updateState(preference: Preference) {
        super.updateState(preference)

        videoCallEditable =
            queryVoLteState(subId).isEnabledByUser && queryImsState(subId).isAllowUserControl
        Log.d(TAG, "updateState: update videoCallEditable: $videoCallEditable")
        updatePreference()
    }

+22 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ class VideoCallingPreferenceControllerTest {
    }

    @Test
    fun onViewCreated_videoCallIsNotReady_isShown() = runBlocking {
    fun onViewCreated_videoCallIsReady_isShown() = runBlocking {
        mockVideoCallingRepository.stub {
            on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(true)
        }
@@ -109,6 +109,27 @@ class VideoCallingPreferenceControllerTest {
        assertThat(preference.isVisible).isTrue()
    }

    @Test
    fun onViewCreated_videoCallIsReady_enabledAndChecked() = runBlocking {
        mockVideoCallingRepository.stub {
            on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(true)
        }
        mockVtQueryImsState.stub {
            on { isEnabledByUser } doReturn true
            on { isAllowUserControl } doReturn true
        }
        mockQueryVoLteState.stub { on { isEnabledByUser } doReturn true }
        mockCallStateRepository.stub {
            on { callStateFlow(SUB_ID) } doReturn flowOf(TelephonyManager.CALL_STATE_IDLE)
        }

        controller.onViewCreated(TestLifecycleOwner())
        delay(100)

        assertThat(preference.isEnabled).isTrue()
        assertThat(preference.isChecked).isTrue()
    }

    @Test
    fun updateState_4gLteOff_disabledAndUnchecked() {
        mockQueryVoLteState.stub { on { isEnabledByUser } doReturn false }