From 8cd58994cb7f66a14d92f6b2a4400ea8cb0e6fbf Mon Sep 17 00:00:00 2001 From: Yannine Alvarez Date: Tue, 19 May 2020 20:21:54 -0400 Subject: [PATCH] Ordenar las clases por carpeta. --- app/src/main/java/com/example/ayudapy/ApiPedidos.kt | 31 ------------------------------- app/src/main/java/com/example/ayudapy/ApiService.kt | 69 --------------------------------------------------------------------- app/src/main/java/com/example/ayudapy/CentroAyuda.kt | 26 -------------------------- app/src/main/java/com/example/ayudapy/Dao.kt | 33 --------------------------------- app/src/main/java/com/example/ayudapy/DataBaseRoom.kt | 24 ------------------------ app/src/main/java/com/example/ayudapy/Entity.kt | 31 ------------------------------- app/src/main/java/com/example/ayudapy/ListaModel.kt | 18 ------------------ app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt | 99 --------------------------------------------------------------------------------------------------- app/src/main/java/com/example/ayudapy/MapsActivity.kt | 19 +++++++++---------- app/src/main/java/com/example/ayudapy/PedidoDetalle.kt | 33 --------------------------------- app/src/main/java/com/example/ayudapy/PedidosAyuda.kt | 34 ---------------------------------- app/src/main/java/com/example/ayudapy/PendienteLista.kt | 13 ++++++------- app/src/main/java/com/example/ayudapy/Repository.kt | 67 ------------------------------------------------------------------- app/src/main/java/com/example/ayudapy/adapter/ListaPedidoAdapter.kt | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/com/example/ayudapy/api/ApiPedidos.kt | 28 ++++++++++++++++++++++++++++ app/src/main/java/com/example/ayudapy/api/ApiService.kt | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/com/example/ayudapy/db/Dao.kt | 32 ++++++++++++++++++++++++++++++++ app/src/main/java/com/example/ayudapy/db/DataBaseRoom.kt | 25 +++++++++++++++++++++++++ app/src/main/java/com/example/ayudapy/db/Entity.kt | 31 +++++++++++++++++++++++++++++++ app/src/main/java/com/example/ayudapy/db/ListaModel.kt | 20 ++++++++++++++++++++ app/src/main/java/com/example/ayudapy/db/Repository.kt | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/com/example/ayudapy/model/CentroAyuda.kt | 26 ++++++++++++++++++++++++++ app/src/main/java/com/example/ayudapy/model/PedidoDetalle.kt | 33 +++++++++++++++++++++++++++++++++ app/src/main/java/com/example/ayudapy/model/PedidosAyuda.kt | 34 ++++++++++++++++++++++++++++++++++ 24 files changed, 492 insertions(+), 482 deletions(-) delete mode 100644 app/src/main/java/com/example/ayudapy/ApiPedidos.kt delete mode 100644 app/src/main/java/com/example/ayudapy/ApiService.kt delete mode 100644 app/src/main/java/com/example/ayudapy/CentroAyuda.kt delete mode 100644 app/src/main/java/com/example/ayudapy/Dao.kt delete mode 100644 app/src/main/java/com/example/ayudapy/DataBaseRoom.kt delete mode 100644 app/src/main/java/com/example/ayudapy/Entity.kt delete mode 100644 app/src/main/java/com/example/ayudapy/ListaModel.kt delete mode 100644 app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt delete mode 100644 app/src/main/java/com/example/ayudapy/PedidoDetalle.kt delete mode 100644 app/src/main/java/com/example/ayudapy/PedidosAyuda.kt delete mode 100644 app/src/main/java/com/example/ayudapy/Repository.kt create mode 100644 app/src/main/java/com/example/ayudapy/adapter/ListaPedidoAdapter.kt create mode 100644 app/src/main/java/com/example/ayudapy/api/ApiPedidos.kt create mode 100644 app/src/main/java/com/example/ayudapy/api/ApiService.kt create mode 100644 app/src/main/java/com/example/ayudapy/db/Dao.kt create mode 100644 app/src/main/java/com/example/ayudapy/db/DataBaseRoom.kt create mode 100644 app/src/main/java/com/example/ayudapy/db/Entity.kt create mode 100644 app/src/main/java/com/example/ayudapy/db/ListaModel.kt create mode 100644 app/src/main/java/com/example/ayudapy/db/Repository.kt create mode 100644 app/src/main/java/com/example/ayudapy/model/CentroAyuda.kt create mode 100644 app/src/main/java/com/example/ayudapy/model/PedidoDetalle.kt create mode 100644 app/src/main/java/com/example/ayudapy/model/PedidosAyuda.kt diff --git a/app/src/main/java/com/example/ayudapy/ApiPedidos.kt b/app/src/main/java/com/example/ayudapy/ApiPedidos.kt deleted file mode 100644 index 222b978..0000000 --- a/app/src/main/java/com/example/ayudapy/ApiPedidos.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.example.ayudapy - -import okhttp3.OkHttpClient -import okhttp3.logging.HttpLoggingInterceptor -import retrofit2.Call -import retrofit2.Retrofit -import retrofit2.converter.gson.GsonConverterFactory -import retrofit2.http.GET -import retrofit2.http.Query - -interface ApiPedidos { - - - companion object{ - val instance:ApiService by lazy{ - - val builder_pedido = Retrofit.Builder() - .baseUrl("https://ayudapy.org/api/v1/helprequestsgeo/") - .addConverterFactory(GsonConverterFactory.create()) - - val client = OkHttpClient.Builder() - - client.addInterceptor(HttpLoggingInterceptor().apply { - level = HttpLoggingInterceptor.Level.BODY - }) - - builder_pedido.client(client.build()) - builder_pedido.build().create(ApiService::class.java) - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/ayudapy/ApiService.kt b/app/src/main/java/com/example/ayudapy/ApiService.kt deleted file mode 100644 index 3091bd6..0000000 --- a/app/src/main/java/com/example/ayudapy/ApiService.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.example.ayudapy - -import okhttp3.OkHttpClient -import okhttp3.logging.HttpLoggingInterceptor -import retrofit2.Call -import retrofit2.Retrofit -import retrofit2.converter.gson.GsonConverterFactory -import retrofit2.http.GET -import retrofit2.http.Path -import retrofit2.http.Query -import java.util.concurrent.TimeUnit - - -interface ApiService { - - @GET("?in_bbox") - fun getListaCentro( - @Query("limit") limit : Int, - @Query("offset") offset : Int - ): Call - - - /* @GET("helprequestsgeo/") - fun getHelpRequests(@Query("in_bbox") boundaryBox: String): Call*/ - - @GET("?in_bbox") - fun getListaPedidos( - @Query("limit") limit : Int, - @Query("offset") offset : Int - ): Call - - @GET("{id}") - fun getPedidoDetalle( - @Path("id") id : Int - ): Call - - - companion object { - // init Retrofit base server instance - val redditClient by lazy { ApiService.invoke("https://ayudapy.org/api/v1/donationcenters/") } - val stackClient by lazy { ApiService.invoke("https://ayudapy.org/api/v1/helprequestsgeo/") } - val pedidoDetalle by lazy { ApiService.invoke("https://ayudapy.org/api/v1/helprequests/") } - - private val loggingInterceptor = HttpLoggingInterceptor().apply { - this.level = HttpLoggingInterceptor.Level.BODY - } - - operator fun invoke(baseUrl: String): ApiService { - val client = OkHttpClient.Builder().apply { - /**addNetworkInterceptor(StethoInterceptor()) */ - addNetworkInterceptor(loggingInterceptor) - connectTimeout(10, TimeUnit.MINUTES) - readTimeout(10, TimeUnit.MINUTES) - writeTimeout(10, TimeUnit.MINUTES) - }.build() - - return Retrofit.Builder() - .client(client) - .baseUrl(baseUrl) -// .addCallAdapterFactory(CoroutineCallAdapterFactory()) - .addConverterFactory(GsonConverterFactory.create()) - .build() - .create(ApiService::class.java) - } - } - - - -} \ No newline at end of file diff --git a/app/src/main/java/com/example/ayudapy/CentroAyuda.kt b/app/src/main/java/com/example/ayudapy/CentroAyuda.kt deleted file mode 100644 index 9c48d6b..0000000 --- a/app/src/main/java/com/example/ayudapy/CentroAyuda.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.example.ayudapy - - -data class CentroAyuda ( - val count: Long, - val next: Any? = null, - val previous: Any? = null, - val results: List -) - -data class Result ( - val id: Long, - val name: String, - val phone: String, - val location: Location, - val address: String, - val city: String, - val cityCode: String, - val active: Boolean, - val added: String -) - -data class Location ( - val type: String, - val coordinates: List -) diff --git a/app/src/main/java/com/example/ayudapy/Dao.kt b/app/src/main/java/com/example/ayudapy/Dao.kt deleted file mode 100644 index 56b6a71..0000000 --- a/app/src/main/java/com/example/ayudapy/Dao.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.example.ayudapy - -import androidx.lifecycle.LiveData -import androidx.room.* -import androidx.room.OnConflictStrategy.REPLACE - -@Dao -interface DaoPedido { - - @Query("SELECT * FROM pedido_save") - fun getAll(): LiveData> - - @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insert(pedido: PedidoSave) - - @Delete - fun delete(pedido: PedidoSave) - - -} -/* -* @Dao -interface studentDao{ - @Query("SELECT * FROM studentTbl") - fun allStudents():List - - @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insert(student:Student) -}*/ - - /* @Query("UPDATE pedido_save SET name =:studentName, nim =:studentNim, gender =:studentGen WHERE id =:studentId") - fun update(studentId: Long, studentName:String, studentNim:String, studentGen:String)*/ - diff --git a/app/src/main/java/com/example/ayudapy/DataBaseRoom.kt b/app/src/main/java/com/example/ayudapy/DataBaseRoom.kt deleted file mode 100644 index a223646..0000000 --- a/app/src/main/java/com/example/ayudapy/DataBaseRoom.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.example.ayudapy - -import android.content.Context -import androidx.room.Database -import androidx.room.Room -import androidx.room.RoomDatabase -@Database(entities = arrayOf(PedidoSave::class), version = 1) -abstract class pedidoDataBase : RoomDatabase() { - abstract fun daoPedido():DaoPedido - - companion object { - private var INSTANCE: pedidoDataBase? = null - fun getInstance(context: Context): pedidoDataBase { - if (INSTANCE == null) { - INSTANCE = Room.databaseBuilder( - context, - pedidoDataBase::class.java, - "roomdb") - .build() - } - return INSTANCE as pedidoDataBase - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/ayudapy/Entity.kt b/app/src/main/java/com/example/ayudapy/Entity.kt deleted file mode 100644 index 468a1e7..0000000 --- a/app/src/main/java/com/example/ayudapy/Entity.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.example.ayudapy - -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.PrimaryKey -import org.jetbrains.annotations.NotNull - -@Entity(tableName = "pedido_save") - class PedidoSave { - - @PrimaryKey - var id: Long = 0 - - @ColumnInfo(name = "title") - lateinit var title: String - @ColumnInfo(name = "message") - lateinit var message: String - @ColumnInfo(name = "name") - lateinit var name: String - @ColumnInfo(name = "phone") - lateinit var phone: String - @ColumnInfo(name = "address") - lateinit var address: String - - // @ColumnInfo(name = "location") var location: String, -// @ColumnInfo(name = "active") var active: String, - @ColumnInfo(name = "added") - lateinit var added: String -} - - diff --git a/app/src/main/java/com/example/ayudapy/ListaModel.kt b/app/src/main/java/com/example/ayudapy/ListaModel.kt deleted file mode 100644 index 1bf1d31..0000000 --- a/app/src/main/java/com/example/ayudapy/ListaModel.kt +++ /dev/null @@ -1,18 +0,0 @@ -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> = db.daoPedido().getAll() - - fun insert(student:PedidoSave){ - db.daoPedido().insert(student) - } - fun delete(student:PedidoSave){ - db.daoPedido().delete(student) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt b/app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt deleted file mode 100644 index 59a7675..0000000 --- a/app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt +++ /dev/null @@ -1,99 +0,0 @@ -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.* -import java.time.LocalDate -import java.time.LocalDateTime -import java.time.format.DateTimeFormatter -import java.time.format.FormatStyle - - - -class RecyclerViewAdapter(val pedido: List) - : RecyclerView.Adapter(){ - - 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) - .inflate(R.layout.pendientes_items,parent,false) - return ViewHolder(v) - } - - - - - @RequiresApi(Build.VERSION_CODES.O) - override fun onBindViewHolder(holder: RecyclerViewAdapter.ViewHolder, position: Int) { - // localDate.getDayOfMonth(); - //localDate.getMonthValue(); - - val formatter = DateTimeFormatter.BASIC_ISO_DATE - val formatted = pedido[position].added.format(formatter) - - val fecha = formatted.substring(8..9) - - // dateTime.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM)) - val parsedDate = LocalDateTime.parse(pedido[position].added, DateTimeFormatter.ISO_DATE_TIME) - val formatteDate = parsedDate.format(DateTimeFormatter.ofPattern("dd MMM yyyy HH:mm")) - - val mes = formatteDate.substring(3..5) - - println("Este es el substring de mes: $mes y este es formateadp $formatteDate") - - holder.date_day.text = fecha - 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 - } - - 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 date_month = itemView.date_month - val title = itemView.title - val message_view = itemView.message_view - val delete_layout = itemView.delete_layout - - - - } -} - diff --git a/app/src/main/java/com/example/ayudapy/MapsActivity.kt b/app/src/main/java/com/example/ayudapy/MapsActivity.kt index 75be4be..7742158 100644 --- a/app/src/main/java/com/example/ayudapy/MapsActivity.kt +++ b/app/src/main/java/com/example/ayudapy/MapsActivity.kt @@ -1,7 +1,6 @@ package com.example.ayudapy import android.Manifest -import android.content.Entity import android.content.Intent import android.content.pm.PackageManager import android.location.Location @@ -18,10 +17,12 @@ import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat 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.example.ayudapy.api.ApiService +import com.example.ayudapy.db.PedidoSave +import com.example.ayudapy.db.pedidoDataBase +import com.example.ayudapy.model.CentroAyuda +import com.example.ayudapy.model.PedidosAyuda +import com.example.ayudapy.model.Resultado import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import com.google.android.gms.maps.CameraUpdateFactory @@ -35,9 +36,6 @@ import com.google.android.gms.maps.model.MarkerOptions import com.google.android.material.bottomsheet.BottomSheetDialog import kotlinx.android.synthetic.main.alert_dialog_contacto.view.* import kotlinx.android.synthetic.main.fragment_pedido.view.* -import kotlinx.android.synthetic.main.info.* -import kotlinx.android.synthetic.main.pendientes_lista.* -import org.jetbrains.anko.doAsync import retrofit2.Call import retrofit2.Callback import retrofit2.Response @@ -54,7 +52,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker private var selectedMarker:Marker?=null - private lateinit var mDb:pedidoDataBase + private lateinit var mDb: pedidoDataBase companion object{ @@ -359,7 +357,8 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker // Initialize a new student val pedido = Thread{ - var pedidoEntity = PedidoSave() + var pedidoEntity = + PedidoSave() pedidoEntity.id = pedidoDetalle!!.id pedidoEntity.added = pedidoDetalle!!.added pedidoEntity.address = pedidoDetalle!!.address diff --git a/app/src/main/java/com/example/ayudapy/PedidoDetalle.kt b/app/src/main/java/com/example/ayudapy/PedidoDetalle.kt deleted file mode 100644 index 54e1591..0000000 --- a/app/src/main/java/com/example/ayudapy/PedidoDetalle.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.example.ayudapy - -data class PedidoDetalle ( - val count: Long, - val next: String, - val previous: Any? = null, - val results: List -) - -data class Resultado ( - val id: Long, - val title: String, - val message: String, - val name: String, - val phone: String, - val address: String, - val city: String, - val location: locacion, - val picture: String? = null, - val active: Boolean, - val added: String -) - -data class locacion ( - val type: Type, - val coordinates: List -) - -enum class Type { - Point -} - - diff --git a/app/src/main/java/com/example/ayudapy/PedidosAyuda.kt b/app/src/main/java/com/example/ayudapy/PedidosAyuda.kt deleted file mode 100644 index 06ccc80..0000000 --- a/app/src/main/java/com/example/ayudapy/PedidosAyuda.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.example.ayudapy - -data class PedidosAyuda ( - val type: String, - val features: List -) - -data class Feature ( - val type: FeatureType, - val geometry: Geometry, - val properties: Properties -) - -data class Geometry ( - val type: GeometryType, - val coordinates: List -) - -enum class GeometryType { - Point -} - -data class Properties ( - val pk: Long, - val title: String, - val name: String, - val added: String -) - -enum class FeatureType { - Feature -} - - diff --git a/app/src/main/java/com/example/ayudapy/PendienteLista.kt b/app/src/main/java/com/example/ayudapy/PendienteLista.kt index d5fa789..babf57a 100644 --- a/app/src/main/java/com/example/ayudapy/PendienteLista.kt +++ b/app/src/main/java/com/example/ayudapy/PendienteLista.kt @@ -1,22 +1,20 @@ 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 com.example.ayudapy.adapter.RecyclerViewAdapter +import com.example.ayudapy.db.PedidoViewModel +import com.example.ayudapy.db.pedidoDataBase import kotlinx.android.synthetic.main.pendientes_lista.* class PendienteLista : AppCompatActivity() { private lateinit var model: PedidoViewModel - private lateinit var mDb:pedidoDataBase + private lateinit var mDb: pedidoDataBase override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.pendientes_lista) @@ -33,7 +31,8 @@ class PendienteLista : AppCompatActivity() { // Observe the model model.allPedidos.observe(this, Observer{ pedido-> // Data bind the recycler view - recycler_view.adapter = RecyclerViewAdapter(pedido) + recycler_view.adapter = + RecyclerViewAdapter(pedido) }) diff --git a/app/src/main/java/com/example/ayudapy/Repository.kt b/app/src/main/java/com/example/ayudapy/Repository.kt deleted file mode 100644 index 3c03f89..0000000 --- a/app/src/main/java/com/example/ayudapy/Repository.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.example.ayudapy - -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> = pedidoDao.getAll() - - @WorkerThread - fun insert(word: PedidoSave) { - pedidoDao.insert(word) - } - - @WorkerThread - fun delete(word: PedidoSave) { - pedidoDao.delete(word) - } - - /* --------------- BORRAR TODOS LOS DATOS -------------- */ - - /*fun deleteAll() { - deleteAllWordsAsyncTask(wordDao).execute() - }*/ - - /* private class deleteAllWordsAsyncTask internal constructor(private val mAsyncTaskDao: DaoPedido) : - AsyncTask() { - - 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() { - - 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() { - override fun doInBackground(vararg params: Word?): Void? { - mAsyncTaskDao.update(params[0]!!) - return null - } - }*/ -} \ No newline at end of file diff --git a/app/src/main/java/com/example/ayudapy/adapter/ListaPedidoAdapter.kt b/app/src/main/java/com/example/ayudapy/adapter/ListaPedidoAdapter.kt new file mode 100644 index 0000000..2801ed8 --- /dev/null +++ b/app/src/main/java/com/example/ayudapy/adapter/ListaPedidoAdapter.kt @@ -0,0 +1,96 @@ +package com.example.ayudapy.adapter + +import android.content.Context +import android.os.Build +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.annotation.RequiresApi +import androidx.recyclerview.widget.RecyclerView +import com.example.ayudapy.R +import com.example.ayudapy.db.PedidoSave +import com.example.ayudapy.db.pedidoDataBase +import kotlinx.android.synthetic.main.pendientes_items.view.* +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter + + +class RecyclerViewAdapter(val pedido: List) + : RecyclerView.Adapter(){ + + lateinit var context: Context + private lateinit var db: pedidoDataBase + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) + : ViewHolder { + val v: View = LayoutInflater.from(parent.context) + .inflate(R.layout.pendientes_items,parent,false) + return ViewHolder(v) + } + + + + + @RequiresApi(Build.VERSION_CODES.O) + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + // localDate.getDayOfMonth(); + //localDate.getMonthValue(); + + val formatter = DateTimeFormatter.BASIC_ISO_DATE + val formatted = pedido[position].added.format(formatter) + + val fecha = formatted.substring(8..9) + + // dateTime.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM)) + val parsedDate = LocalDateTime.parse(pedido[position].added, DateTimeFormatter.ISO_DATE_TIME) + val formatteDate = parsedDate.format(DateTimeFormatter.ofPattern("dd MMM yyyy HH:mm")) + + val mes = formatteDate.substring(3..5) + + println("Este es el substring de mes: $mes y este es formateadp $formatteDate") + + holder.date_day.text = fecha + 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 + } + + 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 date_month = itemView.date_month + val title = itemView.title + val message_view = itemView.message_view + val delete_layout = itemView.delete_layout + + + + } +} + diff --git a/app/src/main/java/com/example/ayudapy/api/ApiPedidos.kt b/app/src/main/java/com/example/ayudapy/api/ApiPedidos.kt new file mode 100644 index 0000000..5c522d1 --- /dev/null +++ b/app/src/main/java/com/example/ayudapy/api/ApiPedidos.kt @@ -0,0 +1,28 @@ +package com.example.ayudapy.api + +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory + +interface ApiPedidos { + + + companion object{ + val instance: ApiService by lazy{ + + val builder_pedido = Retrofit.Builder() + .baseUrl("https://ayudapy.org/api/v1/helprequestsgeo/") + .addConverterFactory(GsonConverterFactory.create()) + + val client = OkHttpClient.Builder() + + client.addInterceptor(HttpLoggingInterceptor().apply { + level = HttpLoggingInterceptor.Level.BODY + }) + + builder_pedido.client(client.build()) + builder_pedido.build().create(ApiService::class.java) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ayudapy/api/ApiService.kt b/app/src/main/java/com/example/ayudapy/api/ApiService.kt new file mode 100644 index 0000000..61b525a --- /dev/null +++ b/app/src/main/java/com/example/ayudapy/api/ApiService.kt @@ -0,0 +1,84 @@ +package com.example.ayudapy.api + +import com.example.ayudapy.model.CentroAyuda +import com.example.ayudapy.model.PedidosAyuda +import com.example.ayudapy.model.Resultado +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Call +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory +import retrofit2.http.GET +import retrofit2.http.Path +import retrofit2.http.Query +import java.util.concurrent.TimeUnit + + +interface ApiService { + + @GET("?in_bbox") + fun getListaCentro( + @Query("limit") limit : Int, + @Query("offset") offset : Int + ): Call + + + /* @GET("helprequestsgeo/") + fun getHelpRequests(@Query("in_bbox") boundaryBox: String): Call*/ + + @GET("?in_bbox") + fun getListaPedidos( + @Query("limit") limit : Int, + @Query("offset") offset : Int + ): Call + + @GET("{id}") + fun getPedidoDetalle( + @Path("id") id : Int + ): Call + + + companion object { + // init Retrofit base server instance + val redditClient by lazy { + invoke( + "https://ayudapy.org/api/v1/donationcenters/" + ) + } + val stackClient by lazy { + invoke( + "https://ayudapy.org/api/v1/helprequestsgeo/" + ) + } + val pedidoDetalle by lazy { + invoke( + "https://ayudapy.org/api/v1/helprequests/" + ) + } + + private val loggingInterceptor = HttpLoggingInterceptor().apply { + this.level = HttpLoggingInterceptor.Level.BODY + } + + operator fun invoke(baseUrl: String): ApiService { + val client = OkHttpClient.Builder().apply { + /**addNetworkInterceptor(StethoInterceptor()) */ + addNetworkInterceptor(loggingInterceptor) + connectTimeout(10, TimeUnit.MINUTES) + readTimeout(10, TimeUnit.MINUTES) + writeTimeout(10, TimeUnit.MINUTES) + }.build() + + return Retrofit.Builder() + .client(client) + .baseUrl(baseUrl) +// .addCallAdapterFactory(CoroutineCallAdapterFactory()) + .addConverterFactory(GsonConverterFactory.create()) + .build() + .create(ApiService::class.java) + } + } + + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ayudapy/db/Dao.kt b/app/src/main/java/com/example/ayudapy/db/Dao.kt new file mode 100644 index 0000000..3d349e7 --- /dev/null +++ b/app/src/main/java/com/example/ayudapy/db/Dao.kt @@ -0,0 +1,32 @@ +package com.example.ayudapy.db + +import androidx.lifecycle.LiveData +import androidx.room.* + +@Dao +interface DaoPedido { + + @Query("SELECT * FROM pedido_save") + fun getAll(): LiveData> + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insert(pedido: PedidoSave) + + @Delete + fun delete(pedido: PedidoSave) + + +} +/* +* @Dao +interface studentDao{ + @Query("SELECT * FROM studentTbl") + fun allStudents():List + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insert(student:Student) +}*/ + + /* @Query("UPDATE pedido_save SET name =:studentName, nim =:studentNim, gender =:studentGen WHERE id =:studentId") + fun update(studentId: Long, studentName:String, studentNim:String, studentGen:String)*/ + diff --git a/app/src/main/java/com/example/ayudapy/db/DataBaseRoom.kt b/app/src/main/java/com/example/ayudapy/db/DataBaseRoom.kt new file mode 100644 index 0000000..1d141fe --- /dev/null +++ b/app/src/main/java/com/example/ayudapy/db/DataBaseRoom.kt @@ -0,0 +1,25 @@ +package com.example.ayudapy.db + +import android.content.Context +import androidx.room.Database +import androidx.room.Room +import androidx.room.RoomDatabase + +@Database(entities = arrayOf(PedidoSave::class), version = 1) +abstract class pedidoDataBase : RoomDatabase() { + abstract fun daoPedido(): DaoPedido + + companion object { + private var INSTANCE: pedidoDataBase? = null + fun getInstance(context: Context): pedidoDataBase { + if (INSTANCE == null) { + INSTANCE = Room.databaseBuilder( + context, + pedidoDataBase::class.java, + "roomdb") + .build() + } + return INSTANCE as pedidoDataBase + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ayudapy/db/Entity.kt b/app/src/main/java/com/example/ayudapy/db/Entity.kt new file mode 100644 index 0000000..b8519b7 --- /dev/null +++ b/app/src/main/java/com/example/ayudapy/db/Entity.kt @@ -0,0 +1,31 @@ +package com.example.ayudapy.db + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import org.jetbrains.annotations.NotNull + +@Entity(tableName = "pedido_save") + class PedidoSave { + + @PrimaryKey + var id: Long = 0 + + @ColumnInfo(name = "title") + lateinit var title: String + @ColumnInfo(name = "message") + lateinit var message: String + @ColumnInfo(name = "name") + lateinit var name: String + @ColumnInfo(name = "phone") + lateinit var phone: String + @ColumnInfo(name = "address") + lateinit var address: String + + // @ColumnInfo(name = "location") var location: String, +// @ColumnInfo(name = "active") var active: String, + @ColumnInfo(name = "added") + lateinit var added: String +} + + diff --git a/app/src/main/java/com/example/ayudapy/db/ListaModel.kt b/app/src/main/java/com/example/ayudapy/db/ListaModel.kt new file mode 100644 index 0000000..7a68c55 --- /dev/null +++ b/app/src/main/java/com/example/ayudapy/db/ListaModel.kt @@ -0,0 +1,20 @@ +package com.example.ayudapy.db + +import androidx.lifecycle.AndroidViewModel +import androidx.lifecycle.LiveData +import android.app.Application +import com.example.ayudapy.db.PedidoSave +import com.example.ayudapy.db.pedidoDataBase + + +class PedidoViewModel(application:Application): AndroidViewModel(application){ + private val db: pedidoDataBase = pedidoDataBase.getInstance(application) + internal val allPedidos : LiveData> = db.daoPedido().getAll() + + fun insert(student: PedidoSave){ + db.daoPedido().insert(student) + } + fun delete(student: PedidoSave){ + db.daoPedido().delete(student) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ayudapy/db/Repository.kt b/app/src/main/java/com/example/ayudapy/db/Repository.kt new file mode 100644 index 0000000..6401573 --- /dev/null +++ b/app/src/main/java/com/example/ayudapy/db/Repository.kt @@ -0,0 +1,68 @@ +package com.example.ayudapy.db + +import androidx.annotation.WorkerThread +import androidx.lifecycle.LiveData +import com.example.ayudapy.db.DaoPedido +import com.example.ayudapy.db.PedidoSave + +// 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> = pedidoDao.getAll() + + @WorkerThread + fun insert(word: PedidoSave) { + pedidoDao.insert(word) + } + + @WorkerThread + fun delete(word: PedidoSave) { + pedidoDao.delete(word) + } + + /* --------------- BORRAR TODOS LOS DATOS -------------- */ + + /*fun deleteAll() { + deleteAllWordsAsyncTask(wordDao).execute() + }*/ + + /* private class deleteAllWordsAsyncTask internal constructor(private val mAsyncTaskDao: DaoPedido) : + AsyncTask() { + + 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() { + + 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() { + override fun doInBackground(vararg params: Word?): Void? { + mAsyncTaskDao.update(params[0]!!) + return null + } + }*/ +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ayudapy/model/CentroAyuda.kt b/app/src/main/java/com/example/ayudapy/model/CentroAyuda.kt new file mode 100644 index 0000000..9034acc --- /dev/null +++ b/app/src/main/java/com/example/ayudapy/model/CentroAyuda.kt @@ -0,0 +1,26 @@ +package com.example.ayudapy.model + + +data class CentroAyuda ( + val count: Long, + val next: Any? = null, + val previous: Any? = null, + val results: List +) + +data class Result ( + val id: Long, + val name: String, + val phone: String, + val location: Location, + val address: String, + val city: String, + val cityCode: String, + val active: Boolean, + val added: String +) + +data class Location ( + val type: String, + val coordinates: List +) diff --git a/app/src/main/java/com/example/ayudapy/model/PedidoDetalle.kt b/app/src/main/java/com/example/ayudapy/model/PedidoDetalle.kt new file mode 100644 index 0000000..3bb36a1 --- /dev/null +++ b/app/src/main/java/com/example/ayudapy/model/PedidoDetalle.kt @@ -0,0 +1,33 @@ +package com.example.ayudapy.model + +data class PedidoDetalle ( + val count: Long, + val next: String, + val previous: Any? = null, + val results: List +) + +data class Resultado ( + val id: Long, + val title: String, + val message: String, + val name: String, + val phone: String, + val address: String, + val city: String, + val location: locacion, + val picture: String? = null, + val active: Boolean, + val added: String +) + +data class locacion ( + val type: Type, + val coordinates: List +) + +enum class Type { + Point +} + + diff --git a/app/src/main/java/com/example/ayudapy/model/PedidosAyuda.kt b/app/src/main/java/com/example/ayudapy/model/PedidosAyuda.kt new file mode 100644 index 0000000..c6e4259 --- /dev/null +++ b/app/src/main/java/com/example/ayudapy/model/PedidosAyuda.kt @@ -0,0 +1,34 @@ +package com.example.ayudapy.model + +data class PedidosAyuda ( + val type: String, + val features: List +) + +data class Feature ( + val type: FeatureType, + val geometry: Geometry, + val properties: Properties +) + +data class Geometry ( + val type: GeometryType, + val coordinates: List +) + +enum class GeometryType { + Point +} + +data class Properties ( + val pk: Long, + val title: String, + val name: String, + val added: String +) + +enum class FeatureType { + Feature +} + + -- libgit2 0.26.0