Merged update TLE and Trans buttons into one

This commit is contained in:
Arty Bishop committed 2020-09-09 21:13:24 +01:00
1 parent 53d61e530e
commit e97cc49e22
6 files changed
+13 -80

No files matched your search

@@ -140,12 +140,7 @@ class MainActivity : AppCompatActivity(), TleSourcesDialogFragment.SourcesSubmit
})
viewModel.getUpdateStatus().observe(this, Observer { result ->
when (result) {
is Result.Success -> {
when (result.data) {
0 -> getString(R.string.update_tle_success).toast(this)
1 -> getString(R.string.update_trans_success).toast(this)
}
}
is Result.Success -> getString(R.string.update_tle_success).toast(this)
is Result.Error -> getString(R.string.update_failure).toast(this)
}
})
@@ -166,12 +161,11 @@ class MainActivity : AppCompatActivity(), TleSourcesDialogFragment.SourcesSubmit
it.lockButton()
}
drawerBinding.drawerBtnTleUrl.setOnClickListener {
showTleSourcesDialog()
mainBinding.drawerLayout.closeDrawers()
it.lockButton()
TleSourcesDialogFragment(viewModel.getTleSources()).apply {
setSourcesListener(this@MainActivity)
show(supportFragmentManager, "TleSourcesDialog")
}
drawerBinding.drawerBtnTrans.setOnClickListener {
viewModel.updateTransmitters()
mainBinding.drawerLayout.closeDrawers()
it.lockButton()
}
drawerBinding.drawerBtnGithub.setOnClickListener {
@@ -182,16 +176,8 @@ class MainActivity : AppCompatActivity(), TleSourcesDialogFragment.SourcesSubmit
drawerBinding.drawerBtnExit.setOnClickListener { finish() }
}
private fun showTleSourcesDialog() {
val sources = viewModel.getTleSources()
TleSourcesDialogFragment(sources).apply {
setSourcesListener(this@MainActivity)
show(supportFragmentManager, "TleSourcesDialog")
}
}
override fun onSourcesSubmit(list: List<TleSource>) {
viewModel.updateEntriesFromWeb(list)
viewModel.updateSatData(list)
}
private fun View.lockButton() {
@@ -91,11 +91,12 @@ class SharedViewModel @Inject constructor(
}
}
fun updateEntriesFromWeb(list: List<TleSource>) {
fun updateSatData(list: List<TleSource>) {
viewModelScope.launch(Dispatchers.IO) {
try {
repository.updateSources(list)
val selected = repository.getSelectedEntries().map { it.catNum }
repository.updateSources(list)
repository.updateTransmitters()
repository.updateEntriesFromUrl(list)
repository.updateEntriesSelection(selected)
_updateStatus.postValue(Result.Success(0))
@@ -112,17 +113,6 @@ class SharedViewModel @Inject constructor(
}
}
fun updateTransmitters() {
viewModelScope.launch(Dispatchers.IO) {
try {
repository.updateTransmitters()
_updateStatus.postValue(Result.Success(1))
} catch (e: Exception) {
_updateStatus.postValue(Result.Error(e))
}
}
}
fun calculatePasses() {
_satPassList.postValue(Result.InProgress)
calculationJob?.cancel()
@@ -1,28 +0,0 @@
<!--
~ Look4Sat. Amateur radio and weather satellite tracker and passes predictor for Android.
~ Copyright (C) 2019, 2020 Arty Bishop (bishop.arty@gmail.com)
~
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program; if not, write to the Free Software Foundation, Inc.,
~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/themeIcon"
android:pathData="M12,11c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM18,13c0,-3.31 -2.69,-6 -6,-6s-6,2.69 -6,6c0,2.22 1.21,4.15 3,5.19l1,-1.74c-1.19,-0.7 -2,-1.97 -2,-3.45 0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,1.48 -0.81,2.75 -2,3.45l1,1.74c1.79,-1.04 3,-2.97 3,-5.19zM12,3C6.48,3 2,7.48 2,13c0,3.7 2.01,6.92 4.99,8.65l1,-1.73C5.61,18.53 4,15.96 4,13c0,-4.42 3.58,-8 8,-8s8,3.58 8,8c0,2.96 -1.61,5.53 -4,6.92l1,1.73c2.99,-1.73 5,-4.95 5,-8.65 0,-5.52 -4.48,-10 -10,-10z" />
</vector>
+2 -13
View File
@@ -118,21 +118,10 @@
android:layout_width="0dp"
android:drawableEnd="@drawable/ic_update_tle"
android:text="@string/update_tle_web"
app:layout_constraintBottom_toTopOf="@+id/drawer_btn_trans"
app:layout_constraintEnd_toStartOf="@+id/guidelineRight"
app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@+id/drawer_btn_tle_file" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/drawer_btn_trans"
style="@style/DrawerHeader.Button"
android:layout_width="0dp"
android:drawableEnd="@drawable/ic_update_trans"
android:text="@string/update_trans"
app:layout_constraintBottom_toTopOf="@+id/drawer_btn_github"
app:layout_constraintEnd_toStartOf="@+id/guidelineRight"
app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@+id/drawer_btn_tle_url" />
app:layout_constraintTop_toBottomOf="@+id/drawer_btn_tle_file" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/drawer_btn_github"
@@ -146,7 +135,7 @@
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@+id/drawer_btn_trans" />
app:layout_constraintTop_toBottomOf="@+id/drawer_btn_tle_url" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/drawerBtnExit"
+1 -3
View File
@@ -28,9 +28,7 @@
<string name="update_loc_failure">Проверьте настройки GPS</string>
<string name="update_tle_file">Обновить TLE из файла</string>
<string name="update_tle_web">Обновить TLE по ссылке</string>
<string name="update_tle_success">Файл TLE обновлен</string>
<string name="update_trans">Обновить трансиверы</string>
<string name="update_trans_success">База трансиверов обновлена</string>
<string name="update_tle_success">Данные спутников обновлены</string>
<string name="update_failure">Проверьте интернет-подключение</string>
<string name="exit_app">Выход</string>
+1 -3
View File
@@ -30,9 +30,7 @@
<string name="update_loc_failure">Check your Location settings</string>
<string name="update_tle_file">Import TLE from file</string>
<string name="update_tle_web">Import TLE from web</string>
<string name="update_tle_success">TLE was updated</string>
<string name="update_trans">Update transceivers</string>
<string name="update_trans_success">Transceivers DB updated</string>
<string name="update_tle_success">Satellite data was updated</string>
<string name="update_failure">Check your internet connection</string>
<string name="goto_github" translatable="false">GitHub</string>
<string name="exit_app">Exit</string>