Commit 7f81bfb4 by Yannine Alvarez

Agregar función room.

parent 1623ce2c
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
//apply plugin: 'com.android.library'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-kapt'
...@@ -63,6 +64,7 @@ dependencies { ...@@ -63,6 +64,7 @@ dependencies {
//implementation 'com.squareup.okio:okio:2.4.3' //implementation 'com.squareup.okio:okio:2.4.3'
//noinspection GradleCompatible //noinspection GradleCompatible
implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
...@@ -73,8 +75,12 @@ dependencies { ...@@ -73,8 +75,12 @@ dependencies {
implementation 'android.arch.persistence.room:runtime:1.1.1' implementation 'android.arch.persistence.room:runtime:1.1.1'
kapt 'android.arch.persistence.room:compiler:1.1.1' kapt 'android.arch.persistence.room:compiler:1.1.1'
implementation 'org.jetbrains.anko:anko-common:0.9'
//implementation "android.arch.lifecycle:extensions:1.1.1" //implementation "android.arch.lifecycle:extensions:1.1.1"
//implementation "android.arch.persistence.room:runtime:1.0.0-rc1" //implementation "android.arch.persistence.room:runtime:1.0.0-rc1"
//kapt "android.arch.persistence.room:compiler:1.0.0-rc1" //kapt "android.arch.persistence.room:compiler:1.0.0-rc1"
} }
...@@ -9,12 +9,21 @@ interface DaoPedido { ...@@ -9,12 +9,21 @@ interface DaoPedido {
@Query("SELECT * from pedido_save") @Query("SELECT * from pedido_save")
fun getAll(): List<PedidoSave> fun getAll(): List<PedidoSave>
@Insert(onConflict = REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(pedido: PedidoSave) fun insert(pedido: PedidoSave)
@Delete @Delete
fun delete(pedido: PedidoSave) fun delete(pedido: PedidoSave)
} }
/*
* @Dao
interface studentDao{
@Query("SELECT * FROM studentTbl")
fun allStudents():List<Student>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(student:Student)
}*/
/* @Query("UPDATE pedido_save SET name =:studentName, nim =:studentNim, gender =:studentGen WHERE id =:studentId") /* @Query("UPDATE pedido_save SET name =:studentName, nim =:studentNim, gender =:studentGen WHERE id =:studentId")
fun update(studentId: Long, studentName:String, studentNim:String, studentGen:String)*/ fun update(studentId: Long, studentName:String, studentNim:String, studentGen:String)*/
......
...@@ -4,27 +4,21 @@ import android.content.Context ...@@ -4,27 +4,21 @@ import android.content.Context
import androidx.room.Database import androidx.room.Database
import androidx.room.Room import androidx.room.Room
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
@Database(entities = arrayOf(PedidoSave::class), version = 1) @Database(entities = arrayOf(PedidoSave::class), version = 1)
abstract class PedidoDataBase : RoomDatabase() { abstract class pedidoDataBase : RoomDatabase() {
abstract fun daoPedido():DaoPedido
abstract fun daoPedido(): DaoPedido
companion object { companion object {
private var INSTANCE: PedidoDataBase? = null private var INSTANCE: pedidoDataBase? = null
fun getInstance(context: Context): pedidoDataBase {
fun getInstance(context: Context): PedidoDataBase? {
if (INSTANCE == null) { if (INSTANCE == null) {
synchronized(PedidoDataBase::class) { INSTANCE = Room.databaseBuilder(
INSTANCE = Room.databaseBuilder(context.getApplicationContext(), context,
PedidoDataBase::class.java, "pedidodata.db") pedidoDataBase::class.java,
.build() "roomdb")
} .build()
} }
return INSTANCE return INSTANCE as pedidoDataBase
}
fun destroyInstance() {
INSTANCE = null
} }
} }
} }
\ No newline at end of file
...@@ -30,13 +30,18 @@ import com.google.android.gms.maps.model.Marker ...@@ -30,13 +30,18 @@ import com.google.android.gms.maps.model.Marker
import com.google.android.gms.maps.model.MarkerOptions import com.google.android.gms.maps.model.MarkerOptions
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import kotlinx.android.synthetic.main.alert_dialog_contacto.view.* import kotlinx.android.synthetic.main.alert_dialog_contacto.view.*
import kotlinx.android.synthetic.main.fragment_pedido.*
import kotlinx.android.synthetic.main.fragment_pedido.view.* import kotlinx.android.synthetic.main.fragment_pedido.view.*
import kotlinx.android.synthetic.main.fragment_pedido.view.pedido_id
import org.jetbrains.anko.doAsync
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarkerClickListener { class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarkerClickListener {
private lateinit var mMap: GoogleMap private lateinit var mMap: GoogleMap
...@@ -45,6 +50,9 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker ...@@ -45,6 +50,9 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
internal lateinit var infoButton: Button internal lateinit var infoButton: Button
private var selectedMarker:Marker?=null private var selectedMarker:Marker?=null
private lateinit var mDb:pedidoDataBase
companion object{ companion object{
private const val LOCATION_PERMISSION_REQUEST_CODE=1 private const val LOCATION_PERMISSION_REQUEST_CODE=1
} }
...@@ -68,7 +76,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker ...@@ -68,7 +76,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
return false return false
} }
} }
private var pedidoDatabase:PedidoDataBase? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
...@@ -79,6 +87,10 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker ...@@ -79,6 +87,10 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
.findFragmentById(R.id.map) as SupportMapFragment .findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this) mapFragment.getMapAsync(this)
// Initialize the room database
mDb = pedidoDataBase.getInstance(applicationContext)
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this) fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
//intent para mandar a la siguiente pantalla el boton //intent para mandar a la siguiente pantalla el boton
...@@ -120,7 +132,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker ...@@ -120,7 +132,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
Log.i("Mensaje", "Se tiene permiso!") Log.i("Mensaje", "Se tiene permiso!")
} }
pedidoDatabase = PedidoDataBase.getInstance(this)
} }
...@@ -331,6 +343,28 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker ...@@ -331,6 +343,28 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
pedidoDetalle.title,pedidoDetalle.message,pedidoDetalle.name,pedidoDetalle.phone, pedidoDetalle.title,pedidoDetalle.message,pedidoDetalle.name,pedidoDetalle.phone,
pedidoDetalle.address,pedidoDetalle.added))*/ pedidoDetalle.address,pedidoDetalle.added))*/
// Initialize a new student
val pedido = PedidoSave(id = pedidoDetalle!!.id,
added = pedidoDetalle!!.added,
address = pedidoDetalle!!.address,
message = pedidoDetalle!!.message,
name = pedidoDetalle!!.name,
phone = pedidoDetalle!!.phone,
title = pedidoDetalle!!.title
)
doAsync {
//Application.database.myDAO().insertUser(user)
mDb.daoPedido().insert(pedido)
}
view.pendiente_button.setBackgroundResource(R.drawable.icon_pendientes_checked)
} }
view.listo_button.setOnClickListener{ view.listo_button.setOnClickListener{
...@@ -350,9 +384,6 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker ...@@ -350,9 +384,6 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
) )
} }
/* fun insertToDb(pedido:PedidoSave){
}*/
//permiso para acceder a la ubicacion del dispositvo //permiso para acceder a la ubicacion del dispositvo
private fun setup(){ private fun setup(){
......
package com.example.ayudapy
class Repository {
}
\ No newline at end of file
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