diff --git a/Frontend/.idea/Frontend.iml b/Frontend/.idea/Frontend.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/Frontend/.idea/Frontend.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Frontend/Android/.idea/runConfigurations.xml b/Frontend/Android/.idea/runConfigurations.xml
new file mode 100644
index 0000000..797acea
--- /dev/null
+++ b/Frontend/Android/.idea/runConfigurations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/CocktailDetailActivity.kt b/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/CocktailDetailActivity.kt
index a11fbb7..f5e86cf 100644
--- a/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/CocktailDetailActivity.kt
+++ b/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/CocktailDetailActivity.kt
@@ -9,8 +9,10 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
+import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
+import androidx.core.content.ContextCompat
import com.team03.cocktailrecipesapp.dialogs.DeleteRecipeDialogFragment
import com.team03.cocktailrecipesapp.error_listener.DeleteRecipeErrorListener
import com.team03.cocktailrecipesapp.error_listener.GetRecipeErrorListener
@@ -21,7 +23,7 @@ import kotlinx.android.synthetic.main.rating_layout.view.*
import kotlinx.android.synthetic.main.trending_cocktail_list_card.cocktail_difficulty
import kotlinx.android.synthetic.main.trending_cocktail_list_card.cocktail_name
import kotlinx.android.synthetic.main.trending_cocktail_list_card.cocktail_rating_bar
-
+import kotlinx.android.synthetic.main.trending_cocktail_list_card.view.*
public interface RatingInterface {
fun onSelectedData(rating: Int);
@@ -73,8 +75,10 @@ class RecipeAdapter(private val context: Context,
class CocktailDetailActivity : AppCompatActivity(), RatingInterface {
- var recipe_id = -1
- var my_rating = 0
+ var isLiked = false;
+ var recipe_id = 0;
+ var my_rating = 0;
+
// lateinit var imgBtnRate : ImageButton
override fun onCreate(savedInstanceState: Bundle?) {
@@ -83,8 +87,7 @@ class CocktailDetailActivity : AppCompatActivity(), RatingInterface {
cocktail_creator_username.setOnClickListener { onRecipeCreatorClick() }
val b = intent.extras
-// imgBtnRate = findViewById(R.id.imgBtnRate)
-
+ recipe_id = -1 // or other values
if (b != null) recipe_id = b.getInt("cocktail_id")
@@ -138,6 +141,15 @@ class CocktailDetailActivity : AppCompatActivity(), RatingInterface {
cocktail_instruction.text = recipe.instruction
my_rating = recipe.my_rating
cocktail_creator_username.text = recipe.creator_user
+ if (recipe.liked != 0)
+ {
+ isLiked = true
+ var imgLike = findViewById(R.id.imageButtonLike);
+ imgLike.setImageDrawable(ContextCompat.getDrawable(applicationContext, R.drawable.heart_filled ))
+ }
+
+
+
if (recipe.is_mine == 1)
delete_recipe_button.visibility = View.VISIBLE;
@@ -146,7 +158,6 @@ class CocktailDetailActivity : AppCompatActivity(), RatingInterface {
val adapter = RecipeAdapter(this, recipe.ingredients)
listView.adapter = adapter
-
setVisibleAfterLoading()
}
@@ -179,7 +190,9 @@ class CocktailDetailActivity : AppCompatActivity(), RatingInterface {
cocktail_instruction.visibility = View.INVISIBLE
cocktail_creator_username.visibility = View.INVISIBLE
cocktail_creator_text.visibility = View.INVISIBLE
-
+ imageButtonLike.visibility = View.INVISIBLE
+ imgBtnRate.visibility = View.INVISIBLE
+ tvRating.visibility = View.INVISIBLE
prepTimeText.visibility = View.INVISIBLE
prepTimeText3.visibility = View.INVISIBLE
ingredients.visibility = View.INVISIBLE
@@ -199,7 +212,9 @@ class CocktailDetailActivity : AppCompatActivity(), RatingInterface {
cocktail_instruction.visibility = View.VISIBLE
cocktail_creator_username.visibility = View.VISIBLE
cocktail_creator_text.visibility = View.VISIBLE
-
+ imageButtonLike.visibility = View.VISIBLE
+ imgBtnRate.visibility = View.VISIBLE
+ tvRating.visibility = View.VISIBLE
prepTimeText.visibility = View.VISIBLE
prepTimeText3.visibility = View.VISIBLE
ingredients.visibility = View.VISIBLE
@@ -210,6 +225,61 @@ class CocktailDetailActivity : AppCompatActivity(), RatingInterface {
progressbar.visibility = View.INVISIBLE
}
+ fun onUnsuccessfullLike(){
+ //TODO ERROR_MSG
+ System.out.println("not successful\n")
+ }
+
+ fun onSuccessfullLike(){
+ var imgLike = findViewById(R.id.imageButtonLike);
+ if(!isLiked) {
+ imgLike.setImageDrawable(ContextCompat.getDrawable(applicationContext, R.drawable.heart_filled ));
+ isLiked = true
+ } else {
+ imgLike.setImageDrawable(ContextCompat.getDrawable(applicationContext, R.drawable.hearth_empty ));
+ isLiked = false
+ }
+ }
+
+ fun like(user_id: Int, recipe_id: Int): Boolean {
+ val server = serverAPI(this)
+ val listener = LikeListener(::onSuccessfullLike)
+ val error_listener = LikeErrorListener(::onUnsuccessfullLike)
+ val answer = server.likeRecipe(user_id, recipe_id,
+ listener, error_listener);
+ if (answer == 1)
+ {
+ return false
+ }
+ return true
+ }
+
+ fun unlike(user_id: Int, recipe_id: Int): Boolean {
+ val server = serverAPI(this)
+ val listener = LikeListener(::onSuccessfullLike)
+ val error_listener = LikeErrorListener(::onUnsuccessfullLike)
+ val answer = server.unlikeRecipe(user_id, recipe_id,
+ listener, error_listener);
+ if (answer == 1)
+ {
+ return false
+ }
+ return true
+ }
+
+ fun likeOnClick(view: View) {
+ if(isLiked){
+ run {
+ unlike(userId, recipe_id);
+ }
+
+ }
+ else{
+ run {
+ like(userId, recipe_id);
+ }
+ }
+ }
fun rateRecipe(view: View)
{
diff --git a/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/LikeErrorListener.kt b/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/LikeErrorListener.kt
new file mode 100644
index 0000000..95abe4b
--- /dev/null
+++ b/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/LikeErrorListener.kt
@@ -0,0 +1,16 @@
+package com.team03.cocktailrecipesapp
+
+import com.android.volley.Response
+import com.android.volley.VolleyError
+
+class LikeErrorListener : Response.ErrorListener {
+ private var onErrorLike : (() -> Unit);
+
+ constructor(_onErrorRegister: (() -> Unit)){
+ onErrorLike = _onErrorRegister;
+ }
+
+ override fun onErrorResponse(error: VolleyError) {
+ onErrorLike.invoke();
+ }
+}
\ No newline at end of file
diff --git a/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/LikeListener.kt b/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/LikeListener.kt
new file mode 100644
index 0000000..6a427cc
--- /dev/null
+++ b/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/LikeListener.kt
@@ -0,0 +1,23 @@
+package com.team03.cocktailrecipesapp
+
+import com.android.volley.Response
+import com.google.gson.Gson
+import org.json.JSONObject
+
+data class AnswerSuccess(
+ var success: Boolean,
+ var message: String
+)
+
+class LikeListener : Response.Listener {
+ private var onSuccessfullLike : (() -> Unit);
+
+ constructor(_onSuccessfullLike: (() -> Unit)){
+ onSuccessfullLike = _onSuccessfullLike;
+ }
+
+ override fun onResponse(response: JSONObject) {
+ val answer = Gson().fromJson(response.toString(), AnswerSuccess::class.java)
+ onSuccessfullLike.invoke();
+ }
+}
\ No newline at end of file
diff --git a/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/MainActivity.kt b/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/MainActivity.kt
index 7919e69..ca9250d 100644
--- a/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/MainActivity.kt
+++ b/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/MainActivity.kt
@@ -20,6 +20,7 @@ class MainActivity : SharedPreferencesActivity() {
lateinit var recipesLayout: LinearLayout
override fun onCreate(savedInstanceState: Bundle?) {
+
super.onCreate(savedInstanceState)
super.onStart()
var language = shared.getString("Language", "")
diff --git a/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/serverAPI.kt b/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/serverAPI.kt
index 23de270..76fa1d4 100644
--- a/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/serverAPI.kt
+++ b/Frontend/Android/app/src/main/java/com/team03/cocktailrecipesapp/serverAPI.kt
@@ -141,6 +141,20 @@ class serverAPI(context: Context)
return sendRequest(json, "like-recipe", listener, error_listener)
}
+
+ fun unlikeRecipe(user_id: Int, recipe_id: Int, listener: Response.Listener, error_listener: Response.ErrorListener) : Int
+ {
+ val unlike_recipe_json = """
+ {
+ "user_id": """" + user_id.toString() + """",
+ "recipe_id": """" + recipe_id.toString() + """"
+ }
+ """
+
+ val json = JSONObject(unlike_recipe_json)
+ return sendRequest(json, "unlike-recipe", listener, error_listener)
+ }
+
private fun sendRequest(jsonObject: JSONObject, service: String, listener: Response.Listener, error_listener: Response.ErrorListener) : Int
{
val queue = Volley.newRequestQueue(context_)
diff --git a/Frontend/Android/app/src/main/res/drawable/heart_filled.png b/Frontend/Android/app/src/main/res/drawable/heart_filled.png
new file mode 100644
index 0000000..039020a
Binary files /dev/null and b/Frontend/Android/app/src/main/res/drawable/heart_filled.png differ
diff --git a/Frontend/Android/app/src/main/res/drawable/hearth_empty.png b/Frontend/Android/app/src/main/res/drawable/hearth_empty.png
new file mode 100644
index 0000000..e3a04b4
Binary files /dev/null and b/Frontend/Android/app/src/main/res/drawable/hearth_empty.png differ
diff --git a/Frontend/Android/app/src/main/res/layout/activity_cocktail_detail.xml b/Frontend/Android/app/src/main/res/layout/activity_cocktail_detail.xml
index 440ac4b..56c9e0e 100644
--- a/Frontend/Android/app/src/main/res/layout/activity_cocktail_detail.xml
+++ b/Frontend/Android/app/src/main/res/layout/activity_cocktail_detail.xml
@@ -225,5 +225,16 @@
app:layout_constraintStart_toEndOf="@+id/cocktail_creator_text"
app:layout_constraintTop_toTopOf="@+id/cocktail_creator_text" />
+
+