mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added toast extension function
This commit is contained in:
1 parent
d804c20bd0
commit
a5c08c2614
5 files changed
+28
-52
No files matched your search
@@ -30,7 +30,6 @@ import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
@@ -50,6 +49,7 @@ import com.rtbishop.look4sat.data.Result
|
||||
import com.rtbishop.look4sat.databinding.ActivityMainBinding
|
||||
import com.rtbishop.look4sat.databinding.DialogTleUrlBinding
|
||||
import com.rtbishop.look4sat.databinding.DrawerHeaderBinding
|
||||
import com.rtbishop.look4sat.utility.GeneralUtils.toast
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
@@ -131,8 +131,10 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
is Result.Error -> {
|
||||
when (result.exception) {
|
||||
is SecurityException -> toast(getString(R.string.err_no_permissions))
|
||||
is IllegalArgumentException -> toast(getString(R.string.update_loc_failure))
|
||||
is SecurityException ->
|
||||
getString(R.string.err_no_permissions).toast(this)
|
||||
is IllegalArgumentException ->
|
||||
getString(R.string.update_loc_failure).toast(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,11 +143,11 @@ class MainActivity : AppCompatActivity() {
|
||||
when (result) {
|
||||
is Result.Success -> {
|
||||
when (result.data) {
|
||||
0 -> toast(getString(R.string.update_tle_success))
|
||||
1 -> toast(getString(R.string.update_trans_success))
|
||||
0 -> getString(R.string.update_tle_success).toast(this)
|
||||
1 -> getString(R.string.update_trans_success).toast(this)
|
||||
}
|
||||
}
|
||||
is Result.Error -> toast(getString(R.string.update_failure))
|
||||
is Result.Error -> getString(R.string.update_failure).toast(this)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -202,10 +204,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun toast(message: String) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
private fun View.lockButton() {
|
||||
lifecycleScope.launch {
|
||||
this@lockButton.isEnabled = false
|
||||
@@ -217,7 +215,7 @@ class MainActivity : AppCompatActivity() {
|
||||
private fun requestLocationUpdate() {
|
||||
if (ContextCompat.checkSelfPermission(this, permLocation) != permGranted) {
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permLocation)) {
|
||||
toast(getString(R.string.err_no_permissions))
|
||||
getString(R.string.err_no_permissions).toast(this)
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this, arrayOf(permLocation), permLocationCode)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ package com.rtbishop.look4sat.ui.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
@@ -38,6 +37,7 @@ import com.rtbishop.look4sat.ui.MainActivity
|
||||
import com.rtbishop.look4sat.ui.SharedViewModel
|
||||
import com.rtbishop.look4sat.ui.views.MapView
|
||||
import com.rtbishop.look4sat.utility.GeneralUtils
|
||||
import com.rtbishop.look4sat.utility.GeneralUtils.toast
|
||||
import com.rtbishop.look4sat.utility.PassPredictor
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -69,9 +69,7 @@ class MapViewFragment : Fragment(R.layout.fragment_map_view) {
|
||||
private fun setupObservers(binding: FragmentMapViewBinding) {
|
||||
viewModel.getGSP().observe(viewLifecycleOwner, androidx.lifecycle.Observer { result ->
|
||||
when (result) {
|
||||
is Result.Success -> {
|
||||
gsp = result.data
|
||||
}
|
||||
is Result.Success -> gsp = result.data
|
||||
}
|
||||
})
|
||||
|
||||
@@ -99,11 +97,7 @@ class MapViewFragment : Fragment(R.layout.fragment_map_view) {
|
||||
refreshView()
|
||||
} else {
|
||||
binding.fabMap.setOnClickListener {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
getString(R.string.err_no_sat_selected),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
getString(R.string.err_no_sat_selected).toast(mainActivity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ package com.rtbishop.look4sat.ui.fragments
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.ui.MainActivity
|
||||
import com.rtbishop.look4sat.ui.SharedViewModel
|
||||
import com.rtbishop.look4sat.utility.GeneralUtils.toast
|
||||
|
||||
class PreferencesFragment : PreferenceFragmentCompat(),
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
@@ -54,21 +54,15 @@ class PreferencesFragment : PreferenceFragmentCompat(),
|
||||
|
||||
findPreference<EditTextPreference>(keyLat)?.apply {
|
||||
summaryProvider = provider
|
||||
|
||||
setOnBindEditTextListener {
|
||||
it.inputType = InputType.TYPE_CLASS_NUMBER or
|
||||
InputType.TYPE_NUMBER_FLAG_DECIMAL or
|
||||
InputType.TYPE_NUMBER_FLAG_SIGNED
|
||||
}
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val valueStr = newValue.toString()
|
||||
if (valueStr.isEmpty() || valueStr == "-" || valueStr.toDouble() < -90.0 || valueStr.toDouble() > 90.0) {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
getString(R.string.pref_lat_input_error),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
getString(R.string.pref_lat_input_error).toast(mainActivity)
|
||||
return@setOnPreferenceChangeListener false
|
||||
}
|
||||
return@setOnPreferenceChangeListener true
|
||||
@@ -77,61 +71,45 @@ class PreferencesFragment : PreferenceFragmentCompat(),
|
||||
|
||||
findPreference<EditTextPreference>(keyLon)?.apply {
|
||||
summaryProvider = provider
|
||||
|
||||
setOnBindEditTextListener {
|
||||
it.inputType = InputType.TYPE_CLASS_NUMBER or
|
||||
InputType.TYPE_NUMBER_FLAG_DECIMAL or
|
||||
InputType.TYPE_NUMBER_FLAG_SIGNED
|
||||
}
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val valueStr = newValue.toString()
|
||||
if (valueStr.isEmpty() || valueStr == "-" || valueStr.toDouble() < -180.0 || valueStr.toDouble() > 180.0) {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
getString(R.string.pref_lon_input_error),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
getString(R.string.pref_lon_input_error).toast(mainActivity)
|
||||
return@setOnPreferenceChangeListener false
|
||||
}
|
||||
return@setOnPreferenceChangeListener true
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<EditTextPreference>(keyAlt)?.apply {
|
||||
summaryProvider = provider
|
||||
|
||||
setOnBindEditTextListener {
|
||||
it.inputType = InputType.TYPE_CLASS_NUMBER or
|
||||
InputType.TYPE_NUMBER_FLAG_DECIMAL or
|
||||
InputType.TYPE_NUMBER_FLAG_SIGNED
|
||||
}
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val valueStr = newValue.toString()
|
||||
if (valueStr.isEmpty() || valueStr == "-" || valueStr.toDouble() < -413.0 || valueStr.toDouble() > 8850.0) {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
getString(R.string.pref_alt_input_error),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
getString(R.string.pref_alt_input_error).toast(mainActivity)
|
||||
return@setOnPreferenceChangeListener false
|
||||
}
|
||||
return@setOnPreferenceChangeListener true
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<EditTextPreference>(keyDelay)?.apply {
|
||||
summaryProvider = provider
|
||||
|
||||
setOnBindEditTextListener { it.inputType = InputType.TYPE_CLASS_NUMBER }
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val valueStr = newValue.toString()
|
||||
if (valueStr.isEmpty() || valueStr.toLong() < 250 || valueStr.toLong() > 10000) {
|
||||
Toast.makeText(
|
||||
mainActivity,
|
||||
getString(R.string.pref_refresh_rate_input_error),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
getString(R.string.pref_refresh_rate_input_error).toast(mainActivity)
|
||||
return@setOnPreferenceChangeListener false
|
||||
}
|
||||
return@setOnPreferenceChangeListener true
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.rtbishop.look4sat.utility
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import java.util.*
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
@@ -25,4 +27,8 @@ object GeneralUtils {
|
||||
val radius = r * (piDiv2 - elevation) / piDiv2
|
||||
return (radius * sin(piDiv2 - azimuth)).toFloat()
|
||||
}
|
||||
|
||||
fun Any.toast(context: Context, duration: Int = Toast.LENGTH_SHORT): Toast {
|
||||
return Toast.makeText(context, this.toString(), duration).apply { show() }
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialotTleTitle"
|
||||
android:id="@+id/dialogTleTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
@@ -24,8 +24,8 @@
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textWebEditText"
|
||||
app:layout_constraintEnd_toEndOf="@+id/dialogTlePos"
|
||||
app:layout_constraintStart_toStartOf="@+id/dialotTleTitle"
|
||||
app:layout_constraintTop_toBottomOf="@+id/dialotTleTitle" />
|
||||
app:layout_constraintStart_toStartOf="@+id/dialogTleTitle"
|
||||
app:layout_constraintTop_toBottomOf="@+id/dialogTleTitle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialogTleNeg"
|
||||
|
||||
Reference in new issue
Block a user