Skip to content
Snippets Groups Projects
Commit b6af9d22 authored by Christian Dresen's avatar Christian Dresen
Browse files

Finalized Barcode Reader

Fixed Keyboard
parent d6b19128
No related branches found
No related tags found
No related merge requests found
Showing
with 85 additions and 34 deletions
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<meta-data android:name="AA_DB_NAME" android:value="warppay_data.db" /> <meta-data android:name="AA_DB_NAME" android:value="warppay.db" />
<meta-data android:name="AA_DB_VERSION" android:value="8" /> <meta-data android:name="AA_DB_VERSION" android:value="9.1" />
<activity <activity
android:name="ms.warpzone.warppay.MainActivity" android:name="ms.warpzone.warppay.MainActivity"
......
...@@ -20,6 +20,7 @@ import android.widget.TextView; ...@@ -20,6 +20,7 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import ms.warpzone.warppay.R; import ms.warpzone.warppay.R;
import ms.warpzone.warppay.data.models.local.Product;
import ms.warpzone.warppay.data.models.local.User; import ms.warpzone.warppay.data.models.local.User;
import ms.warpzone.warppay.dialogs.NewUserDialog; import ms.warpzone.warppay.dialogs.NewUserDialog;
...@@ -143,11 +144,19 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -143,11 +144,19 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
if(this.manager.getCurrentUser() != null) { if(this.manager.getCurrentUser() != null) {
if (event.getAction() == KeyEvent.ACTION_UP) { if (event.getAction() == KeyEvent.ACTION_UP) {
if (KeyEvent.KEYCODE_ENTER == event.getKeyCode()) { if (KeyEvent.KEYCODE_ENTER == event.getKeyCode()) {
Toast.makeText(this, this.barcode, Toast.LENGTH_LONG).show(); Product p = Product.getOneByBarcode(this.barcode.trim().replace("\n", "").toString());
if (p != null) {
Order order = new Order(p);
UiManager.getInstance().addOrder(order);
this.manager.addOrder(order);
} else {
Toast.makeText(this, "Barcode not found: "+this.barcode, Toast.LENGTH_LONG).show();
}
this.barcode = ""; this.barcode = "";
} else { } else {
this.barcode += (char) event.getUnicodeChar(); this.barcode += (char) event.getUnicodeChar();
} }
} }
} }
return super.dispatchKeyEvent(event); return super.dispatchKeyEvent(event);
......
...@@ -45,6 +45,7 @@ public class Product extends Model { ...@@ -45,6 +45,7 @@ public class Product extends Model {
this.count = count; this.count = count;
} }
public int getPid() { public int getPid() {
return pid; return pid;
} }
...@@ -104,11 +105,10 @@ public class Product extends Model { ...@@ -104,11 +105,10 @@ public class Product extends Model {
} }
public String toString() { public String toString() {
return this.name + " " + this.category; return this.name + " " + this.category+" "+this.barcode;
} }
public static List<Product> getByCategory(String category) { public static List<Product> getByCategory(String category) {
Log.d("APP", category);
return new Select() return new Select()
.from(Product.class) .from(Product.class)
.where("category = ?", category) .where("category = ?", category)
...@@ -121,4 +121,11 @@ public class Product extends Model { ...@@ -121,4 +121,11 @@ public class Product extends Model {
.where("name = ?", product_name) .where("name = ?", product_name)
.executeSingle(); .executeSingle();
} }
public static Product getOneByBarcode(String barcode) {
return new Select()
.from(Product.class)
.where("barcode = ?", barcode)
.executeSingle();
}
} }
...@@ -8,6 +8,7 @@ public class RestProduct { ...@@ -8,6 +8,7 @@ public class RestProduct {
private int id; private int id;
private String name; private String name;
private String category; private String category;
private String barcode;
private Float price_vk; private Float price_vk;
private int stock_count; private int stock_count;
...@@ -15,10 +16,11 @@ public class RestProduct { ...@@ -15,10 +16,11 @@ public class RestProduct {
super(); super();
} }
public RestProduct(int id, String name, String category, Float price_vk, int stock_count) { public RestProduct(int id, String name, String category,String barcode, Float price_vk, int stock_count) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.category = category; this.category = category;
this.barcode = barcode;
this.price_vk = price_vk; this.price_vk = price_vk;
this.stock_count = stock_count; this.stock_count = stock_count;
} }
...@@ -68,6 +70,7 @@ public class RestProduct { ...@@ -68,6 +70,7 @@ public class RestProduct {
p.setPid(this.id); p.setPid(this.id);
p.setName(this.name); p.setName(this.name);
p.setCategory(this.category); p.setCategory(this.category);
p.setBarcode(this.barcode);
p.setPrice(this.price_vk); p.setPrice(this.price_vk);
p.setCount(this.stock_count); p.setCount(this.stock_count);
return p; return p;
...@@ -78,8 +81,13 @@ public class RestProduct { ...@@ -78,8 +81,13 @@ public class RestProduct {
restProduct.setId(product.getPid()); restProduct.setId(product.getPid());
restProduct.setName(product.getName()); restProduct.setName(product.getName());
restProduct.setCategory(product.getCategory()); restProduct.setCategory(product.getCategory());
restProduct.setBarcode(product.getBarcode());
restProduct.setCount(product.getCount()); restProduct.setCount(product.getCount());
restProduct.setPrice(product.getPrice()); restProduct.setPrice(product.getPrice());
return restProduct; return restProduct;
} }
public void setBarcode(String barcode) {
this.barcode = barcode;
}
} }
...@@ -51,6 +51,7 @@ public class ChargeCustomDialog extends Dialog implements ...@@ -51,6 +51,7 @@ public class ChargeCustomDialog extends Dialog implements
} }
if(amount > 0.0) if(amount > 0.0)
MainManager.getInstance().chargeAmount(amount); MainManager.getInstance().chargeAmount(amount);
this.numPick.setEnabled(false);
dismiss(); dismiss();
} }
} }
...@@ -10,6 +10,7 @@ import android.widget.TextView; ...@@ -10,6 +10,7 @@ import android.widget.TextView;
import ms.warpzone.warppay.R; import ms.warpzone.warppay.R;
import ms.warpzone.warppay.manager.DataManager; import ms.warpzone.warppay.manager.DataManager;
import ms.warpzone.warppay.manager.MainManager; import ms.warpzone.warppay.manager.MainManager;
import ms.warpzone.warppay.manager.UiManager;
public class PayChoiceDialog extends Dialog implements View.OnClickListener { public class PayChoiceDialog extends Dialog implements View.OnClickListener {
...@@ -54,6 +55,7 @@ public class PayChoiceDialog extends Dialog implements View.OnClickListener { ...@@ -54,6 +55,7 @@ public class PayChoiceDialog extends Dialog implements View.OnClickListener {
default: default:
break; break;
} }
dismiss(); dismiss();
} }
} }
...@@ -76,7 +76,6 @@ public class DataManager { ...@@ -76,7 +76,6 @@ public class DataManager {
this.currentUser.setCredit(this.currentUser.getCredit() - this.totalAmount); this.currentUser.setCredit(this.currentUser.getCredit() - this.totalAmount);
this.currentUser.save(); this.currentUser.save();
} }
Log.d("USER", String.valueOf(this.currentUser.getCredit()));
this.totalAmount = 0.0; this.totalAmount = 0.0;
} }
......
...@@ -26,6 +26,7 @@ import ms.warpzone.warppay.MainActivity; ...@@ -26,6 +26,7 @@ import ms.warpzone.warppay.MainActivity;
import ms.warpzone.warppay.R; import ms.warpzone.warppay.R;
import ms.warpzone.warppay.data.SQLiteService; import ms.warpzone.warppay.data.SQLiteService;
import ms.warpzone.warppay.data.models.local.Category; import ms.warpzone.warppay.data.models.local.Category;
import ms.warpzone.warppay.data.models.local.Product;
import ms.warpzone.warppay.data.models.local.User; import ms.warpzone.warppay.data.models.local.User;
import ms.warpzone.warppay.data.RestService; import ms.warpzone.warppay.data.RestService;
import ms.warpzone.warppay.data.models.rest.RestCategory; import ms.warpzone.warppay.data.models.rest.RestCategory;
...@@ -113,8 +114,6 @@ public class MainManager { ...@@ -113,8 +114,6 @@ public class MainManager {
} }
public void refreshData() { public void refreshData() {
Log.d("REST", "Refreshing user data");
this.restService.getAllUser().enqueue(new Callback<List<RestUser>>() { this.restService.getAllUser().enqueue(new Callback<List<RestUser>>() {
@Override @Override
public void onResponse(Response<List<RestUser>> response, Retrofit retrofit) { public void onResponse(Response<List<RestUser>> response, Retrofit retrofit) {
...@@ -134,7 +133,6 @@ public class MainManager { ...@@ -134,7 +133,6 @@ public class MainManager {
this.restService.getAllCategories().enqueue(new Callback<List<RestCategory>>() { this.restService.getAllCategories().enqueue(new Callback<List<RestCategory>>() {
@Override @Override
public void onResponse(Response<List<RestCategory>> response, Retrofit retrofit) { public void onResponse(Response<List<RestCategory>> response, Retrofit retrofit) {
Log.d("HALLO",response.message());
List<Category> categoryList = MainManager.getInstance().sqLiteService.refreshCategoryData(response.body()); List<Category> categoryList = MainManager.getInstance().sqLiteService.refreshCategoryData(response.body());
if (categoryList != null) { if (categoryList != null) {
MainManager.getInstance().uiManager.showCategoryButtons(); MainManager.getInstance().uiManager.showCategoryButtons();
...@@ -231,6 +229,7 @@ public class MainManager { ...@@ -231,6 +229,7 @@ public class MainManager {
if (DataManager.getInstance().getCurrentUser().getCredit()>=totalAmount || cash){ if (DataManager.getInstance().getCurrentUser().getCredit()>=totalAmount || cash){
DataManager.getInstance().performPayment(cash); DataManager.getInstance().performPayment(cash);
MainManager.getInstance().clearCurrentUser(); MainManager.getInstance().clearCurrentUser();
} else { } else {
Toast.makeText(mainActivity, mainActivity.getResources().getString(R.string.please_charge), Toast.LENGTH_LONG).show(); Toast.makeText(mainActivity, mainActivity.getResources().getString(R.string.please_charge), Toast.LENGTH_LONG).show();
} }
......
package ms.warpzone.warppay.manager; package ms.warpzone.warppay.manager;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build; import android.os.Build;
import android.provider.Contacts; import android.provider.Contacts;
import android.util.Log; import android.util.Log;
...@@ -28,6 +30,7 @@ import ms.warpzone.warppay.R; ...@@ -28,6 +30,7 @@ import ms.warpzone.warppay.R;
import ms.warpzone.warppay.data.models.local.Category; import ms.warpzone.warppay.data.models.local.Category;
import ms.warpzone.warppay.data.models.local.Product; import ms.warpzone.warppay.data.models.local.Product;
import ms.warpzone.warppay.data.models.local.User; import ms.warpzone.warppay.data.models.local.User;
import ms.warpzone.warppay.data.models.rest.RestProduct;
import ms.warpzone.warppay.dialogs.ChargeDialog; import ms.warpzone.warppay.dialogs.ChargeDialog;
import ms.warpzone.warppay.dialogs.NewUserDialog; import ms.warpzone.warppay.dialogs.NewUserDialog;
import ms.warpzone.warppay.dialogs.PayChoiceDialog; import ms.warpzone.warppay.dialogs.PayChoiceDialog;
...@@ -43,8 +46,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap ...@@ -43,8 +46,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
private ImageButton btnRefresh; private ImageButton btnRefresh;
private TextView txtSum,txtCredit; private TextView txtSum,txtCredit;
private ListView lstOrdered; private ListView lstOrdered;
private GridLayout gridProducts; private GridLayout gridCategories;
private EditText txtBarcode;
private AutoCompleteTextView atxvName; private AutoCompleteTextView atxvName;
private ListViewAdapter lstOrderedAdapter; private ListViewAdapter lstOrderedAdapter;
...@@ -95,7 +97,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap ...@@ -95,7 +97,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
this.atxvName.setFocusable(true); this.atxvName.setFocusable(true);
this.atxvName.requestFocus(); this.atxvName.requestFocus();
this.gridProducts = (GridLayout) mainActivity.findViewById(R.id.gridProducts); this.gridCategories = (GridLayout) mainActivity.findViewById(R.id.gridCategories);
this.btnLogout.setVisibility(View.INVISIBLE); this.btnLogout.setVisibility(View.INVISIBLE);
this.enableControls(false); this.enableControls(false);
this.mainActivity = mainActivity; this.mainActivity = mainActivity;
...@@ -105,7 +107,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap ...@@ -105,7 +107,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
if (view.requestFocus()) { if (view.requestFocus()) {
InputMethodManager imm = (InputMethodManager) InputMethodManager imm = (InputMethodManager)
this.mainActivity.getSystemService(this.mainActivity.getApplicationContext().INPUT_METHOD_SERVICE); this.mainActivity.getSystemService(this.mainActivity.getApplicationContext().INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
} }
} }
protected void refreshTotalTextView(double totalAmount) { protected void refreshTotalTextView(double totalAmount) {
...@@ -125,23 +127,36 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap ...@@ -125,23 +127,36 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
protected void clearCurrentUser() { protected void clearCurrentUser() {
this.atxvName.setText(""); this.atxvName.setText("");
if(this.atxvName.requestFocus()) {
this.showSoftKeyboard(this.mainActivity.getCurrentFocus());
}
this.lstOrderedAdapter.clear(); this.lstOrderedAdapter.clear();
this.enableControls(false); this.enableControls(false);
this.btnLogout.setVisibility(View.INVISIBLE); this.btnLogout.setVisibility(View.INVISIBLE);
this.refreshCreditTextView(0.0); this.refreshCreditTextView(0.0);
this.refreshTotalTextView(0.0); this.refreshTotalTextView(0.0);
if(this.atxvName.requestFocus()) {
this.showSoftKeyboard(this.mainActivity.getCurrentFocus());
}
} }
private void enableControls(boolean enable) { private void enableControls(boolean enable) {
int visible;
if(enable)
visible= View.VISIBLE;
else
visible= View.INVISIBLE;
this.atxvName.setEnabled(!enable); this.atxvName.setEnabled(!enable);
this.btnRefresh.setEnabled(!enable); this.btnRefresh.setEnabled(!enable);
this.btnCharge.setEnabled(enable);
this.btnPay.setEnabled(enable);
this.btnLogout.setEnabled(enable); this.btnLogout.setEnabled(enable);
this.gridCategories.setVisibility(visible);
this.btnPay.setEnabled(enable);
this.btnPay.setVisibility(visible);
if(DataManager.getInstance().getIs_guest()) {
this.btnCharge.setEnabled(false);
this.btnCharge.setVisibility(View.INVISIBLE);
} else {
this.btnCharge.setEnabled(enable);
this.btnCharge.setVisibility(visible);
}
} }
protected void refreshUserData(List<User> userList) { protected void refreshUserData(List<User> userList) {
...@@ -166,7 +181,16 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap ...@@ -166,7 +181,16 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
new ChargeDialog().show(); new ChargeDialog().show();
break; break;
case R.id.btnPay: case R.id.btnPay:
new PayChoiceDialog().show(); PayChoiceDialog payChoiceDialog = new PayChoiceDialog();
payChoiceDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (MainManager.getInstance().getCurrentUser() == null)
MainManager.getInstance().clearCurrentUser();
}
});
payChoiceDialog.show();
break; break;
case R.id.btnLogout: case R.id.btnLogout:
MainManager.getInstance().clearCurrentUser(); MainManager.getInstance().clearCurrentUser();
...@@ -178,21 +202,20 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap ...@@ -178,21 +202,20 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
MainManager.getInstance().refreshData(); MainManager.getInstance().refreshData();
break; break;
case R.id.btnGuest: case R.id.btnGuest:
DataManager.getInstance().setIs_guest(true);
MainManager.getInstance().setCurrentUser(new User("Guest",0,"")); MainManager.getInstance().setCurrentUser(new User("Guest",0,""));
this.atxvName.setText("Gast"); this.atxvName.setText("Gast");
this.atxvName.dismissDropDown(); this.atxvName.dismissDropDown();
DataManager.getInstance().setIs_guest(true);
} }
} }
// @ToDo: Key handling für beide Fälle (BarCode und Username)
// @ToDo: Tastatur spinnt noch rum //@ToDo: Custom Charge spinnt
// @ToDo: payment dismiss spinnt
@Override @Override
public boolean onKey(View v, int keyCode, KeyEvent event) { public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction()==KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { if (event.getAction() == KeyEvent.ACTION_UP) {
Log.d("APP", String.valueOf(v.getId())+" "+R.id.txtUsername); if (KeyEvent.KEYCODE_ENTER == event.getKeyCode()) {
/*if(v.getId() == R.id.txtBarcode) {
Log.d("APP", this.txtBarcode.getText().toString());
} else*/ if (v.getId() == R.id.txtUsername) {
if (this.atxvAdapter.getCount() == 1) { if (this.atxvAdapter.getCount() == 1) {
MainManager.getInstance().setCurrentUser((User) this.atxvAdapter.getItem(0)); MainManager.getInstance().setCurrentUser((User) this.atxvAdapter.getItem(0));
this.atxvName.setText(this.atxvAdapter.getItem(0).toString()); this.atxvName.setText(this.atxvAdapter.getItem(0).toString());
...@@ -200,6 +223,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap ...@@ -200,6 +223,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
DataManager.getInstance().setIs_guest(false); DataManager.getInstance().setIs_guest(false);
} }
return false; return false;
} }
} }
return false; return false;
...@@ -215,7 +239,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap ...@@ -215,7 +239,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
public void showCategoryButtons() { public void showCategoryButtons() {
List<Category> categoryList = Category.getAll(); List<Category> categoryList = Category.getAll();
this.gridProducts.removeAllViews(); this.gridCategories.removeAllViews();
for (Category c: categoryList) { for (Category c: categoryList) {
Button catButton = new Button(this.mainActivity.getApplicationContext()); Button catButton = new Button(this.mainActivity.getApplicationContext());
catButton.setText(c.getName()); catButton.setText(c.getName());
...@@ -223,7 +247,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap ...@@ -223,7 +247,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
catButton.setWidth(150); catButton.setWidth(150);
catButton.setGravity(0); catButton.setGravity(0);
catButton.setOnClickListener(new CategoryOnClickListener()); catButton.setOnClickListener(new CategoryOnClickListener());
this.gridProducts.addView(catButton); this.gridCategories.addView(catButton);
} }
for (int i=categoryList.size();i<12;i++) { for (int i=categoryList.size();i<12;i++) {
Button btn = new Button(this.mainActivity.getApplicationContext()); Button btn = new Button(this.mainActivity.getApplicationContext());
...@@ -232,7 +256,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap ...@@ -232,7 +256,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
btn.setGravity(0); btn.setGravity(0);
btn.setText(""); btn.setText("");
btn.setEnabled(false); btn.setEnabled(false);
this.gridProducts.addView(btn); this.gridCategories.addView(btn);
} }
} }
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
android:layout_columnSpan="1" android:layout_columnSpan="1"
android:layout_row="0" android:layout_row="0"
android:imeOptions="actionNext" android:imeOptions="actionNext"
android:inputType="textNoSuggestions"
android:singleLine="true" /> android:singleLine="true" />
<Space <Space
...@@ -90,13 +91,14 @@ ...@@ -90,13 +91,14 @@
android:layout_row="2" /> android:layout_row="2" />
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridProducts" android:id="@+id/gridCategories"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_gravity="left" android:layout_gravity="left"
android:columnCount="4" android:columnCount="4"
android:orientation="horizontal" android:orientation="horizontal"
android:rowCount="3"></GridLayout> android:rowCount="3"
android:visibility="invisible"></GridLayout>
<Space <Space
android:layout_width="20px" android:layout_width="20px"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment