dodaj wstępną wersję ekranu wyników

This commit is contained in:
Kacper Dudzic 2020-02-14 23:22:23 +01:00
parent bbaca66e3e
commit b31d569759
13 changed files with 409 additions and 48 deletions

View File

@ -14,8 +14,9 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".PullDatabase"></activity> <activity android:name=".Results"></activity>
<activity android:name=".ConnectDatabase" /> <activity android:name=".ProductsAdapter" />
<activity android:name=".Product" />
<activity android:name=".DecodeFail" /> <activity android:name=".DecodeFail" />
<activity android:name=".Decode" /> <activity android:name=".Decode" />
<activity android:name=".TakePhoto" /> <activity android:name=".TakePhoto" />

View File

@ -1,14 +0,0 @@
package com.example.lookifyv2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class ConnectDatabase extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_connect_database);
}
}

View File

@ -15,6 +15,8 @@ public class MainActivity extends AppCompatActivity {
private Button button_help; private Button button_help;
private Button button_about; private Button button_about;
private Button button_results;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -24,6 +26,8 @@ public class MainActivity extends AppCompatActivity {
button_help = findViewById(R.id.help_start_button); button_help = findViewById(R.id.help_start_button);
button_about = findViewById(R.id.about_start_button); button_about = findViewById(R.id.about_start_button);
button_results = findViewById(R.id.results_start_button);
button_scan.setOnClickListener(new View.OnClickListener() { button_scan.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -43,6 +47,13 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
button_results.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openResults();
}
});
//Dezaktywacja przycisku skanowania, jeśli nie ma dostępu do kamery; żądanie dostępu do kamery i zapisu //Dezaktywacja przycisku skanowania, jeśli nie ma dostępu do kamery; żądanie dostępu do kamery i zapisu
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
button_scan.setEnabled(false); button_scan.setEnabled(false);
@ -75,4 +86,11 @@ public class MainActivity extends AppCompatActivity {
Intent intent_Scan = new Intent(this, TakePhoto.class); Intent intent_Scan = new Intent(this, TakePhoto.class);
startActivity(intent_Scan); startActivity(intent_Scan);
} }
public void openResults(){
Intent intent_Results = new Intent(this, Results.class);
startActivity(intent_Results);
}
} }

View File

@ -0,0 +1,137 @@
package com.example.lookifyv2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class Product extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_product);
}
/**
* Created by AndroidBash on 09/05/2016.
*/
private int id;
private String imageLink;
private String productPrice;
private String productCode;
private String productName;
private String productRetailer;
private String productColour;
private String productStyle;
private String productCollection;
private String productType;
private String productSex;
public Product(int id, String imageLink, String productPrice, String productCode, String productName, String productRetailer,
String productColour, String productStyle, String productCollection, String productType, String productSex) {
this.id = id;
this.imageLink = imageLink;
this.productPrice = productPrice;
this.productCode = productCode;
this.productName = productName;
this.productRetailer = productRetailer;
this.productColour = productColour;
this.productStyle = productStyle;
this.productCollection = productCollection;
this.productType = productType;
this.productSex = productSex;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getImageLink() {
return imageLink;
}
public void setImageLink(String imageLink) {
this.imageLink = imageLink;
}
public String getproductPrice() {
return productPrice;
}
public void setproductPrice(String productPrice) {
this.productPrice = productPrice;
}
public String getproductCode() {
return productCode;
}
public void setproductCode(String productCode) {
this.productCode = productCode;
}
public String getproductName() {
return productName;
}
public void setproductName(String productName) {
this.productName = productName;
}
public String getproductRetailer() {
return productRetailer;
}
public void setproductRetailer(String productRetailer) {
this.productRetailer = productRetailer;
}
public String getproductColour() {
return productColour;
}
public void setproductColour(String productColour) {
this.productColour = productColour;
}
public String getproductStyle() {
return productStyle;
}
public void setproductStyle(String productStyle) {
this.productStyle = productStyle;
}
public String getproductCollection() {
return productCollection;
}
public void setproductCollection(String productCollection) {
this.productCollection = productCollection;
}
public String getproductType() {
return productType;
}
public void setproductType(String productType) {
this.productType = productType;
}
public String getproductSex() {
return productSex;
}
public void setproductSex(String productSex) {
this.productSex = productSex;
}
}

View File

