Skip to content
Snippets Groups Projects
Commit 8e642120 authored by rayhanp1402's avatar rayhanp1402
Browse files

feat: Reset/delete all transactions

parent d9a8acbd
2 merge requests!13Release,!11proper save for gmail
......@@ -130,8 +130,8 @@ class SettingsFragment : Fragment() {
resetButton.setOnClickListener{
Toast.makeText(appContext, "Transaksi di-reset ...", Toast.LENGTH_SHORT).show()
showConfirmationDialog("Reset", "Apakah Anda yakin ingin me-reset data transaksi?") {
//todo
transactionsViewModel.deleteAllTransactions()
Toast.makeText(appContext, "Transaksi berhasil di-reset ...", Toast.LENGTH_SHORT).show()
}
}
......
......@@ -32,6 +32,10 @@ class TransactionsViewModel(
suspend fun getAllTransactionsList(): List<Transactions> {
return repository.getAllTransactionsList()
}
fun deleteAllTransactions() = viewModelScope.launch {
repository.deleteAllTransactions()
}
}
class TransactionsViewModelFactory(private val repository: TransactionsRepository): ViewModelProvider.Factory {
......
......@@ -23,4 +23,7 @@ interface TransactionsDao {
@Query("SELECT * FROM transactions WHERE transactions.id == :transactionsId")
suspend fun getTransactionById(transactionsId: Int?): Transactions
@Query("DELETE FROM transactions")
suspend fun deleteAllTransactions()
}
\ No newline at end of file
......@@ -23,4 +23,9 @@ class TransactionsRepository(private val transactionsDao: TransactionsDao) {
suspend fun getAllTransactionsList(): List<Transactions> {
return transactionsDao.getTransactionsList()
}
@WorkerThread
suspend fun deleteAllTransactions() {
transactionsDao.deleteAllTransactions()
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment