Dodaj funkcjonalność usuwania tymczasowego zrobionego zdjęcia, dodaj obsługę sytuacji, w których aplikacja nie ma dostępu do internetu, zmodyfikuj ekran błędu, by wyświetlał komunikat zależny od rodzaju błędu, dodaj strzałkę cofającą do poprzedniego ekranu na paskach części z activity, usuń zbędne przyciski cofające do menu

This commit is contained in:
Kacper Dudzic 2020-02-25 00:05:03 +01:00
parent edbee6c566
commit 5c0af6ed33
13 changed files with 279 additions and 85 deletions

View File

@ -10,5 +10,14 @@ public class About extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onSupportNavigateUp(){
finish();
return true;
}
}

View File

@ -0,0 +1,19 @@
package com.example.lookifyv2;
import java.io.IOException;
public class CheckInternet {
//https://stackoverflow.com/a/27312494/12566206
public boolean isOnline() {
Runtime runtime = Runtime.getRuntime();
try {
Process ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
int exitValue = ipProcess.waitFor();
return (exitValue == 0);
}
catch (IOException e) { e.printStackTrace(); }
catch (InterruptedException e) { e.printStackTrace(); }
return false;
}
}

View File

@ -2,8 +2,12 @@ package com.example.lookifyv2;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@ -26,6 +30,7 @@ import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import java.io.File;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
@ -69,10 +74,26 @@ public class Decode extends AppCompatActivity {
}
public void decodePic() {
//pobieramy adres pliku przekazywany przez poprzednie activity
CheckInternet check = new CheckInternet();
if(!check.isOnline()){
Bundle extras = getIntent().getExtras();
filePath = extras.getString("takenPic");
File filefordeletion = new File(filePath);
filefordeletion.delete();
Intent intent_DecodeFail = new Intent(this, DecodeFail.class);
intent_DecodeFail.putExtra("status", "offline");
startActivity(intent_DecodeFail);
finish();
}
//Pobieranie adresu pliku przekazanego przez poprzednie activity, tworzenie mata ze zdjęcia i usuwanie zdjęcia
Bundle extras = getIntent().getExtras();
filePath = extras.getString("takenPic");
matPic = Imgcodecs.imread(filePath);
File filefordeletion = new File(filePath);
filefordeletion.delete();
Mat matPicG = new Mat();
Mat matPicGB = new Mat();
Mat matPicGBT = new Mat();
@ -129,20 +150,19 @@ public class Decode extends AppCompatActivity {
reminder = -1;
e.printStackTrace();
Intent intent_DecodeFail = new Intent(this, DecodeFail.class);
intent_DecodeFail.putExtra("status", "notfound");
startActivity(intent_DecodeFail);
finish();
}
if(reminder == 0) {
Toast.makeText(this, contents,
Toast.makeText(this, "Zidentyfikowany kod: " + contents,
Toast.LENGTH_SHORT).show();
Intent intent_Results = new Intent(this, Results.class);
intent_Results.putExtra("decodedcode", contents);
startActivity(intent_Results);
finish();
}
}

View File

@ -7,39 +7,33 @@ import android.graphics.PorterDuff;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class DecodeFail extends AppCompatActivity {
private Button button_tryagain;
private Button button_backtomain;
String status;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_decode_fail);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Bundle extras = getIntent().getExtras();
status = extras.getString("status");
showMessage(status);
button_tryagain = findViewById(R.id.try_again_button);
button_tryagain.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
button_backtomain = findViewById(R.id.backto_main_button);
button_backtomain.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
button_tryagain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openScan();
}
});
button_backtomain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Finish();
}
});
}
public void Finish(){
finish();
}
public void openScan(){
@ -47,4 +41,25 @@ public class DecodeFail extends AppCompatActivity {
startActivity(intent_Scan);
finish();
}
public void showMessage(String status){
if(status.equals("notfound")){
TextView message = findViewById(R.id.text_notfound);
message.setVisibility(View.VISIBLE);
}
else if(status.equals("offline")){
TextView message = findViewById(R.id.text_offline);
message.setVisibility(View.VISIBLE);
}
else{
TextView message = findViewById(R.id.text_notindatabase);
message.setVisibility(View.VISIBLE);
}
}
@Override
public boolean onSupportNavigateUp(){
finish();
return true;
}
}

View File

@ -1,11 +1,15 @@
package com.example.lookifyv2;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.PorterDuff;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
@ -39,6 +43,26 @@ public class Favourites extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_favourites);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
CheckInternet check = new CheckInternet();
if(!check.isOnline()){
TextView nointernetmessage = findViewById(R.id.nointernetmessage);
nointernetmessage.setVisibility(View.VISIBLE);
Button button_refresh;
button_refresh = findViewById(R.id.refresh_button);
button_refresh.getBackground().setColorFilter(0xFFFFFFFF, PorterDuff.Mode.MULTIPLY);
button_refresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recreate();
}
});
button_refresh.setVisibility(View.VISIBLE);
}
recyclerView = findViewById(R.id.favouriterecyclerview);
products = new ArrayList<>();
favourites = new ArrayList<>();
@ -90,7 +114,7 @@ public class Favourites extends AppCompatActivity {
protected void onPostExecute(Void aVoid) {
adapter.notifyDataSetChanged();
getFavourites();//funkcja
getFavourites();
}
};
asyncTask.execute();
@ -120,4 +144,9 @@ public class Favourites extends AppCompatActivity {
}
}
}
@Override
public boolean onSupportNavigateUp(){
finish();
return true;
}
}

View File

@ -10,5 +10,14 @@ public class Help extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onSupportNavigateUp(){
finish();
return true;
}
}

View File

