Kaynağa Gözat

discover page con info window

Andres Ramos 4 yıl önce
ebeveyn
işleme
3497ac5060

+ 2
- 1
Floradex20/app/build.gradle Dosyayı Görüntüle

43
     implementation 'androidx.cardview:cardview:1.0.0'
43
     implementation 'androidx.cardview:cardview:1.0.0'
44
     implementation 'androidx.recyclerview:recyclerview:1.1.0'
44
     implementation 'androidx.recyclerview:recyclerview:1.1.0'
45
     implementation 'com.github.bumptech.glide:glide:4.10.0'
45
     implementation 'com.github.bumptech.glide:glide:4.10.0'
46
-    implementation 'androidx.appcompat:appcompat:1.2.0'//Glide
46
+    implementation 'androidx.appcompat:appcompat:1.2.0'
47
+    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'//Glide
47
     annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
48
     annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
48
     implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
49
     implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
49
 //    implementation 'androidx.core:core-ktx:1.3.2'
50
 //    implementation 'androidx.core:core-ktx:1.3.2'

+ 6
- 0
Floradex20/app/src/main/AndroidManifest.xml Dosyayı Görüntüle

19
                 <category android:name="android.intent.category.LAUNCHER" />
19
                 <category android:name="android.intent.category.LAUNCHER" />
20
             </intent-filter>
20
             </intent-filter>
21
         </activity>
21
         </activity>
22
+        <activity
23
+            android:name=".ventana"
24
+            android:parentActivityName=".MainActivity">
25
+
26
+
27
+        </activity>
22
     </application>
28
     </application>
23
 
29
 
24
 </manifest>
30
 </manifest>

+ 1
- 1
Floradex20/app/src/main/java/com/example/floradex20/Data.kt Dosyayı Görüntüle

17
     val status: String,
17
     val status: String,
18
     val synonyms: List<String>,
18
     val synonyms: List<String>,
19
     val year: Int
19
     val year: Int
20
-)
20
+)

+ 42
- 19
Floradex20/app/src/main/java/com/example/floradex20/FlowerAdapter.kt Dosyayı Görüntüle

1
 package com.example.floradex20
1
 package com.example.floradex20
2
 
2
 
3
+import android.util.Log
3
 import android.view.LayoutInflater
4
 import android.view.LayoutInflater
4
 import android.view.View
5
 import android.view.View
5
 import android.view.ViewGroup
6
 import android.view.ViewGroup
7
 import android.widget.TextView
8
 import android.widget.TextView
8
 import androidx.recyclerview.widget.RecyclerView
9
 import androidx.recyclerview.widget.RecyclerView
9
 import com.squareup.picasso.Picasso
10
 import com.squareup.picasso.Picasso
10
-import kotlin.coroutines.coroutineContext
11
 
11
 
