Skip to content

Commit

Permalink
Added a function to clear the database #79
Browse files Browse the repository at this point in the history
  • Loading branch information
rt-bishop committed Feb 19, 2022
1 parent a7427f3 commit e9dc166
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ class LocalSource(
override suspend fun updateTransmitters(transmitters: List<Transmitter>) {
transmittersDao.updateTransmitters(transmitters.toFramework())
}

override suspend fun clearData() {
entriesDao.deleteEntries()
transmittersDao.deleteTransmitters()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
binding.prefsData.updateBtnWeb.setOnClickListener {
findNavController().navigateSafe(R.id.action_prefs_to_sources)
}
binding.prefsData.updateBtnClear.setOnClickListener { viewModel.clearData() }
getNavResult<List<String>>(R.id.nav_settings, "sources") { sources ->
viewModel.updateDataFromWeb(sources)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class SettingsViewModel @Inject constructor(
repository.updateDataFromWeb(sources)
}

fun clearData() {
repository.clearData()
}

fun getUseUTC(): Boolean = settings.getUseUTC()

fun setUseUTC(value: Boolean) = settings.setUseUTC(value)
Expand Down
24 changes: 19 additions & 5 deletions app/src/main/res/layout/card_prefs_update.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
style="@style/AppButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:drawableStart="@drawable/ic_update_web"
android:text="@string/update_web"
android:text="Web"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/update_btn_file"
app:layout_constraintHorizontal_bias="0.5"
Expand All @@ -51,14 +51,28 @@
style="@style/AppButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:drawableStart="@drawable/ic_update_file"
android:text="@string/update_file"
android:text="File"
app:layout_constraintBaseline_toBaselineOf="@+id/update_btn_web"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@+id/update_btn_clear"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/update_btn_web" />

<Button
android:id="@+id/update_btn_clear"
style="@style/AppButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:drawableStart="@drawable/ic_update_file"
android:text="Clear"
app:layout_constraintBaseline_toBaselineOf="@+id/update_btn_web"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/update_btn_file" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>
4 changes: 3 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
<item name="android:windowBackground">@color/surfaceBg</item>
</style>

<style name="AppButton">
<style name="AppButton" parent="Widget.Material3.Button">
<item name="android:backgroundTint">@color/surfaceButton</item>
<item name="android:ellipsize">end</item>
<item name="cornerRadius">@dimen/card_corner_high</item>
<item name="rippleColor">@color/themeLight</item>
<item name="android:maxLines">1</item>
<item name="android:textAllCaps">false</item>
<item name="android:textColor">@color/themeLight</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ class DataRepository(
}
}

override fun clearData() {
repositoryScope.launch {
_updateState.value = DataState.Loading
localSource.clearData()
_updateState.value = DataState.Success(0L)
}
}

override fun getSatelliteItems(): Flow<List<SatItem>> = localSource.getSatelliteItems()

override suspend fun getSelectedSatellites() = localSource.getSelectedSatellites()
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/com/rtbishop/look4sat/data/ILocalSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ interface ILocalSource {
suspend fun updateEntriesSelection(catnums: List<Int>, isSelected: Boolean)

suspend fun updateTransmitters(transmitters: List<Transmitter>)

suspend fun clearData()
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ interface IDataRepository {

fun updateDataFromWeb(sources: List<String>)

fun clearData()

fun getSatelliteItems(): Flow<List<SatItem>>

suspend fun getSelectedSatellites(): List<Satellite>
Expand Down

0 comments on commit e9dc166

Please sign in to comment.