Skip to content

Commit

Permalink
WIP: Handles navigating back from the tower map fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrowlands committed Nov 1, 2024
1 parent 5135ac9 commit cfcbb6f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.navigation.fragment.findNavController
import com.craxiom.networksurvey.SimChangeReceiver
import com.craxiom.networksurvey.listeners.ICellularSurveyRecordListener
import com.craxiom.networksurvey.model.CellularProtocol
Expand Down Expand Up @@ -186,7 +185,7 @@ class TowerMapFragment : AServiceDataFragment(), ICellularSurveyRecordListener {
builder.setNegativeButton("Reject") { dialog, _ ->
PreferenceUtils.setAcceptMapPrivacy(requireContext(), false)
dialog.dismiss()
findNavController().popBackStack() // Go back to the previous fragment // TODO WIP Test this
navigateBack()
}
builder.show()
}
Expand Down Expand Up @@ -221,7 +220,7 @@ class TowerMapFragment : AServiceDataFragment(), ICellularSurveyRecordListener {
}

NsTheme {
TowerMapScreen(viewModel = viewModel!!)
TowerMapScreen(viewModel = viewModel!!, onBackButtonPressed = ::navigateBack)
}

if (servingCell != null)
Expand All @@ -231,4 +230,9 @@ class TowerMapFragment : AServiceDataFragment(), ICellularSurveyRecordListener {
)
}
}

private fun navigateBack() {
val nsActivity = activity ?: return
nsActivity.onBackPressed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Info
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
Expand Down Expand Up @@ -106,7 +107,10 @@ private const val MAX_TOWERS_ON_MAP = 5000
* NS backend.
*/
@Composable
internal fun TowerMapScreen(viewModel: TowerMapViewModel = viewModel()) {
internal fun TowerMapScreen(
viewModel: TowerMapViewModel = viewModel(),
onBackButtonPressed: () -> Unit
) {

val paddingInsets by viewModel.paddingInsets.collectAsStateWithLifecycle()

Expand Down Expand Up @@ -153,6 +157,22 @@ internal fun TowerMapScreen(viewModel: TowerMapViewModel = viewModel()) {
.padding(top = statusBarHeight + 4.dp, end = 16.dp)
) {
Row {
Spacer(modifier = Modifier.width(8.dp))

IconButton(onClick = { onBackButtonPressed() }) {
Icon(
Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Back button",
tint = MaterialTheme.colorScheme.onSurface,
modifier = Modifier
.size(56.dp)
.padding(0.dp)
.background(color = MaterialTheme.colorScheme.primary)
)
}

Spacer(modifier = Modifier.weight(1f))

IconButton(onClick = { showInfoDialog = true }) {
Icon(
Icons.Default.Info,
Expand All @@ -164,6 +184,7 @@ internal fun TowerMapScreen(viewModel: TowerMapViewModel = viewModel()) {
.background(color = MaterialTheme.colorScheme.onSurface)
)
}

Spacer(modifier = Modifier.width(16.dp))

Button(
Expand Down

0 comments on commit cfcbb6f

Please sign in to comment.