Satellite tracker and pass predictor for Android, inspired by Gpredict
Kotlin amsatcelestrakgpsham-radiohamlibhamradiokotlinnasaradiosatellitesatellite-datasatellite-positionsatellite-predictionsatellitessatnogssdrspacespacexstarlink
Attached action to button in the drawer header. Added LiveData debug toasts. Libraries update.
Arty Bishop52fa9ab60328
diff --git a/app/src/main/java/com/rtbishop/lookingsat/ui/MainActivity.kt b/app/src/main/java/com/rtbishop/lookingsat/ui/MainActivity.ktindex 0d05866f..3b396342 100644--- a/app/src/main/java/com/rtbishop/lookingsat/ui/MainActivity.kt+++ b/app/src/main/java/com/rtbishop/lookingsat/ui/MainActivity.kt@@ -10,6 +10,7 @@ import android.os.CountDownTimerimport android.view.Menuimport android.view.MenuItemimport android.view.View+import android.widget.ImageButtonimport android.widget.TextViewimport android.widget.Toastimport androidx.appcompat.app.AppCompatActivity@@ -18,7 +19,7 @@ import androidx.constraintlayout.widget.ConstraintLayoutimport androidx.core.app.ActivityCompatimport androidx.core.content.ContextCompatimport androidx.drawerlayout.widget.DrawerLayout-import androidx.lifecycle.ViewModelProviders+import androidx.lifecycle.ViewModelProviderimport androidx.navigation.findNavControllerimport androidx.navigation.ui.AppBarConfigurationimport androidx.navigation.ui.navigateUp@@ -44,6 +45,11 @@ class MainActivity : AppCompatActivity() {private lateinit var drawerLat: TextViewprivate lateinit var drawerLon: TextViewprivate lateinit var drawerHeight: TextView+ private lateinit var drawerBtnLoc: ImageButton+ private lateinit var drawerBtnTle: ImageButton+ private lateinit var drawerBtnTrans: ImageButton+ private lateinit var drawerBtnGithub: ImageButton+ private lateinit var drawerBtnExit: ImageButtonoverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)@@ -51,11 +57,10 @@ class MainActivity : AppCompatActivity() {setupComponents()setupDrawer()setupTimer()- updateLocation()}private fun setupComponents() {- viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)+ viewModel = ViewModelProvider(this).get(MainViewModel::class.java)timerLayout = findViewById(R.id.timer_layout)timeToAos = findViewById(R.id.time_to_aos)@@ -70,6 +75,12 @@ class MainActivity : AppCompatActivity() {drawerLon = header.findViewById(R.id.drawer_lon_value)drawerHeight = header.findViewById(R.id.drawer_height_value)+ drawerBtnLoc = header.findViewById(R.id.drawer_btn_loc)+ drawerBtnTle = header.findViewById(R.id.drawer_btn_tle)+ drawerBtnTrans = header.findViewById(R.id.drawer_btn_trans)+ drawerBtnGithub = header.findViewById(R.id.drawer_btn_github)+ drawerBtnExit = header.findViewById(R.id.drawer_btn_exit)+val navController = findNavController(R.id.nav_host)appBarConfig = AppBarConfiguration(setOf(R.id.nav_sky, R.id.nav_single_sat), drawerLayout)setupActionBarWithNavController(navController, appBarConfig)@@ -77,7 +88,7 @@ class MainActivity : AppCompatActivity() {navController.addOnDestinationChangedListener { _, destination, _ ->when {- destination.id == R.id.nav_sky -> {+ destination.id == R.id.nav_sky || destination.id == R.id.nav_single_sat -> {this.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAITtoolbar.visibility = View.VISIBLEtimerLayout.visibility = View.VISIBLE@@ -94,11 +105,26 @@ class MainActivity : AppCompatActivity() {}private fun setupDrawer() {+ viewModel.debugMessage.observe(this, androidx.lifecycle.Observer { debug_message ->+ if (debug_message != "") {+ Toast.makeText(this, debug_message, Toast.LENGTH_SHORT).show()+ }+ })+viewModel.gsp.observe(this, androidx.lifecycle.Observer { gsp ->drawerLat.text = String.format("%.4f", gsp.latitude)drawerLon.text = String.format("%.4f", gsp.longitude)drawerHeight.text = String.format("%.1fm", gsp.heightAMSL)})++ drawerBtnLoc.setOnClickListener { updateLocation() }+ drawerBtnTle.setOnClickListener { viewModel.updateTwoLineElementFile() }+ drawerBtnTrans.setOnClickListener { viewModel.updateTransmittersDatabase() }+ drawerBtnGithub.setOnClickListener {+ val intentGitHub = Intent(Intent.ACTION_VIEW, Uri.parse(githubUrl))+ startActivity(intentGitHub)+ }+ drawerBtnExit.setOnClickListener { finish() }}private fun setupTimer() {@@ -139,15 +165,6 @@ class MainActivity : AppCompatActivity() {}}- private fun goToGithub() {- val intentGitHub = Intent(Intent.ACTION_VIEW, Uri.parse(githubUrl))- startActivity(intentGitHub)- }-- private fun exit() {- finish()- }-override fun onRequestPermissionsResult(reqCode: Int, perms: Array<out String>, res: IntArray) {when (reqCode) {permLocationCode -> {diff --git a/app/src/main/java/com/rtbishop/lookingsat/vm/MainViewModel.kt b/app/src/main/java/com/rtbishop/lookingsat/vm/MainViewModel.ktindex e7327ac8..ea35daf7 100644--- a/app/src/main/java/com/rtbishop/lookingsat/vm/MainViewModel.kt+++ b/app/src/main/java/com/rtbishop/lookingsat/vm/MainViewModel.kt@@ -4,7 +4,6 @@ import android.app.Applicationimport android.content.Contextimport android.content.SharedPreferencesimport android.location.Location-import android.widget.Toastimport androidx.core.content.editimport androidx.lifecycle.AndroidViewModelimport androidx.lifecycle.LiveData@@ -21,25 +20,38 @@ import java.io.IOExceptionclass MainViewModel(application: Application) : AndroidViewModel(application) {+ private val keyLat = "LATITUDE"+ private val keyLon = "LONGITUDE"+ private val keyHeight = "HEIGHT"+private val repository: Repository = Injector.provideRepository(application)private val preferences = PreferenceManager.getDefaultSharedPreferences(application)private val fusedLocationClient = LocationServices.getFusedLocationProviderClient(application)- private val _gsp = MutableLiveData<GroundStationPosition>()+ private val _debugMessage = MutableLiveData("")+ val debugMessage: LiveData<String> = _debugMessage+ private val _gsp = MutableLiveData<GroundStationPosition>(+ GroundStationPosition(+ preferences.getDouble(keyLat, 0.0),+ preferences.getDouble(keyLon, 0.0),+ preferences.getDouble(keyHeight, 0.0)+ )+ )val gsp: LiveData<GroundStationPosition> = _gspfun updateLocation() {fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? ->- val lat = location?.latitude ?: 51.5074- val lon = location?.longitude ?: 0.1278- val height = location?.altitude ?: 48.0+ val lat = location?.latitude ?: 0.0+ val lon = location?.longitude ?: 0.0+ val height = location?.altitude ?: 0.0preferences.edit {- putDouble("LATITUDE", lat)- putDouble("LONGITUDE", lon)- putDouble("HEIGHT", height)+ putDouble(keyLat, lat)+ putDouble(keyLon, lon)+ putDouble(keyHeight, height)apply()}_gsp.postValue(GroundStationPosition(lat, lon, height))+ _debugMessage.postValue("Location was updated")}}@@ -50,9 +62,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {getApplication<Application>().openFileOutput(fileName, Context.MODE_PRIVATE).use {it.write(repository.fetchTleStream().readBytes())}- Toast.makeText(getApplication(), "TLE file was updated", Toast.LENGTH_SHORT).show()+ _debugMessage.postValue("TLE file was updated")} catch (exception: IOException) {- Toast.makeText(getApplication(), "Could not update TLE", Toast.LENGTH_SHORT).show()+ _debugMessage.postValue("Couldn't update TLE file")}}}@@ -61,9 +73,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {viewModelScope.launch(Dispatchers.IO) {try {repository.updateTransmittersDatabase()- Toast.makeText(getApplication(), "", Toast.LENGTH_SHORT).show()+ _debugMessage.postValue("Transmitters were updated")} catch (exception: IOException) {- Toast.makeText(getApplication(), "", Toast.LENGTH_SHORT).show()+ _debugMessage.postValue("Couldn't update transmitters")}}}diff --git a/build.gradle b/build.gradleindex 3c59fa6d..bbcb13a7 100644--- a/build.gradle+++ b/build.gradle@@ -8,7 +8,7 @@ buildscript {}dependencies {- classpath 'com.android.tools.build:gradle:3.5.1'+ classpath 'com.android.tools.build:gradle:3.5.2'classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"}}@@ -33,7 +33,7 @@ ext {preference = '1.1.0'navigation = '2.1.0'- lifecycle = '2.1.0'+ lifecycle = '2.2.0-rc01'work = '2.2.0'room = '2.2.1'