Browse Source

Discover page en Android

Andres Ramos 3 years ago
parent
commit
c1377615fb

+ 1
- 1
Floradex20/app/build.gradle View File

@@ -59,7 +59,7 @@ dependencies {
59 59
 //    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
60 60
 //    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
61 61
 //    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
62
-//    implementation "com.squareup.picasso:picasso:2.71828"
62
+    implementation "com.squareup.picasso:picasso:2.71828"
63 63
 //    implementation "org.jetbrains.anko:anko-common:0.9"
64 64
 //    implementation 'com.squareup.okhttp3:okhttp:4.9.0'
65 65
 //    implementation 'com.android.support:recyclerview-v7:28.0.0'

+ 7
- 2
Floradex20/app/src/main/java/com/example/floradex20/FlowerAdapter.kt View File

@@ -6,6 +6,8 @@ import android.view.ViewGroup
6 6
 import android.widget.ImageView
7 7
 import android.widget.TextView
8 8
 import androidx.recyclerview.widget.RecyclerView
9
+import com.squareup.picasso.Picasso
10
+import kotlin.coroutines.coroutineContext
9 11
 
10 12
 class FlowerAdapter(val flowers: List<Data>): RecyclerView.Adapter<PlantViewHolder>() {
11 13
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlantViewHolder {
@@ -23,14 +25,17 @@ class FlowerAdapter(val flowers: List<Data>): RecyclerView.Adapter<PlantViewHold
23 25
 }
24 26
 
25 27
 class PlantViewHolder(itemView : View): RecyclerView.ViewHolder(itemView){
26
-    private val photo:ImageView = itemView.findViewById(R.id.flower_photo)
28
+    val photo:ImageView = itemView.findViewById(R.id.flower_photo)
27 29
     private val title:TextView = itemView.findViewById(R.id.flower_name)
28 30
 //    private val overview:TextView = itemView.findViewById(R.id.movie_overview)
29 31
 //    private val rating:TextView = itemView.findViewById(R.id.movie_rating)
30 32
 
31 33
     fun bind(plant: Data) {
32 34
         //Pomer pa que salga foto de la planta
33
-//        photo.setImageResource(R.drawable.Flor_de_maga.jpeg)
35
+        val imageurl:String = plant.image_url
36
+//        photo.setImageResource(R.drawable.plant.image_url)
37
+//        ImageView photo = (ImageView) itemView.findViewbyId(R.id.flower_photo)
38
+        Picasso.get().load(imageurl).into(photo)
34 39
         title.text = "Name: "+plant.common_name
35 40
 //        overview.text = plant.overview
36 41
 //        rating.text = "Rating : "+plant.vote_average.toString()

+ 8
- 8
Floradex20/app/src/main/java/com/example/floradex20/MainActivity.kt View File

@@ -63,21 +63,21 @@ class MainActivity : AppCompatActivity() {
63 63
 
64 64
         val request = ServiceBuilder.buildService(TrefleService::class.java)
65 65
         val call : Call<PlantListss> = request.getPlants(getString(R.string.TOKEN))
66
-////        Log.i("Call Plant List", call.toString())
66
+//        Log.i("Call Plant List", call.toString())
67 67
         call.enqueue(object : Callback<PlantListss>{
68 68
             override fun onResponse(call: Call<PlantListss>, response: Response<PlantListss>) {
69
-//                Log.i("response", response.body().toString())
69
+////                Log.i("response", response.body().toString())
70 70
                 if (response.isSuccessful){
71 71
 //                    Log.i("Status", "Respones fue succesful")
72 72
                     recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
73
-////                        progress_bar.visibility = View.GONE
73
+//////                        progress_bar.visibility = View.GONE
74 74
                     recyclerView.apply {
75
-//                        Log.i("velllllllllllllllllllll", response.body().toString())
75
+////                        Log.i("velllllllllllllllllllll", response.body().toString())
76 76
                         setHasFixedSize(true)
77
-//                        layoutManager = LinearLayoutManager(this@MainActivity)
78
-//                        adapter = FlowerAdapter(response.body()!!.data)
79
-//                        recyclerView.setAdapter(adapter)
80
-//                        recyclerView.setLayoutManager(layoutManager)
77
+                        layoutManager = LinearLayoutManager(this@MainActivity)
78
+                        adapter = FlowerAdapter(response.body()!!.data)
79
+                        recyclerView.setAdapter(adapter)
80
+                        recyclerView.setLayoutManager(layoutManager)
81 81
                     }
82 82
                 }
83 83
             }

+ 3
- 0
Floradex20/app/src/main/res/layout/layout.xml View File

@@ -23,6 +23,7 @@
23 23
                 android:id="@+id/flower_photo"
24 24
                 android:src="@drawable/flor_de_maga"
25 25
                 android:contentDescription="Flower Image" />
26
+<!--                />-->
26 27
 
27 28
             <TextView
28 29
                 android:layout_below="@+id/flower_photo"
@@ -33,6 +34,8 @@
33 34
                 android:textSize="15sp"
34 35
                 android:text="Flower Name "/>
35 36
 
37
+
38
+
36 39
         </RelativeLayout>
37 40
 
38 41
     </androidx.cardview.widget.CardView>