Commit f73a1684 authored by Christian Dresen's avatar Christian Dresen
Browse files

no message

parent 69157104
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AndroidLintRtlHardcoded" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
......@@ -94,8 +94,8 @@
<orderEntry type="library" exported="" name="jackson-annotations-2.0.1" level="project" />
<orderEntry type="library" exported="" name="okhttp-2.7.5" level="project" />
<orderEntry type="library" exported="" name="spring-android-rest-template-1.0.1.RELEASE" level="project" />
<orderEntry type="library" exported="" name="gson-2.7" level="project" />
<orderEntry type="library" exported="" name="antlr4-runtime-4.5.3" level="project" />
<orderEntry type="library" exported="" name="gson-2.7" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="spring-android-core-1.0.1.RELEASE" level="project" />
<orderEntry type="library" exported="" name="codepath-utils" level="project" />
......
......@@ -17,7 +17,7 @@
<meta-data android:name="AA_DB_NAME" android:value="warpdrink_data.db" />
<meta-data android:name="AA_DB_VERSION" android:value="5" />
<meta-data android:name="AA_DB_VERSION" android:value="6" />
<meta-data
android:name="AA_MODELS"
android:value="ms.itsecteam.warpdrink.data.objects.User" />
......
......@@ -3,6 +3,7 @@ package ms.itsecteam.warpdrink.data;
import java.util.List;
import ms.itsecteam.warpdrink.data.models.rest.RestCategory;
import ms.itsecteam.warpdrink.data.models.rest.RestProduct;
import ms.itsecteam.warpdrink.data.models.rest.RestTransaction;
import ms.itsecteam.warpdrink.data.models.rest.RestUser;
......@@ -30,6 +31,9 @@ public interface RestService {
@GET("products/")
Call<List<RestProduct>> getAllProducts();
@GET("categories/")
Call<List<RestCategory>> getAllCategories();
@PUT("transaction/{userid}/")
Call<Void> saveTransaction(@Path("userid") String uid, @Body RestTransaction transaction);
}
\ No newline at end of file
......@@ -6,9 +6,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import ms.itsecteam.warpdrink.data.models.local.Category;
import ms.itsecteam.warpdrink.data.models.local.Product;
import ms.itsecteam.warpdrink.data.models.local.Setting;
import ms.itsecteam.warpdrink.data.models.local.User;
import ms.itsecteam.warpdrink.data.models.rest.RestCategory;
import ms.itsecteam.warpdrink.data.models.rest.RestProduct;
import ms.itsecteam.warpdrink.data.models.rest.RestUser;
......@@ -52,6 +54,18 @@ public class SQLiteService {
return ret_val;
}
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);
}
Log.d("App", Arrays.toString(c.toArray()));
return ret_val;
}
public List<Product> refreshProductData(List<RestProduct> body) {
Product.deleteAll();
List<Product> ret_val = new ArrayList<>();
......
package ms.itsecteam.warpdrink.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.util.List;
@Table(name = "Category")
public class Category extends Model {
@Column(name = "cid")
private int cid;
@Column(name = "name")
private String name;
public Category() {
super();
}
public Category(int cid, String name) {
this.cid = cid;
this.name = name;
}
public int getCid() {
return cid;
}
public void setCid(int pid) {
this.cid = cid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static List<Category> getAll() {
return new Select()
.from(Category.class)
.execute();
}
public static void deleteAll() {
new Delete().from(Category.class).execute();
}
public String toString() {
return this.name;
}
}
package ms.itsecteam.warpdrink.data.models.local;
import android.util.Log;
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
......@@ -89,7 +91,21 @@ public class Product extends Model {
}
public String toString() {
return this.name;
return this.name + " " + this.category;
}
public static List<Product> getByCategory(String category) {
Log.d("APP", category);
return new Select()
.from(Product.class)
.where("category = ?", category)
.execute();
}
public static Product getOneByName(String product_name) {
return new Select()
.from(Product.class)
.where("name = ?", product_name)
.executeSingle();
}
}
package ms.itsecteam.warpdrink.data.models.rest;
import ms.itsecteam.warpdrink.data.models.local.Category;
public class RestCategory {
private int id;
private String name;
public RestCategory() {
super();
}
public RestCategory(int id, String name) {
this.id = id;
this.name = name;
}
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 Category toLocalCategory() {
Category c = new Category();
c.setCid(this.id);
c.setName(this.name);
return c;
}
public static RestCategory fromLocalrestCategory(Category category) {
RestCategory restCategory = new RestCategory();
restCategory.setId(category.getCid());
restCategory.setName(category.getName());
return restCategory;
}
}
package ms.itsecteam.warpdrink.dialogs;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.GridLayout;
import java.util.List;
import ms.itsecteam.warpdrink.MainActivity;
import ms.itsecteam.warpdrink.R;
import ms.itsecteam.warpdrink.data.models.local.Product;
import ms.itsecteam.warpdrink.manager.MainManager;
import ms.itsecteam.warpdrink.manager.UiManager;
import ms.itsecteam.warpdrink.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.setText(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.setText("");
btn.setEnabled(false);
this.gridProducts.addView(btn);
}
}
@Override
public void onClick(View view) {
Button clicked = (Button) view;
String product_name = (String) clicked.getText();
Product product = Product.getOneByName(product_name);
Order order = new Order(product);
UiManager.getInstance().addOrder(order);
MainManager.getInstance().addOrder(order);
dismiss();
}
}
package ms.itsecteam.warpdrink.listener;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import ms.itsecteam.warpdrink.dialogs.ProductDialog;
import ms.itsecteam.warpdrink.manager.UiManager;
public class CategoryOnClickListener implements View.OnClickListener {
@Override
public void onClick(View view) {
Button clicked = (Button) view;
String category = (String) clicked.getText();
new ProductDialog(category).show();
}
}
......@@ -3,15 +3,15 @@ package ms.itsecteam.warpdrink.manager;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;
import java.util.List;
import ms.itsecteam.warpdrink.MainActivity;
import ms.itsecteam.warpdrink.R;
import ms.itsecteam.warpdrink.data.SQLiteService;
import ms.itsecteam.warpdrink.data.models.local.Product;
import ms.itsecteam.warpdrink.data.models.local.Category;
import ms.itsecteam.warpdrink.data.models.local.User;
import ms.itsecteam.warpdrink.data.RestService;
import ms.itsecteam.warpdrink.data.models.rest.RestCategory;
import ms.itsecteam.warpdrink.data.models.rest.RestProduct;
import ms.itsecteam.warpdrink.data.models.rest.RestTransaction;
import ms.itsecteam.warpdrink.data.models.rest.RestUser;
......@@ -78,6 +78,22 @@ public class MainManager {
}
});
this.restService.getAllCategories().enqueue(new Callback<List<RestCategory>>() {
@Override
public void onResponse(Response<List<RestCategory>> response, Retrofit retrofit) {
List<Category> categoryList = MainManager.getInstance().sqLiteService.refreshCategoryData(response.body());
if (categoryList != null) {
MainManager.getInstance().uiManager.showCategoryButtons();
}
Toast.makeText(MainManager.getInstance().mainActivity, "Refresh successful", Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Throwable t) {
Log.d("REST", t.getMessage());
}
});
this.restService.getAllProducts().enqueue(new Callback<List<RestProduct>>() {
@Override
public void onResponse(Response<List<RestProduct>> response, Retrofit retrofit) {
......
package ms.itsecteam.warpdrink.manager;
import android.annotation.TargetApi;
import android.os.Build;
import android.text.Editable;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
......@@ -8,6 +11,8 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
......@@ -17,10 +22,12 @@ import java.util.List;
import ms.itsecteam.warpdrink.MainActivity;
import ms.itsecteam.warpdrink.R;
import ms.itsecteam.warpdrink.data.models.local.Category;
import ms.itsecteam.warpdrink.data.models.local.Product;
import ms.itsecteam.warpdrink.data.models.local.User;
import ms.itsecteam.warpdrink.dialogs.ChargeDialog;
import ms.itsecteam.warpdrink.dialogs.NewUserDialog;
import ms.itsecteam.warpdrink.listener.CategoryOnClickListener;
import ms.itsecteam.warpdrink.orderList.ListViewAdapter;
import ms.itsecteam.warpdrink.orderList.ListViewAdapterProducts;
import ms.itsecteam.warpdrink.orderList.Order;
......@@ -32,7 +39,8 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
private ImageButton btnRefresh;
private TextView txtSum,txtCredit;
private ListView lstOrdered;
private ListView lstProduct;
private GridLayout gridProducts;
private EditText txtBarcode;
private AutoCompleteTextView atxvName;
private ListViewAdapter lstOrderedAdapter;
......@@ -49,6 +57,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
private UiManager() {}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void initUi(MainActivity mainActivity) {
this.txtSum = (TextView) mainActivity.findViewById(R.id.txtSum);
this.txtCredit = (TextView)mainActivity.findViewById(R.id.txtCredit);
......@@ -60,15 +69,15 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
this.btnPay = (Button) mainActivity.findViewById(R.id.btnPay);
this.btnCharge = (Button) mainActivity.findViewById(R.id.btnCharge);
this.txtBarcode = (EditText) mainActivity.findViewById(R.id.txtBarcode);
this.txtBarcode.setShowSoftInputOnFocus(false);
this.txtBarcode.setOnKeyListener(this);
this.lstOrderedAdapter = new ListViewAdapter(mainActivity, R.layout.order_list_item, new ArrayList<Order>());
this.lstProductAdapter = new ListViewAdapterProducts(mainActivity, R.layout.product_list_item, Product.getAll());
this.lstOrdered = (ListView) mainActivity.findViewById(R.id.lstOrdered);
this.lstOrdered.setAdapter(this.lstOrderedAdapter);
this.lstProduct = (ListView) mainActivity.findViewById(R.id.lstProduct);
this.lstProduct.setAdapter(this.lstProductAdapter);
this.lstProduct.setOnItemClickListener(this);
this.users = User.getAll();
this.atxvAdapter = new ArrayAdapter(mainActivity, android.R.layout.select_dialog_item, this.users);
this.atxvName = (AutoCompleteTextView) mainActivity.findViewById(R.id.atxvName);
......@@ -79,6 +88,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
this.atxvName.setFocusableInTouchMode(true);
this.atxvName.setFocusable(true);
this.gridProducts = (GridLayout) mainActivity.findViewById(R.id.gridProducts);
this.btnLogout.setVisibility(View.INVISIBLE);
this.enableControls(false);
this.mainActivity = mainActivity;
......@@ -112,12 +122,12 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
}
private void enableControls(boolean enable) {
this.txtBarcode.requestFocus();
this.atxvName.setEnabled(!enable);
this.btnRefresh.setEnabled(!enable);
this.btnCharge.setEnabled(enable);
this.btnPay.setEnabled(enable);
this.btnLogout.setEnabled(enable);
this.lstProduct.setEnabled(enable);
}
protected void refreshUserData(List<User> userList) {
......@@ -137,16 +147,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
@Override
public void onClick(View v) {
Log.d("HALLO", Integer.toString(v.getId()));
switch (v.getId()) {
/* case R.id.btnOneEuro:
this.lstOrderedAdapter.insert(new Order(1.0), this.lstOrderedAdapter.getCount());
MainManager.getInstance().addOrder(1.0);
break;
case R.id.btnFiftyCent:
this.lstOrderedAdapter.insert(new Order(0.5), this.lstOrderedAdapter.getCount());
MainManager.getInstance().addOrder(0.5);
break;*/
case R.id.btnCharge:
new ChargeDialog().show();
break;
......@@ -164,33 +165,57 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
break;
}
}
// @ToDo: Key handling für beide Fälle (BarCode und Username)
// @ToDo: Tastatur spinnt noch rum
@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) {
MainManager.getInstance().setCurrentUser((User) this.atxvAdapter.getItem(0));
this.atxvName.setText(this.atxvAdapter.getItem(0).toString());
this.atxvName.dismissDropDown();
Log.d("APP", String.valueOf(v.getId())+" "+R.id.txtUsername);
if(v.getId() == R.id.txtBarcode) {
Log.d("APP", this.txtBarcode.getText().toString());
} else if (v.getId() == R.id.txtUsername) {
if (this.atxvAdapter.getCount() == 1) {
MainManager.getInstance().setCurrentUser((User) this.atxvAdapter.getItem(0));
this.atxvName.setText(this.atxvAdapter.getItem(0).toString());
this.atxvName.dismissDropDown();
}
return true;
}
return true;
}
return false;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (parent.getId()) {
case R.id.lstProduct:
Product p = this.lstProductAdapter.getItem(position);
Order order = new Order(p);
this.lstOrderedAdapter.insert(new Order(p), this.lstOrderedAdapter.getCount());
MainManager.getInstance().addOrder(order);
break;
case -1:
MainManager.getInstance().setCurrentUser((User) this.atxvAdapter.getItem(position));
break;
}
}
public void showCategoryButtons() {
List<Category> categoryList = Category.getAll();
this.gridProducts.removeAllViews();
for (Category c: categoryList) {
Button catButton = new Button(this.mainActivity.getApplicationContext());
catButton.setText(c.getName());
catButton.setHeight(120);
catButton.setWidth(150);
catButton.setOnClickListener(new CategoryOnClickListener());
this.gridProducts.addView(catButton);
}
for (int i=categoryList.size();i<12;i++) {
Button btn = new Button(this.mainActivity.getApplicationContext());
btn.setHeight(120);
btn.setWidth(150);
btn.setText("");
btn.setEnabled(false);
this.gridProducts.addView(btn);
}
}
public void addOrder(Order order) {
this.lstOrderedAdapter.insert(order, this.lstOrderedAdapter.getCount());
}
}
......@@ -36,7 +36,7 @@ public class ListViewAdapter extends ArrayAdapter<Order> {
holder = new OrderHolder();
holder.order = items.get(position);
holder.btnRemoveOrder = (ImageButton)row.findViewById(R.id.btnRemoveOrder);
holder.btnRemoveOrder = (ImageButton) row.findViewById(R.id.btnRemoveOrder);
holder.btnRemoveOrder.setTag(holder.order);
holder.value = (TextView)row.findViewById(R.id.txtOrderValue);
......
......@@ -67,13 +67,15 @@
android:layout_column="1"
android:layout_row="2" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lstProduct"
android:layout_row="2"
android:layout_column="12"
android:choiceMode="singleChoice" />
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:columnCount="4"
android:orientation="horizontal"
android:id="@+id/gridProducts"
android:rowCount="3">
</GridLayout>
<Space
android:layout_width="20px"
......@@ -184,6 +186,11 @@
android:onClick="onClick"
android:layout_height="wrap_content" />