Dan Ballard pushed to branch firefox-android-115.2.1-13.5-1 at The Tor Project / Applications / firefox-android
Commits: 737cb590 by clairehurst at 2024-05-06T15:30:26-06:00 fixup! Add Tor integration and UI
- - - - -
2 changed files:
- fenix/app/src/main/java/org/mozilla/fenix/tor/TorLogsComposeFragment.kt - fenix/app/src/main/java/org/mozilla/fenix/tor/TorLogsViewModel.kt
Changes:
===================================== fenix/app/src/main/java/org/mozilla/fenix/tor/TorLogsComposeFragment.kt ===================================== @@ -8,7 +8,9 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -16,15 +18,20 @@ 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.FloatingActionButton +import androidx.compose.material.Icon +import androidx.compose.material.Scaffold 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.res.painterResource import androidx.compose.ui.unit.dp import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import mozilla.components.ui.colors.PhotonColors +import org.mozilla.fenix.R
class TorLogsComposeFragment : Fragment() { private val viewModel: TorLogsViewModel by viewModels() @@ -36,47 +43,72 @@ class TorLogsComposeFragment : Fragment() { ): 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) - } - } + Scaffold( + floatingActionButton = { CopyLogsButton() }, + content = { TorLogs(paddingValues = it) }, + ) + } + } + } + + @Composable + private fun TorLogs(paddingValues: PaddingValues) { + 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) + .padding(paddingValues) + .background(PhotonColors.Ink50), // Standard background color + ) { + 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 { + @Composable + @Stable + private 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.timestamp.toString(), - color = PhotonColors.LightGrey40, - modifier = modifier - .padding(bottom = 4.dp), + text = log.text, + color = PhotonColors.LightGrey05, ) } - Text( - text = log.text, - color = PhotonColors.LightGrey05, + } + + @Composable + private fun CopyLogsButton() { + FloatingActionButton( + onClick = { viewModel.copyAllLogsToClipboard() }, + content = { + Icon( + painter = painterResource(id = R.drawable.ic_copy), + contentDescription = getString(R.string.share_copy_link_to_clipboard), + ) + }, + backgroundColor = PhotonColors.Violet50, // Same color as connect button + contentColor = PhotonColors.LightGrey05, ) } }
===================================== fenix/app/src/main/java/org/mozilla/fenix/tor/TorLogsViewModel.kt ===================================== @@ -63,10 +63,10 @@ class TorLogsViewModel(application: Application) : AndroidViewModel(application) } }
- fun copyAllLogsToClipboard() { // TODO add kebab menu in top right corner which includes option to "Copy all logs" + fun copyAllLogsToClipboard() { clipboardManager.setPrimaryClip( ClipData.newPlainText( - "Copied Text", + getApplication<Application>().getString(R.string.preferences_tor_logs), getAllTorLogs(), ), )
View it on GitLab: https://gitlab.torproject.org/tpo/applications/firefox-android/-/commit/737c...