Dodaj szkielet kafelku identyfikującego zeskanowany produkt; dodaj przejście pomiędzy activity dekodowania a activity wyników; dodaj odrzucaniekodów nie znajdujących się w bazie danych w activity wyników

This commit is contained in:
Kacper Dudzic 2020-02-17 23:58:13 +01:00
parent 049f2dcdb4
commit 7514f6bf10
7 changed files with 142 additions and 158 deletions

View File

@ -15,7 +15,8 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".Popup"></activity> <activity android:name=".Popup"></activity>
<activity android:name=".Results" /> <activity android:name=".Results"
android:theme="@style/NoBar"/>
<activity android:name=".ProductsAdapter" /> <activity android:name=".ProductsAdapter" />
<activity android:name=".Product" /> <activity android:name=".Product" />
<activity android:name=".DecodeFail" /> <activity android:name=".DecodeFail" />

View File

@ -118,6 +118,7 @@ public class Decode extends AppCompatActivity {
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats); hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
hints.put(DecodeHintType.TRY_HARDER, true); hints.put(DecodeHintType.TRY_HARDER, true);
int reminder = 0;
//Szukanie kodu na wczytanym zdjęciu //Szukanie kodu na wczytanym zdjęciu
MultiFormatReader reader = new MultiFormatReader(); MultiFormatReader reader = new MultiFormatReader();
String contents = null; String contents = null;
@ -125,13 +126,18 @@ public class Decode extends AppCompatActivity {
Result result = reader.decode(bitmap, hints); Result result = reader.decode(bitmap, hints);
contents = result.getText(); contents = result.getText();
} catch (NotFoundException e) { } catch (NotFoundException e) {
reminder = -1;
e.printStackTrace(); e.printStackTrace();
Intent intent_DecodeFail = new Intent(this, DecodeFail.class); Intent intent_DecodeFail = new Intent(this, DecodeFail.class);
startActivity(intent_DecodeFail); startActivity(intent_DecodeFail);
Decode.this.finish(); finish();
}
if(reminder == 0) {
Intent intent_Results = new Intent(this, Results.class);
intent_Results.putExtra("decodedcode", contents);
startActivity(intent_Results);
finish();
} }
Toast toast = Toast.makeText(this, contents, Toast.LENGTH_LONG);
toast.show();
} }
//Druga część potrzebna do ładowania OpenCV w odpowiednim momencie //Druga część potrzebna do ładowania OpenCV w odpowiednim momencie

View File

@ -3,6 +3,7 @@ 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.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -31,6 +32,7 @@ public class Results extends AppCompatActivity {
private RecyclerView recyclerView; private RecyclerView recyclerView;
private GridLayoutManager gridLayout; private GridLayoutManager gridLayout;
private ProductsAdapter adapter; private ProductsAdapter adapter;
String decodedCode;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -41,6 +43,24 @@ 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);

View File

