mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added initial code for the custom tle import from url
This commit is contained in:
1 parent
3b5c3a8bb3
commit
d804c20bd0
7 files changed
+108
-24
No files matched your search
@@ -36,8 +36,8 @@ class DefaultRepository @Inject constructor(
|
||||
private val remoteSource: RemoteSource
|
||||
) : Repository {
|
||||
|
||||
override suspend fun updateEntriesFromFile(uri: Uri) {
|
||||
resolver.openInputStream(uri)?.use {
|
||||
override suspend fun updateEntriesFromFile(tleUri: Uri) {
|
||||
resolver.openInputStream(tleUri)?.use {
|
||||
withContext(Dispatchers.IO) {
|
||||
val tleList = TLE.importSat(it)
|
||||
val entries = tleList.map { SatEntry(it) }
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.rtbishop.look4sat.data.Transmitter
|
||||
|
||||
interface Repository {
|
||||
|
||||
suspend fun updateEntriesFromFile(uri: Uri)
|
||||
suspend fun updateEntriesFromFile(tleUri: Uri)
|
||||
|
||||
suspend fun updateEntriesFromUrl(tleUrl: String)
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.rtbishop.look4sat.ui
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
import android.content.Intent
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.pm.PackageManager
|
||||
@@ -33,6 +34,7 @@ import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@@ -46,6 +48,7 @@ import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.dagger.ViewModelFactory
|
||||
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 kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -162,7 +165,8 @@ class MainActivity : AppCompatActivity() {
|
||||
it.lockButton()
|
||||
}
|
||||
drawerBinding.drawerBtnTleUrl.setOnClickListener {
|
||||
viewModel.updateEntriesFromWeb()
|
||||
showTleUrlDialog()
|
||||
mainBinding.drawerLayout.closeDrawers()
|
||||
it.lockButton()
|
||||
}
|
||||
drawerBinding.drawerBtnTrans.setOnClickListener {
|
||||
@@ -177,6 +181,27 @@ class MainActivity : AppCompatActivity() {
|
||||
drawerBinding.drawerBtnExit.setOnClickListener { finish() }
|
||||
}
|
||||
|
||||
private fun showTleUrlDialog() {
|
||||
var tleUrl = ""
|
||||
val dialogBinding = DialogTleUrlBinding.inflate(layoutInflater).apply {
|
||||
dialogTleInput.addTextChangedListener {
|
||||
tleUrl = it.toString()
|
||||
}
|
||||
dialogTleNeg.setOnClickListener {
|
||||
|
||||
}
|
||||
dialogTlePos.setOnClickListener {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
AlertDialog.Builder(this).apply {
|
||||
setView(dialogBinding.root)
|
||||
create()
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun toast(message: String) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
@@ -98,10 +98,15 @@ class SharedViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun updateEntriesFromWeb() {
|
||||
fun updateEntriesFromWeb(tleUrl: String? = null) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val url = prefsManager.getTleUrl()
|
||||
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)
|
||||
|
||||
@@ -139,9 +139,9 @@ class PassListFragment : Fragment(R.layout.fragment_pass_list) {
|
||||
etHoursAhead.setText(hoursAhead.toString())
|
||||
etMinEl.setText(minEl.toString())
|
||||
|
||||
val builder = AlertDialog.Builder(mainActivity)
|
||||
builder.setTitle(getString(R.string.dialog_filter_passes))
|
||||
.setPositiveButton(getString(R.string.btn_ok)) { _, _ ->
|
||||
AlertDialog.Builder(mainActivity).apply {
|
||||
setTitle(getString(R.string.dialog_filter_passes))
|
||||
setPositiveButton(getString(R.string.btn_ok)) { _, _ ->
|
||||
val hoursStr = etHoursAhead.text.toString()
|
||||
val elevationStr = etMinEl.text.toString()
|
||||
if (hoursStr.isNotEmpty() && elevationStr.isNotEmpty()) {
|
||||
@@ -174,12 +174,13 @@ class PassListFragment : Fragment(R.layout.fragment_pass_list) {
|
||||
).show()
|
||||
|
||||
}
|
||||
.setNegativeButton(getString(R.string.btn_cancel)) { dialog, _ ->
|
||||
setNegativeButton(getString(R.string.btn_cancel)) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
}
|
||||
.setView(satPassPrefView)
|
||||
.create()
|
||||
.show()
|
||||
setView(satPassPrefView)
|
||||
create()
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showSelectSatDialog(
|
||||
|
||||
@@ -29,10 +29,10 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="@string/dialog_select_sat"
|
||||
android:textSize="21sp"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
@@ -42,8 +42,9 @@
|
||||
android:id="@+id/dialog_search"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginTop="4dp"
|
||||
app:layout_constraintEnd_toEndOf="@+id/dialog_title"
|
||||
app:layout_constraintStart_toStartOf="@+id/dialog_title"
|
||||
app:layout_constraintTop_toBottomOf="@+id/dialog_title" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
@@ -53,18 +54,17 @@
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/dialog_btn_negative"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/dialog_title"
|
||||
app:layout_constraintStart_toStartOf="@+id/dialog_title"
|
||||
app:layout_constraintTop_toBottomOf="@+id/dialog_search" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_btn_neutral"
|
||||
style="@style/SatEntryDialogText"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:text="@string/btn_all_none"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/dialog_btn_negative"
|
||||
app:layout_constraintStart_toStartOf="@+id/dialog_recycler" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_btn_negative"
|
||||
@@ -79,10 +79,10 @@
|
||||
style="@style/SatEntryDialogText"
|
||||
android:layout_width="36dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:gravity="end"
|
||||
android:text="@string/btn_ok"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
app:layout_constraintEnd_toEndOf="@+id/dialog_recycler" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/dialogTle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialotTleTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="TextView"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/dialogTleInput"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hint="https://server/with/tle.txt"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textWebEditText"
|
||||
app:layout_constraintEnd_toEndOf="@+id/dialogTlePos"
|
||||
app:layout_constraintStart_toStartOf="@+id/dialotTleTitle"
|
||||
app:layout_constraintTop_toBottomOf="@+id/dialotTleTitle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialogTleNeg"
|
||||
style="@style/SatEntryDialogText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:text="@string/btn_cancel"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/dialogTlePos"
|
||||
app:layout_constraintEnd_toStartOf="@+id/dialogTlePos" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialogTlePos"
|
||||
style="@style/SatEntryDialogText"
|
||||
android:layout_width="36dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:gravity="end"
|
||||
android:text="@string/btn_ok"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/dialogTleInput" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in new issue
Block a user