12
-class FlowerAdapter(val flowers: List<Data>): RecyclerView.Adapter<PlantViewHolder>() {
12
+
13
+class FlowerAdapter(val flowers: List<Data>, private val listener: OnItemClickListener): RecyclerView.Adapter<FlowerAdapter.PlantViewHolder>() {
14
+
15
+//    var listen: onItemClickListener
16
+//    this.listen = listener
17
+//    val listen:OnItemClickListener = listener
13
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlantViewHolder {
18
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlantViewHolder {
14
         val view = LayoutInflater.from(parent.context).inflate(R.layout.layout, parent, false)
19
         val view = LayoutInflater.from(parent.context).inflate(R.layout.layout, parent, false)
15
         return PlantViewHolder(view)
20
         return PlantViewHolder(view)
20
     }
25
     }
21
 
26
 
22
     override fun onBindViewHolder(holder: PlantViewHolder, position: Int) {
27
     override fun onBindViewHolder(holder: PlantViewHolder, position: Int) {
23
-        return holder.bind(flowers[position])
28
+
29
+        return holder.bind(flowers[position], holder)
24
     }
30
     }
25
-}
26
 
31
 
27
-class PlantViewHolder(itemView : View): RecyclerView.ViewHolder(itemView){
28
-    val photo:ImageView = itemView.findViewById(R.id.flower_photo)
29
-    private val title:TextView = itemView.findViewById(R.id.flower_name)
30
-//    private val overview:TextView = itemView.findViewById(R.id.movie_overview)
31
-//    private val rating:TextView = itemView.findViewById(R.id.movie_rating)
32
-
33
-    fun bind(plant: Data) {
34
-        //Pomer pa que salga foto de la planta
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)
39
-        title.text = "Name: "+plant.common_name
40
-//        overview.text = plant.overview
41
-//        rating.text = "Rating : "+plant.vote_average.toString()
32
+
33
+    inner class PlantViewHolder(itemView : View): RecyclerView.ViewHolder(itemView), View.OnClickListener {
34
+
35
+        val photo: ImageView = itemView.findViewById(R.id.flower_photo)
36
+        private val title: TextView = itemView.findViewById(R.id.flower_name)
37
+
38
+        init {
39
+            photo.setOnClickListener(this)
40
+        }
41
+
42
+        override fun onClick(view: View?) {
43
+            val position = adapterPosition
44
+            if (position != RecyclerView.NO_POSITION) {
45
+                listener.onItemClick(position)
46
+            }
47
+
48
+        }
49
+
50
+        fun bind(plant: Data, plantviewer: PlantViewHolder) {
51
+            //Pone foto y nombre de la planta a la tarjeta
52
+            val imageurl: String = plant.image_url
53
+            Picasso.get().load(imageurl).into(photo)
54
+            //Nombre de la planta
55
+            title.text = "Name: " + plant.common_name
56
+
57
+        }
58
+
59
+
42
     }
60
     }
43
 
61
 
62
+    public interface OnItemClickListener {
63
+
64
+        //Metodo que va a usar el activity pa hacer cosas
65
+        fun onItemClick(position: Int)
66
+    }
44
 }
67
 }
45
 
68
 
46
 
69
 

+ 38
- 28
Floradex20/app/src/main/java/com/example/floradex20/MainActivity.kt Dosyayı Görüntüle

1
 package com.example.floradex20
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
 import android.os.Bundle
8
 import android.os.Bundle
5
 import android.util.Log
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
 import android.widget.Toast
11
 import android.widget.Toast
10
 import androidx.appcompat.app.AppCompatActivity
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
 import okhttp3.OkHttpClient
15
 import okhttp3.OkHttpClient
16
 import retrofit2.Call
16
 import retrofit2.Call
17
 import retrofit2.Callback
17
 import retrofit2.Callback
18
 import retrofit2.Response
18
 import retrofit2.Response
19
 import retrofit2.Retrofit
19
 import retrofit2.Retrofit
20
 import retrofit2.converter.gson.GsonConverterFactory
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
 //Cosas para que lleguen las flores
24
 //Cosas para que lleguen las flores
51
 
44
 
52
 
45
 
53
 //Main Activity
46
 //Main Activity
