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

Commit ce73cba9 authored by Haijie Hong's avatar Haijie Hong
Browse files

Scroll to top when opening more settings page

Test: local tested
Flag: EXEMPT minor fix
Bug: 343317785
Change-Id: I5e90e4b1b3bcd5329c6574655ad6a3dee537438c
parent 9c67a100
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -26,9 +26,13 @@ import android.os.Bundle
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.core.graphics.drawable.toDrawable
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -227,6 +231,7 @@ class DeviceDetailsFragmentFormatterImpl(

        dashboardFragment.lifecycleScope.launch {
            if (isLoading) {
                scrollToTop()
                dashboardFragment.setLoading(false, false)
                isLoading = false
            }
@@ -493,6 +498,19 @@ class DeviceDetailsFragmentFormatterImpl(
        }
    }

    private fun scrollToTop() {
        // Temporary fix to make sure the screen is scroll to the top when rendering.
        ComposePreference(context).apply {
            order = -1
            isEnabled = false
            isSelectable = false
            setContent { Spacer(modifier = Modifier.height(1.dp)) }
        }.also {
            dashboardFragment.preferenceScreen.addPreference(it)
            dashboardFragment.scrollToPreference(it)
        }
    }

    private fun getPreferenceKey(settingId: Int) = "DEVICE_SETTING_${settingId}"

    private class SpotlightPreference(context: Context) : Preference(context) {
+1 −1
Original line number Diff line number Diff line
@@ -404,7 +404,7 @@ class DeviceDetailsFragmentFormatterTest {
        for (i in 0..<fragment.preferenceScreen.preferenceCount) {
            prefs.add(fragment.preferenceScreen.getPreference(i))
        }
        return prefs
        return prefs.filter { it.key != null }
    }

    class TestFragment(context: Context) : DashboardFragment() {