Commit dc67dd59 by Yannine Alvarez

Agregar repository, model, adapter para recyclerview.

parent 12dbd616
...@@ -79,6 +79,16 @@ dependencies { ...@@ -79,6 +79,16 @@ dependencies {
implementation 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1' implementation 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'
// ViewModel and LiveData
def lifecycle_version = "2.0.0"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
// // COROUTINES
// api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutines"
// api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"
//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"
......
...@@ -6,8 +6,9 @@ import androidx.room.OnConflictStrategy.REPLACE ...@@ -6,8 +6,9 @@ import androidx.room.OnConflictStrategy.REPLACE
@Dao @Dao
interface DaoPedido { interface DaoPedido {
@Query("SELECT * from pedido_save")
fun getAll(): List<PedidoSave> @Query("SELECT * FROM pedido_save")
fun getAll(): LiveData<List<PedidoSave>>
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(pedido: PedidoSave) fun insert(pedido: PedidoSave)
......
package com.example.ayudapy
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import android.app.Application
class PedidoViewModel(application:Application): AndroidViewModel(application){
private val db:pedidoDataBase = pedidoDataBase.getInstance(application)
internal val allPedidos : LiveData<List<PedidoSave>> = db.daoPedido().getAll()
fun insert(student:PedidoSave){
db.daoPedido().insert(student)
}
}
\ No newline at end of file
package com.example.ayudapy
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.pendientes_items.view.*
class RecyclerViewAdapter(val pedido: List<PedidoSave>)
: RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>(){
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int)
: RecyclerViewAdapter.ViewHolder {
val v: View = LayoutInflater.from(parent.context)
.inflate(R.layout.pendientes_items,parent,false)
return ViewHolder(v)
}
override fun onBindViewHolder(holder: RecyclerViewAdapter.ViewHolder, position: Int) {
holder.date_day.text = pedido[position].added
holder.title.text = pedido[position].title
holder.message_view.text = pedido[position].message
}
override fun getItemCount(): Int {
return pedido.size
}
override fun getItemId(position: Int): Long {
return super.getItemId(position)
}
override fun getItemViewType(position: Int): Int {
return super.getItemViewType(position)
}
class ViewHolder(itemView:View): RecyclerView.ViewHolder(itemView){
val date_day = itemView.date_day
val title = itemView.title
val message_view = itemView.message_view
}
}
...@@ -18,6 +18,10 @@ import androidx.appcompat.app.AlertDialog ...@@ -18,6 +18,10 @@ import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices import com.google.android.gms.location.LocationServices
import com.google.android.gms.maps.CameraUpdateFactory import com.google.android.gms.maps.CameraUpdateFactory
...@@ -32,6 +36,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog ...@@ -32,6 +36,7 @@ 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.view.* import kotlinx.android.synthetic.main.fragment_pedido.view.*
import kotlinx.android.synthetic.main.info.* import kotlinx.android.synthetic.main.info.*
import kotlinx.android.synthetic.main.pendientes_lista.*
import org.jetbrains.anko.doAsync import org.jetbrains.anko.doAsync
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
...@@ -51,6 +56,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker ...@@ -51,6 +56,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
private lateinit var mDb:pedidoDataBase 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
} }
...@@ -124,6 +130,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker ...@@ -124,6 +130,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
//agregar permiso para llamar //agregar permiso para llamar
val permissionCheck: Int = ContextCompat.checkSelfPermission( val permissionCheck: Int = ContextCompat.checkSelfPermission(
this, Manifest.permission.CALL_PHONE this, Manifest.permission.CALL_PHONE
...@@ -363,12 +370,12 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker ...@@ -363,12 +370,12 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
mDb.daoPedido().insert(pedidoEntity) mDb.daoPedido().insert(pedidoEntity)
mDb.daoPedido().getAll().forEach() /* mDb.daoPedido().getAll().forEach()
{ {
Log.i("Fetch Records", "Id: ${it.id}") Log.i("Fetch Records", "Id: ${it.id}")
println("Name es de pedido: ${it.name}") println("Name es de pedido: ${it.name}")
} }*/
} }
pedido.start() pedido.start()
......
...@@ -3,12 +3,34 @@ package com.example.ayudapy ...@@ -3,12 +3,34 @@ package com.example.ayudapy
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity 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_lista.*
class PendienteLista : AppCompatActivity() { class PendienteLista : AppCompatActivity() {
private lateinit var model: PedidoViewModel
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.pendientes_lista) setContentView(R.layout.pendientes_lista)
val intento: Intent = intent
// Get the view model
model = ViewModelProviders.of(this).get(PedidoViewModel::class.java)
// Specify layout for recycler view
val linearLayoutManager = LinearLayoutManager(
this, RecyclerView.VERTICAL,false)
recycler_view.layoutManager = linearLayoutManager
// Observe the model
model.allPedidos.observe(this, Observer{ pedido->
// Data bind the recycler view
recycler_view.adapter = RecyclerViewAdapter(pedido)
})
} }
} }
package com.example.ayudapy package com.example.ayudapy
class Repository { 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
}
}*/
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_layout" android:id="@+id/swipe_layout"
android:background="#FFFFFF"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="100dp"
app:dragEdge="right" app:dragEdge="right"
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
android:id="@+id/front_layout" android:id="@+id/front_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#FFFFFF"
android:paddingStart="8dp" android:paddingStart="8dp"
android:paddingEnd="8dp"> android:paddingEnd="8dp">
...@@ -39,6 +41,7 @@ ...@@ -39,6 +41,7 @@
android:id="@+id/card_view" android:id="@+id/card_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#FFFFFF"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:foreground="?android:attr/selectableItemBackground" android:foreground="?android:attr/selectableItemBackground"
...@@ -51,7 +54,8 @@ ...@@ -51,7 +54,8 @@
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="#FFFFFF">
<LinearLayout <LinearLayout
android:id="@+id/llDate" android:id="@+id/llDate"
...@@ -112,6 +116,7 @@ ...@@ -112,6 +116,7 @@
android:layout_below="@id/title" android:layout_below="@id/title"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:layout_toEndOf="@id/view" android:layout_toEndOf="@id/view"
android:textColor="@color/colorPrimary"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="2" android:maxLines="2"
tools:text="Message" /> tools:text="Message" />
......
...@@ -5,4 +5,8 @@ ...@@ -5,4 +5,8 @@
<color name="colorAccent">#03DAC5</color> <color name="colorAccent">#03DAC5</color>
<color name="colorBlancoTransparente">#33FFFFFF</color> <color name="colorBlancoTransparente">#33FFFFFF</color>
<color name="light_gray">#CCC</color> <color name="light_gray">#CCC</color>
<color name="colorAccentDark">#009A9B</color>
<color name="pink">#FD5C7F</color>
<color name="red">#f44336</color>
<color name="green">#388E3C</color>
</resources> </resources>
...@@ -13,5 +13,29 @@ ...@@ -13,5 +13,29 @@
<item name="cornerRadius">12dp</item> <item name="cornerRadius">12dp</item>
</style> </style>
<style name="BaseAppTheme" parent="AppTheme" />
<style name="CustomBottomSheetDialog" parent="@style/ThemeOverlay.MaterialComponents.BottomSheetDialog">
<item name="bottomSheetStyle">@style/CustomBottomSheet</item>
</style>
<style name="CustomBottomSheet" parent="Widget.MaterialComponents.BottomSheet.Modal">
<item name="shapeAppearance">@style/BottomSheetShapeAppearance</item>
</style>
<style name="BottomSheetShapeAppearance">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">12dp</item>
</style>
<style name="BottomDialogFragmentBar">
<item name="android:layout_width">80dp</item>
<item name="android:layout_height">4dp</item>
<item name="android:layout_marginTop">16dp</item>
<item name="android:background">@drawable/background_round</item>
</style>
</resources> </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