Repository.kt 1.81 KB
Newer Older
Yannine Alvarez committed
1 2
package com.example.ayudapy

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
import android.os.AsyncTask
import androidx.annotation.WorkerThread
import androidx.lifecycle.LiveData

// Declares the DAO as a private property in the constructor. Pass in the DAO
// instead of the whole database, because you only need access to the DAO

class PedidoRepository(private val pedidoDao: DaoPedido) {

    val allPedidos: LiveData<List<PedidoSave>> = pedidoDao.getAll()

    @WorkerThread
    fun insert(word: PedidoSave) {
        pedidoDao.insert(word)
    }


    /* --------------- BORRAR TODOS LOS DATOS -------------- */

    /*fun deleteAll() {
        deleteAllWordsAsyncTask(wordDao).execute()
    }*/

   /* private class deleteAllWordsAsyncTask internal constructor(private val mAsyncTaskDao: DaoPedido) :
        AsyncTask<Void, Void, Void>() {

        override fun doInBackground(vararg voids: Void): Void? {
            mAsyncTaskDao.delete()
            return null
        }
    }*/

    /* ---------------- BORRAR UN SOLO DATO ---------------- */

   /* fun deleteWord(word: PedidoSave) {
        deleteWordAsyncTask(wordDao).execute(word)
    }

    private class deleteWordAsyncTask internal constructor(private val mAsyncTaskDao: DaoPedido) :
        AsyncTask<PedidoSave, Void, Void>() {

        override fun doInBackground(vararg params: PedidoSave): Void? {
            mAsyncTaskDao.delete(params[0])
            return null
        }
    }*/

    /* -------------- ACTUALIZAR UN SOLO DATO ----------------

    fun update(word: Word) {
        updateWordAsyncTask(wordDao).execute(word)
    }

    private class updateWordAsyncTask internal constructor(private val mAsyncTaskDao: WordDao) :
        AsyncTask<Word, Void, Void>() {
        override fun doInBackground(vararg params: Word?): Void? {
            mAsyncTaskDao.update(params[0]!!)
            return null
        }
    }*/
Yannine Alvarez committed
63
}