mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Further changes to TLE custom sources dialog
This commit is contained in:
1 parent
ec03c76fa1
commit
7f26d2b136
10 files changed
+200
-68
No files matched your search
@@ -1,3 +1,3 @@
|
||||
package com.rtbishop.look4sat.data
|
||||
|
||||
data class TleSource(var url: String)
|
||||
data class TleSource(var url: String = String())
|
||||
@@ -45,15 +45,17 @@ import com.rtbishop.look4sat.Look4SatApp
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.dagger.ViewModelFactory
|
||||
import com.rtbishop.look4sat.data.Result
|
||||
import com.rtbishop.look4sat.data.TleSource
|
||||
import com.rtbishop.look4sat.databinding.ActivityMainBinding
|
||||
import com.rtbishop.look4sat.databinding.DialogTleUrlBinding
|
||||
import com.rtbishop.look4sat.databinding.DrawerHeaderBinding
|
||||
import com.rtbishop.look4sat.ui.fragments.TleSourcesDialogFragment
|
||||
import com.rtbishop.look4sat.utility.GeneralUtils.toast
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
class MainActivity : AppCompatActivity(), TleSourcesDialogFragment.SourcesSubmitListener {
|
||||
|
||||
private val pickFileReqCode = 111
|
||||
private val permLocationCode = 101
|
||||
@@ -165,7 +167,7 @@ class MainActivity : AppCompatActivity() {
|
||||
it.lockButton()
|
||||
}
|
||||
drawerBinding.drawerBtnTleUrl.setOnClickListener {
|
||||
showTleUrlDialog()
|
||||
showTleSourcesDialog()
|
||||
mainBinding.drawerLayout.closeDrawers()
|
||||
it.lockButton()
|
||||
}
|
||||
@@ -187,7 +189,7 @@ class MainActivity : AppCompatActivity() {
|
||||
dialogBinding.apply {
|
||||
var tleUrl = String()
|
||||
dialogTleInput.apply {
|
||||
hint = viewModel.getTleUrl()
|
||||
// hint = viewModel.getTleUrl()
|
||||
addTextChangedListener { tleUrl = it.toString() }
|
||||
}
|
||||
dialogTleNeg.setOnClickListener {
|
||||
@@ -201,6 +203,19 @@ class MainActivity : AppCompatActivity() {
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun showTleSourcesDialog() {
|
||||
val sources = viewModel.getTleSources().map { TleSource(it) }
|
||||
TleSourcesDialogFragment(sources).apply {
|
||||
setSourcesListener(this@MainActivity)
|
||||
show(supportFragmentManager, "TleSourcesDialog")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSourcesSubmit(list: List<TleSource>) {
|
||||
val sources = list.map { it.url }.toSet()
|
||||
viewModel.setTleSource(sources)
|
||||
}
|
||||
|
||||
private fun View.lockButton() {
|
||||
lifecycleScope.launch {
|
||||
this@lockButton.isEnabled = false
|
||||
|
||||
@@ -59,7 +59,6 @@ class SharedViewModel @Inject constructor(
|
||||
fun getRefreshRate() = prefsManager.getRefreshRate()
|
||||
fun getHoursAhead() = prefsManager.getHoursAhead()
|
||||
fun getMinElevation() = prefsManager.getMinElevation()
|
||||
fun getTleUrl() = prefsManager.getTleUrl()
|
||||
fun setPositionFromPref() = _gsp.postValue(Result.Success(prefsManager.getPosition()))
|
||||
suspend fun getAllEntries() = repository.getAllEntries()
|
||||
|
||||
@@ -102,15 +101,15 @@ class SharedViewModel @Inject constructor(
|
||||
fun updateEntriesFromWeb(tleUrl: String? = null) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val url = if (tleUrl.isNullOrEmpty()) {
|
||||
prefsManager.getTleUrl()
|
||||
} else {
|
||||
prefsManager.setTleUrl(tleUrl)
|
||||
tleUrl
|
||||
}
|
||||
val selected = repository.getSelectedEntries().map { it.catNum }
|
||||
repository.updateEntriesFromUrl(url)
|
||||
repository.updateEntriesSelection(selected)
|
||||
// val url = if (tleUrl.isNullOrEmpty()) {
|
||||
// prefsManager.getTleUrl()
|
||||
// } else {
|
||||
// prefsManager.setTleUrl(tleUrl)
|
||||
// tleUrl
|
||||
// }
|
||||
// val selected = repository.getSelectedEntries().map { it.catNum }
|
||||
// repository.updateEntriesFromUrl(url)
|
||||
// repository.updateEntriesSelection(selected)
|
||||
_updateStatus.postValue(Result.Success(0))
|
||||
} catch (e: Exception) {
|
||||
_updateStatus.postValue(Result.Error(e))
|
||||
|
||||
@@ -1,9 +1,28 @@
|
||||
/*
|
||||
* Look4Sat. Amateur radio and weather satellite tracker and passes predictor for Android.
|
||||
* Copyright (C) 2019, 2020 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 2 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, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.rtbishop.look4sat.ui.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.rtbishop.look4sat.data.TleSource
|
||||
import com.rtbishop.look4sat.databinding.ItemTleSourceBinding
|
||||
@@ -25,8 +44,9 @@ class TleSourcesAdapter(private var sources: MutableList<TleSource>) :
|
||||
return sources.size
|
||||
}
|
||||
|
||||
fun setSources(sources: MutableList<TleSource>) {
|
||||
this.sources = sources
|
||||
fun setSources(list: MutableList<TleSource>) {
|
||||
sources = list
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun getSources(): MutableList<TleSource> {
|
||||
@@ -37,14 +57,14 @@ class TleSourcesAdapter(private var sources: MutableList<TleSource>) :
|
||||
RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
fun bind(source: TleSource) {
|
||||
binding.tleSourceUrl.setText(source.url)
|
||||
binding.tleSourceUrl.doAfterTextChanged {
|
||||
source.url = it.toString()
|
||||
}
|
||||
binding.tleSourceBtnDel.setOnClickListener {
|
||||
sources.remove(source)
|
||||
notifyItemRemoved(adapterPosition)
|
||||
}
|
||||
binding.tleSourceUrl.addTextChangedListener {
|
||||
source.url = it.toString()
|
||||
notifyItemChanged(adapterPosition)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Look4Sat. Amateur radio and weather satellite tracker and passes predictor for Android.
|
||||
* Copyright (C) 2019, 2020 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 2 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, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.rtbishop.look4sat.ui.fragments
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatDialogFragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.rtbishop.look4sat.data.TleSource
|
||||
import com.rtbishop.look4sat.databinding.DialogTleSourcesBinding
|
||||
import com.rtbishop.look4sat.ui.adapters.TleSourcesAdapter
|
||||
|
||||
class TleSourcesDialogFragment(sources: List<TleSource>) :
|
||||
AppCompatDialogFragment() {
|
||||
|
||||
private lateinit var sourcesListener: SourcesSubmitListener
|
||||
private var sourcesAdapter = TleSourcesAdapter(sources.toMutableList())
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val binding = DialogTleSourcesBinding.inflate(requireActivity().layoutInflater)
|
||||
val tleSourcesDialog = Dialog(requireActivity()).apply {
|
||||
setContentView(binding.root)
|
||||
window?.setLayout(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
|
||||
binding.tleSourcesRecycler.apply {
|
||||
layoutManager = LinearLayoutManager(activity)
|
||||
adapter = sourcesAdapter
|
||||
}
|
||||
|
||||
binding.tleSourceBtnAdd.setOnClickListener {
|
||||
val tempSources = sourcesAdapter.getSources()
|
||||
tempSources.add(TleSource())
|
||||
sourcesAdapter.setSources(tempSources)
|
||||
sourcesAdapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
binding.tleSourcesBtnNeg.setOnClickListener { dismiss() }
|
||||
binding.tleSourcesBtnPos.setOnClickListener {
|
||||
sourcesListener.onSourcesSubmit(sourcesAdapter.getSources())
|
||||
dismiss()
|
||||
}
|
||||
|
||||
return tleSourcesDialog
|
||||
}
|
||||
|
||||
fun setSourcesListener(listener: SourcesSubmitListener): TleSourcesDialogFragment {
|
||||
sourcesListener = listener
|
||||
return this
|
||||
}
|
||||
|
||||
interface SourcesSubmitListener {
|
||||
fun onSourcesSubmit(list: List<TleSource>)
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,6 @@ class PrefsManager @Inject constructor(
|
||||
private val keyAltitude = "altitude"
|
||||
private val keyRefreshRate = "rate"
|
||||
private val keyCompass = "compass"
|
||||
private val keyTleUrl = "tleUrl"
|
||||
private val keyTleSources = "tleSources"
|
||||
private val defaultHoursAhead = 8
|
||||
private val defaultMinEl = 16.0
|
||||
@@ -67,10 +66,6 @@ class PrefsManager @Inject constructor(
|
||||
return GroundStationPosition(lat, lon, alt)
|
||||
}
|
||||
|
||||
fun getTleUrl(): String {
|
||||
return preferences.getString(keyTleUrl, defaultTleUrl)!!
|
||||
}
|
||||
|
||||
fun setHoursAhead(hours: Int) {
|
||||
preferences.edit {
|
||||
putInt(keyHoursAhead, hours)
|
||||
@@ -94,19 +89,14 @@ class PrefsManager @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun setTleUrl(tleUrl: String) {
|
||||
preferences.edit {
|
||||
putString(keyTleUrl, tleUrl)
|
||||
}
|
||||
}
|
||||
|
||||
fun getTleSources(): Set<String> {
|
||||
return preferences.getStringSet(keyTleSources, null) ?: emptySet()
|
||||
return preferences.getStringSet(keyTleSources, null) ?: setOf(defaultTleUrl)
|
||||
}
|
||||
|
||||
fun setTleSources(sources: Set<String>) {
|
||||
preferences.edit {
|
||||
putStringSet(keyTleSources, sources)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,34 +9,65 @@
|
||||
android:id="@+id/tleSourcesTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="@string/placeholder"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/manage_tle_sources"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintEnd_toStartOf="@+id/tleSourceBtnAdd"
|
||||
app:layout_constraintHorizontal_bias="0.51"
|
||||
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tleSourceBtnAdd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:contentDescription="@string/placeholder"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/tleSourcesTitle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/tleSourcesTitle"
|
||||
app:layout_constraintTop_toTopOf="@+id/tleSourcesTitle"
|
||||
app:srcCompat="@android:drawable/ic_menu_add" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/tleSourcesRecycler"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/tleSourceBtnAdd"
|
||||
android:layout_marginBottom="4dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/tleSourcesWarning"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tleSourcesTitle"
|
||||
app:layout_constraintVertical_chainStyle="packed" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/tleSourceBtnAdd"
|
||||
app:layout_constraintVertical_chainStyle="packed">
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tleSourcesWarning"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/please_make_sure_you_use_https_url_for_tle_source"
|
||||
app:layout_constraintBottom_toTopOf="@+id/tleSourcesBtnPos"
|
||||
app:layout_constraintEnd_toEndOf="@+id/tleSourcesRecycler"
|
||||
app:layout_constraintStart_toStartOf="@+id/tleSourcesRecycler" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tleSourcesBtnNeg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:text="@string/btn_cancel"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/tleSourcesBtnPos"
|
||||
app:layout_constraintEnd_toStartOf="@+id/tleSourcesBtnPos"
|
||||
app:layout_constraintHorizontal_chainStyle="spread_inside" />
|
||||
@@ -47,20 +78,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="@string/btn_ok"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/tleSourcesRecycler" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tleSourceBtnAdd"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:contentDescription="@string/placeholder"
|
||||
app:layout_constraintBottom_toTopOf="@+id/tleSourcesBtnPos"
|
||||
app:layout_constraintEnd_toEndOf="@+id/tleSourcesRecycler"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="@+id/tleSourcesRecycler"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tleSourcesRecycler"
|
||||
app:srcCompat="@android:drawable/ic_menu_add" />
|
||||
app:layout_constraintEnd_toEndOf="@+id/tleSourceBtnAdd" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -6,30 +6,38 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4dp">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/tleSourceUrl"
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/tleSourceInputLayout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/placeholder"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textUri"
|
||||
android:text="@string/placeholder"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/tleSourceBtnDel"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintHorizontal_chainStyle="packed"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/tleSourceUrl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:hint="@string/tle_source"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textUri" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tleSourceBtnDel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:contentDescription="@string/placeholder"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/tleSourceUrl"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/tleSourceInputLayout"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/tleSourceUrl"
|
||||
app:layout_constraintTop_toTopOf="@+id/tleSourceUrl"
|
||||
app:layout_constraintStart_toEndOf="@+id/tleSourceInputLayout"
|
||||
app:layout_constraintTop_toTopOf="@+id/tleSourceInputLayout"
|
||||
app:srcCompat="@android:drawable/ic_menu_close_clear_cancel" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -141,4 +141,6 @@
|
||||
|
||||
<string name="map_gsp">СТЦ</string>
|
||||
<string name="update_loc_failure">Проверьте ваши настройки GPS</string>
|
||||
<string name="manage_tle_sources">Manage TLE sources</string>
|
||||
<string name="tle_source">TLE source</string>
|
||||
</resources>
|
||||
@@ -166,4 +166,7 @@
|
||||
|
||||
<string name="map_gsp">GSP</string>
|
||||
<string name="placeholder" translatable="false">Placeholder</string>
|
||||
<string name="manage_tle_sources">Manage TLE sources</string>
|
||||
<string name="please_make_sure_you_use_https_url_for_tle_source" translatable="false">Please use HTTPS URLs only</string>
|
||||
<string name="tle_source">TLE source</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user