diff --git a/Lookify/app/src/main/java/com/example/lookifyv2/About.java b/Lookify/app/src/main/java/com/example/lookifyv2/About.java index 0084d3d..5a2ba5b 100644 --- a/Lookify/app/src/main/java/com/example/lookifyv2/About.java +++ b/Lookify/app/src/main/java/com/example/lookifyv2/About.java @@ -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; } } diff --git a/Lookify/app/src/main/java/com/example/lookifyv2/CheckInternet.java b/Lookify/app/src/main/java/com/example/lookifyv2/CheckInternet.java new file mode 100644 index 0000000..450efdb --- /dev/null +++ b/Lookify/app/src/main/java/com/example/lookifyv2/CheckInternet.java @@ -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; + } +} diff --git a/Lookify/app/src/main/java/com/example/lookifyv2/Decode.java b/Lookify/app/src/main/java/com/example/lookifyv2/Decode.java index 7caf170..111f4d1 100644 --- a/Lookify/app/src/main/java/com/example/lookifyv2/Decode.java +++ b/Lookify/app/src/main/java/com/example/lookifyv2/Decode.java @@ -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(); - - } } diff --git a/Lookify/app/src/main/java/com/example/lookifyv2/DecodeFail.java b/Lookify/app/src/main/java/com/example/lookifyv2/DecodeFail.java index 0df8c2c..d9eb36f 100644 --- a/Lookify/app/src/main/java/com/example/lookifyv2/DecodeFail.java +++ b/Lookify/app/src/main/java/com/example/lookifyv2/DecodeFail.java @@ -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; + } } diff --git a/Lookify/app/src/main/java/com/example/lookifyv2/Favourites.java b/Lookify/app/src/main/java/com/example/lookifyv2/Favourites.java index d4835a9..5f2bc29 100644 --- a/Lookify/app/src/main/java/com/example/lookifyv2/Favourites.java +++ b/Lookify/app/src/main/java/com/example/lookifyv2/Favourites.java @@ -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; + } } diff --git a/Lookify/app/src/main/java/com/example/lookifyv2/Help.java b/Lookify/app/src/main/java/com/example/lookifyv2/Help.java index 3269eff..9e9423c 100644 --- a/Lookify/app/src/main/java/com/example/lookifyv2/Help.java +++ b/Lookify/app/src/main/java/com/example/lookifyv2/Help.java @@ -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; } } diff --git a/Lookify/app/src/main/java/com/example/lookifyv2/Popup.java b/Lookify/app/src/main/java/com/example/lookifyv2/Popup.java index 3d08800..8402799 100644 --- a/Lookify/app/src/main/java/com/example/lookifyv2/Popup.java +++ b/Lookify/app/src/main/java/com/example/lookifyv2/Popup.java @@ -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("" + "Kolor:" + " " + bundle.getSerializable("productcolour"))); productStyle.setText(Html.fromHtml("" + "Styl:" + " " + bundle.getSerializable("productstyle"))); productCollection.setText(Html.fromHtml("" + "Kolekcja:" + " " + 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; } } diff --git a/Lookify/app/src/main/java/com/example/lookifyv2/Results.java b/Lookify/app/src/main/java/com/example/lookifyv2/Results.java index 13934cd..6ee5833 100644 --- a/Lookify/app/src/main/java/com/example/lookifyv2/Results.java +++ b/Lookify/app/src/main/java/com/example/lookifyv2/Results.java @@ -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; + } } diff --git a/Lookify/app/src/main/res/drawable/buzka.png b/Lookify/app/src/main/res/drawable/buzka.png new file mode 100644 index 0000000..7834c38 Binary files /dev/null and b/Lookify/app/src/main/res/drawable/buzka.png differ diff --git a/Lookify/app/src/main/res/drawable/lookify_logo_text.png b/Lookify/app/src/main/res/drawable/lookify_logo_text.png index 828bda1..1726ca5 100644 Binary files a/Lookify/app/src/main/res/drawable/lookify_logo_text.png and b/Lookify/app/src/main/res/drawable/lookify_logo_text.png differ diff --git a/Lookify/app/src/main/res/layout/activity_decode_fail.xml b/Lookify/app/src/main/res/layout/activity_decode_fail.xml index 42f5335..cf5a5b3 100644 --- a/Lookify/app/src/main/res/layout/activity_decode_fail.xml +++ b/Lookify/app/src/main/res/layout/activity_decode_fail.xml @@ -6,43 +6,77 @@ android:layout_height="match_parent" tools:context=".DecodeFail"> + + + + + android:visibility="gone"/> + + + +