App schneller

App wurde schneller durch Optimierung der Datenbankabfragen und durch besseres Object Handling
This commit is contained in:
Georg Reisinger 2019-02-18 19:31:42 +01:00
parent 24f55b60c8
commit 6a0649b9ab
23 changed files with 493 additions and 324 deletions

Binary file not shown.

View File

@ -36,23 +36,30 @@ import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.gson.JsonSerializer;
import com.squareup.picasso.Picasso;
import org.json.JSONException;
import org.w3c.dom.Text;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Base64;
import java.util.List;
import at.smartshopper.smartshopper.customViews.SpaceItemDecoration;
import at.smartshopper.smartshopper.db.Database;
import at.smartshopper.smartshopper.shoppinglist.Shoppinglist;
import at.smartshopper.smartshopper.shoppinglist.ShoppinglistAdapter;
public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnItemClicked, ShoppinglistAdapter.OnChangeItemClick, ShoppinglistAdapter.OnShareClick {
public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnItemClicked, ShoppinglistAdapter.OnShoppinglistClick, ShoppinglistAdapter.OnChangeItemClick, ShoppinglistAdapter.OnShareClick {
private Database db = new Database();
private final Database db = new Database();
private SwipeRefreshLayout ownswiperefresh, sharedswiperefresh;
private FloatingActionButton addShoppinglistFab;
private PopupWindow popupWindowAdd, popupShare, popupAddShare;
@ -336,10 +343,11 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte
sharedRecycler.setHasFixedSize(true);
sharedRecycler.setLayoutManager(new LinearLayoutManager(this));
List<Shoppinglist> ownListsList = db.getSharedShoppinglists(uid);
ShoppinglistAdapter shpAdapter = new ShoppinglistAdapter(Dash.this, ownListsList);
ShoppinglistAdapter shpAdapter = new ShoppinglistAdapter(Dash.this, ownListsList, db);
shpAdapter.setOnDelClick(Dash.this);
shpAdapter.setOnChangeClick(Dash.this);
shpAdapter.setOnShareClick(Dash.this);
shpAdapter.setOnShoppinglistClick(Dash.this);
sharedRecycler.setAdapter(shpAdapter);
}
@ -354,10 +362,12 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte
ownRecycleView.setHasFixedSize(true);
ownRecycleView.setLayoutManager(new LinearLayoutManager(this));
List<Shoppinglist> ownListsList = db.getMyShoppinglists(uid);
ShoppinglistAdapter shpAdapter = new ShoppinglistAdapter(Dash.this, ownListsList);
ShoppinglistAdapter shpAdapter = new ShoppinglistAdapter(Dash.this, ownListsList, db);
shpAdapter.setOnDelClick(Dash.this);
shpAdapter.setOnChangeClick(Dash.this);
shpAdapter.setOnShareClick(Dash.this);
shpAdapter.setOnShoppinglistClick(Dash.this);
ownRecycleView.setAdapter(shpAdapter);
}
@ -646,4 +656,13 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte
popupShare.showAtLocation(v, Gravity.CENTER, 0, 0);
popupShare.update();
}
@Override
public void onShoppinglistClick(String sl_id, View v) {
Intent intent = new Intent(this, ShoppinglistDetails.class);
intent.putExtra("sl_id", sl_id);
startActivity(intent);
}
}

View File

