@@ -9,15 +9,12 @@ import androidx.compose.foundation.layout.Arrangement
99import androidx.compose.foundation.layout.Column
1010import androidx.compose.foundation.layout.Row
1111import androidx.compose.foundation.layout.Spacer
12- import androidx.compose.foundation.layout.WindowInsets
1312import androidx.compose.foundation.layout.fillMaxHeight
1413import androidx.compose.foundation.layout.padding
1514import androidx.compose.foundation.layout.size
16- import androidx.compose.foundation.layout.statusBars
1715import androidx.compose.foundation.lazy.LazyColumn
1816import androidx.compose.material3.Icon
1917import androidx.compose.material3.MaterialTheme
20- import androidx.compose.material3.Scaffold
2118import androidx.compose.material3.Text
2219import androidx.compose.runtime.Composable
2320import androidx.compose.runtime.LaunchedEffect
@@ -50,7 +47,7 @@ fun TaildropView(
5047 requestedTransfers : StateFlow <List <Ipn .OutgoingFile >>,
5148 applicationScope : CoroutineScope ,
5249 viewModel : TaildropViewModel =
53- viewModel(factory = TaildropViewModelFactory (requestedTransfers, applicationScope))
50+ viewModel(factory = TaildropViewModelFactory (requestedTransfers, applicationScope)),
5451) {
5552 val TAG = " TaildropView"
5653 val focusRequester = remember { FocusRequester () }
@@ -64,29 +61,28 @@ fun TaildropView(
6461 }
6562 }
6663
67- Scaffold (contentWindowInsets = WindowInsets .statusBars, topBar = { Header (R .string.share) }) {
68- paddingInsets ->
69- Column (modifier = Modifier .focusRequester(focusRequester).focusable().padding(paddingInsets)) {
70- val showDialog = viewModel.showDialog.collectAsState().value
64+ Column (modifier = Modifier .focusRequester(focusRequester).focusable()) {
65+ val showDialog = viewModel.showDialog.collectAsState().value
7166
72- showDialog?.let { ErrorDialog (type = it, action = { viewModel.showDialog.set(null ) }) }
67+ showDialog?.let { ErrorDialog (type = it, action = { viewModel.showDialog.set(null ) }) }
7368
74- FileShareHeader (
75- fileTransfers = requestedTransfers.collectAsState().value,
76- totalSize = viewModel.totalSize)
69+ FileShareHeader (
70+ fileTransfers = requestedTransfers.collectAsState().value,
71+ totalSize = viewModel.totalSize,
72+ )
7773
78- when (viewModel.state.collectAsState().value) {
79- Ipn .State .Running -> {
80- val peers by viewModel.myPeers.collectAsState()
81- val context = LocalContext .current
82- FileSharePeerList (
83- peers = peers,
84- stateViewGenerator = { peerId -> viewModel.TrailingContentForPeer (peerId = peerId) },
85- onShare = { viewModel.share(context, it) })
86- }
87- else -> {
88- FileShareConnectView { viewModel.startVPN() }
89- }
74+ when (viewModel.state.collectAsState().value) {
75+ Ipn .State .Running -> {
76+ val peers by viewModel.myPeers.collectAsState()
77+ val context = LocalContext .current
78+ FileSharePeerList (
79+ peers = peers,
80+ stateViewGenerator = { peerId -> viewModel.TrailingContentForPeer (peerId = peerId) },
81+ onShare = { viewModel.share(context, it) },
82+ )
83+ }
84+ else -> {
85+ FileShareConnectView { viewModel.startVPN() }
9086 }
9187 }
9288 }
@@ -96,7 +92,7 @@ fun TaildropView(
9692fun FileSharePeerList (
9793 peers : List <Tailcfg .Node >,
9894 stateViewGenerator : @Composable (String ) -> Unit ,
99- onShare : (Tailcfg .Node ) -> Unit
95+ onShare : (Tailcfg .Node ) -> Unit ,
10096) {
10197 SectionDivider (stringResource(R .string.my_devices))
10298
@@ -105,11 +101,13 @@ fun FileSharePeerList(
105101 Column (
106102 modifier = Modifier .padding(horizontal = 8 .dp).fillMaxHeight(),
107103 verticalArrangement = Arrangement .Center ,
108- horizontalAlignment = Alignment .CenterHorizontally ) {
109- Text (
110- stringResource(R .string.no_devices_to_share_with),
111- style = MaterialTheme .typography.titleMedium)
112- }
104+ horizontalAlignment = Alignment .CenterHorizontally ,
105+ ) {
106+ Text (
107+ stringResource(R .string.no_devices_to_share_with),
108+ style = MaterialTheme .typography.titleMedium,
109+ )
110+ }
113111 }
114112 false -> {
115113 LazyColumn {
@@ -119,7 +117,8 @@ fun FileSharePeerList(
119117 peer = peer,
120118 onClick = { onShare(peer) },
121119 subtitle = { peer.Hostinfo .OS ? : " " },
122- trailingContent = { stateViewGenerator(peer.StableID ) })
120+ trailingContent = { stateViewGenerator(peer.StableID ) },
121+ )
123122 }
124123 }
125124 }
@@ -132,17 +131,20 @@ fun FileShareConnectView(onToggle: () -> Unit) {
132131 Column (
133132 modifier = Modifier .padding(horizontal = 16 .dp).fillMaxHeight(),
134133 verticalArrangement = Arrangement .spacedBy(6 .dp, alignment = Alignment .CenterVertically ),
135- horizontalAlignment = Alignment .CenterHorizontally ) {
136- Text (
137- stringResource(R .string.connect_to_your_tailnet_to_share_files),
138- style = MaterialTheme .typography.titleMedium)
139- Spacer (modifier = Modifier .size(1 .dp))
140- PrimaryActionButton (onClick = onToggle) {
141- Text (
142- text = stringResource(id = R .string.connect),
143- fontSize = MaterialTheme .typography.titleMedium.fontSize)
144- }
145- }
134+ horizontalAlignment = Alignment .CenterHorizontally ,
135+ ) {
136+ Text (
137+ stringResource(R .string.connect_to_your_tailnet_to_share_files),
138+ style = MaterialTheme .typography.titleMedium,
139+ )
140+ Spacer (modifier = Modifier .size(1 .dp))
141+ PrimaryActionButton (onClick = onToggle) {
142+ Text (
143+ text = stringResource(id = R .string.connect),
144+ fontSize = MaterialTheme .typography.titleMedium.fontSize,
145+ )
146+ }
147+ }
146148}
147149
148150@Composable
@@ -155,23 +157,26 @@ fun FileShareHeader(fileTransfers: List<Ipn.OutgoingFile>, totalSize: Long) {
155157 true ->
156158 Text (
157159 stringResource(R .string.no_files_to_share),
158- style = MaterialTheme .typography.titleMedium)
160+ style = MaterialTheme .typography.titleMedium,
161+ )
159162 false -> {
160163
161164 when (fileTransfers.size) {
162165 1 -> Text (fileTransfers[0 ].Name , style = MaterialTheme .typography.titleMedium)
163166 else ->
164167 Text (
165168 stringResource(R .string.file_count, fileTransfers.size),
166- style = MaterialTheme .typography.titleMedium)
169+ style = MaterialTheme .typography.titleMedium,
170+ )
167171 }
168172 }
169173 }
170174 val size = Formatter .formatFileSize(LocalContext .current, totalSize.toLong())
171175 Text (
172176 size,
173177 style = MaterialTheme .typography.titleSmall,
174- color = MaterialTheme .colorScheme.secondary)
178+ color = MaterialTheme .colorScheme.secondary,
179+ )
175180 }
176181 }
177182 }
@@ -185,7 +190,8 @@ fun IconForTransfer(transfers: List<Ipn.OutgoingFile>) {
185190 Icon (
186191 painter = painterResource(R .drawable.warning),
187192 contentDescription = " no files" ,
188- modifier = Modifier .size(32 .dp))
193+ modifier = Modifier .size(32 .dp),
194+ )
189195 1 -> {
190196 // Show a thumbnail for single image shares.
191197 val context = LocalContext .current
@@ -194,20 +200,23 @@ fun IconForTransfer(transfers: List<Ipn.OutgoingFile>) {
194200 AsyncImage (
195201 model = transfers[0 ].uri,
196202 contentDescription = " one file" ,
197- modifier = Modifier .size(40 .dp))
203+ modifier = Modifier .size(40 .dp),
204+ )
198205 return
199206 }
200207
201208 Icon (
202209 painter = painterResource(R .drawable.single_file),
203210 contentDescription = " files" ,
204- modifier = Modifier .size(40 .dp))
211+ modifier = Modifier .size(40 .dp),
212+ )
205213 }
206214 }
207215 else ->
208216 Icon (
209217 painter = painterResource(R .drawable.single_file),
210218 contentDescription = " files" ,
211- modifier = Modifier .size(40 .dp))
219+ modifier = Modifier .size(40 .dp),
220+ )
212221 }
213222}
0 commit comments