@ -13,13 +13,31 @@ import com.bumptech.glide.Glide;
public class Popup extends AppCompatActivity {
Button button_back;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_popup);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
CheckInternet check = new CheckInternet();
if(!check.isOnline()){
TextView nointernetmessage = findViewById(R.id.popupnointernetmessage);
nointernetmessage.setVisibility(View.VISIBLE);
Button button_refresh;
button_refresh = findViewById(R.id.popuprefresh_button);
button_refresh.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
button_refresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recreate();
}
});
button_refresh.setVisibility(View.VISIBLE);
}
ImageView productImage = findViewById(R.id.productimagedet);
TextView productCode = findViewById(R.id.productcodedet);
TextView productName = findViewById(R.id.productnamedet);
@ -40,15 +58,11 @@ public class Popup extends AppCompatActivity {
productColour.setText(Html.fromHtml("<b>" + "Kolor:" + "</b> " + bundle.getSerializable("productcolour")));
productStyle.setText(Html.fromHtml("<b>" + "Styl:" + "</b> " + bundle.getSerializable("productstyle")));
productCollection.setText(Html.fromHtml("<b>" + "Kolekcja:" + "</b> " + bundle.getSerializable("productcollection")));
}
button_back = findViewById(R.id.back_button);
button_back.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
button_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
@Override
public boolean onSupportNavigateUp(){
finish();
return true;
}
}

View File

@ -59,6 +59,9 @@ public class Results extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_results);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
recyclerView = findViewById(R.id.recyclerview);
products = new ArrayList<>();
productstop6 = new ArrayList<>();
@ -123,12 +126,11 @@ public class Results extends AppCompatActivity {
}
if(foundPosition == -1){
Intent intent_DecodeFail = new Intent(Results.this, DecodeFail.class);
intent_DecodeFail.putExtra("status", "notindatabase");
startActivity(intent_DecodeFail);
finish();
}
//int foundPosition = 2; //TESTESTSRETSTETSTETT
ImageView imageView = findViewById(R.id.foundproductimage);
TextView foundProductPrice = findViewById(R.id.foundproductprice);
TextView foundProductName = findViewById(R.id.foundproductname);
@ -248,6 +250,12 @@ public class Results extends AppCompatActivity {
}
}
@Override
public boolean onSupportNavigateUp(){
finish();
return true;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -6,43 +6,77 @@
android:layout_height="match_parent"
tools:context=".DecodeFail">
<ImageView
android:id="@+id/fail_pic"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="32dp"
android:layout_marginBottom="32dp"
android:src="@drawable/buzka"
app:layout_constraintBottom_toTopOf="@+id/text_dummy"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView"
android:id="@+id/text_dummy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="Ups! Kodu nie znaleziono lub nie znajduje się on w bazie!"
app:layout_constraintBottom_toTopOf="@+id/try_again_button"
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" />
<TextView
android:id="@+id/text_notfound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ups! Kodu nie znaleziono!"
android:textColor="#000000"
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"
app:layout_constraintVertical_bias="1.0" />
android:visibility="gone"/>
<TextView
android:id="@+id/text_notindatabase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ups! Zidentyfikowany kod nie znajduje się w bazie!"
android:textColor="#000000"
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"
android:visibility="gone"
android:gravity="center"/>
<TextView
android:id="@+id/text_offline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ups! Brak połączenia z internetem!"
android:textColor="#000000"
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"
android:visibility="gone"/>
<Button
android:id="@+id/try_again_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Spróbuj ponownie"
app:layout_constraintBottom_toBottomOf="parent"
android:textColor="#FFFFFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textColor="#FFFFFF"/>
<Button
android:id="@+id/backto_main_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Powrót do menu"
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/try_again_button"
app:layout_constraintVertical_bias="0.0"
android:textColor="#FFFFFF"/>
app:layout_constraintTop_toBottomOf="@+id/text_dummy" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -14,7 +14,33 @@
android:layout_centerInParent="true"
android:layout_marginTop="712dp"
android:text="Nie obserwujesz żadnych produktów..."
android:visibility="gone" />
android:visibility="gone"
android:textColor="#000000"/>
<TextView
android:id="@+id/nointernetmessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="712dp"
android:text="Błąd przy łączeniu z internetem!"
android:visibility="gone"
android:textColor="#000000"/>
<Button
android:id="@+id/refresh_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="275dp"
android:layout_marginEnd="163dp"
android:layout_marginRight="163dp"
android:text="Odśwież"
android:textColor="#67BAFF"
android:visibility="gone"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/favouriterecyclerview"

View File

@ -6,6 +6,37 @@
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/popupnointernetmessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="132dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:gravity="center"
android:text="Nie udało się załadować obrazka, błąd przy łączeniu z internetem!"
android:textColor="#000000"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/productimagedet" />
<Button
android:id="@+id/popuprefresh_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Odśwież"
android:textColor="#FFFFFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/popupnointernetmessage"
android:visibility="gone"/>
<ImageView
android:id="@+id/productimagedet"
android:layout_width="match_parent"
@ -23,6 +54,7 @@
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
@ -35,6 +67,7 @@
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
@ -47,6 +80,7 @@
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
@ -59,6 +93,7 @@
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
@ -71,6 +106,7 @@
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
@ -83,6 +119,7 @@
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
@ -95,6 +132,7 @@
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="#000000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
@ -102,31 +140,4 @@
app:layout_constraintTop_toBottomOf="@+id/productcollectiondet"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="@+id/back_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="Zamknij"
app:layout_constraintBottom_toBottomOf="parent"
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"
android:textColor="#FFFFFF"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<!--
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_width="350dp"
android:layout_height="475dp"
android:padding="5dp"
android:layout_gravity="center"
-->