@ -27,18 +27,20 @@ import java.sql.SQLException;
import java.util.List;
import at.smartshopper.smartshopper.R;
import at.smartshopper.smartshopper.customViews.SpaceItemDecoration;
import at.smartshopper.smartshopper.db.Database;
import at.smartshopper.smartshopper.shoppinglist.details.item.Item;
import at.smartshopper.smartshopper.shoppinglist.details.item.ItemAdapter;
public class ItemListActivity extends Activity implements ItemAdapter.OnItemEditClicked, ItemAdapter.OnItemDelClicked {
public class ItemListActivity extends Activity implements ItemAdapter.OnItemEditClicked, ItemAdapter.OnItemDelClicked, ItemAdapter.OnItemCheckClicked {
private String group_id, groupNameString;
private String sl_id;
private PopupWindow popupWindowItem;
private FloatingActionButton fabAddItem;
private TextView groupName;
private String colorString;
private Database db = new Database();
private Database db;
private View colorView;
private SwipeRefreshLayout swipeRefreshLayoutItem;
@ -52,6 +54,7 @@ public class ItemListActivity extends Activity implements ItemAdapter.OnItemEdit
this.group_id = myIntent.getStringExtra("group_id"); // will return "FirstKeyValue"
this.sl_id = myIntent.getStringExtra("sl_id"); // will return "SecondKeyValue"
this.groupNameString = myIntent.getStringExtra("groupNameString"); // will return "SecondKeyValue"
this.db = new Database();
this.groupName = (TextView)findViewById(R.id.groupViewName);
this.groupName.setText(groupNameString);
@ -110,14 +113,16 @@ public class ItemListActivity extends Activity implements ItemAdapter.OnItemEdit
private void showItems(String group_id, String sl_id) throws SQLException, JSONException {
RecyclerView itemsListRecycler = findViewById(R.id.itemsListRecycler);
int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.item_spacing);
itemsListRecycler.addItemDecoration(new SpaceItemDecoration(spacingInPixels));
itemsListRecycler.setHasFixedSize(true);
itemsListRecycler.setLayoutManager(new LinearLayoutManager(this));
List<Item> itemList = new Database().getItemsOfGroup(group_id, sl_id);
List<Item> itemList = db.getItemsOfGroup(group_id, sl_id);
ItemAdapter itemAdapter = new ItemAdapter(itemList);
itemAdapter.setOnItemEditClick(this);
itemAdapter.setItemDelClick(this);
itemAdapter.setOnItemCheckClick(this);
itemsListRecycler.setAdapter(itemAdapter);
}
@ -229,9 +234,24 @@ public class ItemListActivity extends Activity implements ItemAdapter.OnItemEdit
popupWindowItem.setOutsideTouchable(false);
popupWindowItem.setFocusable(true);
popupWindowItem.setAnimationStyle(R.style.popup_window_animation_phone);
popupWindowItem.showAtLocation(v, Gravity.CENTER, 0, 0);
popupWindowItem.update();
}
@Override
public void onItemCheckClicked(String uid, String name, String itemId, String groupId, String sl_id, int count) {
try {
swipeRefreshLayoutItem.setRefreshing(true);
db.setDoneItem(uid, name, itemId, groupId, sl_id, count);
showItems(group_id, sl_id);
swipeRefreshLayoutItem.setRefreshing(false);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
}

View File

@ -20,12 +20,19 @@ import android.widget.PopupWindow;
import android.widget.TextView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.squareup.picasso.Picasso;
import org.json.JSONException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import at.smartshopper.smartshopper.R;
import at.smartshopper.smartshopper.customViews.SpaceItemDecoration;
import at.smartshopper.smartshopper.db.Database;
import at.smartshopper.smartshopper.shoppinglist.Shoppinglist;
import at.smartshopper.smartshopper.shoppinglist.details.Details;
@ -34,11 +41,10 @@ import at.smartshopper.smartshopper.shoppinglist.details.group.Group;
public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGroupEditClicked, DetailsAdapter.OnGroupDeleteClicked, DetailsAdapter.OnCardClicked {
private Database db = new Database();
private Database db;
private FloatingActionButton fab;
private String colorString;
private PopupWindow popupWindow;
private PopupWindow popupWindowItem;
private Button colorBtn;
private SwipeRefreshLayout detailsSwiperefresh;
@ -47,14 +53,11 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shoppinglist_details);
fab = findViewById(R.id.addGroupFab);
db = new Database();
colorBtn = (Button) findViewById(R.id.groupColor);
Bundle bundle = getIntent().getExtras();
String sl_id = null; // or other values
if (bundle != null)
sl_id = bundle.getString("sl_id");
Intent intent = getIntent();
String sl_id = intent.getStringExtra("sl_id");
//Toast.makeText(this, "Click detected on item " + position, Toast.LENGTH_LONG).show();
try {
Shoppinglist shoppinglist = db.getShoppinglist(sl_id);
@ -105,6 +108,7 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
}
/**
* Zeigt ein Popup zum bearbeiten und erstellen von groups
* Wenn from db true ist wird die groupid benötigt
@ -201,6 +205,8 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
popupWindow.setOutsideTouchable(false);
popupWindow.setFocusable(true);
popupWindow.setAnimationStyle(R.style.popup_window_animation_phone);
popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);
popupWindow.update();
@ -249,12 +255,14 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
*/
private void showDetails(String sl_id) throws SQLException, JSONException {
RecyclerView detailsRecycleView = (RecyclerView) findViewById(R.id.groupRecycle);
int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.item_spacing);
detailsRecycleView.addItemDecoration(new SpaceItemDecoration(spacingInPixels));
detailsRecycleView.setHasFixedSize(true);
detailsRecycleView.setLayoutManager(new LinearLayoutManager(this));
List<Details> detailsList = db.getListDetails(sl_id);
List<Details> detailsList = db.getListDetails(sl_id);
DetailsAdapter detailsAdapter = new DetailsAdapter(detailsList);
DetailsAdapter detailsAdapter = new DetailsAdapter(detailsList, db);
detailsAdapter.setGroupEditClick(this);
detailsAdapter.setGroupDeleteClick(this);
detailsAdapter.setCardClick(this);

View File

@ -0,0 +1,29 @@
package at.smartshopper.smartshopper.customViews;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
private int space;
public SpaceItemDecoration(int space) {
this.space = space;
}
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
outRect.left = space;
outRect.right = space;
outRect.bottom = space;
//Add top margin only for the first item to avoid double space between items
if (parent.getChildLayoutPosition(view) == 0) {
outRect.top = space;
} else {
outRect.top = 0;
}
}
}

View File

