diff --git a/app/build.gradle b/app/build.gradle index 4a19b1cb..9a8ce060 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,6 @@ dependencies { implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle" implementation "androidx.work:work-runtime-ktx:$work" - implementation "androidx.paging:paging-runtime:$paging" implementation "androidx.room:room-runtime:$room" implementation "androidx.room:room-ktx:$room" kapt "androidx.room:room-compiler:$room" diff --git a/app/src/main/java/com/rtbishop/lookingsat/MainActivity.kt b/app/src/main/java/com/rtbishop/lookingsat/MainActivity.kt index 1512ccba..0f216d95 100644 --- a/app/src/main/java/com/rtbishop/lookingsat/MainActivity.kt +++ b/app/src/main/java/com/rtbishop/lookingsat/MainActivity.kt @@ -12,6 +12,7 @@ import android.os.CountDownTimer import android.view.Menu import android.view.MenuItem import android.view.View +import android.widget.ImageView import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity @@ -49,7 +50,9 @@ class MainActivity : AppCompatActivity() { private lateinit var preferences: SharedPreferences private lateinit var drawerLat: TextView private lateinit var drawerLon: TextView + private lateinit var drawerHeight: TextView private lateinit var drawerSubTitle: TextView + private lateinit var drawerGetLocation: ImageView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -57,12 +60,7 @@ class MainActivity : AppCompatActivity() { setupComponents() setupNavigation() setupTimer() - updateDrawerText() - } - - private fun updateDrawerText() { - drawerLat.text = preferences.getString("LATITUDE", "-180.0000")?.substring(0, 9) - drawerLon.text = preferences.getString("LONGITUDE", "-60.0000")?.substring(0, 9) + updateDrawerValues() } private fun setupComponents() { @@ -82,7 +80,9 @@ class MainActivity : AppCompatActivity() { val header = navView.getHeaderView(0) drawerLat = header.findViewById(R.id.drawer_lat_value) drawerLon = header.findViewById(R.id.drawer_lon_value) - drawerSubTitle = header.findViewById(R.id.drawer_subtitle) + drawerHeight = header.findViewById(R.id.drawer_height_value) + drawerSubTitle = header.findViewById(R.id.drawer_link) + drawerGetLocation = header.findViewById(R.id.drawer_get_location) val navController = findNavController(R.id.nav_host) appBarConfig = AppBarConfiguration(setOf(R.id.nav_sky), drawerLayout) @@ -109,6 +109,10 @@ class MainActivity : AppCompatActivity() { drawerSubTitle.setOnClickListener { openGitHub() } + + drawerGetLocation.setOnClickListener { + updateLocation() + } } private fun setupTimer() { @@ -138,27 +142,6 @@ class MainActivity : AppCompatActivity() { } private fun updateLocation() { - fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? -> - val currentLat = location?.latitude - val currentLon = location?.longitude - val currentHeight = location?.altitude - - preferences.edit { - putString("LATITUDE", currentLat.toString()) - putString("LONGITUDE", currentLon.toString()) - putString("HEIGHT", currentHeight.toString()) - apply() - } - updateDrawerText() - } - } - - private fun openGitHub() { - val intentGitHub = Intent(Intent.ACTION_VIEW, Uri.parse(GITHUB_URL)) - startActivity(intentGitHub) - } - - private fun checkPermissions() { if (ContextCompat.checkSelfPermission(this, LOCATION_PERM) != GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, LOCATION_PERM)) { Toast.makeText(this, "Missing permissions", Toast.LENGTH_LONG).show() @@ -166,10 +149,41 @@ class MainActivity : AppCompatActivity() { ActivityCompat.requestPermissions(this, arrayOf(LOCATION_PERM), LOCATION_REQ) } } else { - updateLocation() + getPreciseLocation() } } + private fun getPreciseLocation() { + fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? -> + val lat = location?.latitude ?: 0.0 + val lon = location?.longitude ?: 0.0 + val height = location?.altitude ?: 0.0 + + preferences.edit { + putDouble("LATITUDE", lat) + putDouble("LONGITUDE", lon) + putDouble("HEIGHT", height) + apply() + } + updateDrawerValues() + } + } + + private fun updateDrawerValues() { + val lat = preferences.getDouble("LATITUDE", 0.0) + val lon = preferences.getDouble("LONGITUDE", 0.0) + val height = preferences.getDouble("HEIGHT", 0.0) + + drawerLat.text = String.format("%.4f", lat) + drawerLon.text = String.format("%.4f", lon) + drawerHeight.text = String.format("%.1fm", height) + } + + private fun openGitHub() { + val intentGitHub = Intent(Intent.ACTION_VIEW, Uri.parse(GITHUB_URL)) + startActivity(intentGitHub) + } + override fun onRequestPermissionsResult( requestCode: Int, permissions: Array, @@ -178,7 +192,7 @@ class MainActivity : AppCompatActivity() { when (requestCode) { LOCATION_REQ -> { if (grantResults.isNotEmpty() && grantResults[0] == GRANTED) { - updateLocation() + getPreciseLocation() } } } @@ -196,7 +210,6 @@ class MainActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.update_location -> checkPermissions() R.id.fetch_trans -> Toast.makeText(this, "Fetch transmit", Toast.LENGTH_SHORT).show() R.id.save_to_db -> Toast.makeText(this, "Saving to DB", Toast.LENGTH_SHORT).show() R.id.load_from_db -> Toast.makeText(this, "Loading from DB", Toast.LENGTH_SHORT).show() @@ -207,3 +220,9 @@ class MainActivity : AppCompatActivity() { return super.onOptionsItemSelected(item) } } + +fun SharedPreferences.Editor.putDouble(key: String, double: Double): SharedPreferences.Editor = + putLong(key, java.lang.Double.doubleToRawLongBits(double)) + +fun SharedPreferences.getDouble(key: String, default: Double) = + java.lang.Double.longBitsToDouble(getLong(key, java.lang.Double.doubleToRawLongBits(default))) \ No newline at end of file diff --git a/app/src/main/java/com/rtbishop/lookingsat/ui/SettingsFragment.kt b/app/src/main/java/com/rtbishop/lookingsat/ui/SettingsFragment.kt deleted file mode 100644 index ff1844e6..00000000 --- a/app/src/main/java/com/rtbishop/lookingsat/ui/SettingsFragment.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.rtbishop.lookingsat.ui - -import android.os.Bundle -import androidx.preference.PreferenceFragmentCompat -import com.rtbishop.lookingsat.R - -class SettingsFragment : PreferenceFragmentCompat() { - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - setPreferencesFromResource(R.xml.preference, rootKey) - } -} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_location.xml b/app/src/main/res/drawable/ic_location.xml new file mode 100644 index 00000000..5470c151 --- /dev/null +++ b/app/src/main/res/drawable/ic_location.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index 939fdda7..41ef0d5d 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -8,15 +8,13 @@ + android:layout_height="wrap_content"> + android:background="?attr/colorPrimary"> + app:srcCompat="@drawable/ic_sat_desc_left" /> + style="@style/DrawerHeader.Title" + android:layout_marginStart="8dp" + android:text="@string/title" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@+id/drawer_sat_img" /> + app:layout_constraintBottom_toTopOf="@+id/drawer_lon_value" + app:layout_constraintStart_toStartOf="@+id/drawer_lon" /> + app:layout_constraintBaseline_toBaselineOf="@+id/drawer_lat" + app:layout_constraintStart_toEndOf="@+id/drawer_lat" /> + app:layout_constraintBottom_toTopOf="@+id/drawer_height_value" + app:layout_constraintStart_toStartOf="@+id/drawer_height" /> + + + + + + + app:layout_constraintTop_toTopOf="@+id/drawer_lat_value" + app:srcCompat="@drawable/ic_location" /> + + diff --git a/app/src/main/res/menu/drawer_menu.xml b/app/src/main/res/menu/drawer_menu.xml index ff65922b..d811d233 100644 --- a/app/src/main/res/menu/drawer_menu.xml +++ b/app/src/main/res/menu/drawer_menu.xml @@ -12,10 +12,6 @@ android:title="@string/menu_map" /> - - - - diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 26dbe969..5d70f712 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -23,11 +23,6 @@ android:label="@string/menu_map" tools:layout="@layout/fragment_worldmap" /> - - #C0C0C0 #C0C0C0 - #181818 + #212121 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 377b512b..ba6c6979 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,4 +1,4 @@ - 232dp + 280dp 16dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e31d843e..0a3c53b5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,7 +1,9 @@ + LookingSat - L∞kingSat - https://github.com/rt-bishop/LookingSat + L∞king + S@t + https://github.com/rt-bishop/LookingSat Sky at a Glance Radar View @@ -12,14 +14,14 @@ Credits Allow the app to get your location - Latitude: - -30.0000 + Latitude: + -90.0000 Ground station latitude from -90 to 90 - Longitude: - -60.0000 + Longitude: + -180.0000 Ground station longitude from -180 to 180 - Height: - 64 + Height AMSL: + 51.0m Ground station height in meters AMSL Update location diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 8bd30b66..ab618002 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -13,8 +13,25 @@ @android:color/transparent - - + + + + diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml deleted file mode 100644 index 2cf6eeda..00000000 --- a/app/src/main/res/xml/preference.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/build.gradle b/build.gradle index d61d33a0..a66a5bf5 100644 --- a/build.gradle +++ b/build.gradle @@ -34,8 +34,7 @@ ext { navigation = '2.1.0' lifecycle = '2.1.0' work = '2.2.0' - paging = '2.1.0' - room = '2.2.0' + room = '2.2.1' retrofit = '2.6.2'