Skip to content

Commit

Permalink
GNSS Failure Dialog Support
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrowlands committed Nov 4, 2024
1 parent 7d20803 commit a5ca33c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.navigation.NavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI.navigateUp
import androidx.preference.PreferenceManager
import com.craxiom.networksurvey.constants.NetworkSurveyConstants
import com.craxiom.networksurvey.listeners.IGnssFailureListener
import com.craxiom.networksurvey.services.GrpcConnectionService
import com.craxiom.networksurvey.services.NetworkSurveyService
import com.craxiom.networksurvey.services.NetworkSurveyService.SurveyServiceBinder
import com.craxiom.networksurvey.ui.main.GnssFailureDialog
import com.craxiom.networksurvey.ui.main.MainCompose
import com.craxiom.networksurvey.util.NsUtils
import com.craxiom.networksurvey.util.PreferenceUtils
Expand Down Expand Up @@ -103,37 +99,35 @@ class NetworkSurveyActivity : AppCompatActivity() {

gnssFailureListener = IGnssFailureListener {
try {
setContent {
GnssFailureDialog( // FIXME Do this for real
onDismiss = { }
) { }
}

val fragmentView = LayoutInflater.from(this).inflate(R.layout.gnss_failure, null)

val gnssFailureDialog = AlertDialog.Builder(this)
.setView(fragmentView)
.setPositiveButton(R.string.ok) { dialog: DialogInterface?, id: Int ->
val rememberDecisionCheckBox =
fragmentView.findViewById<CheckBox>(R.id.failureRememberDecisionCheckBox)
val checked = rememberDecisionCheckBox.isChecked
if (checked) {
PreferenceUtils.saveBoolean(
Application.get()
.getString(R.string.pref_key_ignore_raw_gnss_failure), true
)
// No need for GNSS failure updates anymore
if (networkSurveyService != null) {
networkSurveyService!!.clearGnssFailureListener()
runOnUiThread {
Timber.e("BLAH BLAH BLAH")
val fragmentView =
LayoutInflater.from(this).inflate(R.layout.gnss_failure, null)

val gnssFailureDialog = AlertDialog.Builder(this)
.setView(fragmentView)
.setPositiveButton(R.string.ok) { _: DialogInterface?, _: Int ->
val rememberDecisionCheckBox =
fragmentView.findViewById<CheckBox>(R.id.failureRememberDecisionCheckBox)
val checked = rememberDecisionCheckBox.isChecked
if (checked) {
PreferenceUtils.saveBoolean(
Application.get()
.getString(R.string.pref_key_ignore_raw_gnss_failure), true
)
// No need for GNSS failure updates anymore
if (networkSurveyService != null) {
networkSurveyService!!.clearGnssFailureListener()
}
}
}
}
.create()
.create()

gnssFailureDialog.show()
val viewById =
gnssFailureDialog.findViewById<TextView>(R.id.failureDescriptionTextView)
if (viewById != null) viewById.movementMethod = LinkMovementMethod.getInstance()
gnssFailureDialog.show()
val viewById =
gnssFailureDialog.findViewById<TextView>(R.id.failureDescriptionTextView)
if (viewById != null) viewById.movementMethod = LinkMovementMethod.getInstance()
}
} catch (t: Throwable) {
Timber.e(t, "Something went wrong when trying to show the GNSS Failure Dialog")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,6 @@ import com.craxiom.networksurvey.R
import com.craxiom.networksurvey.model.GnssType
import com.craxiom.networksurvey.util.PreferenceUtils

@Composable
fun GnssFailureDialog(onDismiss: () -> Unit, onConfirm: (Boolean) -> Unit) {
val checkedState = remember { mutableStateOf(false) }

// TODO Validate that this dialog works
AlertDialog(
onDismissRequest = onDismiss,
confirmButton = {
TextButton(
onClick = { onConfirm(checkedState.value) }
) { Text("OK") }
},
text = {
Column {
Text("GNSS Failure")
Checkbox(
checked = checkedState.value,
onCheckedChange = { checkedState.value = it }
)
}
}
)
}

@Composable
fun GnssFilterDialog(
initialItems: Array<String>,
Expand Down
2 changes: 1 addition & 1 deletion networksurvey/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ but work independently, so you have full control over how you handle your data.<
<!-- GNSS Failure Alert -->
<string name="app_icon_description">App Icon</string>
<string name="not_supported_title">GNSS Features May Not Work</string>
<string name="not_supported_description">Network Survey is not receiving raw GNSS measurements from the phone, which are required for generating the GNSS GeoPackage files, or streaming GNSS records over MQTT. For more information and a list of devices that support raw GNSS, consult Android\'s <a href="https://developer.android.com/guide/topics/sensors/gnss">Raw GNSS Measurements</a> guide.</string>
<string name="not_supported_description">Network Survey is not receiving raw GNSS measurements from the phone, which are required for generating the GNSS GeoPackage/CSV files, or streaming GNSS records over MQTT. For more information and a list of devices that support raw GNSS, consult Android\'s <a href="https://developer.android.com/guide/topics/sensors/gnss">Raw GNSS Measurements</a> guide.</string>
<string name="remember_my_decision">Don\'t ask me again</string>

<!-- GNSS Status View -->
Expand Down

0 comments on commit a5ca33c

Please sign in to comment.