@ -3,17 +3,25 @@ package at.smartshopper.smartshopper.db;
import android.os.StrictMode;
import android.util.Log;
import com.google.firebase.auth.FirebaseAuth;
import com.google.gson.JsonSerializer;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import at.smartshopper.smartshopper.shoppinglist.Member;
import at.smartshopper.smartshopper.shoppinglist.Shoppinglist;
import at.smartshopper.smartshopper.shoppinglist.details.Details;
import at.smartshopper.smartshopper.shoppinglist.details.group.Group;
@ -21,18 +29,28 @@ import at.smartshopper.smartshopper.shoppinglist.details.item.Item;
public class Database {
private Connection conect;
final String HOST = "188.166.124.80";
final String DB_NAME = "smartshopperdb";
final String USERNAME = "smartshopper-user";
final String PASSWORD = "jW^v#&LjNY_b3-k*jYj!U4Xz?T??m_D6249XAeWZ#7C^FRbKm!c_Dt+qj@4&a-Hs";
final int PORT = 5432;
private transient Connection conect;
final private String HOST = "188.166.124.80";
final private String DB_NAME = "smartshopperdb";
final private String USERNAME = "smartshopper-user";
final private String PASSWORD = "jW^v#&LjNY_b3-k*jYj!U4Xz?T??m_D6249XAeWZ#7C^FRbKm!c_Dt+qj@4&a-Hs";
final private int PORT = 5432;
final private int sl_idLength = 10;
final private int groupIdLength = 10;
final private int itemIdLength = 10;
final private int inviteLength = 50;
/**
* Macht nix
*/
public Database() {
try {
connectDatabase();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
@ -49,8 +67,60 @@ public class Database {
System.out.println("Database connected!");
}
/**
* Setzt ein Item auf erledigt indem es in Done items verschoben wird
*
* @param uid Die User id, von dem das item geändert werden soll
* @param name Der name des Items
* @param count Die Anzahl des Items
* @throws SQLException
*/
public void setDoneItem(String uid, String name, String item_id, String groupId, String sl_id, int count) throws SQLException, JSONException {
java.sql.Date date = new java.sql.Date(new java.util.Date().getDate());
List<Member> members = getMembers(sl_id);
Member admin = getAdmin(sl_id);
sqlUpdate5ParamLastIsDateAndInt("INSERT INTO \"Done_Purchase\" (purchased_item_id, username, name, count, date) VALUES(?,?,?,?,?)", generateItemId(), admin.getUid(), name, count, date);
for (int i = 0; i < members.size(); i++) {
sqlUpdate5ParamLastIsDateAndInt("INSERT INTO \"Done_Purchase\" (purchased_item_id, username, name, count, date) VALUES(?,?,?,?,?)", generateItemId(), members.get(i).getUid(), name, count, date);
}
sqlUpdate3Param("DELETE FROM \"Item\" WHERE item_id = ? AND group_id = ? AND sl_id = ?", item_id, groupId, sl_id);
}
/**
* Holt den Admin einer Shoppingliste
*
* @param sl_id Die Shoppingliste von welcher der Admin gewünscht ist
* @return Member Objekt das mit den Daten des Admins gefüllt ist
* @throws SQLException
* @throws JSONException
*/
public Member getAdmin(String sl_id) throws SQLException, JSONException {
String SQL = "SELECT row_to_json(\"User\") as obj FROM \"User\" JOIN \"Shoppinglist_member\" USING (username) WHERE sl_id = ?";
JSONObject jsonObject = new JSONObject(executeQuery(SQL, sl_id));
return new Member(jsonObject.getString("username"), jsonObject.getString("message_id"));
}
/**
* Holt alle mitglieder einer Shoppingliste
*
* @param sl_id Die Shoppingliste von der die Mitglieder gefragt sind
* @throws SQLException
*/
public List<Member> getMembers(String sl_id) throws SQLException, JSONException {
String SQL = "SELECT row_to_json(\"User\") as obj FROM \"User\" JOIN \"Shoppinglist_member\" USING (username) WHERE sl_id = ?";
ArrayList<Member> members = new ArrayList();
List<JSONObject> jsonObjects = executeQueryJSONObject(SQL, sl_id);
for(int i = 0; i < jsonObjects.size(); i++){
JSONObject jsonObject = jsonObjects.get(i);
members.add(new Member(jsonObject.getString("username"), jsonObject.getString("message_id")));
}
return members;
}
/**
* Entfernt einen invitelink anhand des invitelinks
*
* @param invitelink Löscht den invitelink aus der ganzen db
* @throws SQLException
* @throws JSONException
@ -63,70 +133,56 @@ public class Database {
/**
* Gibt den Invite link einer Shoppingliste zurück, wenn keiner vorhanden ist --> null
*
* @param sl_id Die shoppinglist von der der invitelimnk gefragt ist
* @return Der invite link
* @throws SQLException
* @throws JSONException
*/
public String getInviteLink(String sl_id) throws SQLException, JSONException{
connectDatabase();
public String getInviteLink(String sl_id) throws SQLException, JSONException {
String SQL = "Select invitelink from \"Shoppinglist\" WHERE sl_id = ?";
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, sl_id);
ResultSet rs = pstmt.executeQuery();
rs.next();
String returnLink = rs.getString(1);
String returnLink = executeQuery(SQL, sl_id);
return returnLink;
}
/**
* Sucht anhand des invitelinks eine Shoppingliste und gibt dessen sl_id zurück
*
* @param invitelink Der invitelink nach dem gesucht werden soll
* @return Die sl_id die dem invitelink zugeordnet ist
* @throws SQLException
* @throws JSONException
*/
private String getSlIdFromInvite(String invitelink) throws SQLException, JSONException{
connectDatabase();
private String getSlIdFromInvite(String invitelink) throws SQLException, JSONException {
String SQL = "Select sl_id from \"Shoppinglist\" WHERE invitelink = ?";
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, invitelink);
ResultSet rs = pstmt.executeQuery();
rs.next();
String returnSl_id = rs.getString(1);
String returnSl_id = executeQuery(SQL, invitelink);
return returnSl_id;
}
/**
* Fügt einen invite link zu den shoppinglisten hinzu
*
* @param invitelink Der invite link der hinzugefügt werden soll
* @param uid Der user zu dem der invitelink hinzugefügt werden soll
* @param uid Der user zu dem der invitelink hinzugefügt werden soll
* @throws SQLException
* @throws JSONException
*/
public void addInviteLink(String invitelink, String uid) throws SQLException, JSONException {
String sl_id = getSlIdFromInvite(invitelink);
if(!sl_id.equals("null")){
if (!sl_id.equals("null")) {
sqlUpdate2Param("INSERT INTO \"Shoppinglist_member\" (username, sl_id) VALUES (?, ?)", uid, sl_id);
}
}
/**
* Erstellt einen neuen InviteLink
*
* @param sl_id
* @return Der neue InviteLink
* @throws SQLException
*/
public String createInviteLink(String sl_id) throws SQLException{
public String createInviteLink(String sl_id) throws SQLException {
String invitelink = generateInviteLink();
sqlUpdate2Param("UPDATE \"Shoppinglist\" SET invitelink = ? WHERE sl_id = ?", invitelink, sl_id);
return invitelink;
@ -134,32 +190,24 @@ public class Database {
/**
* Wenn die Shoppingliste bereits geshared ist wird true zurückgegeben
*
* @param sl_id Die Liste die geprüft werden soll
* @return True wenn die liste bereits geshared ist
* @throws SQLException
* @throws JSONException
*/
public boolean isShared(String sl_id) throws SQLException, JSONException {
connectDatabase();
String SQL = "SELECT row_to_json(\"Shoppinglist\") AS obj FROM \"Shoppinglist\" WHERE sl_id = ?";
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, sl_id);
ResultSet rs = pstmt.executeQuery();
boolean returnBoolean = false;
while(rs.next()){
JSONObject jsonObject = new JSONObject(rs.getString(1));
Log.d("isShared LOG ", jsonObject.getString("invitelink"));
if(jsonObject.getString("invitelink").equals("null")){
List<JSONObject> jsonObjects = executeQueryJSONObject(SQL, sl_id);
for(int i = 0; i < jsonObjects.size(); i++){
JSONObject jsonObject = jsonObjects.get(i);
if (jsonObject.getString("invitelink").equals("null")) {
returnBoolean = false;
}else{
} else {
returnBoolean = true;
}
}
return returnBoolean;
}
@ -177,19 +225,13 @@ public class Database {
/**
* Gibt den Besitzer einer Shoppingliste zurück
*
* @param sl_id Shoppingliste von der der Besitzer gefunden werden soll
* @return Die uid des Besitzers
*/
public String getShoppinglistOwner(String sl_id) throws SQLException {
connectDatabase();
String SQL = "Select username from \"Shoppinglist_admin\" WHERE sl_id = ?";
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, sl_id);
ResultSet rs = pstmt.executeQuery();
String owner = rs.getString(1);
String owner = executeQuery(SQL, sl_id);
return owner;
}
@ -297,16 +339,7 @@ public class Database {
*/
public Item getItem(String item_id) throws SQLException, JSONException {
String SQL = "SELECT row_to_json(\"Item\") AS obj FROM \"Item\" JOIN \"Group\" USING (group_id) WHERE item_id = ?";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, item_id);
ResultSet rs = pstmt.executeQuery();
rs.next();
String resultString = rs.getString(1);
JSONObject jsonObject = new JSONObject(resultString);
JSONObject jsonObject = new JSONObject(executeQuery(SQL, item_id));
return new Item(generateItemId(), jsonObject.getString("group_id"), jsonObject.getString("sl_id"), jsonObject.getString("name"), jsonObject.getString("count"));
}
@ -320,17 +353,7 @@ public class Database {
*/
public Group getGroup(String group_id, String sl_id) throws SQLException, JSONException {
String SQL = "SELECT row_to_json(\"Group\") AS obj FROM \"Group\" WHERE group_id = ? AND sl_id = ?";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
System.out.println(sl_id);
pstmt.setString(1, group_id);
pstmt.setString(2, sl_id);
ResultSet rs = pstmt.executeQuery();
rs.next();
String resultString = rs.getString(1);
JSONObject jsonObject = new JSONObject(resultString);
JSONObject jsonObject = new JSONObject(executeQuery2Param(SQL, group_id, sl_id));
return new Group(jsonObject.getString("group_id"), jsonObject.getString("sl_id"), jsonObject.getString("name"), jsonObject.getString("color"), jsonObject.getString("hidden"));
}
@ -357,8 +380,8 @@ public class Database {
* @param color Farbe der Shoppingliste
* @throws SQLException
*/
public void addShoppinglist(String name, String description, String username, String color) throws SQLException {
String sl_id = generateSL_Id();
public void addShoppinglist(String name, String description, String username, String color) throws SQLException, JSONException {
String sl_id = generateSL_Id(sl_idLength);
if (!checkIfUserExists(username)) {
createUser(username);
}
@ -376,11 +399,7 @@ public class Database {
*/
private void createAdmin(String sl_id, String username) throws SQLException {
String SQL = "INSERT INTO \"Shoppinglist_admin\" (username, sl_id) VALUES (?, ?)";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, username);
pstmt.setString(2, sl_id);
pstmt.executeUpdate();
sqlUpdate2Param(SQL, username, sl_id);
}
/**
@ -394,13 +413,7 @@ public class Database {
*/
private void createShoppinglist(String sl_id, String name, String description, String color) throws SQLException {
String SQL = "INSERT INTO \"Shoppinglist\" (sl_id, name, description, color) VALUES (?, ?, ?, ?)";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, sl_id);
pstmt.setString(2, name);
pstmt.setString(3, description);
pstmt.setString(4, color);
pstmt.executeUpdate();
sqlUpdate4Param(SQL, sl_id, name, description, color);
}
/**
@ -411,11 +424,7 @@ public class Database {
*/
private void createUser(String username) throws SQLException {
String SQL = "INSERT INTO \"User\" (username) VALUES (?)";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, username);
pstmt.executeUpdate();
sqlUpdate(SQL, username);
}
/**
@ -425,14 +434,14 @@ public class Database {
* @return True wenn User existiert, False wenn nicht
* @throws SQLException
*/
private boolean checkIfUserExists(String username) throws SQLException {
private boolean checkIfUserExists(String username) throws SQLException, JSONException {
String SQL = "SELECT username FROM \"User\"";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
ResultSet rs = pstmt.executeQuery();
ArrayList<String> outUserList = new ArrayList<String>();
while (rs.next()) {
outUserList.add(rs.getString(1));
List<JSONObject> jsonObjects = executeQueryJSONObject(SQL, username);
for (int i = 0; i < jsonObjects.size(); i++) {
JSONObject jsonObject = jsonObjects.get(i);
outUserList.add(jsonObject.getString("username"));
}
if (outUserList.contains(username)) {
@ -440,8 +449,6 @@ public class Database {
} else {
return false;
}
}
/**
@ -454,64 +461,36 @@ public class Database {
* @throws SQLException Ein PostgreSQL Fehler
*/
public List<Shoppinglist> getMyShoppinglists(String uid) throws JSONException, SQLException {
String SQL = "SELECT row_to_json(\"Shoppinglist\") AS obj FROM \"Shoppinglist\" JOIN \"Shoppinglist_admin\" USING (sl_id) WHERE username = ?";
connectDatabase();
final String SQL = "SELECT row_to_json(\"Shoppinglist\") AS obj FROM \"Shoppinglist\" JOIN \"Shoppinglist_admin\" USING (sl_id) WHERE username = ?";
ArrayList<Shoppinglist> shoppinglistsList = new ArrayList<Shoppinglist>();
ResultSet rs = null;
try (PreparedStatement pstmt = conect.prepareStatement(SQL)) {
pstmt.setString(1, uid);
rs = pstmt.executeQuery();
System.out.println(uid);
while (rs.next()) {
String shoppinglist = rs.getString(1);
JSONObject jsonObject = new JSONObject(shoppinglist);
shoppinglistsList.add(new Shoppinglist(jsonObject.getString("sl_id"), jsonObject.getString("name"), jsonObject.getString("description"), jsonObject.getString("invitelink"), jsonObject.getString("color")));
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
List<JSONObject> jsonObjects = executeQueryJSONObject(SQL, uid);
for (int i = 0; i < jsonObjects.size(); i++) {
JSONObject jsonObject = jsonObjects.get(i);
shoppinglistsList.add(new Shoppinglist(jsonObject.getString("sl_id"), jsonObject.getString("name"), jsonObject.getString("description"), jsonObject.getString("invitelink"), jsonObject.getString("color")));
}
Log.d("DATABASE SHOPPINGLISTS", shoppinglistsList.toString());
return (List<Shoppinglist>) shoppinglistsList;
return shoppinglistsList;
}
/**
* Verbindet sich mit dem server
* Holt alle shared shoppinglists des users
*
* @param uid User von dem die Shared Shoppinglists geholt werden sollen
* @return Die Shared Shoppinglisten des Users
* @throws SQLException
* @throws JSONException
*/
public List<Shoppinglist> getSharedShoppinglists(String uid) throws SQLException, JSONException {
connectDatabase();
String SQL = "SELECT row_to_json(\"Shoppinglist\") AS obj FROM \"Shoppinglist\" JOIN \"Shoppinglist_member\" USING (sl_id) WHERE username = ?";
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, uid);
ResultSet rs = pstmt.executeQuery();
System.out.println(uid);
final String SQL = "SELECT row_to_json(\"Shoppinglist\") AS obj FROM \"Shoppinglist\" JOIN \"Shoppinglist_member\" USING (sl_id) WHERE username = ?";
ArrayList<Shoppinglist> shoppinglistArrayList = new ArrayList<Shoppinglist>();
while(rs.next()){
String shoppinglist = rs.getString(1);
JSONObject jsonObject = new JSONObject(shoppinglist);
List<JSONObject> jsonObjects = executeQueryJSONObject(SQL, uid);
for (int i = 0; i < jsonObjects.size(); i++) {
JSONObject jsonObject = jsonObjects.get(i);
shoppinglistArrayList.add(new Shoppinglist(jsonObject.getString("sl_id"), jsonObject.getString("name"), jsonObject.getString("description"), jsonObject.getString("invitelink"), jsonObject.getString("color")));
}
return (List<Shoppinglist>) shoppinglistArrayList;
return shoppinglistArrayList;
}
@ -540,7 +519,7 @@ public class Database {
detailsArrayList.add(detailsTmp);
}
return (List<Details>) detailsArrayList;
return detailsArrayList;
}
@ -573,11 +552,11 @@ public class Database {
*
* @return Neue Sl_id
*/
private String generateSL_Id() {
private String generateSL_Id(int length) {
String possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
String output = "";
for (int i = 0; i < 8; i++) {
for (int i = 0; i < length; i++) {
output += possible.charAt((int) Math.floor(Math.random() * possible.length()));
}
@ -592,7 +571,7 @@ public class Database {
* @return Neue group_id
*/
private String generateGroupId() {
return generateSL_Id();
return generateSL_Id(groupIdLength);
}
/**
@ -601,7 +580,7 @@ public class Database {
* @return Neue item_id
*/
public String generateItemId() {
return generateSL_Id();
return generateSL_Id(itemIdLength);
}
/**
@ -610,10 +589,33 @@ public class Database {
* @return Neue intielink
*/
public String generateInviteLink() {
return generateSL_Id();
return generateSL_Id(inviteLength);
}
/**
* Holt alle erledigten Items eines Users
*
* @return Die erledigten Items in eines Users
* @throws SQLException
* @throws JSONException
*/
public List<Item> getDoneItems() throws SQLException, JSONException {
final String SQL = "SELECT row_to_json(\"Done_Purchase\") AS obj FROM \"Done_Purchase\" WHERE username = ?";
final String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
ArrayList<Item> listItems = new ArrayList<Item>();
List<JSONObject> jsonObjects = executeQueryJSONObject(SQL, uid);
for (int i = 0; i < jsonObjects.size(); i++) {
JSONObject jsonObject = jsonObjects.get(i);
String itemId = jsonObject.getString("purchased_item_id");
String name = jsonObject.getString("name");
String count = jsonObject.getInt("count") + "";
listItems.add(new Item(itemId, null, null, name, count));
}
return listItems;
}
/**
* Holt alle Items einer bestimmten shoppingliste, angegeben durch die shoppinglist id
*
@ -624,26 +626,15 @@ public class Database {
*/
public List<Item> getItems(String sl_id) throws SQLException, JSONException {
String SQL = "SELECT row_to_json(\"Item\") AS obj FROM \"Item\" JOIN \"Group\" USING (group_id) WHERE \"Group\".sl_id = ?";
connectDatabase();
ArrayList<Item> listItems = new ArrayList<Item>();
ResultSet rsitems = null;
try (PreparedStatement pstmt = conect.prepareStatement(SQL)) {
pstmt.setString(1, sl_id);
rsitems = pstmt.executeQuery();
System.out.println(sl_id);
while (rsitems.next()) {
String itemsString = rsitems.getString(1);
JSONObject jsonObject = new JSONObject(itemsString);
listItems.add(new Item(jsonObject.getString("item_id"), jsonObject.getString("group_id"), jsonObject.getString("sl_id"), jsonObject.getString("name"), jsonObject.getString("count")));
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
List<JSONObject> jsonObjects = executeQueryJSONObject(SQL, sl_id);
for (int i = 0; i < jsonObjects.size(); i++) {
JSONObject jsonObject = jsonObjects.get(i);
listItems.add(new Item(jsonObject.getString("item_id"), jsonObject.getString("group_id"), jsonObject.getString("sl_id"), jsonObject.getString("name"), jsonObject.getString("count")));
}
return (List<Item>) listItems;
return listItems;
}
@ -657,32 +648,114 @@ public class Database {
*/
private List<Group> getGroups(String sl_id) throws SQLException, JSONException {
String SQLGroups = "SELECT row_to_json(\"Group\") AS obj FROM \"Group\" JOIN \"Shoppinglist\" USING (sl_id) WHERE sl_id = ?";
connectDatabase();
ResultSet rsgroups = null;
List<JSONObject> jsonObjects = executeQueryJSONObject(SQLGroups, sl_id);
ArrayList<Group> listGroup = new ArrayList<Group>();
try (PreparedStatement pstmt = conect.prepareStatement(SQLGroups)) {
pstmt.setString(1, sl_id);
rsgroups = pstmt.executeQuery();
System.out.println(sl_id);
while (rsgroups.next()) {
String groupString = rsgroups.getString(1);
JSONObject jsonObject = new JSONObject(groupString);
listGroup.add(new Group(jsonObject.getString("group_id"), jsonObject.getString("sl_id"), jsonObject.getString("name"), jsonObject.getString("color"), jsonObject.getString("hidden")));
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
for (int i = 0; i < jsonObjects.size(); i++) {
JSONObject jsonObject = jsonObjects.get(i);
listGroup.add(new Group(jsonObject.getString("group_id"), jsonObject.getString("sl_id"), jsonObject.getString("name"), jsonObject.getString("color"), jsonObject.getString("hidden")));
}
return (List<Group>) listGroup;
return listGroup;
}
/**
* Hollt eine Shoppingliste vom server
*
* @param sl_id Shoppingliste welche heruntergelanden werden soll
* @return Ein Shoppinglist Objekt
* @throws SQLException
* @throws JSONException
*/
public Shoppinglist getShoppinglist(String sl_id) throws SQLException, JSONException {
String SQL = "SELECT row_to_json(\"Shoppinglist\") AS obj FROM \"Shoppinglist\" JOIN \"Shoppinglist_admin\" USING (sl_id) WHERE sl_id = ?";
JSONObject jsonObject = new JSONObject(executeQuery(SQL, sl_id));
return new Shoppinglist(sl_id, jsonObject.getString("name"), jsonObject.getString("description"), jsonObject.getString("invitelink"), jsonObject.getString("color"));
}
/**
* Führt ein SQL Befehl aus und gibt die antwort in ein JSONObject List
*
* @param SQL Der SQL der auszuführen ist
* @param param 1. Param
* @param param 2. Param
* @return Das ergebnis als JSONObject
* @throws SQLException
* @throws JSONException
*/
public List<JSONObject> executeQueryJSONObject2Param(String SQL, String param, String param2) throws SQLException, JSONException {
ArrayList<JSONObject> jsonObjects = new ArrayList<JSONObject>();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
pstmt.setString(2, param2);
ResultSet rsgroups = pstmt.executeQuery();
System.out.println(param);
while (rsgroups.next()) {
String groupString = rsgroups.getString(1);
JSONObject jsonObject = new JSONObject(groupString);
jsonObjects.add(jsonObject);
}
return jsonObjects;
}
/**
* Führt ein SQL Befehl aus und gibt die antwort in ein JSONObject List
*
* @param SQL Der SQL der auszuführen ist
* @param param 1. Param
* @return Das ergebnis als JSONObject
* @throws SQLException
* @throws JSONException
*/
public List<JSONObject> executeQueryJSONObject(String SQL, String param) throws SQLException, JSONException {
ArrayList<JSONObject> jsonObjects = new ArrayList<JSONObject>();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
ResultSet rsgroups = pstmt.executeQuery();
System.out.println(param);
while (rsgroups.next()) {
String groupString = rsgroups.getString(1);
JSONObject jsonObject = new JSONObject(groupString);
jsonObjects.add(jsonObject);
}
return jsonObjects;
}
/**
* Führt ein SQL mit einem Parameter aus und liefert den ersten String
*
* @param SQL SQL Befehl
* @param param 1. Param
* @param param 2. Param
* @return Erster result String
* @throws SQLException
*/
private String executeQuery2Param(String SQL, String param, String param2) throws SQLException {
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
pstmt.setString(2, param2);
ResultSet rs = pstmt.executeQuery();
rs.next();
return rs.getString(1);
}
/**
* Führt ein SQL mit einem Parameter aus und liefert den ersten String
*
* @param SQL SQL Befehl
* @param param 1. Param
* @return Erster result String
* @throws SQLException
*/
private String executeQuery(String SQL, String param) throws SQLException {
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
ResultSet rs = pstmt.executeQuery();
rs.next();
return rs.getString(1);
}
/**
* Bearbeitet die Eigenschaften einer Shoppingliste
@ -721,7 +794,7 @@ public class Database {
* @throws SQLException
*/
private void sqlUpdate4ParamFirstInt(String SQL, int param, String param2, String param3, String param4) throws SQLException {
connectDatabase();
//connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setInt(1, param);
pstmt.setString(2, param2);
@ -730,6 +803,28 @@ public class Database {
pstmt.executeUpdate();
}
/**
* Führt einen SQL Befehl durch der keine rückgabe hat.
*
* @param SQL Der SQL befehl
* @param param ein Parameter
* @param param2 ein 2. Parameter
* @param param3 ein 3. parameter
* @param param4 ein 4. Parameter
* @param param5 Ein datum des Typen java.sql.Date
* @throws SQLException
*/
private void sqlUpdate5ParamLastIsDateAndInt(String SQL, String param, String param2, String param3, int param4, java.sql.Date param5) throws SQLException {
//connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
pstmt.setString(2, param2);
pstmt.setString(3, param3);
pstmt.setInt(4, param4);
pstmt.setDate(5, param5);
pstmt.executeUpdate();
}
/**
* Führt einen SQL Befehl durch der keine rückgabe hat.
*
@ -742,7 +837,7 @@ public class Database {
* @throws SQLException
*/
private void sqlUpdate5Param(String SQL, String param, String param2, String param3, String param4, int param5) throws SQLException {
connectDatabase();
//connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
pstmt.setString(2, param2);
@ -763,7 +858,7 @@ public class Database {
* @throws SQLException
*/
private void sqlUpdate4Param(String SQL, String param, String param2, String param3, String param4) throws SQLException {
connectDatabase();
//connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
pstmt.setString(2, param2);
@ -782,7 +877,7 @@ public class Database {
* @throws SQLException
*/
private void sqlUpdate3Param(String SQL, String param, String param2, String param3) throws SQLException {
connectDatabase();
//connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
pstmt.setString(2, param2);
@ -801,7 +896,7 @@ public class Database {
* @throws SQLException
*/
private void sqlUpdate2Param(String SQL, String param, String param2) throws SQLException {
connectDatabase();
//connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
pstmt.setString(2, param2);
@ -816,60 +911,10 @@ public class Database {
* @throws SQLException
*/
private void sqlUpdate(String SQL, String param) throws SQLException {
connectDatabase();
//connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
pstmt.executeUpdate();
}
/**
* Hollt eine Shoppingliste vom server
*
* @param sl_id Shoppingliste welche heruntergelanden werden soll
* @return Ein Shoppinglist Objekt
* @throws SQLException
* @throws JSONException
*/
public Shoppinglist getShoppinglist(String sl_id) throws SQLException, JSONException {
String SQL = "SELECT row_to_json(\"Shoppinglist\") AS obj FROM \"Shoppinglist\" JOIN \"Shoppinglist_admin\" USING (sl_id) WHERE sl_id = ?";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
System.out.println(sl_id);
pstmt.setString(1, sl_id);
ResultSet rs = pstmt.executeQuery();
rs.next();
String resultString = rs.getString(1);
JSONObject jsonObject = new JSONObject(resultString);
return new Shoppinglist(sl_id, jsonObject.getString("name"), jsonObject.getString("description"), jsonObject.getString("invitelink"), jsonObject.getString("color"));
}
/**
* NICHT VERWENDEN FUNKTIONIERT NICHT!!
* <p>
* <p>
* NUR EIN KOPIE SAMPLE
* <p>
* Beim Start wird die Verbindung zum Server hergesetellt. Dann wird das resultSet von dem SQL reqest zurückgegeben
*
* @param SQL Der zumachende SQL Request
* @param uid Die UID des Benutzers, für den die Abfrage gemacht wird
* @return Das entstandene Result set, mit der Antwort des Servers
*/
private ResultSet databaseRequest(String SQL, String uid) throws SQLException {
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, uid);
ResultSet rs = pstmt.executeQuery();
System.out.println(uid);
//HIER
//WEITER
//PROGRAMMIEREN
return rs;
}
}

View File

@ -0,0 +1,17 @@
package at.smartshopper.smartshopper.db;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
public class SerializableDatabase implements JsonSerializer<Database> {
@Override
public JsonElement serialize(Database src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject object = new JsonObject();
return null;
}
}

View File

@ -0,0 +1,18 @@
package at.smartshopper.smartshopper.shoppinglist;
public class Member {
private String uid, msid;
public Member(String uid, String msid){
this.uid = uid;
this.msid = msid;
}
public String getUid() {
return uid;
}
public String getMsid() {
return msid;
}
}

View File

@ -33,18 +33,20 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
private OnChangeItemClick onChangeClick;
private OnItemClicked onClick;
private OnShareClick onShareClick;
private at.smartshopper.smartshopper.db.Database db;
private Database db;
//this context we will use to inflate the layout
private Context mCtx;
//we are storing all the products in a list
private List<Shoppinglist> shoppinglist;
private OnShoppinglistClick onShoppinglistClick;
//getting the context and product list with constructor
public ShoppinglistAdapter(Context mCtx, List<Shoppinglist> shoppinglist) {
public ShoppinglistAdapter(Context mCtx, List<Shoppinglist> shoppinglist, Database db) {
this.mCtx = mCtx;
this.shoppinglist = shoppinglist;
this.db = db;
}
/**
@ -72,48 +74,32 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
public void onBindViewHolder(ShoppinglistViewHolder holder, final int position) {
//getting the product of the specified position,
final Shoppinglist shoppinglist = this.shoppinglist.get(position);
ImageButton shareButton = holder.share;
final ImageButton shareButton = holder.share;
TextView beschreibung = holder.textViewBeschreibung;
beschreibung.setText(shoppinglist.getdescription());
Picasso.get().load(R.drawable.share).into(shareButton);
db = new Database();
//binding the data with the viewholder views
holder.textViewTitle.setText(shoppinglist.getname());
System.out.println(shoppinglist.getname());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), ShoppinglistDetails.class);
Bundle bundle = new Bundle();
bundle.putString("sl_id", shoppinglist.getSlId());
intent.putExtras(bundle);
v.getContext().startActivity(intent);
onShoppinglistClick.onShoppinglistClick(shoppinglist.getSlId(), v);
}
});
holder.bearbeiten.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onChangeClick.onChangeItemClick(shoppinglist.getSlId(), v);
}
});
holder.del.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onClick.onItemClick(shoppinglist.getSlId());
}
});
shareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -207,7 +193,20 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
this.onShareClick = onShareClick;
}
/**
* Interface damit onoclick in der dash activity ausgeführt werden kann
*/
public interface OnShoppinglistClick{
void onShoppinglistClick(String sl_id, View v);
}
/**
* Setzt das OnChangeItemClick event
* @param onShoppinglistClick Der Click event Listener
*/
public void setOnShoppinglistClick(OnShoppinglistClick onShoppinglistClick){
this.onShoppinglistClick = onShoppinglistClick;
}

View File

@ -16,7 +16,7 @@ import com.squareup.picasso.Picasso;
import java.util.List;
import at.smartshopper.smartshopper.R;
import at.smartshopper.smartshopper.activitys.ItemListActivity;
import at.smartshopper.smartshopper.activitys.ShoppinglistDetails;
import at.smartshopper.smartshopper.customViews.SpaceItemDecoration;
import at.smartshopper.smartshopper.db.Database;
import at.smartshopper.smartshopper.shoppinglist.details.item.ItemShoppinglistDetailsAdapter;
@ -26,9 +26,11 @@ public class DetailsAdapter extends RecyclerView.Adapter<DetailsAdapter.MyViewHo
private OnGroupEditClicked onGroupEditClicked;
private OnGroupDeleteClicked onGroupDeleteClicked;
private OnCardClicked onCardClicked;
private Database db;
public DetailsAdapter(List<Details> details) {
public DetailsAdapter(List<Details> details, Database db) {
this.details = details;
this.db = db;
}
/**
@ -62,6 +64,9 @@ public class DetailsAdapter extends RecyclerView.Adapter<DetailsAdapter.MyViewHo
View groupColor = viewHolder.grouoColor;
ImageButton editGroup = viewHolder.editGroup;
int spacingInPixels = viewHolder.itemView.getContext().getResources().getDimensionPixelSize(R.dimen.item_spacing);
itemsrecycle.addItemDecoration(new SpaceItemDecoration(spacingInPixels));
itemsrecycle.setHasFixedSize(true);
itemsrecycle.setLayoutManager(new LinearLayoutManager(new Activity()));
List<at.smartshopper.smartshopper.shoppinglist.details.item.Item> itemsList = details.get(i).getItems();
@ -70,7 +75,7 @@ public class DetailsAdapter extends RecyclerView.Adapter<DetailsAdapter.MyViewHo
itemsrecycle.setAdapter(itemAdapter);
final Database db = new Database();
int cardcolor;

View File

@ -9,9 +9,11 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.firebase.auth.FirebaseAuth;
import com.squareup.picasso.Picasso;
import org.json.JSONException;
@ -22,12 +24,14 @@ import java.util.List;
import at.smartshopper.smartshopper.R;
import at.smartshopper.smartshopper.db.Database;
import at.smartshopper.smartshopper.shoppinglist.ShoppinglistAdapter;
public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.MyViewHolder> {
private List<at.smartshopper.smartshopper.shoppinglist.details.item.Item> data;
private OnItemEditClicked onItemEditClick;
private OnItemDelClicked onItemDelClicked;
private OnItemCheckClicked onItemCheckClick;
public ItemAdapter(List<at.smartshopper.smartshopper.shoppinglist.details.item.Item> data) {
this.data = data;
@ -63,27 +67,13 @@ public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.MyViewHolder>
CheckBox itemErledigt = myViewHolder.erledigtItem;
ImageView itemDel = myViewHolder.itemDel;
CardView itemCardView = myViewHolder.itemCardView;
//View colorBox = myViewHolder.colorBox;
/*
int cardcolor = 0;
try {
Database db = new Database();
cardcolor = Color.parseColor(db.getGroup(data.get(i).getGroup_id(), data.get(i).getSl_id()).getColor());
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
try {
colorBox.setBackgroundColor(cardcolor);
}catch (Exception e){
e.printStackTrace();
}
*/
itemErledigt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
onItemCheckClick.onItemCheckClicked(FirebaseAuth.getInstance().getCurrentUser().getUid(), data.get(i).getName(), data.get(i).getItem_id(), data.get(i).getGroup_id(), data.get(i).getSl_id(), Integer.parseInt(itemAnzahl.getText().toString()));
}
});
itemName.setText(data.get(i).getName());
@ -123,6 +113,14 @@ public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.MyViewHolder>
this.onItemEditClick = onItemEditClick;
}
public interface OnItemCheckClicked {
void onItemCheckClicked(String uid, String name, String itemId, String groupId, String sl_id, int count);
}
public void setOnItemCheckClick(OnItemCheckClicked onItemCheckClick) {
this.onItemCheckClick = onItemCheckClick;
}
@Override
public int getItemCount() {
return data.size();

View File

@ -7,9 +7,11 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.firebase.auth.FirebaseAuth;
import com.squareup.picasso.Picasso;
import org.json.JSONException;
@ -56,8 +58,7 @@ public class ItemShoppinglistDetailsAdapter extends RecyclerView.Adapter<ItemSho
@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, final int i) {
final TextView itemName = myViewHolder.itemName;
TextView itemAnzahl = myViewHolder.itemAnzahl;
CheckBox itemErledigt = myViewHolder.erledigtItem;
final TextView itemAnzahl = myViewHolder.itemAnzahl;
CardView itemCardView = myViewHolder.itemCardView;
itemCardView.setOnClickListener(new View.OnClickListener() {
@ -97,7 +98,6 @@ public class ItemShoppinglistDetailsAdapter extends RecyclerView.Adapter<ItemSho
public static class MyViewHolder extends RecyclerView.ViewHolder {
TextView itemName, itemAnzahl;
CheckBox erledigtItem;
CardView itemCardView;
public MyViewHolder(View itemView) {
@ -105,7 +105,6 @@ public class ItemShoppinglistDetailsAdapter extends RecyclerView.Adapter<ItemSho
this.itemName = (TextView) itemView.findViewById(R.id.nameItem);
this.itemAnzahl = (TextView) itemView.findViewById(R.id.anzahlItem);
this.erledigtItem = (CheckBox) itemView.findViewById(R.id.erledigtItem);
this.itemCardView = (CardView) itemView.findViewById(R.id.itemCardView);
}
}

View File

@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
tools:context=".activitys.ItemListActivity">
<android.support.v4.widget.SwipeRefreshLayout
@ -33,7 +34,8 @@
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
android:layout_height="wrap_content"
app:cardElevation="4dp">
<LinearLayout
android:layout_width="match_parent"

View File

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
app:cardElevation="4dp">
<TableLayout
android:layout_width="match_parent"
@ -21,11 +22,11 @@
<ImageButton
android:id="@+id/groupClose"
app:srcCompat="@drawable/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:background="@color/fui_transparent" />
android:background="@color/fui_transparent"
app:srcCompat="@drawable/close" />
</LinearLayout>
</TableRow>

View File

@ -3,7 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="8dp">
app:cardCornerRadius="8dp"
app:cardElevation="4dp">
<TableLayout
android:layout_width="match_parent"

View File

@ -4,7 +4,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
app:cardElevation="4dp">
<TableLayout
android:layout_width="match_parent"
@ -68,7 +69,7 @@
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
android:gravity="center">
<Button
android:id="@+id/shareCopy"

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" >
app:cardElevation="4dp">
<TableLayout
android:layout_width="match_parent"

View File

@ -4,6 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="8dp"
app:cardElevation="4dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">

View File

@ -8,6 +8,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardElevation="4dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">

View File

@ -6,7 +6,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#DBDBDB"
app:cardCornerRadius="8dp">
app:cardCornerRadius="8dp"
app:cardElevation="2dp">
<LinearLayout

View File

@ -5,7 +5,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#DBDBDB"
app:cardCornerRadius="8dp">
app:cardCornerRadius="8dp"
app:cardElevation="2dp">
<LinearLayout

View File

@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ownLists"
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ownLists"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="8dp">
card_view:cardCornerRadius="8dp"
card_view:cardElevation="4dp"
card_view:cardUseCompatPadding="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"

View File

@ -1,3 +1,4 @@
<resources>
<dimen name="fab_margin">16dp</dimen>
<dimen name="item_spacing">8dp</dimen>
</resources>