Skip to content

Commit

Permalink
Add share button for user copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Nov 15, 2023
1 parent c146f8f commit 97694a6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ fun MullvadMediumTopBar(
scrollBehavior = scrollBehavior,
colors =
TopAppBarDefaults.mediumTopAppBarColors(
containerColor = MaterialTheme.colorScheme.background
containerColor = MaterialTheme.colorScheme.background,
actionIconContentColor = MaterialTheme.colorScheme.onPrimary.copy(AlphaTopBar),
),
actions = actions
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package net.mullvad.mullvadvpn.compose.screen

import android.content.Intent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import net.mullvad.mullvadvpn.R
Expand Down Expand Up @@ -44,12 +49,29 @@ fun ViewLogsScreen(
uiState: ViewLogsUiState,
onBackClick: () -> Unit = {},
) {
val context = LocalContext.current
val shareLogs: (logs: String) -> Unit = {
val sendIntent: Intent =
Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, uiState.allLines.joinToString("\n"))
type = "text/plain"
}
val shareIntent = Intent.createChooser(sendIntent, null)

context.startActivity(shareIntent)
}

Scaffold(
topBar = {
MullvadMediumTopBar(
title = stringResource(id = R.string.view_logs),
navigationIcon = { NavigateBackIconButton(onBackClick) }
navigationIcon = { NavigateBackIconButton(onBackClick) },
actions = {
IconButton(onClick = { shareLogs(uiState.allLines.joinToString("\n")) }) {
Icon(imageVector = Icons.Default.Share, contentDescription = null)
}
}
)
}
) {
Expand All @@ -70,7 +92,6 @@ fun ViewLogsScreen(
color = MaterialTheme.colorScheme.primary
)
} else {
val scrollState = rememberScrollState()
val state = rememberLazyListState()
LazyColumn(
state = state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

private const val EMPTY_STRING = ""
private const val NEWLINE_STRING = "\n"
import net.mullvad.mullvadvpn.constant.EMPTY_STRING
import net.mullvad.mullvadvpn.constant.NEWLINE_STRING

@Composable
fun CustomTextField(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package net.mullvad.mullvadvpn.constant

const val EMPTY_STRING = ""
const val NEWLINE_STRING = "\n"
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.constant.NEWLINE_STRING
import net.mullvad.mullvadvpn.dataproxy.MullvadProblemReport

data class ViewLogsUiState(val allLines: List<String> = emptyList(), val isLoading: Boolean = true)
data class ViewLogsUiState(
val allLines: List<String> = emptyList(),
val isLoading: Boolean = true
) {
fun text() = allLines.joinToString(NEWLINE_STRING)
}

class ViewLogsViewModel(private val mullvadProblemReporter: MullvadProblemReport) : ViewModel() {

Expand Down

0 comments on commit 97694a6

Please sign in to comment.