mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-04 11:37:22 +00:00
Added Api 21 support. Fixed the bug with geostationary satellites calculations. Showing them on top of the list in separate ViewHolders.
This commit is contained in:
1 parent
94e4b5fb31
commit
6ead302634
16 files changed
+209
-59
No files matched your search
@@ -103,18 +103,49 @@ class PassPredictor(private val tle: TLE, private val qth: GroundStationPosition
|
||||
var lastAOS: Date
|
||||
var count = 0
|
||||
|
||||
do {
|
||||
if (count > 0) windBackTime = false
|
||||
val pass = nextSatPass(trackStartDate, windBackTime)
|
||||
lastAOS = pass.startTime
|
||||
passes.add(pass)
|
||||
trackStartDate = Date(pass.endTime.time + threeQuarterOrbitMinutes() * 60L * 1000L)
|
||||
count++
|
||||
} while (lastAOS < trackEndDate)
|
||||
if (tle.isDeepspace) {
|
||||
passes.add(nextGeoSatPass(start))
|
||||
} else {
|
||||
do {
|
||||
if (count > 0) windBackTime = false
|
||||
val pass = nextSatPass(trackStartDate, windBackTime)
|
||||
lastAOS = pass.startTime
|
||||
passes.add(pass)
|
||||
trackStartDate = Date(pass.endTime.time + threeQuarterOrbitMinutes() * 60L * 1000L)
|
||||
count++
|
||||
} while (lastAOS < trackEndDate)
|
||||
}
|
||||
|
||||
return passes
|
||||
}
|
||||
|
||||
private fun nextGeoSatPass(date: Date): SatPassTime {
|
||||
val aosAzimuth: Int
|
||||
val losAzimuth: Int
|
||||
val tca: Date
|
||||
val polePassed: String
|
||||
val cal = Calendar.getInstance(timeZone).apply {
|
||||
clear()
|
||||
timeInMillis = date.time
|
||||
}
|
||||
val satPos = getSatPos(cal.time)
|
||||
|
||||
aosAzimuth = (satPos.azimuth / (2.0 * Math.PI) * 360.0).toInt()
|
||||
losAzimuth = (satPos.azimuth / (2.0 * Math.PI) * 360.0).toInt()
|
||||
tca = satPos.time
|
||||
polePassed = getPolePassed(satPos, satPos)
|
||||
|
||||
cal.add(Calendar.HOUR, -12)
|
||||
val startDate = cal.time
|
||||
cal.add(Calendar.HOUR, 24)
|
||||
val endDate = cal.time
|
||||
|
||||
return SatPassTime(
|
||||
startDate, endDate, tca, polePassed, aosAzimuth,
|
||||
losAzimuth, satPos.elevation / (2.0 * Math.PI) * 360.0
|
||||
)
|
||||
}
|
||||
|
||||
private fun nextSatPass(date: Date, windBack: Boolean = false): SatPassTime {
|
||||
val aosAzimuth: Int
|
||||
val losAzimuth: Int
|
||||
|
||||
@@ -187,14 +187,4 @@ class MainActivity : AppCompatActivity() {
|
||||
val navController = findNavController(R.id.nav_host)
|
||||
return navController.navigateUp(appBarConfig) || super.onSupportNavigateUp()
|
||||
}
|
||||
//
|
||||
// private fun ImageButton.enable() {
|
||||
// this.isEnabled = true
|
||||
// this.alpha = 1.0f
|
||||
// }
|
||||
//
|
||||
// private fun ImageButton.disable() {
|
||||
// this.isEnabled = false
|
||||
// this.alpha = 0.25f
|
||||
// }
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.github.amsacode.predict4java.GroundStationPosition
|
||||
@@ -146,19 +147,19 @@ class MapViewFragment : Fragment() {
|
||||
private val scale = resources.displayMetrics.density
|
||||
private val groundTrackPaint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
color = resources.getColor(R.color.satTrack, mainActivity.theme)
|
||||
color = ContextCompat.getColor(mainActivity, R.color.satTrack)
|
||||
style = Paint.Style.STROKE
|
||||
strokeWidth = scale
|
||||
}
|
||||
private val footprintPaint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
color = resources.getColor(R.color.satFootprint, mainActivity.theme)
|
||||
color = ContextCompat.getColor(mainActivity, R.color.satFootprint)
|
||||
style = Paint.Style.STROKE
|
||||
strokeWidth = scale
|
||||
}
|
||||
private val txtPaint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
color = resources.getColor(R.color.satFootprint, mainActivity.theme)
|
||||
color = ContextCompat.getColor(mainActivity, R.color.satFootprint)
|
||||
style = Paint.Style.FILL
|
||||
strokeWidth = scale
|
||||
textSize = 16f
|
||||
|
||||
@@ -245,7 +245,7 @@ class PassListFragment : Fragment() {
|
||||
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
aosTimerText.text = String.format(
|
||||
mainActivity.getString(R.string.pat_timer_aos),
|
||||
mainActivity.getString(R.string.pat_timer),
|
||||
TimeUnit.MILLISECONDS.toHours(millisUntilFinished) % 60,
|
||||
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) % 60,
|
||||
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) % 60
|
||||
@@ -265,7 +265,7 @@ class PassListFragment : Fragment() {
|
||||
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
aosTimerText.text = String.format(
|
||||
mainActivity.getString(R.string.pat_timer_los),
|
||||
mainActivity.getString(R.string.pat_timer),
|
||||
TimeUnit.MILLISECONDS.toHours(millisUntilFinished) % 60,
|
||||
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) % 60,
|
||||
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) % 60
|
||||
@@ -281,6 +281,6 @@ class PassListFragment : Fragment() {
|
||||
isTimerSet = false
|
||||
}
|
||||
if (resetToNull) aosTimerText.text =
|
||||
String.format(getString(R.string.pat_timer_aos), 0, 0, 0)
|
||||
String.format(getString(R.string.pat_timer), 0, 0, 0)
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@@ -132,24 +133,24 @@ class PolarViewFragment : Fragment() {
|
||||
|
||||
private val radarPaint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
color = resources.getColor(R.color.themeLight, mainActivity.theme)
|
||||
color = ContextCompat.getColor(mainActivity, R.color.themeLight)
|
||||
style = Paint.Style.STROKE
|
||||
strokeWidth = scale
|
||||
}
|
||||
private val txtPaint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
color = resources.getColor(R.color.themeAccent, mainActivity.theme)
|
||||
color = ContextCompat.getColor(mainActivity, R.color.themeAccent)
|
||||
textSize = txtSize
|
||||
}
|
||||
private val trackPaint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
color = resources.getColor(R.color.satTrack, mainActivity.theme)
|
||||
color = ContextCompat.getColor(mainActivity, R.color.satTrack)
|
||||
style = Paint.Style.STROKE
|
||||
strokeWidth = scale
|
||||
}
|
||||
private val satPaint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
color = resources.getColor(R.color.themeAccent, mainActivity.theme)
|
||||
color = ContextCompat.getColor(mainActivity, R.color.themeAccent)
|
||||
style = Paint.Style.FILL
|
||||
}
|
||||
private val path: Path = Path()
|
||||
@@ -163,7 +164,7 @@ class PolarViewFragment : Fragment() {
|
||||
setPassText()
|
||||
drawRadarView(canvas)
|
||||
drawRadarText(canvas)
|
||||
drawPassTrajectory(canvas)
|
||||
if (!satPass.tle.isDeepspace) drawPassTrajectory(canvas)
|
||||
drawSatellite(canvas)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import com.rtbishop.look4sat.ui.PassListFragmentDirections
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class SatPassAdapter : RecyclerView.Adapter<SatPassAdapter.SatPassHolder>() {
|
||||
class SatPassAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
||||
private var satPassList = mutableListOf<SatPass>()
|
||||
|
||||
@@ -71,15 +71,31 @@ class SatPassAdapter : RecyclerView.Adapter<SatPassAdapter.SatPassHolder>() {
|
||||
return satPassList.size
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SatPassHolder {
|
||||
val itemView = LayoutInflater
|
||||
.from(parent.context)
|
||||
.inflate(R.layout.card_pass, parent, false)
|
||||
return SatPassHolder(itemView)
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (satPassList[position].tle.isDeepspace) 1
|
||||
else 0
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SatPassHolder, position: Int) {
|
||||
holder.bind(satPassList[position])
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
return if (viewType == 0) {
|
||||
val itemView = LayoutInflater
|
||||
.from(parent.context)
|
||||
.inflate(R.layout.card_pass, parent, false)
|
||||
return SatPassHolder(itemView)
|
||||
} else {
|
||||
val itemView = LayoutInflater
|
||||
.from(parent.context)
|
||||
.inflate(R.layout.card_pass_geo, parent, false)
|
||||
SatPassGeoHolder(itemView)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
if (holder.itemViewType == 0) {
|
||||
(holder as SatPassHolder).bind(satPassList[position])
|
||||
} else {
|
||||
(holder as SatPassGeoHolder).bind(satPassList[position])
|
||||
}
|
||||
}
|
||||
|
||||
inner class SatPassHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
@@ -123,4 +139,29 @@ class SatPassAdapter : RecyclerView.Adapter<SatPassAdapter.SatPassHolder>() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class SatPassGeoHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
private val context: Context = itemView.context
|
||||
private val satName = itemView.findViewById<TextView>(R.id.pass_geo_name)
|
||||
private val satId = itemView.findViewById<TextView>(R.id.pass_geo_id)
|
||||
private val satAz = itemView.findViewById<TextView>(R.id.pass_geo_az)
|
||||
private val satEl = itemView.findViewById<TextView>(R.id.pass_geo_el)
|
||||
|
||||
fun bind(satPass: SatPass) {
|
||||
val satPos = satPass.predictor.getSatPos(satPass.pass.startTime)
|
||||
val azimuth = satPos.azimuth * 180 / Math.PI
|
||||
|
||||
satName.text = satPass.tle.name
|
||||
satId.text = String.format(context.getString(R.string.pass_satId), satPass.tle.catnum)
|
||||
satAz.text = String.format(context.getString(R.string.pat_azimuth), azimuth)
|
||||
satEl.text =
|
||||
String.format(context.getString(R.string.pat_elevation), satPass.pass.maxEl)
|
||||
|
||||
itemView.setOnClickListener {
|
||||
val action = PassListFragmentDirections.actionPassToPolar(satPass)
|
||||
itemView.findNavController().navigate(action)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user