@ -10,97 +10,114 @@
android:id="@+id/productimagedet" android:id="@+id/productimagedet"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="300dp" android:layout_height="300dp"
android:scaleType="fitCenter" /> android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/productnamedet"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/productnamedet" android:id="@+id/productnamedet"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="8dp"
android:layout_marginLeft="16dp" android:layout_marginLeft="8dp"
android:paddingLeft="5dp" android:layout_marginTop="8dp"
android:paddingTop="5dp" app:layout_constraintEnd_toEndOf="parent"
android:paddingRight="5dp" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="312dp" /> app:layout_constraintTop_toBottomOf="@+id/productimagedet" />
<TextView <TextView
android:id="@+id/productpricedet" android:id="@+id/productpricedet"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="5dp" android:layout_marginStart="8dp"
android:paddingTop="5dp" android:layout_marginLeft="8dp"
android:paddingRight="5dp" android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.681" app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteX="74dp" /> app:layout_constraintTop_toBottomOf="@+id/productnamedet" />
<TextView <TextView
android:id="@+id/productretailerdet" android:id="@+id/productretailerdet"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="5dp" android:layout_marginStart="8dp"
android:paddingTop="5dp" android:layout_marginLeft="8dp"
android:paddingRight="5dp" android:layout_marginTop="8dp"
tools:layout_editor_absoluteX="56dp" app:layout_constraintEnd_toEndOf="parent"
tools:layout_editor_absoluteY="398dp" /> app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/productpricedet" />
<TextView <TextView
android:id="@+id/productcolourdet" android:id="@+id/productcolourdet"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="5dp" android:layout_marginStart="8dp"
android:paddingTop="5dp" android:layout_marginLeft="8dp"
android:paddingRight="5dp" android:layout_marginTop="8dp"
tools:layout_editor_absoluteX="84dp" app:layout_constraintEnd_toEndOf="parent"
tools:layout_editor_absoluteY="435dp" /> app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/productretailerdet" />
<TextView <TextView
android:id="@+id/productstyledet" android:id="@+id/productstyledet"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="5dp" android:layout_marginStart="8dp"
android:paddingTop="5dp" android:layout_marginLeft="8dp"
android:paddingRight="5dp" android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.596" app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteX="118dp" /> app:layout_constraintTop_toBottomOf="@+id/productcolourdet" />
<TextView <TextView
android:id="@+id/productcollectiondet" android:id="@+id/productcollectiondet"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="5dp" android:layout_marginStart="8dp"
android:paddingTop="5dp" android:layout_marginLeft="8dp"
android:paddingRight="5dp" android:layout_marginTop="8dp"
tools:layout_editor_absoluteX="128dp" app:layout_constraintEnd_toEndOf="parent"
tools:layout_editor_absoluteY="530dp" /> app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/productstyledet" />
<TextView <TextView
android:id="@+id/productcodedet" android:id="@+id/productcodedet"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="5dp" android:layout_marginStart="8dp"
android:paddingTop="5dp" android:layout_marginLeft="8dp"
android:paddingRight="5dp" android:layout_marginTop="8dp"
tools:layout_editor_absoluteX="128dp" app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteY="611dp" /> app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/productcollectiondet"
app:layout_constraintVertical_bias="0.0" />
<Button <Button
android:id="@+id/back_button" android:id="@+id/back_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_marginEnd="8dp"
android:paddingLeft="5dp" android:layout_marginRight="8dp"
android:paddingTop="5dp" android:layout_marginBottom="8dp"
android:paddingRight="5dp"
android:text="Zamknij" android:text="Zamknij"
tools:layout_editor_absoluteX="203dp" app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteY="506dp" /> app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<!-- <!--
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -1,22 +1,47 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:orientation="vertical"
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">
<androidx.recyclerview.widget.RecyclerView <RelativeLayout
android:id="@+id/recyclerview" android:background="#EC2929"
android:layout_weight="0.9"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" 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_marginRight="5dp" />
</RelativeLayout> <TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="0.1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="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_marginRight="5dp" />
</RelativeLayout>
</LinearLayout>

View File

@ -1,92 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="350dp"
android:layout_height="475dp"
android:padding="5dp"
android:layout_gravity="center">
<ImageView
android:id="@+id/productimagedet"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/productcodedet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"/>
<TextView
android:id="@+id/productnamedet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"/>
<TextView
android:id="@+id/productpricedet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"/>
<TextView
android:id="@+id/productretailerdet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"/>
<TextView
android:id="@+id/productcolourdet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"/>
<TextView
android:id="@+id/productstyledet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp" />
<TextView
android:id="@+id/productcollectiondet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"/>
<Button
android:id="@+id/favourite_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dodaj do "
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"/>
<Button
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Powrót"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
<!--
android:layout_width="match_parent"
android:layout_height="match_parent"
-->

View File

@ -8,4 +8,11 @@
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
</style> </style>
<style name="NoBar" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources> </resources>