Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • infrastruktur/warppay-app
  • HoelShare/warppay-app
2 results
Show changes
Commits on Source (25)
Showing
with 592 additions and 96 deletions
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="WarpDrink" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id="WarpPay" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
......
......@@ -24,20 +24,26 @@ android {
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.0.1'
compile group: 'org.mindrot', name: 'jbcrypt', version: '0.4'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
compile group: 'com.squareup.retrofit' , name: 'retrofit' , version: '2.0.0-beta2'
compile group: 'com.squareup.retrofit' , name: 'converter-gson' , version: '2.0.0-beta2'
compile group: 'com.google.code.gson' , name: 'gson' , version: '2.7'
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
compile group: 'com.squareup.okio' , name: 'okio' , version: '1.9.0'
compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.7.5'
compile group: 'org.antlr', name: 'antlr4-runtime', version: '4.5.3'
}
File deleted
......@@ -2,22 +2,25 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ms.warpzone.warppay" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.NFC" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:name="ms.warpzone.warppay.WarpPayApplication"
android:theme="@style/AppTheme">
<meta-data android:name="AA_DB_NAME" android:value="warppay_data.db" />
<meta-data android:name="AA_DB_VERSION" android:value="8" />
<meta-data android:name="AA_DB_NAME" android:value="warppay_new.db" />
<meta-data android:name="AA_DB_VERSION" android:value="15" />
<activity
android:name="ms.warpzone.warppay.MainActivity"
......@@ -39,4 +42,5 @@
</activity>
</application>
</manifest>
......@@ -16,21 +16,25 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.PopupMenu;
import android.widget.Toast;
import ms.warpzone.warppay.R;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import ms.warpzone.warppay.data.models.local.Product;
import ms.warpzone.warppay.data.models.local.User;
import ms.warpzone.warppay.dialogs.NewUserDialog;
import ms.warpzone.warppay.dialogs.SettingsDialog;
import ms.warpzone.warppay.dialogs.BarcodeLearnDialog;
import ms.warpzone.warppay.manager.DataManager;
import ms.warpzone.warppay.manager.MainManager;
import ms.warpzone.warppay.manager.RefreshManager;
import ms.warpzone.warppay.manager.UiManager;
import ms.warpzone.warppay.orderList.Order;
public class MainActivity extends AppCompatActivity implements View.OnClickListener, View.OnKeyListener{
public class MainActivity extends AppCompatActivity implements View.OnClickListener, View.OnKeyListener, PopupMenu.OnMenuItemClickListener {
private MainManager manager;
private NfcAdapter nfcAdapter;
......@@ -38,6 +42,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private IntentFilter[] mIntentFilters;
private String[][] mNFCTechLists;
private String barcode;
private BarcodeLearnDialog barcodeLearnDialog;
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
......@@ -90,7 +96,18 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
DataManager.getInstance().setLastCardId(card_id);
if(this.manager.getCurrentUser() == null) {
User u = User.getByCardId(card_id);
this.manager.setCurrentUser(u);
if(u != null)
MainManager.getInstance().setCurrentUser(u,true);
}
}
@Override
public void onUserInteraction(){
if(MainManager.getInstance().getCurrentUser() != null) {
RefreshManager.getInstance().startTimer();
//MainManager.getInstance().stopScreenSaverTimer();
} else {
RefreshManager.getInstance().stopTimer();
//MainManager.getInstance().resetScreenSaverTimer();
}
}
......@@ -105,9 +122,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
UiManager.getInstance().onClick(v);
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_learn_card_id:
RefreshManager.getInstance().stopTimer();
if (this.manager.getCurrentUser() != null){
new AlertDialog.Builder(this)
.setTitle(this.getResources().getString(R.string.confirm_learn_card))
......@@ -122,12 +141,26 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} else {
Toast.makeText(this, "Bitte User auswählen", Toast.LENGTH_LONG).show();
}
break;
case R.id.action_learn_barcode:
RefreshManager.getInstance().stopTimer();
this.barcodeLearnDialog = new BarcodeLearnDialog();
MainManager.getInstance().setBarcodeLearning(true);
this.barcodeLearnDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
MainManager.getInstance().setBarcodeLearning(false);
}
});
this.barcodeLearnDialog.show();
break;
default:
break;
}
return true;
}
public void removeOrderOnClickHandler(View v) {
MainManager.getInstance().removeOrder((Order) v.getTag());
......@@ -140,48 +173,37 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
List blockedKeys = new ArrayList(Arrays.asList(KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP));
if (blockedKeys.contains(event.getKeyCode())) {
return true;
}
if(this.manager.getCurrentUser() != null) {
if (event.getAction() == KeyEvent.ACTION_UP) {
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 = "";
} else {
this.barcode += (char) event.getUnicodeChar();
}
}
}
return super.dispatchKeyEvent(event);
}
/*
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction()==KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
if(this.atxvAdapter.getCount() == 1) {
setCurrentUser(SQLiteService.getInstance().remoteGetUser(((User) this.atxvAdapter.getItem(0)).getUserid()));
this.atxvName.setText(this.atxvAdapter.getItem(0).toString());
this.atxvName.dismissDropDown();
}
return true;
}
return false;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
setCurrentUser(SQLiteService.getInstance().remoteGetUser(((User) this.atxvAdapter.getItem(position)).getUserid()));
}
@Override
public void onClick(DialogInterface dialog, int which) {
this.currentUser.setCredit(this.currentUser.getCredit() - this.getTotal());
this.currentUser.save();
RestClient.getInstance().saveUserCredit(this.currentUser);
this.clearCurrentUser();
public void onBackPressed() {
// nothing to do here
// … really
}
*/
}
package ms.warpzone.warppay.data;
import java.util.ArrayList;
import java.util.List;
import ms.warpzone.warppay.data.models.rest.RestCategory;
......@@ -34,6 +35,9 @@ public interface RestService {
@GET("categories/")
Call<List<RestCategory>> getAllCategories();
@PUT("transaction/{userid}/")
Call<Void> saveTransaction(@Path("userid") String uid, @Body RestTransaction transaction);
@PUT("transactions/{userid}/")
Call<Void> saveTransaction(@Path("userid") String uid, @Body ArrayList<RestTransaction> transaction);
@PUT("products/{productid}/barcode/")
Call<Void> saveBarcode(@Path("productid") int pid, @Body RestProduct product);
}
\ No newline at end of file
......@@ -2,6 +2,8 @@ package ms.warpzone.warppay.data;
import android.util.Log;
import com.activeandroid.query.Select;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......@@ -45,10 +47,12 @@ public class SQLiteService {
public List<User> refreshUserData(List<RestUser> u) {
User.deleteAll();
List<User> ret_val = new ArrayList<>();
for (RestUser anU : u) {
User usr = anU.toLocalUser();
usr.save();
ret_val.add(usr);
if(u != null) {
for (RestUser anU : u) {
User usr = anU.toLocalUser();
usr.save();
ret_val.add(usr);
}
}
return ret_val;
}
......@@ -56,10 +60,12 @@ public class SQLiteService {
public List<Category> refreshCategoryData(List<RestCategory> c) {
Category.deleteAll();
List<Category> ret_val = new ArrayList<>();
for (RestCategory category : c) {
Category cat = category.toLocalCategory();
cat.save();
ret_val.add(cat);
if(c!=null) {
for (RestCategory category : c) {
Category cat = category.toLocalCategory();
cat.save();
ret_val.add(cat);
}
}
return ret_val;
}
......@@ -67,12 +73,13 @@ public class SQLiteService {
public List<Product> refreshProductData(List<RestProduct> body) {
Product.deleteAll();
List<Product> ret_val = new ArrayList<>();
for (RestProduct anU : body) {
Product prod = anU.toLocalProduct();
prod.save();
ret_val.add(prod);
if (body != null) {
for (RestProduct anU : body) {
Product prod = anU.toLocalProduct();
prod.save();
ret_val.add(prod);
}
}
return ret_val;
}
......
......@@ -17,14 +17,18 @@ public class Category extends Model {
@Column(name = "name")
private String name;
@Column(name = "position")
private float position;
public Category() {
super();
}
public Category(int cid, String name) {
public Category(int cid, String name, Float position) {
super();
this.cid = cid;
this.name = name;
this.position = position;
}
public int getCid() {
......@@ -46,6 +50,8 @@ public class Category extends Model {
public static List<Category> getAll() {
return new Select()
.from(Category.class)
.orderBy("name")
.orderBy("position")
.execute();
}
......@@ -57,4 +63,11 @@ public class Category extends Model {
return this.name;
}
public float getPosition() {
return position;
}
public void setPosition(float position) {
this.position = position;
}
}
......@@ -8,6 +8,8 @@ import com.activeandroid.annotation.Table;
import com.activeandroid.query.Delete;
import com.activeandroid.query.Select;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Table(name = "Products")
......@@ -25,9 +27,11 @@ public class Product extends Model {
@Column(name = "barcode")
private String barcode;
@Column(name = "position")
private float position;
@Column(name = "price")
private float price;
private BigDecimal price;
@Column(name = "count")
private int count;
......@@ -36,15 +40,24 @@ public class Product extends Model {
super();
}
public Product(int pid, String name, String category, float price, int count) {
public Product(int pid, String name, String category, BigDecimal price, int count, float position) {
super();
this.pid = pid;
this.name = name;
this.category = category;
this.price = price;
this.count = count;
this.position = position;
}
public static List<Product> getAllWithoutBarcode() {
return new Select()
.from(Product.class)
.where("barcode = ''")
.execute();
}
public int getPid() {
return pid;
}
......@@ -69,11 +82,11 @@ public class Product extends Model {
this.category = category;
}
public float getPrice() {
public BigDecimal getPrice() {
return price;
}
public void setPrice(float price) {
public void setPrice(BigDecimal price) {
this.price = price;
}
......@@ -93,6 +106,14 @@ public class Product extends Model {
this.barcode = barcode;
}
public float getPosition() {
return position;
}
public void setPosition(float position) {
this.position = position;
}
public static List<Product> getAll() {
return new Select()
.from(Product.class)
......@@ -104,14 +125,15 @@ public class Product extends Model {
}
public String toString() {
return this.name + " " + this.category;
return this.name + " " + this.category+" "+this.barcode;
}
public static List<Product> getByCategory(String category) {
Log.d("APP", category);
return new Select()
.from(Product.class)
.where("category = ?", category)
.orderBy("name")
.orderBy("position")
.execute();
}
......@@ -121,4 +143,11 @@ public class Product extends Model {
.where("name = ?", product_name)
.executeSingle();
}
public static Product getOneByBarcode(String barcode) {
return new Select()
.from(Product.class)
.where("barcode = ?", barcode)
.executeSingle();
}
}
......@@ -6,6 +6,7 @@ import com.activeandroid.annotation.Table;
import com.activeandroid.query.Delete;
import com.activeandroid.query.Select;
import java.math.BigDecimal;
import java.util.List;
@Table(name = "Users")
......@@ -14,21 +15,26 @@ public class User extends Model {
@Column(name = "uid")
private String uid;
@Column(name = "credit")
private double credit;
@Column(name = "pinCode")
private String pinCode;
@Column(name = "card_id")
private String card_id;
@Column(name = "credit")
private BigDecimal credit;
public User() {
super();
}
public User(String uid, double credit, String card_id) {
public User(String uid, String pinCode, BigDecimal credit, String card_id) {
super();
this.uid = uid;
this.credit = credit;
this.card_id = card_id;
this.pinCode = pinCode;
}
public String getUserid() {
......@@ -47,11 +53,11 @@ public class User extends Model {
this.card_id = card_id;
}
public double getCredit() {
public BigDecimal getCredit() {
return credit;
}
public void setCredit(double credit) {
public void setCredit(BigDecimal credit) {
this.credit = credit;
}
......@@ -80,4 +86,11 @@ public class User extends Model {
.executeSingle();
}
public void setPinCode(String pinCode) {
this.pinCode = pinCode;
}
public String getPinCode() {
return pinCode;
}
}
......@@ -7,13 +7,16 @@ public class RestCategory {
private int id;
private String name;
private float position;
public RestCategory() {
super();
}
public RestCategory(int id, String name) {
public RestCategory(int id, String name, float position) {
this.id = id;
this.name = name;
this.position = position;
}
public int getId() {
......@@ -32,10 +35,19 @@ public class RestCategory {
this.name = name;
}
public float getPosition() {
return position;
}
public void setPosition(float position) {
this.position = position;
}
public Category toLocalCategory() {
Category c = new Category();
c.setCid(this.id);
c.setName(this.name);
c.setPosition(this.position);
return c;
}
......@@ -43,6 +55,7 @@ public class RestCategory {
RestCategory restCategory = new RestCategory();
restCategory.setId(category.getCid());
restCategory.setName(category.getName());
restCategory.setPosition(category.getPosition());
return restCategory;
}
}
package ms.warpzone.warppay.data.models.rest;
import java.math.BigDecimal;
import ms.warpzone.warppay.data.models.local.Product;
public class RestProduct {
......@@ -8,19 +10,23 @@ public class RestProduct {
private int id;
private String name;
private String category;
private Float price_vk;
private String barcode;
private BigDecimal price_vk;
private int stock_count;
private float position;
public RestProduct() {
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, BigDecimal price_vk, int stock_count, float position) {
this.id = id;
this.name = name;
this.category = category;
this.barcode = barcode;
this.price_vk = price_vk;
this.stock_count = stock_count;
this.position = position;
}
public int getId() {
......@@ -47,11 +53,11 @@ public class RestProduct {
this.category = category;
}
public Float getPrice() {
public BigDecimal getPrice() {
return price_vk;
}
public void setPrice(Float price) {
public void setPrice(BigDecimal price) {
this.price_vk = price_vk;
}
......@@ -68,8 +74,10 @@ public class RestProduct {
p.setPid(this.id);
p.setName(this.name);
p.setCategory(this.category);
p.setBarcode(this.barcode);
p.setPrice(this.price_vk);
p.setCount(this.stock_count);
p.setPosition(this.position);
return p;
}
......@@ -78,8 +86,26 @@ public class RestProduct {
restProduct.setId(product.getPid());
restProduct.setName(product.getName());
restProduct.setCategory(product.getCategory());
restProduct.setBarcode(product.getBarcode());
restProduct.setCount(product.getCount());
restProduct.setPrice(product.getPrice());
restProduct.setPosition(product.getPosition());
return restProduct;
}
public void setBarcode(String barcode) {
this.barcode = barcode;
}
public String getBarcode() {
return barcode;
}
public float getPosition() {
return position;
}
public void setPosition(float position) {
this.position = position;
}
}
package ms.warpzone.warppay.data.models.rest;
import java.math.BigDecimal;
public class RestTransaction {
private int tid;
private int trans_type;
private RestProduct product;
private double amount;
private BigDecimal amount;
private boolean cash_paid;
public RestTransaction() {
super();
}
public RestTransaction(int tid, int trans_type, RestProduct product, double amount, boolean cash_paid) {
public RestTransaction(int tid, int trans_type, RestProduct product, BigDecimal amount, boolean cash_paid) {
this.tid = tid;
this.trans_type = trans_type;
this.product = product;
......@@ -40,11 +42,11 @@ public class RestTransaction {
this.product = product;
}
public double getAmount() {
public BigDecimal getAmount() {
return amount;
}
public void setAmount(double amount) {
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
......
package ms.warpzone.warppay.data.models.rest;
import java.math.BigDecimal;
import ms.warpzone.warppay.data.models.local.User;
public class RestUser {
private String uid;
private double credit;
private BigDecimal credit;
private String card_id;
private String pinCode;
public RestUser() {
super();
}
public RestUser(String uid, double credit, String card_id) {
public RestUser(String uid, BigDecimal credit, String card_id, String pinCode) {
super();
this.uid = uid;
this.credit = credit;
this.card_id = card_id;
this.pinCode = pinCode;
}
public String getUserid() {
......@@ -36,14 +40,18 @@ public class RestUser {
this.card_id = card_id;
}
public double getCredit() {
public BigDecimal getCredit() {
return credit;
}
public void setCredit(double credit) {
public void setCredit(BigDecimal credit) {
this.credit = credit;
}
public String getPinCode() {
return pinCode;
}
public String toString() {
return this.uid;
}
......@@ -53,13 +61,20 @@ public class RestUser {
u.setCardId(this.card_id);
u.setUserid(this.uid);
u.setCredit(this.credit);
u.setPinCode(this.pinCode);
return u;
}
public static RestUser fromLocalUser(User user) {
RestUser rest_user = new RestUser();
rest_user.setCardId(user.getCardId());
rest_user.setUserid(user.getUserid());
rest_user.setCredit(user.getCredit());
rest_user.setPinCode(user.getPinCode());
return rest_user;
}
public void setPinCode(String pinCode) {
this.pinCode = pinCode;
}
}
package ms.warpzone.warppay.dialogs;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.activeandroid.query.Select;
import org.w3c.dom.Text;
import java.io.IOException;
import java.util.ArrayList;
import ms.warpzone.warppay.MainActivity;
import ms.warpzone.warppay.R;
import ms.warpzone.warppay.data.models.local.Product;
import ms.warpzone.warppay.data.models.rest.RestProduct;
import ms.warpzone.warppay.data.models.rest.RestUser;
import ms.warpzone.warppay.manager.DataManager;
import ms.warpzone.warppay.manager.MainManager;
import ms.warpzone.warppay.manager.RestManager;
import ms.warpzone.warppay.manager.UiManager;
import ms.warpzone.warppay.orderList.ListViewAdapter;
import ms.warpzone.warppay.orderList.Order;
import retrofit.Callback;
import retrofit.Response;
import retrofit.Retrofit;
public class BarcodeLearnDialog extends Dialog implements View.OnClickListener, AdapterView.OnItemClickListener {
public MainActivity c;
public Dialog d;
private Button btnBarcodeSubmit, btnBarcodeDelete, btnExit;
private ListView lstBarcodeProducts;
private ArrayAdapter productAdapter;
private TextView txtBarcodeProductName, txtBarcodeProductBarcode;
private Product act_product;
private String barcode="";
public BarcodeLearnDialog() {
super(MainManager.getInstance().getMainActivity());
this.c = MainManager.getInstance().getMainActivity();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.barcode_learn_dialog);
this.btnExit = (Button) findViewById(R.id.btnBarcodeExit);
this.btnBarcodeSubmit = (Button) findViewById(R.id.btnBarcodeSubmit);
this.btnBarcodeDelete = (Button) findViewById(R.id.btnBarcodeDelete);
this.btnExit.setOnClickListener(this);
this.btnBarcodeSubmit.setOnClickListener(this);
this.btnBarcodeDelete.setOnClickListener(this);
this.enableButtons(false);
this.lstBarcodeProducts = (ListView)findViewById(R.id.lstBarcodeProducts);
this.productAdapter = new ArrayAdapter(MainManager.getInstance().getMainActivity(), android.R.layout.simple_list_item_1, new ArrayList<Product>());
this.lstBarcodeProducts.setAdapter(this.productAdapter);
this.productAdapter.addAll(Product.getAllWithoutBarcode());
this.lstBarcodeProducts.setOnItemClickListener(this);
this.txtBarcodeProductName = (TextView) findViewById(R.id.txtBarcodeProductName);
this.txtBarcodeProductBarcode = (TextView)findViewById(R.id.txtBarcodeProductBarcode);
this.txtBarcodeProductName.setText("");
this.txtBarcodeProductBarcode.setText("");
}
private void enableButtons(boolean enabled) {
this.btnBarcodeSubmit.setEnabled(enabled);
this.btnBarcodeDelete.setEnabled(enabled);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnBarcodeSubmit:
this.barcode = this.txtBarcodeProductBarcode.getText().toString();
if(this.barcode != "" && this.act_product != null) {
this.act_product.setBarcode(this.barcode);
this.act_product.save();
RestProduct p = RestProduct.fromLocalProduct(this.act_product);
RestManager.getInstance().getRestService().saveBarcode(p.getId(),p).enqueue(new Callback<Void>() {
@Override
public void onResponse(Response<Void> response, Retrofit retrofit) {
}
@Override
public void onFailure(Throwable t) {
Log.d("REST", t.getMessage());
}
});
this.productAdapter.remove(this.act_product);
this.act_product = null;
this.txtBarcodeProductBarcode.setText("");
this.txtBarcodeProductName.setText("");
this.barcode = "";
this.setBarcode("");
}
break;
case R.id.btnBarcodeDelete:
this.setBarcode("");
break;
case R.id.btnBarcodeExit:
dismiss();
break;
}
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
this.act_product = (Product) this.productAdapter.getItem(i);
this.txtBarcodeProductName.setText(this.act_product.getName());
}
private void setBarcode(String barcode) {
if(barcode != "") {
this.barcode = barcode;
this.txtBarcodeProductBarcode.setText(barcode);
this.enableButtons(true);
} else {
this.txtBarcodeProductBarcode.setText("");
this.enableButtons(false);
}
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP) {
if (KeyEvent.KEYCODE_ENTER == event.getKeyCode()) {
this.setBarcode(this.barcode.trim().replace("\n", "").toString());
this.barcode = "";
} else {
this.barcode += (char) event.getUnicodeChar();
}
}
return super.dispatchKeyEvent(event);
}
}
......@@ -2,22 +2,28 @@ package ms.warpzone.warppay.dialogs;
import android.app.Dialog;
import android.os.Bundle;
import android.text.InputType;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.NumberPicker;
import java.math.BigDecimal;
import ms.warpzone.warppay.MainActivity;
import ms.warpzone.warppay.R;
import ms.warpzone.warppay.manager.MainManager;
public class ChargeCustomDialog extends Dialog implements
View.OnClickListener {
View.OnClickListener, View.OnKeyListener {
private MainActivity c;
private Dialog d;
private Button btnCustomCharge;
private NumberPicker numPick;
private EditText etxtAmount;
public ChargeCustomDialog(ChargeDialog dialog, MainActivity a) {
super(a);
dialog.dismiss();
......@@ -30,9 +36,10 @@ public class ChargeCustomDialog extends Dialog implements
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.charge_custom_dialog);
this.numPick = (NumberPicker) findViewById(R.id.numPick);
this.numPick.setMinValue(0);
this.numPick.setMaxValue(100);
this.etxtAmount = (EditText) findViewById(R.id.etxtCustomAmount);
//this.etxtAmount.setInputType(InputType.TYPE_CLASS_NUMBER);
this.etxtAmount.setOnKeyListener(this);
this.btnCustomCharge = (Button) findViewById(R.id.btnCustomCharge);
this.btnCustomCharge.setOnClickListener(this);
......@@ -41,16 +48,35 @@ public class ChargeCustomDialog extends Dialog implements
@Override
public void onClick(View v) {
double amount = 0.0;
switch (v.getId()) {
case R.id.btnCustomCharge:
amount = this.numPick.getValue();
this.chargeAmount();
break;
default:
break;
}
if(amount > 0.0)
MainManager.getInstance().chargeAmount(amount);
this.etxtAmount.setEnabled(false);
dismiss();
}
private void chargeAmount() {
try {
String text = this.etxtAmount.getText().toString();
text = text.replace(",",".");
BigDecimal amount = BigDecimal.valueOf(Double.valueOf(text));
if(amount.compareTo(new BigDecimal(0.0)) > 0)
MainManager.getInstance().chargeAmount(amount);
} catch (Exception e) {
}
}
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (KeyEvent.KEYCODE_ENTER == keyEvent.getKeyCode()) {
this.chargeAmount();
}
return false;
}
}
......@@ -6,9 +6,12 @@ import android.view.View;
import android.view.Window;
import android.widget.Button;
import java.math.BigDecimal;
import ms.warpzone.warppay.MainActivity;
import ms.warpzone.warppay.R;
import ms.warpzone.warppay.manager.MainManager;
import ms.warpzone.warppay.manager.UiManager;
public class ChargeDialog extends Dialog implements
android.view.View.OnClickListener {
......@@ -42,24 +45,26 @@ public class ChargeDialog extends Dialog implements
@Override
public void onClick(View v) {
double amount = 0.0;
BigDecimal amount = new BigDecimal(0.0);
switch (v.getId()) {
case R.id.btnFiveEuro:
amount = 5.0;
amount = new BigDecimal(5.0);
break;
case R.id.btnTenEuro:
amount = 10.0;
amount = new BigDecimal(10.0);
break;
case R.id.btnTwentyEuro:
amount = 20.0;
amount = new BigDecimal(20.0);
break;
case R.id.btnOther:
new ChargeCustomDialog(this,this.c).show();
ChargeCustomDialog cd = new ChargeCustomDialog(this,this.c);
UiManager.getInstance().setChargeCustomDialog(cd);
cd.show();
break;
default:
break;
}
if(amount > 0.0)
if(amount.compareTo(new BigDecimal(0.0)) > 0)
MainManager.getInstance().chargeAmount(amount);
dismiss();
}
......
package ms.warpzone.warppay.dialogs;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import ms.warpzone.warppay.R;
public class NotificationDialog {
AlertDialog.Builder builder;
AlertDialog dialog;
private String message;
public NotificationDialog(Context context, String title, String message) {
this.builder = new AlertDialog.Builder(context);
this.builder.setTitle(title);
this.builder.setMessage(message);
}
public NotificationDialog(Context context) {
this.builder = new AlertDialog.Builder(context);
}
public AlertDialog.Builder getBuilder() {
return this.builder;
}
public void show() {
this.show(0);
}
public void setWarning() {
this.builder.setIcon(R.drawable.ic_dialog_alert_holo_light);
this.builder.setCancelable(false);
this.builder.setTitle("WARNING");
}
public void show(int timeout) {
this.dialog = this.builder.create();
this.dialog.show();
if(timeout > 0) {
this.enableAutoDismiss(timeout);
}
}
public void enableAutoDismiss(int time){
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
AlertDialog alertDialog = NotificationDialog.this.dialog;
if (alertDialog != null && alertDialog.isShowing()) {
alertDialog.dismiss();
}
}
};
this.dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
handler.removeCallbacks(runnable);
}
});
handler.postDelayed(runnable, time);
}
public void setMessage(String message) {
this.builder.setMessage(message);
}
public void dismiss() {
if(this.dialog != null) {
this.dialog.dismiss();
}
}
public AlertDialog getDialog() {
return dialog;
}
}
package ms.warpzone.warppay.dialogs;
import android.app.Dialog;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.VideoView;
import java.util.ArrayList;
import ms.warpzone.warppay.MainActivity;
import ms.warpzone.warppay.R;
import ms.warpzone.warppay.data.models.local.Product;
import ms.warpzone.warppay.data.models.rest.RestProduct;
import ms.warpzone.warppay.manager.MainManager;
import retrofit.Callback;
import retrofit.Response;
import retrofit.Retrofit;
public class NyanCatDialog extends Dialog implements View.OnClickListener{
public Dialog d;
public class NewUserDialog extends Dialog implements
View.OnClickListener {
private VideoView vvNyanCat;
public MainActivity c;
public Button btnAddUser;
public TextView txtUsername;
public NewUserDialog() {
public NyanCatDialog() {
super(MainManager.getInstance().getMainActivity());
this.c = MainManager.getInstance().getMainActivity();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.new_user_dialog);
this.btnAddUser = (Button) findViewById(R.id.btnAddUser);
this.btnAddUser.setOnClickListener(this);
this.txtUsername = (TextView) findViewById(R.id.txtUsername);
setContentView(R.layout.nyan_cat_dialog);
this.vvNyanCat = (VideoView) findViewById(R.id.vvNyanCat);
// String uri = "android.resource://" + MainManager.getInstance().getMainActivity().getPackageName() + "/" + R.raw.nyancat;
//this.vvNyanCat.setVideoURI(Uri.parse(uri));
this.vvNyanCat.setOnClickListener(this);
this.vvNyanCat.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
vvNyanCat.start();
}
});
this.vvNyanCat.start();
}
@Override
public void onClick(View v) {
/*
switch (v.getId()) {
case R.id.btnAddUser:
String username = this.txtUsername.getText().toString();
if (!username.equals("")) {
if(!MainManager.getInstance().addUser(username)) {
Toast.makeText(v.getContext(),"Username ist schon vorhanden",Toast.LENGTH_LONG).show();
} else {
Toast.makeText(v.getContext(),"User angelegt",Toast.LENGTH_LONG).show();
dismiss();
}
} else {
Toast.makeText(v.getContext(),"Username darf nicht leer sein",Toast.LENGTH_LONG).show();
}
break;
default:
break;
}
*/
this.vvNyanCat.stopPlayback();
dismiss();
}
}
......@@ -10,6 +10,7 @@ import android.widget.TextView;
import ms.warpzone.warppay.R;
import ms.warpzone.warppay.manager.DataManager;
import ms.warpzone.warppay.manager.MainManager;
import ms.warpzone.warppay.manager.UiManager;
public class PayChoiceDialog extends Dialog implements View.OnClickListener {
......@@ -43,6 +44,7 @@ public class PayChoiceDialog extends Dialog implements View.OnClickListener {
@Override
public void onClick(View v) {
// MainManager.getInstance().startTimer();
switch (v.getId()) {
case R.id.btnCredit:
MainManager.getInstance().performPayment(false);
......@@ -54,6 +56,7 @@ public class PayChoiceDialog extends Dialog implements View.OnClickListener {
default:
break;
}
dismiss();
}
}