Skip to content
Snippets Groups Projects

Bug 42309, Bug 42218: Implement Compose SelectionContainer and Column for better log copying

Files
4
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.tor
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.selection.DisableSelection
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.unit.dp
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import mozilla.components.ui.colors.PhotonColors
class TorLogsComposeFragment : Fragment() {
private val viewModel: TorLogsViewModel by viewModels()
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
return ComposeView(requireContext()).apply {
setContent {
SelectionContainer {
Column(
// Column instead of LazyColumn so that you can select all the logs, and not just one "screen" at a time
// The logs won't be too big so loading them all instead of just whats visible shouldn't be a big deal
modifier = Modifier
.fillMaxSize()
.verticalScroll(state = rememberScrollState(), reverseScrolling = true),
) {
for (log in viewModel.torLogs) {
LogRow(log = log)
}
}
}
}
}
}
}
@Composable
@Stable
fun LogRow(log: TorLog, modifier: Modifier = Modifier) {
Column(
modifier
.fillMaxWidth()
.padding(
start = 16.dp,
end = 16.dp,
bottom = 16.dp,
),
) {
DisableSelection {
Text(
text = log.timestamp.toString(),
color = PhotonColors.LightGrey40,
modifier = modifier
.padding(bottom = 4.dp),
)
}
Text(
text = log.text,
color = PhotonColors.LightGrey05,
)
}
}
Loading