Commit e3266de9 by Yannine Alvarez

Delete en recycler view.

parent 794df526
......@@ -15,6 +15,8 @@ interface DaoPedido {
@Delete
fun delete(pedido: PedidoSave)
}
/*
* @Dao
......
......@@ -12,4 +12,7 @@ class PedidoViewModel(application:Application): AndroidViewModel(application){
fun insert(student:PedidoSave){
db.daoPedido().insert(student)
}
fun delete(student:PedidoSave){
db.daoPedido().delete(student)
}
}
\ No newline at end of file
package com.example.ayudapy
import android.content.Context
import android.graphics.ColorSpace
import android.os.Build
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.pendientes_items.view.*
......@@ -14,9 +16,14 @@ import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
class RecyclerViewAdapter(val pedido: List<PedidoSave>)
: RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>(){
lateinit var context: Context
private lateinit var db:pedidoDataBase
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int)
: RecyclerViewAdapter.ViewHolder {
val v: View = LayoutInflater.from(parent.context)
......@@ -49,8 +56,22 @@ class RecyclerViewAdapter(val pedido: List<PedidoSave>)
holder.date_month.text = mes.toUpperCase()
holder.title.text = pedido[position].title
holder.message_view.text = pedido[position].message
holder.delete_layout.setOnClickListener {
//Toast.makeText(context,"clicked",Toast.LENGTH_SHORT).show()
println("Hace clic ")
// val pedido = Thread{
db.daoPedido().delete(pedido[position])
// }
// pedido.start()
}
}
override fun getItemCount(): Int {
return pedido.size
}
......@@ -63,11 +84,16 @@ class RecyclerViewAdapter(val pedido: List<PedidoSave>)
return super.getItemViewType(position)
}
class ViewHolder(itemView:View): RecyclerView.ViewHolder(itemView){
val date_day = itemView.date_day
val date_month = itemView.date_month
val title = itemView.title
val message_view = itemView.message_view
val delete_layout = itemView.delete_layout
}
}
......@@ -2,16 +2,21 @@ package com.example.ayudapy
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.ListAdapter
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.pendientes_items.view.*
import kotlinx.android.synthetic.main.pendientes_lista.*
class PendienteLista : AppCompatActivity() {
private lateinit var model: PedidoViewModel
private lateinit var mDb:pedidoDataBase
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.pendientes_lista)
......@@ -31,6 +36,7 @@ class PendienteLista : AppCompatActivity() {
recycler_view.adapter = RecyclerViewAdapter(pedido)
})
}
}
......@@ -16,6 +16,10 @@ class PedidoRepository(private val pedidoDao: DaoPedido) {
pedidoDao.insert(word)
}
@WorkerThread
fun delete(word: PedidoSave) {
pedidoDao.delete(word)
}
/* --------------- BORRAR TODOS LOS DATOS -------------- */
......
......@@ -20,10 +20,12 @@
android:foreground="?android:attr/selectableItemBackground">
<TextView
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="16dp"
android:text="@string/eliminar"
android:textColor="@android:color/white"
android:textSize="18sp"
android:textStyle="bold" />
......
......@@ -4,4 +4,5 @@
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="eliminar">Eliminar</string>
</resources>
Markdown is supported
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