mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added dialog for satellite selection. Showing only selected passes in the recycler.
This commit is contained in:
1 parent
09c6353c33
commit
bfc0561c34
3 files changed
+52
-47
No files matched your search
+1
-1
@@ -8,7 +8,7 @@ android {
|
|||||||
buildToolsVersion "29.0.2"
|
buildToolsVersion "29.0.2"
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.rtbishop.lookingsat"
|
applicationId "com.rtbishop.lookingsat"
|
||||||
minSdkVersion 22
|
minSdkVersion 24
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "0.2"
|
versionName "0.2"
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class SkyFragment : Fragment() {
|
|||||||
recView.visibility = View.INVISIBLE
|
recView.visibility = View.INVISIBLE
|
||||||
progressBar.visibility = View.VISIBLE
|
progressBar.visibility = View.VISIBLE
|
||||||
progressBar.isIndeterminate = true
|
progressBar.isIndeterminate = true
|
||||||
satPassList = viewModel.updateRecycler()
|
satPassList = viewModel.getPassesForSelectedSatellites()
|
||||||
recAdapter = SatPassAdapter(satPassList)
|
recAdapter = SatPassAdapter(satPassList)
|
||||||
recView.adapter = recAdapter
|
recView.adapter = recAdapter
|
||||||
progressBar.isIndeterminate = false
|
progressBar.isIndeterminate = false
|
||||||
@@ -67,41 +67,43 @@ class SkyFragment : Fragment() {
|
|||||||
fab.setOnClickListener { showSelectSatDialog() }
|
fab.setOnClickListener { showSelectSatDialog() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private var selectedSatList: List<TLE> = emptyList()
|
|
||||||
|
|
||||||
private fun showSelectSatDialog() {
|
private fun showSelectSatDialog() {
|
||||||
val tleList = mutableListOf<TLE>()
|
val tleSelectedMap = viewModel.tleSelectedMap
|
||||||
val listSize = viewModel.tleList.size
|
val tleMainListSize = viewModel.tleMainList.size
|
||||||
val satList = arrayOfNulls<String>(listSize)
|
|
||||||
val checkedSatList = BooleanArray(listSize)
|
val tleNameArray = arrayOfNulls<String>(tleMainListSize)
|
||||||
if (selectedSatList.isEmpty()) {
|
val tleCheckedArray = BooleanArray(tleMainListSize)
|
||||||
for ((position, tle) in viewModel.tleList.withIndex()) {
|
|
||||||
satList[position] = tle.name
|
if (tleSelectedMap.isEmpty()) {
|
||||||
checkedSatList[position] = false
|
for ((position, tle) in viewModel.tleMainList.withIndex()) {
|
||||||
|
tleNameArray[position] = tle.name
|
||||||
|
tleCheckedArray[position] = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for ((position, tle) in viewModel.tleMainList.withIndex()) {
|
||||||
|
tleNameArray[position] = tle.name
|
||||||
|
tleCheckedArray[position] = viewModel.tleSelectedMap.getOrDefault(tle, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val selectionMap = mutableMapOf<TLE, Boolean>()
|
||||||
val builder = AlertDialog.Builder(activity as MainActivity)
|
val builder = AlertDialog.Builder(activity as MainActivity)
|
||||||
builder.setTitle("Select satellites to track")
|
builder.setTitle("Select satellites to track")
|
||||||
|
.setMultiChoiceItems(tleNameArray, tleCheckedArray) { _, which, isChecked ->
|
||||||
builder.setMultiChoiceItems(satList, checkedSatList) { _, which, isChecked ->
|
selectionMap[viewModel.tleMainList[which]] = isChecked
|
||||||
checkedSatList[which] = isChecked
|
}
|
||||||
}
|
.setPositiveButton("Ok") { _, _ ->
|
||||||
|
for ((tle, value) in selectionMap) {
|
||||||
builder.setPositiveButton("Select") { _, _ ->
|
tleSelectedMap[tle] = value
|
||||||
for (index in checkedSatList.indices) {
|
|
||||||
val checked = checkedSatList[index]
|
|
||||||
if (checked) {
|
|
||||||
tleList.add(viewModel.tleList[index])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
.setNeutralButton("Clear All") { _, _ ->
|
||||||
|
tleSelectedMap.clear()
|
||||||
builder.setNegativeButton("Cancel") { dialog, _ ->
|
}
|
||||||
dialog.cancel()
|
.setNegativeButton("Cancel") { dialog, _ ->
|
||||||
}
|
dialog.cancel()
|
||||||
|
}
|
||||||
val dialog = builder.create()
|
.create()
|
||||||
dialog.show()
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,8 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
)
|
)
|
||||||
val gsp: LiveData<GroundStationPosition> = _gsp
|
val gsp: LiveData<GroundStationPosition> = _gsp
|
||||||
|
|
||||||
var tleList: List<TLE> = loadTwoLineElementFile().sortedWith(compareBy { it.name })
|
var tleMainList = loadTwoLineElementFile().sortedWith(compareBy { it.name })
|
||||||
|
var tleSelectedMap = mutableMapOf<TLE, Boolean>()
|
||||||
|
|
||||||
private fun loadTwoLineElementFile(): List<TLE> {
|
private fun loadTwoLineElementFile(): List<TLE> {
|
||||||
return try {
|
return try {
|
||||||
@@ -61,25 +62,27 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun updateRecycler(): List<SatPass> {
|
suspend fun getPassesForSelectedSatellites(): List<SatPass> {
|
||||||
val satPassList = mutableListOf<SatPass>()
|
val satPassList = mutableListOf<SatPass>()
|
||||||
var sortedList = listOf<SatPass>()
|
var sortedList = listOf<SatPass>()
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
for (tle in tleList.subList(0, 1)) {
|
for ((tle, value) in tleSelectedMap) {
|
||||||
try {
|
if (value) {
|
||||||
Log.d(tag, "Trying ${tle.name}")
|
try {
|
||||||
val passPredictor = PassPredictor(tle, gsp.value)
|
Log.d(tag, "Trying ${tle.name}")
|
||||||
val passes = passPredictor.getPasses(Date(), 6, false)
|
val passPredictor = PassPredictor(tle, gsp.value)
|
||||||
for (pass in passes) {
|
val passes = passPredictor.getPasses(Date(), 6, true)
|
||||||
Log.d(tag, "Trying ${pass.maxEl}")
|
for (pass in passes) {
|
||||||
satPassList.add(SatPass(tle.name, tle.catnum, pass))
|
Log.d(tag, "Trying ${pass.maxEl}")
|
||||||
|
satPassList.add(SatPass(tle.name, tle.catnum, pass))
|
||||||
|
}
|
||||||
|
} catch (exception: IllegalArgumentException) {
|
||||||
|
val tleProblem = "There was a problem with TLE"
|
||||||
|
Log.d(tag, tleProblem)
|
||||||
|
_debugMessage.postValue(tleProblem)
|
||||||
|
} catch (exception: SatNotFoundException) {
|
||||||
|
Log.d(tag, "Certain satellites shall not pass")
|
||||||
}
|
}
|
||||||
} catch (exception: IllegalArgumentException) {
|
|
||||||
val tleProblem = "There was a problem with TLE"
|
|
||||||
Log.d(tag, tleProblem)
|
|
||||||
_debugMessage.postValue(tleProblem)
|
|
||||||
} catch (exception: SatNotFoundException) {
|
|
||||||
Log.d(tag, "Certain satellites shall not pass")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sortedList = satPassList.sortedWith(compareBy { it.pass.startTime })
|
sortedList = satPassList.sortedWith(compareBy { it.pass.startTime })
|
||||||
@@ -111,7 +114,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
getApplication<Application>().openFileOutput(tleFile, Context.MODE_PRIVATE).use {
|
getApplication<Application>().openFileOutput(tleFile, Context.MODE_PRIVATE).use {
|
||||||
it.write(stream.readBytes())
|
it.write(stream.readBytes())
|
||||||
}
|
}
|
||||||
tleList = TLE.importSat(stream)
|
tleMainList = TLE.importSat(stream)
|
||||||
_debugMessage.postValue("TLE file was updated")
|
_debugMessage.postValue("TLE file was updated")
|
||||||
} catch (exception: IOException) {
|
} catch (exception: IOException) {
|
||||||
_debugMessage.postValue("Couldn't update TLE file")
|
_debugMessage.postValue("Couldn't update TLE file")
|
||||||
|
|||||||
Reference in new issue
Block a user