mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added preferences values checks against null
This commit is contained in:
1 parent
3f96fb0933
commit
f9438eb5f7
2 files changed
+41
-26
No files matched your search
@@ -58,7 +58,7 @@ class SettingsFragment : PreferenceFragmentCompat(),
|
||||
InputType.TYPE_NUMBER_FLAG_SIGNED
|
||||
}
|
||||
latPref?.setOnPreferenceChangeListener { _, newValue ->
|
||||
if (newValue.toString().toDouble() < -90.0 || newValue.toString().toDouble() > 90.0) {
|
||||
if (newValue.toString().isEmpty() || newValue.toString().toDouble() < -90.0 || newValue.toString().toDouble() > 90.0) {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
getString(R.string.pref_lat_input_error),
|
||||
@@ -75,7 +75,7 @@ class SettingsFragment : PreferenceFragmentCompat(),
|
||||
InputType.TYPE_NUMBER_FLAG_SIGNED
|
||||
}
|
||||
lonPref?.setOnPreferenceChangeListener { _, newValue ->
|
||||
if (newValue.toString().toDouble() < -180.0 || newValue.toString().toDouble() > 180.0) {
|
||||
if (newValue.toString().isEmpty() || newValue.toString().toDouble() < -180.0 || newValue.toString().toDouble() > 180.0) {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
getString(R.string.pref_lon_input_error),
|
||||
@@ -92,7 +92,7 @@ class SettingsFragment : PreferenceFragmentCompat(),
|
||||
InputType.TYPE_NUMBER_FLAG_SIGNED
|
||||
}
|
||||
altPref?.setOnPreferenceChangeListener { _, newValue ->
|
||||
if (newValue.toString().toDouble() < -413.0 || newValue.toString().toDouble() > 8850.0) {
|
||||
if (newValue.toString().isEmpty() || newValue.toString().toDouble() < -413.0 || newValue.toString().toDouble() > 8850.0) {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
getString(R.string.pref_alt_input_error),
|
||||
@@ -105,7 +105,7 @@ class SettingsFragment : PreferenceFragmentCompat(),
|
||||
|
||||
delayPref?.setOnBindEditTextListener { it.inputType = InputType.TYPE_CLASS_NUMBER }
|
||||
delayPref?.setOnPreferenceChangeListener { _, newValue ->
|
||||
if (newValue.toString().toLong() < 250 || newValue.toString().toLong() > 10000) {
|
||||
if (newValue.toString().isEmpty() || newValue.toString().toLong() < 250 || newValue.toString().toLong() > 10000) {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
getString(R.string.pref_update_freq_input_error),
|
||||
|
||||
@@ -100,7 +100,9 @@ class SkyFragment : Fragment() {
|
||||
swipeLayout.setProgressBackgroundColorSchemeResource(R.color.themeAccent)
|
||||
swipeLayout.setColorSchemeResources(R.color.darkOnLight)
|
||||
swipeLayout.setOnRefreshListener { calculatePasses() }
|
||||
btnPassPrefs.setOnClickListener { showSatPassPrefsDialog() }
|
||||
btnPassPrefs.setOnClickListener {
|
||||
showSatPassPrefsDialog(viewModel.hoursAhead, viewModel.minEl)
|
||||
}
|
||||
fab.setOnClickListener {
|
||||
showSelectSatDialog(viewModel.tleMainList, viewModel.tleSelection)
|
||||
}
|
||||
@@ -120,34 +122,47 @@ class SkyFragment : Fragment() {
|
||||
})
|
||||
}
|
||||
|
||||
private fun showSatPassPrefsDialog() {
|
||||
private fun showSatPassPrefsDialog(hoursAhead: Int, minEl: Double) {
|
||||
val satPassPrefView = View.inflate(mainActivity, R.layout.sat_pass_pref, null)
|
||||
val etHoursAhead = satPassPrefView.findViewById<EditText>(R.id.pref_hours_ahead_et)
|
||||
val etMinEl = satPassPrefView.findViewById<EditText>(R.id.pref_min_el_et)
|
||||
etHoursAhead.setText(viewModel.hoursAhead.toString())
|
||||
etMinEl.setText(viewModel.minEl.toString())
|
||||
etHoursAhead.setText(hoursAhead.toString())
|
||||
etMinEl.setText(minEl.toString())
|
||||
|
||||
val builder = AlertDialog.Builder(mainActivity)
|
||||
builder.setTitle(getString(R.string.dialog_pass_prefs))
|
||||
.setPositiveButton(getString(R.string.btn_ok)) { _, _ ->
|
||||
val hoursAhead = etHoursAhead.text.toString().toInt()
|
||||
val minEl = etMinEl.text.toString().toDouble()
|
||||
if (hoursAhead < 1 || hoursAhead > 168) {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
"Value should be within 1-168 hours",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else if (minEl < 0 || minEl > 90) {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
"Value should be within 0-90 deg",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
viewModel.setPassPrefs(hoursAhead, minEl)
|
||||
calculatePasses()
|
||||
}
|
||||
val hoursStr = etHoursAhead.text.toString()
|
||||
val elevationStr = etMinEl.text.toString()
|
||||
if (hoursStr.isNotEmpty() && elevationStr.isNotEmpty()) {
|
||||
val hours = hoursStr.toInt()
|
||||
val elevation = elevationStr.toDouble()
|
||||
when {
|
||||
hours < 1 || hours > 168 -> {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
"Value should be within 1-168 hours",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
elevation < 0 || elevation > 90 -> {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
"Value should be within 0-90 deg",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
else -> {
|
||||
viewModel.setPassPrefs(hours, elevation)
|
||||
calculatePasses()
|
||||
}
|
||||
}
|
||||
} else Toast.makeText(
|
||||
mainActivity,
|
||||
"Please, enter the value",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
|
||||
}
|
||||
.setNegativeButton(getString(R.string.btn_cancel)) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
|
||||
Reference in new issue
Block a user