54
-class MainActivity : AppCompatActivity() {
47
+class MainActivity : AppCompatActivity(), FlowerAdapter.OnItemClickListener {
55
     private lateinit var recyclerView: RecyclerView
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
     override fun onCreate(savedInstanceState: Bundle?) {
51
     override fun onCreate(savedInstanceState: Bundle?) {
61
         super.onCreate(savedInstanceState)
52
         super.onCreate(savedInstanceState)
63
 
54
 
64
         val request = ServiceBuilder.buildService(TrefleService::class.java)
55
         val request = ServiceBuilder.buildService(TrefleService::class.java)
65
         val call : Call<PlantListss> = request.getPlants(getString(R.string.TOKEN))
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
             override fun onResponse(call: Call<PlantListss>, response: Response<PlantListss>) {
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
                     recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
65
                     recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
73
-//////                        progress_bar.visibility = View.GONE
66
+
74
                     recyclerView.apply {
67
                     recyclerView.apply {
75
-////                        Log.i("velllllllllllllllllllll", response.body().toString())
68
+
76
                         setHasFixedSize(true)
69
                         setHasFixedSize(true)
70
+                        plants = response.body()!!.data
71
+                        adapter = FlowerAdapter(plants, this@MainActivity)
77
                         layoutManager = LinearLayoutManager(this@MainActivity)
72
                         layoutManager = LinearLayoutManager(this@MainActivity)
78
-                        adapter = FlowerAdapter(response.body()!!.data)
73
+
74
+                        //Aqui hay que chequiar si el API response llega bien
79
                         recyclerView.setAdapter(adapter)
75
                         recyclerView.setAdapter(adapter)
80
                         recyclerView.setLayoutManager(layoutManager)
76
                         recyclerView.setLayoutManager(layoutManager)
81
                     }
77
                     }
78
+//
82
                 }
79
                 }
83
             }
80
             }
81
+
84
             override fun onFailure(call: Call<PlantListss>, t: Throwable) {
82
             override fun onFailure(call: Call<PlantListss>, t: Throwable) {
85
                 Toast.makeText(this@MainActivity, "${t.message}", Toast.LENGTH_SHORT).show()
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
+

+ 0
- 11
Floradex20/app/src/main/java/com/example/floradex20/ToyFlower.kt Dosyayı Görüntüle

1
-package com.example.floradex20
2
-
3
-
4
-data class ToyFlowerList(
5
-    val flo_list: List<ToyFlower>
6
-)
7
-
8
-data class ToyFlower(
9
-    val scientific_name : String,
10
-    val color: String
11
-)

+ 43
- 0
Floradex20/app/src/main/java/com/example/floradex20/ventana.kt Dosyayı Görüntüle

1
+package com.example.floradex20
2
+
3
+import android.content.res.Configuration
4
+import android.os.Bundle
5
+import android.util.Log
6
+import android.widget.ImageView
7
+import android.widget.TextView
8
+import androidx.appcompat.app.AppCompatActivity
9
+import com.squareup.picasso.Picasso
10
+
11
+class ventana(): AppCompatActivity() {
12
+
13
+//    val planta:Data = plant
14
+    override fun onCreate(savedInstanceState: Bundle?) {
15
+        super.onCreate(savedInstanceState)
16
+        setContentView(R.layout.ventanita)
17
+
18
+        val plant = intent.getStringArrayExtra("plant_info")
19
+
20
+        val nom_planta = findViewById(R.id.plant_name) as TextView
21
+        val nom_sci = findViewById(R.id.sci_name) as TextView
22
+        val year = findViewById(R.id.year) as TextView
23
+        val author = findViewById(R.id.author) as TextView
24
+        val imagen_planta = findViewById(R.id.plantview) as ImageView
25
+
26
+        nom_planta.text = "Salu2"
27
+
28
+    if (plant != null) {
29
+
30
+        nom_planta.text = plant.get(0)
31
+        nom_sci.text = plant.get(1)
32
+        year.text = plant.get(2)
33
+        author.text = plant.get(3)
34
+        Picasso.get().load(plant.get(4)).into(imagen_planta)
35
+    }
36
+
37
+    else {
38
+        Log.i("Desde ventana kt", "Llega null el valor. Te la mamaste")
39
+    }
40
+
41
+
42
+    }
43
+}

+ 1
- 0
Floradex20/app/src/main/res/layout/layout.xml Dosyayı Görüntüle

8
     <androidx.cardview.widget.CardView
8
     <androidx.cardview.widget.CardView
9
 
9
 
10
         android:id="@+id/card_view"
10
         android:id="@+id/card_view"
11
+        android:clickable="true"
11
         android:layout_width="match_parent"
12
         android:layout_width="match_parent"
12
         android:layout_height="wrap_content"
13
         android:layout_height="wrap_content"
13
         android:layout_margin="10dp">
14
         android:layout_margin="10dp">

+ 75
- 0
Floradex20/app/src/main/res/layout/ventanita.xml Dosyayı Görüntüle

1
+<?xml version="1.0" encoding="utf-8"?>
2
+<androidx.constraintlayout.widget.ConstraintLayout
3
+    xmlns:android="http://schemas.android.com/apk/res/android"
4
+    xmlns:app="http://schemas.android.com/apk/res-auto"
5
+    xmlns:tools="http://schemas.android.com/tools"
6
+    android:id="@+id/Plant_info"
7
+    android:layout_width="match_parent"
8
+    android:layout_height="match_parent"
9
+    tools:context=".MainActivity">
10
+
11
+    <TextView
12
+        android:id="@+id/author"
13
+        android:layout_width="wrap_content"
14
+        android:layout_height="wrap_content"
15
+        android:text="@string/author"
16
+        android:textAppearance="@style/TextAppearance.AppCompat.Large"
17
+        app:layout_constraintBottom_toBottomOf="parent"
18
+        app:layout_constraintEnd_toEndOf="parent"
19
+        app:layout_constraintHorizontal_bias="0.506"
20
+        app:layout_constraintStart_toStartOf="parent"
21
+        app:layout_constraintTop_toBottomOf="@+id/year"
22
+        app:layout_constraintVertical_bias="0.239" />
23
+
24
+    <TextView
25
+        android:id="@+id/sci_name"
26
+        android:layout_width="wrap_content"
27
+        android:layout_height="wrap_content"
28
+        android:text="@string/scientific_name"
29
+        android:textAppearance="@style/TextAppearance.AppCompat.Large"
30
+        app:layout_constraintBottom_toBottomOf="parent"
31
+        app:layout_constraintEnd_toEndOf="parent"
32
+        app:layout_constraintHorizontal_bias="0.507"
33
+        app:layout_constraintStart_toStartOf="parent"
34
+        app:layout_constraintTop_toBottomOf="@+id/plant_name"
35
+        app:layout_constraintVertical_bias="0.155" />
36
+
37
+    <TextView
38
+        android:id="@+id/plant_name"
39
+        android:layout_width="wrap_content"
40
+        android:layout_height="wrap_content"
41
+        android:text="@string/plant_name"
42
+        android:textAppearance="@style/TextAppearance.AppCompat.Large"
43
+        app:layout_constraintBottom_toBottomOf="parent"
44
+        app:layout_constraintEnd_toEndOf="parent"
45
+        app:layout_constraintHorizontal_bias="0.511"
46
+        app:layout_constraintStart_toStartOf="parent"
47
+        app:layout_constraintTop_toTopOf="parent"
48
+        app:layout_constraintVertical_bias="0.57" />
49
+
50
+    <TextView
51
+        android:id="@+id/year"
52
+        android:layout_width="wrap_content"
53
+        android:layout_height="wrap_content"
54
+        android:text="@string/year"
55
+        android:textAppearance="@style/TextAppearance.AppCompat.Large"
56
+        app:layout_constraintBottom_toBottomOf="parent"
57
+        app:layout_constraintEnd_toEndOf="parent"
58
+        app:layout_constraintHorizontal_bias="0.506"
59
+        app:layout_constraintStart_toStartOf="parent"
60
+        app:layout_constraintTop_toBottomOf="@+id/sci_name"
61
+        app:layout_constraintVertical_bias="0.186" />
62
+
63
+    <ImageView
64
+        android:id="@+id/plantview"
65
+        android:layout_width="wrap_content"
66
+        android:layout_height="wrap_content"
67
+        android:contentDescription="@string/plant_display"
68
+        app:layout_constraintBottom_toTopOf="@+id/plant_name"
69
+        app:layout_constraintEnd_toEndOf="parent"
70
+        app:layout_constraintHorizontal_bias="0.498"
71
+        app:layout_constraintStart_toStartOf="parent"
72
+        app:layout_constraintTop_toTopOf="parent"
73
+        app:srcCompat="@drawable/ic_launcher_foreground" />
74
+
75
+</androidx.constraintlayout.widget.ConstraintLayout>