From eee5c725fdb986cb09bf3dd1d69e597fa8850c75 Mon Sep 17 00:00:00 2001 From: Arty Bishop Date: Sat, 18 Jan 2020 18:21:11 +0000 Subject: [PATCH] Further refactoring and strings cleanup. Changed the look of a transmission recycler item. --- .../com/rtbishop/look4sat/MainViewModel.kt | 26 ++-- .../com/rtbishop/look4sat/ui/MainActivity.kt | 33 +++-- .../rtbishop/look4sat/ui/MapViewFragment.kt | 6 +- .../rtbishop/look4sat/ui/PassListFragment.kt | 14 +- .../rtbishop/look4sat/ui/PolarViewFragment.kt | 16 +-- .../look4sat/ui/adapters/SatPassAdapter.kt | 14 +- .../ui/adapters/TransmitterAdapter.kt | 14 +- app/src/main/res/drawable/ic_arrow.xml | 9 ++ app/src/main/res/drawable/ic_trans.xml | 12 ++ app/src/main/res/layout/card_pass.xml | 4 +- app/src/main/res/layout/card_trans.xml | 61 +++++++-- app/src/main/res/layout/drawer_header.xml | 14 +- app/src/main/res/layout/fragment_map_view.xml | 6 +- .../main/res/layout/fragment_polar_view.xml | 18 +-- app/src/main/res/values/strings.xml | 126 ++++++++---------- app/src/main/res/xml/preference.xml | 1 - 16 files changed, 204 insertions(+), 170 deletions(-) create mode 100644 app/src/main/res/drawable/ic_arrow.xml create mode 100644 app/src/main/res/drawable/ic_trans.xml diff --git a/app/src/main/java/com/rtbishop/look4sat/MainViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/MainViewModel.kt index 869da1ab..cd5c0711 100644 --- a/app/src/main/java/com/rtbishop/look4sat/MainViewModel.kt +++ b/app/src/main/java/com/rtbishop/look4sat/MainViewModel.kt @@ -117,7 +117,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { apply() } _gsp.postValue(GroundStationPosition(lat, lon, alt)) - _debugMessage.postValue(app.getString(R.string.updateLocSuccess)) + _debugMessage.postValue(app.getString(R.string.update_loc_success)) } } @@ -142,9 +142,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { } tleMainList = tleList tleSelection = mutableListOf() - _debugMessage.postValue(app.getString(R.string.updateTleSuccess)) + _debugMessage.postValue(app.getString(R.string.update_tle_success)) } catch (exception: IOException) { - _debugMessage.postValue(app.getString(R.string.updateTleFailure)) + _debugMessage.postValue(app.getString(R.string.update_failure)) } } } @@ -153,9 +153,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { viewModelScope.launch(Dispatchers.IO) { try { repository.updateTransmittersDatabase() - _debugMessage.postValue(app.getString(R.string.updateTransSuccess)) + _debugMessage.postValue(app.getString(R.string.update_trans_success)) } catch (exception: IOException) { - _debugMessage.postValue(app.getString(R.string.updateTransFailure)) + _debugMessage.postValue(app.getString(R.string.update_failure)) } } } @@ -190,18 +190,12 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { val predictor = PassPredictor(tle, gsp.value) val passes = predictor.getPasses(dateNow, hoursAhead, true) passes.forEach { - passList.add( - SatPass( - tle, - predictor, - it - ) - ) + passList.add(SatPass(tle, predictor, it)) } } catch (exception: IllegalArgumentException) { - _debugMessage.postValue(app.getString(R.string.error_sat_tle)) + _debugMessage.postValue(app.getString(R.string.err_parse_tle)) } catch (exception: SatNotFoundException) { - _debugMessage.postValue(app.getString(R.string.error_sat_wont_pass)) + _debugMessage.postValue(app.getString(R.string.err_sat_wont_pass)) } } passList.removeAll { it.pass.startTime.after(dateFuture) } @@ -224,7 +218,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { val tleList = ObjectInputStream(tleStream).readObject() tleList as List } catch (exception: FileNotFoundException) { - _debugMessage.postValue(app.getString(R.string.no_tle_found)) + _debugMessage.postValue(app.getString(R.string.err_no_tle_file)) emptyList() } catch (exception: IOException) { _debugMessage.postValue(exception.toString()) @@ -235,7 +229,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { val selectionList = ObjectInputStream(selectionStream).readObject() selectionList as MutableList } catch (exception: FileNotFoundException) { - _debugMessage.postValue(app.getString(R.string.no_selection_found)) + _debugMessage.postValue(app.getString(R.string.err_no_selection_file)) mutableListOf() } catch (exception: IOException) { _debugMessage.postValue(exception.toString()) diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/MainActivity.kt b/app/src/main/java/com/rtbishop/look4sat/ui/MainActivity.kt index 14a5c2e6..ddd44668 100644 --- a/app/src/main/java/com/rtbishop/look4sat/ui/MainActivity.kt +++ b/app/src/main/java/com/rtbishop/look4sat/ui/MainActivity.kt @@ -124,15 +124,19 @@ class MainActivity : AppCompatActivity() { viewModel.debugMessage.observe(this, Observer { message -> Toast.makeText(this, message, Toast.LENGTH_SHORT).show() when (message) { - getString(R.string.updateLocSuccess) -> drawerBtnLoc.enable() - getString(R.string.updateTleSuccess), getString(R.string.updateTleFailure) -> drawerBtnTle.enable() - getString(R.string.updateTransSuccess), getString(R.string.updateTransFailure) -> drawerBtnTrans.enable() + getString(R.string.update_loc_success) -> drawerBtnLoc.enable() + getString(R.string.update_tle_success) -> drawerBtnTle.enable() + getString(R.string.update_trans_success) -> drawerBtnTrans.enable() + getString(R.string.update_failure) -> { + drawerBtnTle.enable() + drawerBtnTrans.enable() + } } }) viewModel.gsp.observe(this, Observer { gsp -> - drawerLat.text = String.format(getString(R.string.pattern_loc), gsp.latitude) - drawerLon.text = String.format(getString(R.string.pattern_loc), gsp.longitude) + drawerLat.text = String.format(getString(R.string.pat_location), gsp.latitude) + drawerLon.text = String.format(getString(R.string.pat_location), gsp.longitude) }) } @@ -159,7 +163,8 @@ class MainActivity : AppCompatActivity() { private fun requestLocationUpdate() { if (ContextCompat.checkSelfPermission(this, permLocation) != permGranted) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, permLocation)) { - Toast.makeText(this, getString(R.string.no_permissions), Toast.LENGTH_LONG).show() + Toast.makeText(this, getString(R.string.err_no_permissions), Toast.LENGTH_LONG) + .show() } else { ActivityCompat.requestPermissions(this, arrayOf(permLocation), permLocationCode) } @@ -182,14 +187,14 @@ class MainActivity : AppCompatActivity() { val navController = findNavController(R.id.nav_host) return navController.navigateUp(appBarConfig) || super.onSupportNavigateUp() } -} -fun ImageButton.enable() { - this.isEnabled = true - this.alpha = 1.0f -} + private fun ImageButton.enable() { + this.isEnabled = true + this.alpha = 1.0f + } -fun ImageButton.disable() { - this.isEnabled = false - this.alpha = 0.25f + private fun ImageButton.disable() { + this.isEnabled = false + this.alpha = 0.25f + } } \ No newline at end of file diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/MapViewFragment.kt b/app/src/main/java/com/rtbishop/look4sat/ui/MapViewFragment.kt index 927a4209..f66d4ab4 100644 --- a/app/src/main/java/com/rtbishop/look4sat/ui/MapViewFragment.kt +++ b/app/src/main/java/com/rtbishop/look4sat/ui/MapViewFragment.kt @@ -205,9 +205,9 @@ class MapViewFragment : Fragment() { if (lon > 180f) lon -= 360f - mapLat.text = String.format(context.getString(R.string.pattern_value_lat), lat) - mapLon.text = String.format(context.getString(R.string.pattern_value_lon), lon) - mapRng.text = String.format(context.getString(R.string.pattern_value_rng), rng) + mapLat.text = String.format(context.getString(R.string.pat_latitude), lat) + mapLon.text = String.format(context.getString(R.string.pat_longitude), lon) + mapRng.text = String.format(context.getString(R.string.pat_range), rng) } private fun drawGroundTrack( diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/PassListFragment.kt b/app/src/main/java/com/rtbishop/look4sat/ui/PassListFragment.kt index 9da72bbb..79bcd7ec 100644 --- a/app/src/main/java/com/rtbishop/look4sat/ui/PassListFragment.kt +++ b/app/src/main/java/com/rtbishop/look4sat/ui/PassListFragment.kt @@ -83,8 +83,8 @@ class PassListFragment : Fragment() { } private fun findViews(view: View) { - aosTimerText = (mainActivity).findViewById(R.id.toolbar_timer) - btnPassPrefs = (mainActivity).findViewById(R.id.toolbar_filter) + aosTimerText = mainActivity.findViewById(R.id.toolbar_timer) + btnPassPrefs = mainActivity.findViewById(R.id.toolbar_filter) swipeLayout = view.findViewById(R.id.pass_list_refresh) satPassRecycler = view.findViewById(R.id.pass_list_recycler) passListFab = view.findViewById(R.id.pass_list_fab) @@ -161,7 +161,7 @@ class PassListFragment : Fragment() { } } else Toast.makeText( mainActivity, - getString(R.string.error_enter_value), + getString(R.string.err_enter_value), Toast.LENGTH_SHORT ).show() @@ -176,7 +176,7 @@ class PassListFragment : Fragment() { private fun showSelectSatDialog(tleMainList: List, selectionList: MutableList) { if (tleMainList.isEmpty()) { - Toast.makeText(mainActivity, getString(R.string.error_update_tle), Toast.LENGTH_SHORT) + Toast.makeText(mainActivity, getString(R.string.err_update_tle), Toast.LENGTH_SHORT) .show() } else { val tleNameArray = arrayOfNulls(tleMainList.size).apply { @@ -235,7 +235,7 @@ class PassListFragment : Fragment() { override fun onTick(millisUntilFinished: Long) { aosTimerText.text = String.format( - mainActivity.getString(R.string.pattern_timer_aos), + mainActivity.getString(R.string.pat_timer_aos), TimeUnit.MILLISECONDS.toHours(millisUntilFinished) % 60, TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) % 60, TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) % 60 @@ -255,7 +255,7 @@ class PassListFragment : Fragment() { override fun onTick(millisUntilFinished: Long) { aosTimerText.text = String.format( - mainActivity.getString(R.string.pattern_timer_los), + mainActivity.getString(R.string.pat_timer_los), TimeUnit.MILLISECONDS.toHours(millisUntilFinished) % 60, TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) % 60, TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) % 60 @@ -271,6 +271,6 @@ class PassListFragment : Fragment() { isTimerSet = false } if (resetToNull) aosTimerText.text = - String.format(getString(R.string.pattern_timer_aos), 0, 0, 0) + String.format(getString(R.string.pat_timer_aos), 0, 0, 0) } } \ No newline at end of file diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/PolarViewFragment.kt b/app/src/main/java/com/rtbishop/look4sat/ui/PolarViewFragment.kt index ddc88ed8..da49c807 100644 --- a/app/src/main/java/com/rtbishop/look4sat/ui/PolarViewFragment.kt +++ b/app/src/main/java/com/rtbishop/look4sat/ui/PolarViewFragment.kt @@ -169,18 +169,14 @@ class PolarViewFragment : Fragment() { private fun setPassText() { satPos = satPass.predictor.getSatPos(Date()) - polarAzimuth.text = String.format( - context.getString(R.string.pattern_value_az), - rad2Deg(satPos.azimuth) - ) - polarElevation.text = String.format( - context.getString(R.string.pattern_value_el), - rad2Deg(satPos.elevation) - ) + polarAzimuth.text = + String.format(context.getString(R.string.pat_azimuth), rad2Deg(satPos.azimuth)) + polarElevation.text = + String.format(context.getString(R.string.pat_elevation), rad2Deg(satPos.elevation)) polarRange.text = - String.format(context.getString(R.string.pattern_value_rng), satPos.range) + String.format(context.getString(R.string.pat_range), satPos.range) polarAltitude.text = - String.format(context.getString(R.string.pattern_value_alt), satPos.altitude) + String.format(context.getString(R.string.pat_altitude), satPos.altitude) } private fun drawRadarView(cvs: Canvas) { diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/adapters/SatPassAdapter.kt b/app/src/main/java/com/rtbishop/look4sat/ui/adapters/SatPassAdapter.kt index 2ca825bf..1eb7b4ca 100644 --- a/app/src/main/java/com/rtbishop/look4sat/ui/adapters/SatPassAdapter.kt +++ b/app/src/main/java/com/rtbishop/look4sat/ui/adapters/SatPassAdapter.kt @@ -93,26 +93,26 @@ class SatPassAdapter : RecyclerView.Adapter() { fun bind(satPass: SatPass) { val aos = SimpleDateFormat( - context.getString(R.string.pattern_time), + context.getString(R.string.pat_time), Locale.getDefault() ).format(satPass.pass.startTime) val los = SimpleDateFormat( - context.getString(R.string.pattern_time), + context.getString(R.string.pat_time), Locale.getDefault() ).format(satPass.pass.endTime) satName.text = satPass.tle.name satId.text = - String.format(context.getString(R.string.pattern_pass_satId), satPass.tle.catnum) + String.format(context.getString(R.string.pass_satId), satPass.tle.catnum) maxEl.text = - String.format(context.getString(R.string.pattern_pass_maxEl), satPass.pass.maxEl) + String.format(context.getString(R.string.pass_maxEl), satPass.pass.maxEl) azimuth.text = String.format( - context.getString(R.string.pattern_pass_azimuth), + context.getString(R.string.pass_azimuth), satPass.pass.aosAzimuth, satPass.pass.losAzimuth ) - aosTime.text = String.format(context.getString(R.string.pattern_pass_aos), aos) - losTime.text = String.format(context.getString(R.string.pattern_pass_los), los) + aosTime.text = String.format(context.getString(R.string.pass_aos), aos) + losTime.text = String.format(context.getString(R.string.pass_los), los) progressBar.progress = satPass.progress itemView.setOnClickListener { diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/adapters/TransmitterAdapter.kt b/app/src/main/java/com/rtbishop/look4sat/ui/adapters/TransmitterAdapter.kt index 5307155f..5b343faf 100644 --- a/app/src/main/java/com/rtbishop/look4sat/ui/adapters/TransmitterAdapter.kt +++ b/app/src/main/java/com/rtbishop/look4sat/ui/adapters/TransmitterAdapter.kt @@ -66,12 +66,12 @@ class TransmitterAdapter : RecyclerView.Adapter + + diff --git a/app/src/main/res/drawable/ic_trans.xml b/app/src/main/res/drawable/ic_trans.xml new file mode 100644 index 00000000..551cf66d --- /dev/null +++ b/app/src/main/res/drawable/ic_trans.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/layout/card_pass.xml b/app/src/main/res/layout/card_pass.xml index 7e20288f..e981db52 100644 --- a/app/src/main/res/layout/card_pass.xml +++ b/app/src/main/res/layout/card_pass.xml @@ -51,7 +51,7 @@ android:id="@+id/pass_aosTime" style="@style/CardPassText" android:layout_marginBottom="4dp" - android:text="@string/pass_aosTime" + android:text="@string/pass_aos" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="@+id/pass_progress" app:layout_constraintTop_toBottomOf="@+id/pass_progress" /> @@ -59,7 +59,7 @@ diff --git a/app/src/main/res/layout/card_trans.xml b/app/src/main/res/layout/card_trans.xml index c999ed49..ead3f749 100644 --- a/app/src/main/res/layout/card_trans.xml +++ b/app/src/main/res/layout/card_trans.xml @@ -16,42 +16,81 @@ + app:layout_constraintBottom_toBottomOf="@+id/imageView" + app:layout_constraintStart_toEndOf="@+id/imageView" + app:layout_constraintTop_toTopOf="@+id/imageView" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/drawer_header.xml b/app/src/main/res/layout/drawer_header.xml index aaff6959..9e167acd 100644 --- a/app/src/main/res/layout/drawer_header.xml +++ b/app/src/main/res/layout/drawer_header.xml @@ -1,7 +1,7 @@ @@ -40,14 +42,14 @@ style="@style/DrawerHeader.ItemValue" android:layout_marginStart="8dp" android:layout_marginTop="4dp" - android:text="@string/drawer_lat_value" + android:text="@string/pat_location" app:layout_constraintStart_toEndOf="@+id/drawer_lat" app:layout_constraintTop_toBottomOf="@+id/drawer_sat_img" /> @@ -55,7 +57,7 @@ android:id="@+id/drawer_lon_value" style="@style/DrawerHeader.ItemValue" android:layout_marginStart="8dp" - android:text="@string/drawer_lon_value" + android:text="@string/pat_location" app:layout_constraintBaseline_toBaselineOf="@+id/drawer_lon" app:layout_constraintStart_toEndOf="@+id/drawer_lon" /> diff --git a/app/src/main/res/layout/fragment_map_view.xml b/app/src/main/res/layout/fragment_map_view.xml index 54c72c25..798efcd5 100644 --- a/app/src/main/res/layout/fragment_map_view.xml +++ b/app/src/main/res/layout/fragment_map_view.xml @@ -32,7 +32,7 @@ style="@style/MapText" android:layout_marginStart="4dp" android:layout_marginTop="4dp" - android:text="@string/pattern_value_lat" + android:text="@string/pat_latitude" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -41,7 +41,7 @@ style="@style/MapText" android:layout_marginTop="4dp" android:layout_marginEnd="4dp" - android:text="@string/pattern_value_lon" + android:text="@string/pat_longitude" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -50,7 +50,7 @@ style="@style/MapText" android:layout_marginEnd="4dp" android:layout_marginBottom="4dp" - android:text="@string/pattern_value_rng" + android:text="@string/pat_range" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" /> diff --git a/app/src/main/res/layout/fragment_polar_view.xml b/app/src/main/res/layout/fragment_polar_view.xml index 76e72a14..95d09a3d 100644 --- a/app/src/main/res/layout/fragment_polar_view.xml +++ b/app/src/main/res/layout/fragment_polar_view.xml @@ -19,31 +19,31 @@ android:id="@+id/polar_azimuth" style="@style/PolarViewText" android:layout_marginStart="4dp" - android:text="@string/polar_azimuth" - app:layout_constraintBottom_toBottomOf="@+id/polar_view_frame" - app:layout_constraintStart_toStartOf="@+id/polar_view_frame" /> + android:text="@string/pat_azimuth" + app:layout_constraintStart_toStartOf="@+id/polar_view_frame" + app:layout_constraintTop_toTopOf="@+id/polar_view_frame" /> + android:text="@string/pat_altitude" + app:layout_constraintBottom_toBottomOf="@+id/polar_view_frame" + app:layout_constraintStart_toStartOf="@+id/polar_view_frame" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bf5cd6dd..f8e26168 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,115 +3,93 @@ Look4Sat L∞king \n4Sat… - Latitude: - 51.5074 - Longitude: - 0.1278 + Latitude: + Longitude: Update location + Location was updated Update TLE file + TLE file was updated Update transmitters DB + Transmitters database was updated + Check your internet connection GitHub Exit - Location was updated - TLE file was updated - Could not update TLE file - Transmitters database was updated - Could not update transmitters - - List of passes + List of Passes Polar View World Map View Settings Credits About the App - Meteor M2–2 - ID: 48680 - Az: 180° -> 360° - MaxEl: 75.5° - AOS - 13:14:15 - LOS - 16:17:18 - - Azimuth: 180.00° - Elevation: 75.50° - Altitude: 850 km - Range: 12000 km - - ARGOS-3 A-DCS 465.9875MHz - Downlink: 465.9875 MHz - Uplink: 465.9875 MHz - Mode: BPSK400 - Inverted: Yes - - Select satellites to track + Select satellites to track… Show ground track for… - Filter passes + Filter passes… hoursAhead Hours ahead Show passes that occur within X hours - Value should be within 1–168 hours + Set the value between 1h and 168h minEl Minimum elevation Show passes with max elevation above - Value should be within 0–90 deg + Set the value between 0° and 90° - Ground station position settings + Ground station position latitude - Latitude - Lat should be within -90 to 90 deg + Latitude, deg + Set the value between -90° and 90° longitude - Longitude - Lon should be within -180 to 180 deg + Longitude, deg + Set the value between -180° and 180° altitude - Altitude - Alt should be within -413 to 8850 m - Other settings + Altitude, m + Set the value between -413m and 8850m + Other rate - Refresh rate - Value should be within 250 to 10000 ms - Views update interval, ms + View refresh rate, ms + Set the value between 250ms and 10000ms - Missing permissions Mode: Null Uplink: Null Downlink: Null - No transmitters found for this Satellite No satellites were shortlisted - TLE file was not found - Selection file was not found + No transmitters found for this Satellite - Certain satellites will never pass - There was a problem with a satellite TLE - Please, update your TLE - Please, enter the value + Missing permissions + Certain satellites shall not pass + Error parsing TLE entry + Please, update your TLE file + Please, enter the value + TLE file was not found + Selection file was not found - %.4f - HH:mm:ss - AOS -%02d:%02d:%02d - LOS -%02d:%02d:%02d + %s + AOS - %s + LOS - %s + Id: %d + MaxEl: %.1f° + Az: %2d° -> %2d° - AOS - %s - LOS - %s - Id: %d - MaxEl: %.1f° - Az: %2d° -> %2d° + %.4f + HH:mm:ss + Azimuth: %.1f° + Elevation: %.1f° + Latitude: %.1f° + Longitude: %.1f° + Range: %.0f km + Altitude: %.0f km + AOS -%02d:%02d:%02d + LOS -%02d:%02d:%02d - Az: %.1f° - El: %.1f° - Lat: %.1f° - Lon: %.1f° - Rng: %.0f km - Alt: %.0f km - - Mode: %s - Inverted: %s - Uplink: %.4f MHz - Uplink: %.4f - %.4f MHz - Downlink: %.4f MHz - Downlink: %.4f - %.4f MHz + %s + Mode: %s + Inverted: %s + Uplink: %.4f MHz + Uplink: %.4f - %.4f MHz + Downlink: %.4f MHz + Downlink: %.4f - %.4f MHz Yes No diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index bd2219d4..6577fb1d 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -26,7 +26,6 @@ android:key="@string/pref_refresh_rate_key" android:selectAllOnFocus="true" android:singleLine="true" - android:summary="@string/pref_refresh_rate_summary" android:title="@string/pref_refresh_rate_title" /> \ No newline at end of file