@ -0,0 +1,107 @@
package com.example.lookifyv2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupMenu; //?????????????????????
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import java.util.List;
public class ProductsAdapter extends RecyclerView.Adapter<ProductsAdapter.ViewHolder>{
private Context context;
private List<Product> products;
public ProductsAdapter(Context context, List<Product> products) {
this.context = context;
this.products = products;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card,parent,false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.productName.setText(products.get(position).getproductName());
holder.productPrice.setText(products.get(position).getproductPrice()); //????????????????????????
Glide.with(context).load(products.get(position).getImageLink()).into(holder.imageView);
}
@Override
public int getItemCount() {
return products.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView productName;
public TextView productPrice;
public ImageView imageView;
public ViewHolder(View itemView) {
super(itemView);
productName = (TextView) itemView.findViewById(R.id.productname);
imageView = (ImageView) itemView.findViewById(R.id.image);
productPrice = (TextView) itemView.findViewById(R.id.productprice);
imageView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int position = getAdapterPosition();
showPopupMenu(v,position);
}
}
private void showPopupMenu(View view, int position) {
PopupMenu popup = new PopupMenu(context, view);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.menu_context, popup.getMenu());
popup.setOnMenuItemClickListener(new MenuClickListener(position));
popup.show();
}
class MenuClickListener implements PopupMenu.OnMenuItemClickListener {
Integer pos;
public MenuClickListener(int pos) {
this.pos=pos;
}
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_favourite:
Toast.makeText(context, products.get(pos).getproductName()+" is added to favourite", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_watch:
Toast.makeText(context, products.get(pos).getproductName()+" is added to watchlist", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_book:
Toast.makeText(context, "Booked Ticket for "+ products.get(pos).getproductName(), Toast.LENGTH_SHORT).show();
return true;
default:
}
return false;
}
}
}

View File

@ -1,14 +0,0 @@
package com.example.lookifyv2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class PullDatabase extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pull_database);
}
}

View File

@ -0,0 +1,110 @@
package com.example.lookifyv2;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class Results extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
private List<Product> products;
private RecyclerView recyclerView;
private GridLayoutManager gridLayout;
private ProductsAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_results);
recyclerView = findViewById(R.id.recyclerview);
products = new ArrayList<>();
getProductsFromDB(0);
gridLayout = new GridLayoutManager(this, 2);
recyclerView.setLayoutManager(gridLayout);
adapter = new ProductsAdapter(this, products);
recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (gridLayout.findLastCompletelyVisibleItemPosition() == products.size() - 1) {
getProductsFromDB(products.get(products.size() - 1).getId());
}
}
});
}
private void getProductsFromDB(int id) {
@SuppressLint("StaticFieldLeak") AsyncTask<Integer, Void, Void> asyncTask = new AsyncTask<Integer, Void, Void>() {
@Override
protected Void doInBackground(Integer... productIds) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://192.168.8.101/products.php?id=" + productIds[0]) //???????????????????
.build();
try {
Response response = client.newCall(request).execute();
JSONArray array = new JSONArray(response.body().string());
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
Product product = new Product(object.getInt("id"), object.getString("product_code"),
object.getString("product_name"), object.getString("product_image"),
object.getString("product_price"), object.getString("product_retailer"),
object.getString("product_colour"), object.getString("product_style"),
object.getString("product_collection"),
object.getString("product_type"), object.getString("product_sex"));
Results.this.products.add(product);
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
adapter.notifyDataSetChanged();
}
};
asyncTask.execute(id);
}
}

View File

@ -43,4 +43,17 @@
app:layout_constraintTop_toBottomOf="@+id/help_start_button" app:layout_constraintTop_toBottomOf="@+id/help_start_button"
app:layout_constraintVertical_bias="0.0" /> app:layout_constraintVertical_bias="0.0" />
<Button
android:id="@+id/results_start_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Results test"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/about_start_button"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -4,6 +4,6 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ConnectDatabase"> tools:context=".Product">
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ProductsAdapter">
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="wrap_content" <RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
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">
<android.support.v7.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="wrap_content" android:layout_height="wrap_content"

View File

@ -4,7 +4,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<android.support.v7.widget.CardView <androidx.cardview.widget.CardView
android:id="@+id/cardview" android:id="@+id/cardview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -28,7 +28,7 @@
android:scaleType="centerCrop" /> android:scaleType="centerCrop" />
<TextView <TextView
android:id="@+id/moviename" 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/image" android:layout_below="@id/image"
@ -41,10 +41,10 @@
android:typeface="sans" /> android:typeface="sans" />
<TextView <TextView
android:id="@+id/genre" android:id="@+id/productprice"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/moviename" android:layout_below="@id/productname"
android:paddingLeft="5dp" android:paddingLeft="5dp"
android:paddingRight="5dp" android:paddingRight="5dp"
android:paddingTop="5dp" android:paddingTop="5dp"
@ -54,6 +54,6 @@
android:typeface="sans" /> android:typeface="sans" />
</RelativeLayout> </RelativeLayout>
</android.support.v7.widget.CardView> </androidx.cardview.widget.CardView>
</LinearLayout> </LinearLayout>

View File

@ -1,16 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<!--
<color name="colorPrimary">#008577</color> <color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color> <color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color> <color name="colorAccent">#D81B60</color>
-->
<color name="primary">#2196F3</color>
<color name="primary_dark">#1976D2</color>
<color name="primary_light">#BBDEFB</color>
<color name="accent">#03A9F4</color>
<color name="primary_text">#FFFFFF</color>
<color name="secondary_text">#727272</color>
<color name="icons">#FFFFFF</color>
<color name="divider">#B6B6B6</color>
</resources> </resources>