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

Commit a58a7646 authored by Haijie Hong's avatar Haijie Hong Committed by Android (Google) Code Review
Browse files

Merge "Scroll to top when opening more settings page" into main

parents 7eacf7e6 ce73cba9
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
            }
@@ -495,6 +500,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() {