Skip to content

Commit

Permalink
Connect recommendations with api + Fix reccomended item row view
Browse files Browse the repository at this point in the history
  • Loading branch information
Franverri committed Nov 2, 2020
1 parent 784f68a commit 2e0d9ad
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
/gradle
/.idea
22 changes: 14 additions & 8 deletions app/src/main/java/ar/uba/fi/remy/ui/inicio/InicioFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,34 @@ class InicioFragment : Fragment() {

//Reemplazar por el llamado a la API para obtener las recetas
val recomendaciones = ArrayList<RecommendedItem>()
recomendaciones.add(RecommendedItem("Recomendación 1", 1, 15, 20, 1))
/* recomendaciones.add(RecommendedItem("Recomendación 1", 1, 15, 20, 1))
recomendaciones.add(RecommendedItem("Recomendación 2", 2, 25, 30, 1))
recomendaciones.add(RecommendedItem("Recomendación 3", 1, 15, 20, 1))
recomendaciones.add(RecommendedItem("Recomendación 4", 3, 25, 30, 1))
recomendaciones.add(RecommendedItem("Recomendación 5", 4, 15, 20, 1))
recomendaciones.add(RecommendedItem("Recomendación 6", 5, 25, 30, 1))
recomendaciones.add(RecommendedItem("Recomendación 6", 5, 25, 30, 1))*/

//Access sharedPreferences
val sharedPref = activity?.getSharedPreferences(
getString(R.string.preference_file), Context.MODE_PRIVATE)
val token = sharedPref?.getString("TOKEN", "")
Log.i("API", token)

/* val queue = Volley.newRequestQueue(activity)
val url = "https://tpp-remy.herokuapp.com/api/v1/ingredients/"
val queue = Volley.newRequestQueue(activity)
val url = "https://tpp-remy.herokuapp.com/api/v1/my_recommendations/"

val jsonObjectRequest = object: JsonObjectRequest(Request.Method.GET, url, null,
Response.Listener { response ->
Log.i("API", "Response: %s".format(response.toString()))
var recomendacionesArray = response.getJSONArray("results")
for (i in 0 until recomendacionesArray.length()) {
var recomendacion = recomendacionesArray.getJSONObject(i)
var title = recomendacion.getJSONObject("recipe").getString("title")
recomendaciones.add(RecommendedItem(title, 2, 15, 20, 1))

val adapter = RecommendedItemAdapter(recomendaciones)
recyclerView.adapter = adapter
}
},
Response.ErrorListener { error ->
Log.e("API", "Error en GET")
Expand All @@ -80,9 +89,6 @@ class InicioFragment : Fragment() {
}


queue.add(jsonObjectRequest)*/

val adapter = RecommendedItemAdapter(recomendaciones)
recyclerView.adapter = adapter
queue.add(jsonObjectRequest)
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/layout/activity_detail_event.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,9 @@
android:src="@drawable/ic_add"
/>

<include layout="@layout/recommended_item" />

<include layout="@layout/recommended_item" />


</LinearLayout>
25 changes: 11 additions & 14 deletions app/src/main/res/layout/recommended_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<LinearLayout
android:padding="12dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<LinearLayout
Expand All @@ -19,7 +19,8 @@
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0.9"
android:orientation="vertical"
android:layout_height="wrap_content">

Expand Down Expand Up @@ -143,20 +144,16 @@

</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/foto"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/food1">

</ImageView>
<ImageView
android:layout_gravity="end"
android:id="@+id/foto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:src="@drawable/food1">

</RelativeLayout>
</ImageView>

</LinearLayout>

Expand Down

0 comments on commit 2e0d9ad

Please sign in to comment.