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
Showing
with 1536 additions and 19 deletions
package ms.itsecteam.warpdrink;
import android.util.Log;
package ms.warpzone.warppay;
import com.activeandroid.ActiveAndroid;
/**
* Created by Chris on 26.06.2015.
*/
public class WarpDrinkApplication extends com.activeandroid.app.Application {
public class WarpPayApplication extends com.activeandroid.app.Application {
@Override
public void onCreate() {
super.onCreate();
Log.d("DATABASE", "INIT");
ActiveAndroid.initialize(this);
}
......
package ms.warpzone.warppay.data;
import java.util.ArrayList;
import java.util.List;
import ms.warpzone.warppay.data.models.rest.RestCategory;
import ms.warpzone.warppay.data.models.rest.RestProduct;
import ms.warpzone.warppay.data.models.rest.RestTransaction;
import ms.warpzone.warppay.data.models.rest.RestUser;
import retrofit.Call;
import retrofit.http.Body;
import retrofit.http.GET;
import retrofit.http.POST;
import retrofit.http.PUT;
import retrofit.http.Path;
public interface RestService {
@GET("users/{user}")
Call<RestUser> getSingleUser(@Path("user") String userid);
@GET("users/")
Call<List<RestUser>> getAllUser();
@POST("users/")
Call<RestUser> addUser(@Body RestUser user);
@PUT("users/{userid}/")
Call<RestUser> saveUser(@Path("userid") String uid, @Body RestUser user);
@GET("products/")
Call<List<RestProduct>> getAllProducts();
@GET("categories/")
Call<List<RestCategory>> getAllCategories();
@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
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;
import ms.warpzone.warppay.data.models.local.Category;
import ms.warpzone.warppay.data.models.local.Product;
import ms.warpzone.warppay.data.models.local.Setting;
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;
public class SQLiteService {
private static SQLiteService instance;
private SQLiteService() {}
public static SQLiteService getInstance () {
if (SQLiteService.instance == null)
SQLiteService.instance = new SQLiteService();
return SQLiteService.instance;
}
public void saveSetting(String key, String value) {
Setting.setSetting(key, value);
}
public String getSetting(String key) {
return this.getSetting(key, "");
}
public String getSetting(String key, String defaultValue) {
String value = Setting.getSetting(key);
if(value == null) {
return defaultValue;
}
return value;
}
public List<User> refreshUserData(List<RestUser> u) {
User.deleteAll();
List<User> ret_val = new ArrayList<>();
if(u != null) {
for (RestUser anU : u) {
User usr = anU.toLocalUser();
usr.save();
ret_val.add(usr);
}
}
return ret_val;
}
public List<Category> refreshCategoryData(List<RestCategory> c) {
Category.deleteAll();
List<Category> ret_val = new ArrayList<>();
if(c!=null) {
for (RestCategory category : c) {
Category cat = category.toLocalCategory();
cat.save();
ret_val.add(cat);
}
}
return ret_val;
}
public List<Product> refreshProductData(List<RestProduct> body) {
Product.deleteAll();
List<Product> ret_val = new ArrayList<>();
if (body != null) {
for (RestProduct anU : body) {
Product prod = anU.toLocalProduct();
prod.save();
ret_val.add(prod);
}
}
return ret_val;
}
}
package ms.itsecteam.warpdrink.data;
import android.util.Log;
package ms.warpzone.warppay.data.models.local;
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
......@@ -10,58 +8,66 @@ import com.activeandroid.query.Select;
import java.util.List;
@Table(name = "Users")
public class User extends Model {
@Table(name = "Category")
public class Category extends Model {
@Column(name = "cid")
private int cid;
@Column(name = "userid")
private int userid;
@Column(name = "name")
private String name;
@Column(name = "credit")
private double credit;
public User() {
@Column(name = "position")
private float position;
public Category() {
super();
}
public User(int userid, String name, double credit) {
public Category(int cid, String name, Float position) {
super();
this.userid = userid;
this.cid = cid;
this.name = name;
this.credit = credit;
this.position = position;
}
public String getName() {
return name;
public int getCid() {
return cid;
}
public void setName(String name) {
this.name = name;
public void setCid(int pid) {
this.cid = cid;
}
public double getCredit() {
return credit;
public String getName() {
return name;
}
public void setCredit(double credit) {
this.credit = credit;
public void setName(String name) {
this.name = name;
}
public static List<User> getAll() {
public static List<Category> getAll() {
return new Select()
.from(User.class)
.from(Category.class)
.orderBy("name")
.orderBy("position")
.execute();
}
public static User getByName(String name) {
return new Select()
.from(User.class)
.where("name = ?", name)
.executeSingle();
}
public static void deleteAll() {
new Delete().from(User.class).execute();
new Delete().from(Category.class).execute();
}
public String toString() {
return this.name;
}
public float getPosition() {
return position;
}
public void setPosition(float position) {
this.position = position;
}
}
package ms.warpzone.warppay.data.models.local;
import android.util.Log;
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
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")
public class Product extends Model {
@Column(name = "pid")
private int pid;
@Column(name = "name")
private String name;
@Column(name = "category")
private String category;
@Column(name = "barcode")
private String barcode;
@Column(name = "position")
private float position;
@Column(name = "price")
private BigDecimal price;
@Column(name = "count")
private int count;
public Product() {
super();
}
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;
}
public void setPid(int pid) {
this.pid = pid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getBarcode() {
return barcode;
}
public void setBarcode(String barcode) {
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)
.execute();
}
public static void deleteAll() {
new Delete().from(Product.class).execute();
}
public String toString() {
return this.name + " " + this.category+" "+this.barcode;
}
public static List<Product> getByCategory(String category) {
return new Select()
.from(Product.class)
.where("category = ?", category)
.orderBy("name")
.orderBy("position")
.execute();
}
public static Product getOneByName(String product_name) {
return new Select()
.from(Product.class)
.where("name = ?", product_name)
.executeSingle();
}
public static Product getOneByBarcode(String barcode) {
return new Select()
.from(Product.class)
.where("barcode = ?", barcode)
.executeSingle();
}
}
package ms.warpzone.warppay.data.models.local;
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.activeandroid.query.Delete;
import com.activeandroid.query.Select;
@Table(name = "Settings")
public class Setting extends Model {
@Column(name = "key")
private String key;
@Column(name = "value")
private String value;
public Setting() {
super();
}
public Setting(String key, String value) {
super();
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
public static String getSetting(String key) {
Setting setting = new Select()
.from(Setting.class)
.where("key = ?", key)
.executeSingle();
if(setting != null)
return setting.getValue();
return null;
}
public void setKey(String key) {
this.key = key;
}
public void setValue(String value) {
this.value = value;
}
public static void setSetting(String key, String value) {
Setting setting = new Select()
.from(Setting.class)
.where("key = ?", key)
.executeSingle();
if(setting != null) {
setting.setValue(value);
} else {
setting = new Setting(key, value);
}
setting.save();
}
public static void deleteAll() {
new Delete().from(Setting.class).execute();
}
public String toString() {
return this.key+":"+this.value;
}
}
package ms.warpzone.warppay.data.models.local;
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
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")
public class User extends Model {
@Column(name = "uid")
private String uid;
@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, 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() {
return uid;
}
public void setUserid(String uid) {
this.uid = uid;
}
public String getCardId() {
return card_id;
}
public void setCardId(String card_id) {
this.card_id = card_id;
}
public BigDecimal getCredit() {
return credit;
}
public void setCredit(BigDecimal credit) {
this.credit = credit;
}
public static List<User> getAll() {
return new Select()
.from(User.class)
.execute();
}
public static User getByName(String uid) {
return new Select()
.from(User.class)
.where("uid = ?", uid)
.executeSingle();
}
public static void deleteAll() {
new Delete().from(User.class).execute();
}
public String toString() {
return this.uid;
}
public static User getByCardId(String card_id) {
return new Select()
.from(User.class)
.where("card_id = ?", card_id)
.executeSingle();
}
public void setPinCode(String pinCode) {
this.pinCode = pinCode;
}
public String getPinCode() {
return pinCode;
}
}
package ms.warpzone.warppay.data.models.rest;
import ms.warpzone.warppay.data.models.local.Category;
public class RestCategory {
private int id;
private String name;
private float position;
public RestCategory() {
super();
}
public RestCategory(int id, String name, float position) {
this.id = id;
this.name = name;
this.position = position;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
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;
}
public static RestCategory fromLocalrestCategory(Category category) {
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 {
private int id;
private String name;
private String category;
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,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() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public BigDecimal getPrice() {
return price_vk;
}
public void setPrice(BigDecimal price) {
this.price_vk = price_vk;
}
public int getCount() {
return stock_count;
}
public void setCount(int stock_count) {
this.stock_count = stock_count;
}
public Product toLocalProduct() {
Product p = new Product();
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;
}
public static RestProduct fromLocalProduct(Product product) {
RestProduct restProduct = new 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 BigDecimal amount;
private boolean cash_paid;
public RestTransaction() {
super();
}
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;
this.amount = amount;
this.cash_paid = cash_paid;
}
public int getTid() {
return tid;
}
public int getTrans_type() {
return trans_type;
}
public void setTrans_type(int trans_type) {
this.trans_type = trans_type;
}
public RestProduct getProduct() {
return product;
}
public void setProduct(RestProduct product) {
this.product = product;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public boolean isCash_paid() {
return cash_paid;
}
public void setCash_paid(boolean cash_paid) {
this.cash_paid = cash_paid;
}
}
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 BigDecimal credit;
private String card_id;
private String pinCode;
public RestUser() {
super();
}
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() {
return uid;
}
public void setUserid(String uid) {
this.uid = uid;
}
public String getCardId() {
return card_id;
}
public void setCardId(String card_id) {
this.card_id = card_id;
}
public BigDecimal getCredit() {
return credit;
}
public void setCredit(BigDecimal credit) {
this.credit = credit;
}
public String getPinCode() {
return pinCode;
}
public String toString() {
return this.uid;
}
public User toLocalUser() {
User u = new User();
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);
}
}
package ms.itsecteam.warpdrink.dialogs;
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 ms.itsecteam.warpdrink.MainActivity;
import ms.itsecteam.warpdrink.R;
import ms.itsecteam.warpdrink.data.User;
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,20 +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) {
User u = this.c.getCurrentUser();
u.setCredit(u.getCredit()+amount);
u.save();
}
this.c.refreshCreditTextView();
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;
}
}
package ms.itsecteam.warpdrink.dialogs;
package ms.warpzone.warppay.dialogs;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import ms.itsecteam.warpdrink.MainActivity;
import ms.itsecteam.warpdrink.R;
import ms.itsecteam.warpdrink.data.User;
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 {
......@@ -18,9 +20,10 @@ public class ChargeDialog extends Dialog implements
public Dialog d;
public Button btnFiveEuro, btnTenEuro, btnTwentyEuro,btnOther;
public ChargeDialog(MainActivity a) {
super(a);
this.c = a;
public ChargeDialog() {
super(MainManager.getInstance().getMainActivity());
this.c = MainManager.getInstance().getMainActivity();
;
}
@Override
......@@ -42,29 +45,27 @@ 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) {
User u = this.c.getCurrentUser();
u.setCredit(u.getCredit()+amount);
u.save();
}
this.c.refreshCreditTextView();
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;
private VideoView vvNyanCat;
public NyanCatDialog() {
super(MainManager.getInstance().getMainActivity());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
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) {
this.vvNyanCat.stopPlayback();
dismiss();
}
}
package ms.warpzone.warppay.dialogs;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
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 {
private Button btnCredit,btnCash;
private TextView txtTotalAmountConfirm;
public PayChoiceDialog() {
super(MainManager.getInstance().getMainActivity());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.pay_choice_dialog);
btnCredit = (Button) findViewById(R.id.btnCredit);
btnCash = (Button) findViewById(R.id.btnCash);
txtTotalAmountConfirm = (TextView) findViewById(R.id.txtTotalAmountConfirm);
txtTotalAmountConfirm.setText("Gesamtbetrag: "+String.valueOf(DataManager.getInstance().getTotalAmount())+" Euro");
btnCredit.setOnClickListener(this);
btnCash.setOnClickListener(this);
if(DataManager.getInstance().getIs_guest())
btnCredit.setEnabled(false);
}
@Override
public void onClick(View v) {
// MainManager.getInstance().startTimer();
switch (v.getId()) {
case R.id.btnCredit:
MainManager.getInstance().performPayment(false);
break;
case R.id.btnCash:
MainManager.getInstance().performPayment(true);
break;
default:
break;
}
dismiss();
}
}
package ms.warpzone.warppay.dialogs;
import android.app.Dialog;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.InputType;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.mindrot.jbcrypt.BCrypt;
import ms.warpzone.warppay.R;
import ms.warpzone.warppay.data.models.local.User;
import ms.warpzone.warppay.manager.DataManager;
import ms.warpzone.warppay.manager.MainManager;
public class PinCodesDialog extends Dialog implements View.OnClickListener, View.OnKeyListener {
private User user;
private Button btnSubmit;
private EditText etxtPinCode;
public PinCodesDialog(User user) {
super(MainManager.getInstance().getMainActivity());
this.user = user;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.pin_code_dialog);
this.btnSubmit = (Button) findViewById(R.id.btnSumit);
this.btnSubmit.setOnClickListener(this);
this.etxtPinCode = (EditText) findViewById(R.id.etxtPinCode);
this.etxtPinCode.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
this.etxtPinCode.setOnKeyListener(this);
}
private void checkPin() {
try {
String pin = this.etxtPinCode.getText().toString();
if (BCrypt.checkpw(pin, this.user.getPinCode())) {
MainManager.getInstance().setCurrentUser(this.user, true);
this.etxtPinCode.setEnabled(false);
dismiss();
} else {
etxtPinCode.setBackgroundColor(Color.RED);
}
} catch(Exception e) {
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnSumit:
this.checkPin();
break;
default:
break;
}
}
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (KeyEvent.KEYCODE_ENTER == keyEvent.getKeyCode()) {
this.checkPin();
}
return false;
}
}
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;
import android.widget.GridLayout;
import java.util.List;
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;
public class ProductDialog extends Dialog implements View.OnClickListener {
private MainActivity c;
public Dialog d;
public GridLayout gridProducts;
private String category;
public ProductDialog(String category) {
super(MainManager.getInstance().getMainActivity());
c = MainManager.getInstance().getMainActivity();
this.category = category;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.product_dialog);
this.gridProducts = (GridLayout) findViewById(R.id.gridProductDialog);
this.gridProducts.setMinimumWidth(300);
this.gridProducts.setMinimumHeight(200);
this.gridProducts.removeAllViews();
List<Product> products= Product.getByCategory(this.category);
for (Product p: products) {
Button prodButton = new Button(this.c.getApplicationContext());
prodButton.setHeight(200);
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());
prodButton.setOnClickListener(this);
this.gridProducts.addView(prodButton);
}
for (int i=products.size();i<15;i++) {
Button btn = new Button(this.c.getApplicationContext());
btn.setHeight(200);
btn.setWidth(200);
btn.setGravity(0);
btn.setText("");
btn.setEnabled(false);
this.gridProducts.addView(btn);
}
}
@Override
public void onClick(View view) {
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);
dismiss();
}
}
package ms.itsecteam.warpdrink.dialogs;
package ms.warpzone.warppay.dialogs;
import android.app.Dialog;
import android.os.Bundle;
......@@ -6,21 +6,18 @@ import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import ms.itsecteam.warpdrink.MainActivity;
import ms.itsecteam.warpdrink.R;
import ms.itsecteam.warpdrink.data.DataApi;
import ms.itsecteam.warpdrink.data.User;
import ms.warpzone.warppay.MainActivity;
import ms.warpzone.warppay.R;
import ms.warpzone.warppay.data.SQLiteService;
public class NewUserDialog extends Dialog implements
public class SettingsDialog extends Dialog implements
View.OnClickListener {
public MainActivity c;
public Dialog d;
public Button btnAddUser;
public TextView txtUsername;
public NewUserDialog(MainActivity a) {
public Button btnSave, btnAbort;
TextView txtApiUrl;
public SettingsDialog(MainActivity a) {
super(a);
this.c = a;
}
......@@ -29,30 +26,27 @@ public class NewUserDialog extends Dialog implements
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.settings_dialog);
this.btnSave = (Button) findViewById(R.id.btnSave);
this.btnSave.setOnClickListener(this);
this.btnAbort = (Button) findViewById(R.id.btnAbort);
this.btnAbort.setOnClickListener(this);
this.txtApiUrl = (TextView) findViewById(R.id.txtApiUrl);
this.txtApiUrl.setText(SQLiteService.getInstance().getSetting("api_url"));
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnAddUser:
String username = this.txtUsername.getText().toString();
if (!username.equals("")) {
if(!DataApi.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();
}
case R.id.btnSave:
SQLiteService.getInstance().saveSetting("api_url",txtApiUrl.getText().toString());
this.dismiss();
break;
case R.id.btnAbort:
this.dismiss();
default:
break;
}
......