Added custom source TLE update dialog

This commit is contained in:
Arty Bishop committed 2021-05-16 19:13:11 +01:00
1 parent 5de8787368
commit 1da35e901a
17 files changed
+113 -296

No files matched your search

@@ -28,10 +28,10 @@ import androidx.core.content.ContextCompat
import androidx.preference.EditTextPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.google.android.material.snackbar.Snackbar
import com.rtbishop.look4sat.R
import com.rtbishop.look4sat.data.PreferencesSource
import com.rtbishop.look4sat.framework.PreferencesProvider
import com.rtbishop.look4sat.utility.showSnack
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
@@ -46,7 +46,7 @@ class AppSettingsFragment : PreferenceFragmentCompat() {
if (isGranted) {
updatePositionFromGPS()
} else {
showSnack(getString(R.string.pref_pos_gps_error))
requireView().showSnack(getString(R.string.pref_pos_gps_error))
}
}
@@ -75,7 +75,7 @@ class AppSettingsFragment : PreferenceFragmentCompat() {
if (Patterns.IP_ADDRESS.matcher(newValue.toString()).matches()) {
return@setOnPreferenceChangeListener true
} else {
showSnack(getString(R.string.tracking_rotator_address_invalid))
requireView().showSnack(getString(R.string.tracking_rotator_address_invalid))
return@setOnPreferenceChangeListener false
}
}
@@ -88,7 +88,7 @@ class AppSettingsFragment : PreferenceFragmentCompat() {
if (portValue.isNotEmpty() && portValue.toInt() in 1024..65535) {
return@setOnPreferenceChangeListener true
} else {
showSnack(getString(R.string.tracking_rotator_port_invalid))
requireView().showSnack(getString(R.string.tracking_rotator_port_invalid))
return@setOnPreferenceChangeListener false
}
}
@@ -97,10 +97,10 @@ class AppSettingsFragment : PreferenceFragmentCompat() {
private fun updatePositionFromQth(qthString: String): Boolean {
return if (preferencesSource.updatePositionFromQTH(qthString)) {
showSnack(getString(R.string.pref_pos_success))
requireView().showSnack(getString(R.string.pref_pos_success))
true
} else {
showSnack(getString(R.string.pref_pos_qth_error))
requireView().showSnack(getString(R.string.pref_pos_qth_error))
false
}
}
@@ -110,14 +110,10 @@ class AppSettingsFragment : PreferenceFragmentCompat() {
val locPermResult = ContextCompat.checkSelfPermission(requireContext(), locPermString)
if (locPermResult == PackageManager.PERMISSION_GRANTED) {
if (preferencesSource.updatePositionFromGPS()) {
showSnack(getString(R.string.pref_pos_success))
} else showSnack(getString(R.string.pref_pos_gps_null))
requireView().showSnack(getString(R.string.pref_pos_success))
} else {
requireView().showSnack(getString(R.string.pref_pos_gps_null))
}
} else requestPermissionLauncher.launch(locPermString)
}
private fun showSnack(message: String) {
Snackbar.make(requireView(), message, Snackbar.LENGTH_SHORT).apply {
setAnchorView(R.id.nav_bottom)
}.show()
}
}
@@ -1,45 +0,0 @@
/*
* Look4Sat. Amateur radio satellite tracker and pass predictor.
* Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.rtbishop.look4sat.presentation.appSplashDialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.appcompat.app.AppCompatDialogFragment
import com.rtbishop.look4sat.R
import com.rtbishop.look4sat.databinding.DialogSplashBinding
class AppSplashDialog : AppCompatDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, group: ViewGroup?, state: Bundle?): View? {
return inflater.inflate(R.layout.dialog_splash, group, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
DialogSplashBinding.bind(view).apply {
dialog?.window?.setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT
)
splashOkButton.setOnClickListener { dismiss() }
}
}
}
@@ -18,18 +18,21 @@
package com.rtbishop.look4sat.presentation.satItemScreen
import android.os.Bundle
import android.util.Patterns
import android.view.View
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.SimpleItemAnimator
import com.google.android.material.snackbar.Snackbar
import com.rtbishop.look4sat.R
import com.rtbishop.look4sat.databinding.DialogSourceBinding
import com.rtbishop.look4sat.databinding.FragmentEntriesBinding
import com.rtbishop.look4sat.domain.model.SatItem
import com.rtbishop.look4sat.framework.model.Result
import com.rtbishop.look4sat.utility.RecyclerDivider
import com.rtbishop.look4sat.utility.showSnack
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
@@ -59,6 +62,7 @@ class SatItemFragment : Fragment(R.layout.fragment_entries) {
addItemDecoration(RecyclerDivider(R.drawable.rec_divider_light))
}
importWeb.setOnClickListener { viewModel.updateEntriesFromWeb(null) }
importSource.setOnClickListener { showSourceDialog() }
importFile.setOnClickListener { filePicker.launch("*/*") }
selectMode.setOnClickListener { viewModel.createModesDialog(requireContext()).show() }
selectAll.setOnClickListener { viewModel.selectCurrentItems() }
@@ -88,11 +92,26 @@ class SatItemFragment : Fragment(R.layout.fragment_entries) {
is Result.Error -> {
binding.entriesProgress.visibility = View.INVISIBLE
binding.entriesRecycler.visibility = View.VISIBLE
val errorMsg = getString(R.string.entries_update_error)
Snackbar.make(requireView(), errorMsg, Snackbar.LENGTH_SHORT).apply {
setAnchorView(R.id.nav_bottom)
}.show()
requireView().showSnack(getString(R.string.entries_update_error))
}
}
}
private fun showSourceDialog() {
val dialogBinding = DialogSourceBinding.inflate(requireActivity().layoutInflater)
val dialogBuilder = AlertDialog.Builder(requireContext()).apply {
setMessage(getString(R.string.sources_title))
setView(dialogBinding.root)
setPositiveButton(android.R.string.ok) { _, _ ->
val editTextInput = dialogBinding.sourceUrl.text.toString()
if (Patterns.WEB_URL.matcher(editTextInput).matches()) {
viewModel.updateEntriesFromWeb(listOf(editTextInput))
} else {
requireView().showSnack(getString(R.string.sources_error))
}
}
setNeutralButton(android.R.string.cancel, null)
}
dialogBuilder.create().show()
}
}
@@ -58,8 +58,8 @@ class SatTransAdapter : RecyclerView.Adapter<SatTransAdapter.TransHolder>() {
RecyclerView.ViewHolder(binding.root) {
private val divider = 1000000f
private val strNo = itemView.context.getString(R.string.btn_no)
private val strYes = itemView.context.getString(R.string.btn_yes)
private val strNo = itemView.context.getString(R.string.no)
private val strYes = itemView.context.getString(R.string.yes)
private val mode = itemView.context.getString(R.string.trans_mode)
private val formatLink = itemView.context.getString(R.string.trans_link_low)
private val formatLinkNull = itemView.context.getString(R.string.trans_no_link)
@@ -18,10 +18,13 @@
package com.rtbishop.look4sat.utility
import android.os.Bundle
import android.view.View
import androidx.annotation.IdRes
import androidx.navigation.NavController
import androidx.navigation.NavOptions
import androidx.navigation.Navigator
import com.google.android.material.snackbar.Snackbar
import com.rtbishop.look4sat.R
import java.util.concurrent.TimeUnit
fun Long.toTimerString(): String {
@@ -38,6 +41,12 @@ fun Double.round(decimals: Int): Double {
return kotlin.math.round(this * multiplier) / multiplier
}
fun View.showSnack(message: String, isAnchored: Boolean = true) {
Snackbar.make(this, message, Snackbar.LENGTH_SHORT).apply {
if (isAnchored) setAnchorView(R.id.nav_bottom)
}.show()
}
fun NavController.navigateSafe(
@IdRes resId: Int,
args: Bundle? = null,