Dodaj w pełni działający kafelek informacji o zidentyfikowanym produkcie
This commit is contained in:
parent
7514f6bf10
commit
f4d742f917
@ -3,16 +3,24 @@ package com.example.lookifyv2;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -33,6 +41,8 @@ public class Results extends AppCompatActivity {
|
|||||||
private GridLayoutManager gridLayout;
|
private GridLayoutManager gridLayout;
|
||||||
private ProductsAdapter adapter;
|
private ProductsAdapter adapter;
|
||||||
String decodedCode;
|
String decodedCode;
|
||||||
|
Button button_favourite;
|
||||||
|
Button button_details;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -43,24 +53,6 @@ public class Results extends AppCompatActivity {
|
|||||||
products = new ArrayList<>();
|
products = new ArrayList<>();
|
||||||
getProductsFromDB(0);
|
getProductsFromDB(0);
|
||||||
|
|
||||||
Bundle extras = getIntent().getExtras();
|
|
||||||
decodedCode = extras.getString("decodedcode");
|
|
||||||
|
|
||||||
int foundPosition = -1;
|
|
||||||
for(int i = 0; i < products.size(); i++){
|
|
||||||
if(decodedCode.equals(products.get(i).getproductCode())){
|
|
||||||
foundPosition = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(foundPosition == -1){
|
|
||||||
Intent intent_DecodeFail = new Intent(this, DecodeFail.class);
|
|
||||||
startActivity(intent_DecodeFail);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
gridLayout = new GridLayoutManager(this, 2);
|
gridLayout = new GridLayoutManager(this, 2);
|
||||||
recyclerView.setLayoutManager(gridLayout);
|
recyclerView.setLayoutManager(gridLayout);
|
||||||
|
|
||||||
@ -117,10 +109,81 @@ public class Results extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void aVoid) {
|
protected void onPostExecute(Void aVoid) {
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Bundle extras = getIntent().getExtras();
|
||||||
|
decodedCode = extras.getString("decodedcode");
|
||||||
|
|
||||||
|
int foundPosition = -1;
|
||||||
|
for(int i = 0; i < products.size(); i++){
|
||||||
|
if(decodedCode.equals(products.get(i).getproductCode())){
|
||||||
|
foundPosition = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(foundPosition == -1){
|
||||||
|
Intent intent_DecodeFail = new Intent(this, DecodeFail.class);
|
||||||
|
startActivity(intent_DecodeFail);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
int foundPosition = 1; //TESTESTSRETSTETSTETT
|
||||||
|
|
||||||
|
ImageView imageView = findViewById(R.id.foundproductimage);
|
||||||
|
TextView foundProductPrice = findViewById(R.id.foundproductprice);
|
||||||
|
TextView foundProductName = findViewById(R.id.foundproductname);
|
||||||
|
TextView getFoundProductRetailer = findViewById(R.id.foundproductretailer);
|
||||||
|
|
||||||
|
Glide.with(Results.this).load(products.get(foundPosition).getImageLink()).into(imageView);
|
||||||
|
foundProductPrice.setText(products.get(foundPosition).getproductPrice());
|
||||||
|
foundProductName.setText(products.get(foundPosition).getproductName());
|
||||||
|
getFoundProductRetailer.setText(products.get(foundPosition).getproductRetailer());
|
||||||
|
|
||||||
|
button_favourite = findViewById(R.id.favourite_button);
|
||||||
|
button_details = findViewById(R.id.details_button);
|
||||||
|
|
||||||
|
final int finalFoundPosition = foundPosition;
|
||||||
|
button_favourite.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
addFavourite(Results.this, finalFoundPosition);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
button_details.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
openDetails(finalFoundPosition);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
asyncTask.execute(id);
|
asyncTask.execute(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void openDetails(int position){
|
||||||
|
Intent intent_Details = new Intent(this, Popup.class);
|
||||||
|
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
|
||||||
|
bundle.putSerializable("productimage", products.get(position).getImageLink());
|
||||||
|
bundle.putSerializable("productcode", products.get(position).getproductCode());
|
||||||
|
bundle.putSerializable("productname", products.get(position).getproductName());
|
||||||
|
bundle.putSerializable("productprice", products.get(position).getproductPrice());
|
||||||
|
bundle.putSerializable("productretailer", products.get(position).getproductRetailer());
|
||||||
|
bundle.putSerializable("productcolour", products.get(position).getproductColour());
|
||||||
|
bundle.putSerializable("productstyle", products.get(position).getproductStyle());
|
||||||
|
bundle.putSerializable("productcollection", products.get(position).getproductCollection());
|
||||||
|
|
||||||
|
intent_Details.putExtras(bundle);
|
||||||
|
|
||||||
|
startActivity(intent_Details);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFavourite(Context context, int position){
|
||||||
|
Toast.makeText(context, "Produkt \"" + products.get(position).getproductName() + "\" został dodany do obserwowanych",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,40 +8,110 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:card_view="http://schemas.android.com/tools">
|
xmlns:card_view="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<RelativeLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:background="#EC2929"
|
|
||||||
android:layout_weight="0.9"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="0.8">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView"
|
android:id="@+id/header"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:layout_marginStart="8dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:layout_marginLeft="8dp"
|
||||||
app:layout_constraintHorizontal_bias="0.5"
|
android:layout_marginTop="8dp"
|
||||||
|
android:text="Rekomendacje dla produktu:"
|
||||||
|
android:textStyle="bold"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
</RelativeLayout>
|
<ImageView
|
||||||
|
android:id="@+id/foundproductimage"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:scaleType="centerInside"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/details_button"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/header"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/foundproductname"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/header" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/foundproductretailer"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/foundproductname" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/foundproductprice"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/foundproductretailer" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/favourite_button"
|
||||||
|
android:layout_width="101dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:text="Obserwuj"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/details_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:text="Szczegóły"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_weight="0.1"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="0.2"
|
||||||
|
android:background="#2196F3">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recyclerview"
|
android:id="@+id/recyclerview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
card_view:cardUseCompatPadding="true"
|
|
||||||
card_view:cardElevation="4dp"
|
|
||||||
card_view:cardCornerRadius="4dp"
|
|
||||||
android:scrollbars="vertical"
|
|
||||||
android:layout_marginTop="6dp"
|
|
||||||
android:layout_marginLeft="5dp"
|
android:layout_marginLeft="5dp"
|
||||||
android:layout_marginRight="5dp" />
|
android:layout_marginTop="6dp"
|
||||||
|
android:layout_marginRight="5dp"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
card_view:cardCornerRadius="4dp"
|
||||||
|
card_view:cardElevation="4dp"
|
||||||
|
card_view:cardUseCompatPadding="true" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -29,7 +29,7 @@
|
|||||||
android:background="?attr/selectableItemBackgroundBorderless"/>
|
android:background="?attr/selectableItemBackgroundBorderless"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/productprice"
|
android:id="@+id/productname"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/productimage"
|
android:layout_below="@id/productimage"
|
||||||
@ -37,17 +37,7 @@
|
|||||||
android:paddingRight="5dp"
|
android:paddingRight="5dp"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="5dp"
|
||||||
android:textColor="@color/cardview_dark_background"
|
android:textColor="@color/cardview_dark_background"
|
||||||
android:textStyle="bold" />
|
/>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/productname"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@id/productprice"
|
|
||||||
android:paddingLeft="5dp"
|
|
||||||
android:paddingRight="5dp"
|
|
||||||
android:paddingTop="5dp"
|
|
||||||
android:textColor="@color/cardview_dark_background" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/productretailer"
|
android:id="@+id/productretailer"
|
||||||
@ -58,6 +48,17 @@
|
|||||||
android:paddingRight="5dp"
|
android:paddingRight="5dp"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="5dp"
|
||||||
android:textColor="@color/cardview_dark_background" />
|
android:textColor="@color/cardview_dark_background" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/productprice"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/productretailer"
|
||||||
|
android:paddingLeft="5dp"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:paddingTop="5dp"
|
||||||
|
android:textColor="@color/cardview_dark_background"
|
||||||
|
android:textStyle="bold" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto"
|
|||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_favourite"
|
android:id="@+id/action_favourite"
|
||||||
android:title="Dodaj do obserwowanych" />
|
android:title="Obserwuj" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_details"
|
android:id="@+id/action_details"
|
||||||
android:title="Szczegóły" />
|
android:title="Szczegóły" />
|
||||||
|
Loading…
Reference in New Issue
Block a user