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 (2)
Showing
with 377 additions and 400 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,7 +24,10 @@ android {
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
}
dependencies {
......@@ -37,6 +40,7 @@ dependencies {
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
......@@ -19,8 +19,8 @@
android:theme="@style/AppTheme">
<meta-data android:name="AA_DB_NAME" android:value="warppay_2.db" />
<meta-data android:name="AA_DB_VERSION" android:value="11" />
<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"
......
......@@ -29,6 +29,7 @@ import ms.warpzone.warppay.data.models.local.User;
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;
......@@ -102,13 +103,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
@Override
public void onUserInteraction(){
if(MainManager.getInstance().getCurrentUser() != null) {
MainManager.getInstance().startTimer();
RefreshManager.getInstance().startTimer();
//MainManager.getInstance().stopScreenSaverTimer();
} else {
MainManager.getInstance().stopTimer();
RefreshManager.getInstance().stopTimer();
//MainManager.getInstance().resetScreenSaverTimer();
}
}
public static String byteArrayToHex(byte[] a) {
......@@ -126,7 +126,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_learn_card_id:
MainManager.getInstance().stopTimer();
RefreshManager.getInstance().stopTimer();
if (this.manager.getCurrentUser() != null){
new AlertDialog.Builder(this)
.setTitle(this.getResources().getString(R.string.confirm_learn_card))
......@@ -143,7 +143,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
break;
case R.id.action_learn_barcode:
MainManager.getInstance().stopTimer();
RefreshManager.getInstance().stopTimer();
this.barcodeLearnDialog = new BarcodeLearnDialog();
MainManager.getInstance().setBarcodeLearning(true);
this.barcodeLearnDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
......
......@@ -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;
......
......@@ -8,6 +8,7 @@ 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;
......@@ -30,7 +31,7 @@ public class Product extends Model {
private float position;
@Column(name = "price")
private float price;
private BigDecimal price;
@Column(name = "count")
private int count;
......@@ -39,7 +40,7 @@ public class Product extends Model {
super();
}
public Product(int pid, String name, String category, float price, int count, float position) {
public Product(int pid, String name, String category, BigDecimal price, int count, float position) {
super();
this.pid = pid;
this.name = name;
......@@ -49,7 +50,7 @@ public class Product extends Model {
this.position = position;
}
public static ArrayList<Product> getAllWithoutBarcode() {
public static List<Product> getAllWithoutBarcode() {
return new Select()
.from(Product.class)
.where("barcode = ''")
......@@ -81,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;
}
......
......@@ -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")
......@@ -21,14 +22,14 @@ public class User extends Model {
private String card_id;
@Column(name = "credit")
private double credit;
private BigDecimal credit;
public User() {
super();
}
public User(String uid, String pinCode, double credit, String card_id) {
public User(String uid, String pinCode, BigDecimal credit, String card_id) {
super();
this.uid = uid;
this.credit = credit;
......@@ -52,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;
}
......
package ms.warpzone.warppay.data.models.rest;
import java.math.BigDecimal;
import ms.warpzone.warppay.data.models.local.Product;
public class RestProduct {
......@@ -9,7 +11,7 @@ public class RestProduct {
private String name;
private String category;
private String barcode;
private Float price_vk;
private BigDecimal price_vk;
private int stock_count;
private float position;
......@@ -17,7 +19,7 @@ public class RestProduct {
super();
}
public RestProduct(int id, String name, String category,String barcode, Float price_vk, int stock_count, float position) {
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;
......@@ -51,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;
}
......
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;
......@@ -14,7 +16,7 @@ public class RestUser {
super();
}
public RestUser(String uid, double credit, String card_id, String pinCode) {
public RestUser(String uid, BigDecimal credit, String card_id, String pinCode) {
super();
this.uid = uid;
this.credit = credit;
......@@ -38,11 +40,11 @@ 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;
}
......
......@@ -27,6 +27,7 @@ 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;
......@@ -95,7 +96,7 @@ public class BarcodeLearnDialog extends Dialog implements View.OnClickListener,
this.act_product.setBarcode(this.barcode);
this.act_product.save();
RestProduct p = RestProduct.fromLocalProduct(this.act_product);
MainManager.getInstance().getRestService().saveBarcode(p.getId(),p).enqueue(new Callback<Void>() {
RestManager.getInstance().getRestService().saveBarcode(p.getId(),p).enqueue(new Callback<Void>() {
@Override
public void onResponse(Response<Void> response, Retrofit retrofit) {
......
......@@ -10,6 +10,8 @@ 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;
......@@ -63,8 +65,8 @@ public class ChargeCustomDialog extends Dialog implements
try {
String text = this.etxtAmount.getText().toString();
text = text.replace(",",".");
double amount = Double.valueOf(text);
if(amount > 0.0)
BigDecimal amount = BigDecimal.valueOf(Double.valueOf(text));
if(amount.compareTo(new BigDecimal(0.0)) > 0)
MainManager.getInstance().chargeAmount(amount);
} catch (Exception e) {
......
......@@ -6,6 +6,8 @@ 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;
......@@ -43,16 +45,16 @@ 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:
ChargeCustomDialog cd = new ChargeCustomDialog(this,this.c);
......@@ -62,7 +64,7 @@ public class ChargeDialog extends Dialog implements
default:
break;
}
if(amount > 0.0)
if(amount.compareTo(new BigDecimal(0.0)) > 0)
MainManager.getInstance().chargeAmount(amount);
dismiss();
}
......
......@@ -44,8 +44,8 @@ public class NyanCatDialog extends Dialog implements View.OnClickListener{
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));
// 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) {
......
......@@ -69,8 +69,6 @@ public class PinCodesDialog extends Dialog implements View.OnClickListener, View
default:
break;
}
dismiss();
}
@Override
......
......@@ -2,6 +2,7 @@ package ms.warpzone.warppay.dialogs;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
......@@ -13,6 +14,7 @@ import ms.warpzone.warppay.MainActivity;
import ms.warpzone.warppay.R;
import ms.warpzone.warppay.data.models.local.Product;
import ms.warpzone.warppay.manager.MainManager;
import ms.warpzone.warppay.manager.RefreshManager;
import ms.warpzone.warppay.manager.UiManager;
import ms.warpzone.warppay.orderList.Order;
......@@ -45,6 +47,7 @@ public class ProductDialog extends Dialog implements View.OnClickListener {
prodButton.setWidth(200);
prodButton.setGravity(0);
String placeholder = "\n\n\n\n\n\n";
placeholder = placeholder.substring(Integer.valueOf(p.getName().length() / 16));
prodButton.setText(p.getName()+placeholder+String.valueOf(p.getPrice())+" Euro");
prodButton.setTag(p.getName());
......@@ -65,10 +68,11 @@ public class ProductDialog extends Dialog implements View.OnClickListener {
@Override
public void onClick(View view) {
MainManager.getInstance().startTimer();
RefreshManager.getInstance().startTimer();
Button clicked = (Button) view;
String product_name = (String) clicked.getTag();
Product product = Product.getOneByName(product_name);
Order order = new Order(product);
UiManager.getInstance().addOrder(order);
MainManager.getInstance().addOrder(order);
......
......@@ -3,6 +3,7 @@ package ms.warpzone.warppay.manager;
import android.util.Log;
import android.widget.Toast;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
......@@ -21,7 +22,12 @@ public class DataManager {
private User currentUser;
private Boolean is_guest=false;
private double totalAmount;
private BigDecimal totalAmount = new BigDecimal(0.0);
public ArrayList<Order> getOrderList() {
return orderList;
}
private ArrayList<Order> orderList;
private String lastCardId;
......@@ -35,7 +41,7 @@ public class DataManager {
public void saveCurrentUser() {
RestUser rest_user = RestUser.fromLocalUser(this.currentUser);
MainManager.getInstance().getRestService().saveUser(rest_user.getUserid(), rest_user).enqueue(new Callback<RestUser>() {
RestManager.getInstance().getRestService().saveUser(rest_user.getUserid(), rest_user).enqueue(new Callback<RestUser>() {
@Override
public void onResponse(Response<RestUser> response, Retrofit retrofit) {
if(response.code() == 403) {
......@@ -60,41 +66,11 @@ public class DataManager {
this.is_guest = is_guest;
}
public void performPayment(Boolean cash) {
ArrayList transactions = new ArrayList<>();
for (Order order:this.orderList) {
RestTransaction transaction = new RestTransaction();
transaction.setProduct(RestProduct.fromLocalProduct(order.getProduct()));
transaction.setTrans_type(2);
if (this.is_guest || cash)
transaction.setCash_paid(true);
transactions.add(transaction);
}
MainManager.getInstance().getRestService().saveTransaction(this.currentUser.getUserid(), transactions).enqueue(new Callback<Void>() {
@Override
public void onResponse(Response<Void> response, Retrofit retrofit) {
Log.d("REST",String.valueOf(response.code()));
}
@Override
public void onFailure(Throwable t) {
Log.d("REST", t.getMessage());
}
});
if(!this.is_guest && !cash) {
this.currentUser.setCredit(this.currentUser.getCredit() - this.totalAmount);
this.currentUser.save();
}
this.totalAmount = 0.0;
}
public void clearCurrentUser() {
this.currentUser = null;
this.totalAmount = 0.0;
this.totalAmount = new BigDecimal(0.0);
this.is_guest=false;
this.orderList = new ArrayList<Order>();
this.orderList = new ArrayList<>();
}
public User getCurrentUser() {
......@@ -105,17 +81,17 @@ public class DataManager {
this.currentUser = currentUser;
}
public double getTotalAmount() {
public BigDecimal getTotalAmount() {
return totalAmount;
}
public void addOrder(Order order) {
this.orderList.add(order);
this.totalAmount += order.getProduct().getPrice();
this.totalAmount = this.totalAmount.add(order.getProduct().getPrice());
}
public void removeOrder(Order order) {
this.orderList.remove(order);
this.totalAmount -= order.getProduct().getPrice();
this.totalAmount = this.totalAmount.subtract(order.getProduct().getPrice());
}
public void setLastCardId(String lastCardId) {
this.lastCardId = lastCardId;
......
package ms.warpzone.warppay.manager;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Handler;
import android.util.Log;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import ms.warpzone.warppay.data.models.local.Category;
import ms.warpzone.warppay.data.models.local.User;
import ms.warpzone.warppay.data.models.rest.RestCategory;
import ms.warpzone.warppay.data.models.rest.RestProduct;
import ms.warpzone.warppay.data.models.rest.RestUser;
import ms.warpzone.warppay.dialogs.NotificationDialog;
import ms.warpzone.warppay.dialogs.NyanCatDialog;
import retrofit.Callback;
import retrofit.Response;
import retrofit.Retrofit;
public class RefreshManager {
private static RefreshManager ourInstance = new RefreshManager();
private Timer timer;
private Timer screenSaverTimer;
private Timer tmrRefresh;
public ProgressDialog pdProcess;
private NotificationDialog ndRefreshError = null;
private RefreshManager() {}
public static RefreshManager getInstance() {
return ourInstance;
}
void refreshData() {
this.refreshData(false);
}
public void refreshData(boolean disableDialog) {
if(this.ndRefreshError != null)
this.ndRefreshError.dismiss();
this.ndRefreshError = null;
if(!disableDialog)
pdProcess = ProgressDialog.show(MainManager.getInstance().getMainActivity(), "Processing...", "Loading...");
RestManager.getInstance().getRestService().getAllUser().enqueue(new Callback<List<RestUser>>() {
@Override
public void onResponse(Response<List<RestUser>> response, Retrofit retrofit) {
if(response.code() == 200 ) {
List<User> userList = MainManager.getInstance().getSqLiteService().refreshUserData(response.body());
if (userList != null) {
UiManager.getInstance().refreshUserData(userList);
}
} else {
RefreshManager.getInstance().showRefreshError();
}
}
@Override
public void onFailure(Throwable t) {
Log.d("REST", t.getMessage());
RefreshManager.getInstance().showRefreshError();
}
});
RestManager.getInstance().getRestService().getAllCategories().enqueue(new Callback<List<RestCategory>>() {
@Override
public void onResponse(Response<List<RestCategory>> response, Retrofit retrofit) {
if(response.code() == 200 ) {
List<Category> categoryList = MainManager.getInstance().getSqLiteService().refreshCategoryData(response.body());
if (categoryList != null) {
UiManager.getInstance().showCategoryButtons();
}
} else {
RefreshManager.getInstance().showRefreshError();
}
}
@Override
public void onFailure(Throwable t) {
Log.d("REST", t.getMessage());
RefreshManager.getInstance().showRefreshError();
}
});
RestManager.getInstance().getRestService().getAllProducts().enqueue(new Callback<List<RestProduct>>() {
@Override
public void onResponse(Response<List<RestProduct>> response, Retrofit retrofit) {
if(response.code() == 200 ) {
List<ms.warpzone.warppay.data.models.local.Product> productList = MainManager.getInstance().getSqLiteService().refreshProductData(response.body());
if (productList != null) {
UiManager.getInstance().refreshProductData(productList);
}
if(RefreshManager.getInstance().pdProcess != null ) {
RefreshManager.getInstance().pdProcess.dismiss();
RefreshManager.getInstance().pdProcess = null;
}
} else {
RefreshManager.getInstance().showRefreshError();
}
}
@Override
public void onFailure(Throwable t) {
Log.d("REST", t.getMessage());
RefreshManager.getInstance().showRefreshError();
}
});
}
public void showRefreshError() {
if(ndRefreshError == null) {
RefreshManager.getInstance().stopRefreshTimer();
if (RefreshManager.getInstance().pdProcess != null) {
RefreshManager.getInstance().pdProcess.dismiss();
RefreshManager.getInstance().pdProcess = null;
}
ndRefreshError = new NotificationDialog(MainManager.getInstance().getMainActivity(),"WARNING","Refresh failed. Please retry!");
ndRefreshError.setWarning();
ndRefreshError.getBuilder().setNeutralButton("Refresh", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
RefreshManager.getInstance().refreshData();
}
});
ndRefreshError.show();
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
RefreshManager.getInstance().refreshData();
}
};
ndRefreshError.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
handler.removeCallbacks(runnable);
}
});
handler.postDelayed(runnable, 10000);
}
}
public void stopTimer() {
if (this.timer != null) {
this.timer.cancel();
this.timer.purge();
}
}
public void startTimer() {
this.stopTimer();
this.timer = new Timer();
TimerTask t = new TimerTask() {
@Override
public void run() {
Handler mainHandler = new Handler(MainManager.getInstance().getMainActivity().getApplicationContext().getMainLooper());
Runnable myRunnable = new Runnable() {
@Override
public void run() {
MainManager.getInstance().clearCurrentUser();
}
};
mainHandler.post(myRunnable);
}
};
this.timer.schedule(t, 60000);
}
public void startRefreshTimer() {
this.tmrRefresh = new Timer();
TimerTask t = new TimerTask() {
@Override
public void run() {
Handler mainHandler = new Handler(MainManager.getInstance().getMainActivity().getApplicationContext().getMainLooper());
Runnable myRunnable = new Runnable() {
@Override
public void run() {
Log.d("REST","REFRESH TIMER RUNNING");
if(MainManager.getInstance().getCurrentUser() == null)
RefreshManager.getInstance().refreshData(true);
}
};
mainHandler.post(myRunnable);
}
};
Log.d("REST","STARTING REFRESH TIMER");
this.tmrRefresh.schedule(t, 60000,60000);
}
public void stopRefreshTimer() {
if (this.tmrRefresh != null) {
this.tmrRefresh.cancel();
this.tmrRefresh.purge();
}
}
public void resetScreenSaverTimer() {
this.stopScreenSaverTimer();
this.screenSaverTimer = new Timer();
TimerTask t = new TimerTask() {
@Override
public void run() {
Handler mainHandler = new Handler(MainManager.getInstance().getMainActivity().getApplicationContext().getMainLooper());
Runnable myRunnable = new Runnable() {
@Override
public void run() {
new NyanCatDialog().show();
}
};
mainHandler.post(myRunnable);
}
};
this.screenSaverTimer.schedule(t, 4000);
}
public void stopScreenSaverTimer() {
if (this.screenSaverTimer != null) {
this.screenSaverTimer.cancel();
this.screenSaverTimer.purge();
}
}
}