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/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/ListaPedidoAdapter.kt b/app/src/main/java/com/example/ayudapy/adapter/ListaPedidoAdapter.kt similarity index 87% rename from app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt rename to app/src/main/java/com/example/ayudapy/adapter/ListaPedidoAdapter.kt index 59a7675..2801ed8 100644 --- a/app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt +++ b/app/src/main/java/com/example/ayudapy/adapter/ListaPedidoAdapter.kt @@ -1,31 +1,28 @@ -package com.example.ayudapy +package com.example.ayudapy.adapter 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 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.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 + private lateinit var db: pedidoDataBase override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) - : RecyclerViewAdapter.ViewHolder { + : ViewHolder { val v: View = LayoutInflater.from(parent.context) .inflate(R.layout.pendientes_items,parent,false) return ViewHolder(v) @@ -35,7 +32,7 @@ class RecyclerViewAdapter(val pedido: List) @RequiresApi(Build.VERSION_CODES.O) - override fun onBindViewHolder(holder: RecyclerViewAdapter.ViewHolder, position: Int) { + override fun onBindViewHolder(holder: ViewHolder, position: Int) { // localDate.getDayOfMonth(); //localDate.getMonthValue(); diff --git a/app/src/main/java/com/example/ayudapy/ApiPedidos.kt b/app/src/main/java/com/example/ayudapy/api/ApiPedidos.kt similarity index 83% rename from app/src/main/java/com/example/ayudapy/ApiPedidos.kt rename to app/src/main/java/com/example/ayudapy/api/ApiPedidos.kt index 222b978..5c522d1 100644 --- a/app/src/main/java/com/example/ayudapy/ApiPedidos.kt +++ b/app/src/main/java/com/example/ayudapy/api/ApiPedidos.kt @@ -1,18 +1,15 @@ -package com.example.ayudapy +package com.example.ayudapy.api 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 instance: ApiService by lazy{ val builder_pedido = Retrofit.Builder() .baseUrl("https://ayudapy.org/api/v1/helprequestsgeo/") diff --git a/app/src/main/java/com/example/ayudapy/ApiService.kt b/app/src/main/java/com/example/ayudapy/api/ApiService.kt similarity index 79% rename from app/src/main/java/com/example/ayudapy/ApiService.kt rename to app/src/main/java/com/example/ayudapy/api/ApiService.kt index 3091bd6..61b525a 100644 --- a/app/src/main/java/com/example/ayudapy/ApiService.kt +++ b/app/src/main/java/com/example/ayudapy/api/ApiService.kt @@ -1,5 +1,8 @@ -package com.example.ayudapy +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 @@ -37,9 +40,21 @@ interface ApiService { 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/") } + 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 diff --git a/app/src/main/java/com/example/ayudapy/Dao.kt b/app/src/main/java/com/example/ayudapy/db/Dao.kt similarity index 93% rename from app/src/main/java/com/example/ayudapy/Dao.kt rename to app/src/main/java/com/example/ayudapy/db/Dao.kt index 56b6a71..3d349e7 100644 --- a/app/src/main/java/com/example/ayudapy/Dao.kt +++ b/app/src/main/java/com/example/ayudapy/db/Dao.kt @@ -1,8 +1,7 @@ -package com.example.ayudapy +package com.example.ayudapy.db import androidx.lifecycle.LiveData import androidx.room.* -import androidx.room.OnConflictStrategy.REPLACE @Dao interface DaoPedido { diff --git a/app/src/main/java/com/example/ayudapy/DataBaseRoom.kt b/app/src/main/java/com/example/ayudapy/db/DataBaseRoom.kt similarity index 90% rename from app/src/main/java/com/example/ayudapy/DataBaseRoom.kt rename to app/src/main/java/com/example/ayudapy/db/DataBaseRoom.kt index a223646..1d141fe 100644 --- a/app/src/main/java/com/example/ayudapy/DataBaseRoom.kt +++ b/app/src/main/java/com/example/ayudapy/db/DataBaseRoom.kt @@ -1,12 +1,13 @@ -package com.example.ayudapy +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 + abstract fun daoPedido(): DaoPedido companion object { private var INSTANCE: pedidoDataBase? = null diff --git a/app/src/main/java/com/example/ayudapy/Entity.kt b/app/src/main/java/com/example/ayudapy/db/Entity.kt similarity index 95% rename from app/src/main/java/com/example/ayudapy/Entity.kt rename to app/src/main/java/com/example/ayudapy/db/Entity.kt index 468a1e7..b8519b7 100644 --- a/app/src/main/java/com/example/ayudapy/Entity.kt +++ b/app/src/main/java/com/example/ayudapy/db/Entity.kt @@ -1,4 +1,4 @@ -package com.example.ayudapy +package com.example.ayudapy.db import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/com/example/ayudapy/ListaModel.kt b/app/src/main/java/com/example/ayudapy/db/ListaModel.kt similarity index 66% rename from app/src/main/java/com/example/ayudapy/ListaModel.kt rename to app/src/main/java/com/example/ayudapy/db/ListaModel.kt index 1bf1d31..7a68c55 100644 --- a/app/src/main/java/com/example/ayudapy/ListaModel.kt +++ b/app/src/main/java/com/example/ayudapy/db/ListaModel.kt @@ -1,18 +1,20 @@ -package com.example.ayudapy +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) + private val db: pedidoDataBase = pedidoDataBase.getInstance(application) internal val allPedidos : LiveData> = db.daoPedido().getAll() - fun insert(student:PedidoSave){ + fun insert(student: PedidoSave){ db.daoPedido().insert(student) } - fun delete(student:PedidoSave){ + fun delete(student: PedidoSave){ db.daoPedido().delete(student) } } \ No newline at end of file diff --git a/app/src/main/java/com/example/ayudapy/Repository.kt b/app/src/main/java/com/example/ayudapy/db/Repository.kt similarity index 95% rename from app/src/main/java/com/example/ayudapy/Repository.kt rename to app/src/main/java/com/example/ayudapy/db/Repository.kt index 3c03f89..6401573 100644 --- a/app/src/main/java/com/example/ayudapy/Repository.kt +++ b/app/src/main/java/com/example/ayudapy/db/Repository.kt @@ -1,8 +1,9 @@ -package com.example.ayudapy +package com.example.ayudapy.db -import android.os.AsyncTask 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 diff --git a/app/src/main/java/com/example/ayudapy/CentroAyuda.kt b/app/src/main/java/com/example/ayudapy/model/CentroAyuda.kt similarity index 95% rename from app/src/main/java/com/example/ayudapy/CentroAyuda.kt rename to app/src/main/java/com/example/ayudapy/model/CentroAyuda.kt index 9c48d6b..9034acc 100644 --- a/app/src/main/java/com/example/ayudapy/CentroAyuda.kt +++ b/app/src/main/java/com/example/ayudapy/model/CentroAyuda.kt @@ -1,4 +1,4 @@ -package com.example.ayudapy +package com.example.ayudapy.model data class CentroAyuda ( diff --git a/app/src/main/java/com/example/ayudapy/PedidoDetalle.kt b/app/src/main/java/com/example/ayudapy/model/PedidoDetalle.kt similarity index 96% rename from app/src/main/java/com/example/ayudapy/PedidoDetalle.kt rename to app/src/main/java/com/example/ayudapy/model/PedidoDetalle.kt index 54e1591..3bb36a1 100644 --- a/app/src/main/java/com/example/ayudapy/PedidoDetalle.kt +++ b/app/src/main/java/com/example/ayudapy/model/PedidoDetalle.kt @@ -1,4 +1,4 @@ -package com.example.ayudapy +package com.example.ayudapy.model data class PedidoDetalle ( val count: Long, diff --git a/app/src/main/java/com/example/ayudapy/PedidosAyuda.kt b/app/src/main/java/com/example/ayudapy/model/PedidosAyuda.kt similarity index 96% rename from app/src/main/java/com/example/ayudapy/PedidosAyuda.kt rename to app/src/main/java/com/example/ayudapy/model/PedidosAyuda.kt index 06ccc80..c6e4259 100644 --- a/app/src/main/java/com/example/ayudapy/PedidosAyuda.kt +++ b/app/src/main/java/com/example/ayudapy/model/PedidosAyuda.kt @@ -1,4 +1,4 @@ -package com.example.ayudapy +package com.example.ayudapy.model data class PedidosAyuda ( val type: String,