|
@@ -1,31 +1,24 @@
|
1
|
1
|
package com.example.floradex20
|
2
|
2
|
|
3
|
|
-import android.app.Activity
|
|
3
|
+//import com.example.floradex20.R
|
|
4
|
+//import com.example.floradex20.Plant
|
|
5
|
+//import com.squareup.picasso.Picasso
|
|
6
|
+//import android.support.v4.app.FragmentActivity
|
|
7
|
+import android.content.Intent
|
4
|
8
|
import android.os.Bundle
|
5
|
9
|
import android.util.Log
|
6
|
|
-import android.widget.ArrayAdapter
|
7
|
|
-import android.widget.ImageView
|
8
|
|
-import android.widget.TextView
|
|
10
|
+import android.view.View
|
9
|
11
|
import android.widget.Toast
|
10
|
12
|
import androidx.appcompat.app.AppCompatActivity
|
11
|
|
-//import com.example.floradex20.R
|
12
|
|
-//import com.example.floradex20.Plant
|
13
|
|
-import com.example.floradex20.R
|
14
|
|
-//import com.squareup.picasso.Picasso
|
|
13
|
+import androidx.recyclerview.widget.LinearLayoutManager
|
|
14
|
+import androidx.recyclerview.widget.RecyclerView
|
15
|
15
|
import okhttp3.OkHttpClient
|
16
|
16
|
import retrofit2.Call
|
17
|
17
|
import retrofit2.Callback
|
18
|
18
|
import retrofit2.Response
|
19
|
19
|
import retrofit2.Retrofit
|
20
|
20
|
import retrofit2.converter.gson.GsonConverterFactory
|
21
|
|
-//import android.support.v4.app.FragmentActivity
|
22
|
|
-import android.view.LayoutInflater
|
23
|
|
-import android.view.View
|
24
|
|
-import android.view.ViewGroup
|
25
|
|
-import androidx.fragment.app.FragmentActivity
|
26
|
|
-import androidx.recyclerview.widget.LinearLayoutManager
|
27
|
|
-import androidx.recyclerview.widget.RecyclerView
|
28
|
|
-import com.google.gson.Gson
|
|
21
|
+import androidx.constraintlayout.widget.ConstraintLayout
|
29
|
22
|
|
30
|
23
|
|
31
|
24
|
//Cosas para que lleguen las flores
|
|
@@ -51,11 +44,9 @@ object ServiceBuilder {
|
51
|
44
|
|
52
|
45
|
|
53
|
46
|
//Main Activity
|
54
|
|
-class MainActivity : AppCompatActivity() {
|
|
47
|
+class MainActivity : AppCompatActivity(), FlowerAdapter.OnItemClickListener {
|
55
|
48
|
private lateinit var recyclerView: RecyclerView
|
56
|
|
-// private lateinit var viewAdapter: RecyclerView.Adapter<PlantList>
|
57
|
|
-// private lateinit var viewManager: RecyclerView.LayoutManager
|
58
|
|
-
|
|
49
|
+ private lateinit var plants: List<Data>
|
59
|
50
|
|
60
|
51
|
override fun onCreate(savedInstanceState: Bundle?) {
|
61
|
52
|
super.onCreate(savedInstanceState)
|
|
@@ -63,28 +54,47 @@ class MainActivity : AppCompatActivity() {
|
63
|
54
|
|
64
|
55
|
val request = ServiceBuilder.buildService(TrefleService::class.java)
|
65
|
56
|
val call : Call<PlantListss> = request.getPlants(getString(R.string.TOKEN))
|
66
|
|
-// Log.i("Call Plant List", call.toString())
|
67
|
|
- call.enqueue(object : Callback<PlantListss>{
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+ //Esta parte hay que loop it para que haga mas de 1 request al API
|
|
60
|
+ call.enqueue(object : Callback<PlantListss> {
|
68
|
61
|
override fun onResponse(call: Call<PlantListss>, response: Response<PlantListss>) {
|
69
|
|
-//// Log.i("response", response.body().toString())
|
70
|
|
- if (response.isSuccessful){
|
71
|
|
-// Log.i("Status", "Respones fue succesful")
|
|
62
|
+
|
|
63
|
+ if (response.isSuccessful) {
|
|
64
|
+
|
72
|
65
|
recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
|
73
|
|
-////// progress_bar.visibility = View.GONE
|
|
66
|
+
|
74
|
67
|
recyclerView.apply {
|
75
|
|
-//// Log.i("velllllllllllllllllllll", response.body().toString())
|
|
68
|
+
|
76
|
69
|
setHasFixedSize(true)
|
|
70
|
+ plants = response.body()!!.data
|
|
71
|
+ adapter = FlowerAdapter(plants, this@MainActivity)
|
77
|
72
|
layoutManager = LinearLayoutManager(this@MainActivity)
|
78
|
|
- adapter = FlowerAdapter(response.body()!!.data)
|
|
73
|
+
|
|
74
|
+ //Aqui hay que chequiar si el API response llega bien
|
79
|
75
|
recyclerView.setAdapter(adapter)
|
80
|
76
|
recyclerView.setLayoutManager(layoutManager)
|
81
|
77
|
}
|
|
78
|
+//
|
82
|
79
|
}
|
83
|
80
|
}
|
|
81
|
+
|
84
|
82
|
override fun onFailure(call: Call<PlantListss>, t: Throwable) {
|
85
|
83
|
Toast.makeText(this@MainActivity, "${t.message}", Toast.LENGTH_SHORT).show()
|
86
|
84
|
}
|
87
|
85
|
})
|
88
|
86
|
}
|
|
87
|
+
|
|
88
|
+ override fun onItemClick(position: Int){
|
|
89
|
+ //Empezar el activity de Jose
|
|
90
|
+ var plant_info = arrayOf<String>(plants[position].common_name.toString(), plants[position].scientific_name.toString()
|
|
91
|
+ , plants[position].year.toString(), plants[position].author.toString(), plants[position].image_url.toString())
|
|
92
|
+ val intent = Intent(this, ventana::class.java).apply {
|
|
93
|
+ putExtra("plant_info", plant_info)
|
|
94
|
+ }
|
|
95
|
+ startActivity(intent)
|
|
96
|
+ Log.i("Position", plant_info.get(0))
|
89
|
97
|
}
|
90
|
98
|
|
|
99
|
+}
|
|
100
|
+
|