diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml deleted file mode 100644 index 70ddf47..0000000 --- a/.idea/assetWizardSettings.xml +++ /dev/null @@ -1,153 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser index 2f1fda8..38396b4 100644 Binary files a/.idea/caches/gradle_models.ser and b/.idea/caches/gradle_models.ser differ diff --git a/.idea/gradle.xml b/.idea/gradle.xml index f43d428..2996d53 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -8,12 +8,6 @@ diff --git a/.idea/misc.xml b/.idea/misc.xml index 51fa3e5..703e5d4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,41 +1,11 @@ - - - + + + + - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 4fbac2b..2b2bc6c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,4 +39,5 @@ dependencies { implementation 'com.android.support:swiperefreshlayout:28.0.0-alpha1' implementation 'com.android.support:cardview-v7:28.0.0' implementation 'com.github.danielnilsson9:color-picker-view:1.4.0@aar' + implementation 'com.android.support:recyclerview-v7:28.0.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 521b65b..3d3910e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,7 +12,10 @@ android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true"> - + + diff --git a/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java b/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java index bf6a4b0..a941daf 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java +++ b/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java @@ -187,6 +187,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte }else{ colorstring = "#" + dbShoppinglist.getcolor(); } + this.color = colorstring; colorBtn.setBackgroundColor(Color.parseColor(colorstring)); name.setText(dbShoppinglist.getname()); description.setText(dbShoppinglist.getdescription()); @@ -410,11 +411,9 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte public void onItemClick(String sl_id) { try { db.delShoppinglist(sl_id); - showOwnShoppingList(FirebaseAuth.getInstance().getCurrentUser().getUid()); + refreshOwnShoppinglist(FirebaseAuth.getInstance().getCurrentUser().getUid()); } catch (SQLException e) { e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); } } diff --git a/app/src/main/java/at/smartshopper/smartshopper/activitys/ItemListActivity.java b/app/src/main/java/at/smartshopper/smartshopper/activitys/ItemListActivity.java new file mode 100644 index 0000000..f15f8f1 --- /dev/null +++ b/app/src/main/java/at/smartshopper/smartshopper/activitys/ItemListActivity.java @@ -0,0 +1,79 @@ +package at.smartshopper.smartshopper.activitys; + +import android.content.Intent; +import android.os.Bundle; +import android.app.Activity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; + +import org.json.JSONException; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import at.smartshopper.smartshopper.R; +import at.smartshopper.smartshopper.db.Database; +import at.smartshopper.smartshopper.shoppinglist.details.Details; +import at.smartshopper.smartshopper.shoppinglist.details.DetailsAdapter; +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 { + private String group_id; + private String sl_id; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_item_list); + + Intent myIntent = getIntent(); // gets the previously created intent + this.group_id = myIntent.getStringExtra("group_id"); // will return "FirstKeyValue" + this.sl_id = myIntent.getStringExtra("sl_id"); // will return "SecondKeyValue" + + + try { + showItems(group_id, sl_id); + } catch (SQLException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + + + } + + private void showItems(String group_id, String sl_id) throws SQLException, JSONException { + RecyclerView itemsListRecycler = findViewById(R.id.itemsListRecycler); + itemsListRecycler.setHasFixedSize(true); + itemsListRecycler.setLayoutManager(new LinearLayoutManager(this)); + List itemList = new Database().getItemsOfGroup(group_id, sl_id); + + + ItemAdapter itemAdapter = new ItemAdapter(itemList); + itemAdapter.setOnItemEditClick(this); + itemAdapter.setItemDelClick(this); + + itemsListRecycler.setAdapter(itemAdapter); + } + + @Override + public void onBackPressed() { + finish(); + Intent intent = new Intent(this, ShoppinglistDetails.class); + intent.putExtra("sl_id", sl_id); + startActivity(intent); + } + + @Override + public void onItemDelClicked(String item_id, String group_id, String sl_id) { + + } + + @Override + public void onItemEditClicked(String item_id, String group_id, String sl_id, String newname, int newcount) { + + } +} diff --git a/app/src/main/java/at/smartshopper/smartshopper/activitys/ShoppinglistDetails.java b/app/src/main/java/at/smartshopper/smartshopper/activitys/ShoppinglistDetails.java index 076eab5..03e963e 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/activitys/ShoppinglistDetails.java +++ b/app/src/main/java/at/smartshopper/smartshopper/activitys/ShoppinglistDetails.java @@ -6,7 +6,6 @@ import android.os.Build; import android.os.Bundle; import android.app.Activity; import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.Gravity; @@ -20,24 +19,23 @@ import android.widget.PopupWindow; import android.widget.Toast; import com.google.firebase.auth.FirebaseAuth; -import com.google.firebase.auth.FirebaseUser; import com.squareup.picasso.Picasso; import org.json.JSONException; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import at.smartshopper.smartshopper.R; import at.smartshopper.smartshopper.db.Database; import at.smartshopper.smartshopper.shoppinglist.Shoppinglist; -import at.smartshopper.smartshopper.shoppinglist.ShoppinglistAdapter; import at.smartshopper.smartshopper.shoppinglist.details.Details; import at.smartshopper.smartshopper.shoppinglist.details.DetailsAdapter; import at.smartshopper.smartshopper.shoppinglist.details.group.Group; import at.smartshopper.smartshopper.shoppinglist.details.item.Item; -public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGroupEditClicked, DetailsAdapter.OnGroupDeleteClicked, DetailsAdapter.OnItemAddClicked { +public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGroupEditClicked, DetailsAdapter.OnGroupDeleteClicked, DetailsAdapter.OnItemAddClicked, DetailsAdapter.OnCardClicked { private Database db = new Database(); private FloatingActionButton fab; @@ -122,9 +120,9 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr if (fromDB) { Group dbgroup = db.getGroup(groupid, sl_id); String colorstring; - if(dbgroup.getColor().contains("#")){ + if (dbgroup.getColor().contains("#")) { colorstring = dbgroup.getColor(); - }else{ + } else { colorstring = "#" + dbgroup.getColor(); } color.setBackgroundColor(Color.parseColor(colorstring)); @@ -207,9 +205,9 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr int color = Integer.parseInt(data.getData().toString()); this.colorString = colorToHexString(color); String colorstring; - if(this.colorString.contains("#")){ + if (this.colorString.contains("#")) { colorstring = this.colorString; - }else{ + } else { colorstring = "#" + this.colorString; } int colorint = Color.parseColor(colorstring); @@ -239,16 +237,19 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr RecyclerView detailsRecycleView = (RecyclerView) findViewById(R.id.groupRecycle); detailsRecycleView.setHasFixedSize(true); detailsRecycleView.setLayoutManager(new LinearLayoutManager(this)); - List
detailsList = db.getListDetails(sl_id); + List
detailsList = db.getListDetails(sl_id); + + DetailsAdapter detailsAdapter = new DetailsAdapter(detailsList); detailsAdapter.setGroupEditClick(this); detailsAdapter.setGroupDeleteClick(this); detailsAdapter.setItemAddClick(this); + detailsAdapter.setCardClick(this); + detailsRecycleView.setAdapter(detailsAdapter); } - private void showPopupItemEdit(final boolean fromDB, final String sl_id, final String group_id, String item_id, View v) throws SQLException, JSONException { final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE); @@ -359,4 +360,13 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr } } + + @Override + public void onCardClick(String group_id, String sl_id, View v) { + finish(); + Intent intent = new Intent(this, ItemListActivity.class); + intent.putExtra("group_id", group_id); + intent.putExtra("sl_id", sl_id); + startActivity(intent); + } } diff --git a/app/src/main/java/at/smartshopper/smartshopper/db/Database.java b/app/src/main/java/at/smartshopper/smartshopper/db/Database.java index 7b5009a..8aa45f0 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/db/Database.java +++ b/app/src/main/java/at/smartshopper/smartshopper/db/Database.java @@ -61,6 +61,44 @@ public class Database { sqlUpdate2Param("DELETE FROM \"Group\" WHERE group_id = ? AND sl_id = ?", group_id, sl_id); } + /** + * Bearbeitet ein Item in der Datenbank + * @param item_id Daqs zu bearbeitende item + * @param group_id Die gruppe in dem da sitem ist + * @param sl_id die shoppinglist in dem das item ist + * @param newname der neue name + * @param newcount die neue anzahl + * @throws SQLException + * @throws JSONException + */ + public void editItem(String item_id, String group_id, String sl_id, String newname, int newcount) throws SQLException, JSONException { + Item olditem = getItem(item_id); + + if (!olditem.getName().equals(newname) && newname != null) { + sqlUpdate4Param("UPDATE \"Item\" SET name = ? WHERE item_id = ? AND group_id = ? AND sl_id = ?", newname, item_id, group_id, sl_id); + } + + /* + if (!oldgroup.getHidden().equals(newhidden) && newhidden != null) { + sqlUpdate3Param("UPDATE \"Group\" SET hidden = ? WHERE group_id = ? AND sl_id = ?", newhidden, group_id, sl_id); + } +*/ + if (Integer.parseInt(olditem.getCount()) != newcount) { + sqlUpdate4ParamFirstInt("UPDATE \"Item\" SET count = ? WHERE item_id = ? AND group_id = ? AND sl_id = ?", newcount, item_id, group_id, sl_id); + } + } + + + /** + * Löscht ein item + * @param item_id Item id + * @param group_id group id + * @param sl_id shoppoinglist id + */ + public void deleteItem(String item_id, String group_id, String sl_id) throws SQLException { + sqlUpdate3Param("DELETE FROM \"Item\" WHERE item_id = ? AND group_id = ? AND sl_id = ?", item_id, group_id, sl_id); + } + /** * Fügt ein neues Item der Datenbank hinzu * @param group_id Die group id in der das neue item angezeigt werden soll @@ -342,6 +380,28 @@ public class Database { } + /** + * Holt alle Items einer bestimmten gruppe + * @param group_id Gruppe welche geholt werden soll + * @param sl_id Die Shoppinglist in der sich die gruppe befindet + * @return + * @throws SQLException + * @throws JSONException + */ + public List getItemsOfGroup(String group_id, String sl_id) throws SQLException, JSONException { + List
details = getListDetails(sl_id); + ArrayList result = new ArrayList(); + + for(Details d : details){ + String group_idtmp = d.getGroup().getGroup_id(); + if(group_idtmp.equals(group_id)){ + result = d.getItems(); + } + } + + return result; + } + /** * Generiert eine neue 8 stellige sl_id * @@ -386,7 +446,7 @@ public class Database { * @throws SQLException * @throws JSONException */ - private List getItems(String sl_id) throws SQLException, JSONException { + public List 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(); @@ -482,17 +542,15 @@ public class Database { * @param param2 ein 2. Parameter * @param param3 ein 3. parameter * @param param4 ein 4. Parameter - * @param param5 ein 5. Parameter * @throws SQLException */ - private void sqlUpdate5Param(String SQL, String param, String param2, String param3, String param4, String param5) throws SQLException { + private void sqlUpdate4ParamFirstInt(String SQL, int param, String param2, String param3, String param4) throws SQLException { connectDatabase(); PreparedStatement pstmt = conect.prepareStatement(SQL); - pstmt.setString(1, param); + pstmt.setInt(1, param); pstmt.setString(2, param2); pstmt.setString(3, param3); pstmt.setString(4, param4); - pstmt.setString(5, param5); pstmt.executeUpdate(); } diff --git a/app/src/main/java/at/smartshopper/smartshopper/shoppinglist/ShoppinglistAdapter.java b/app/src/main/java/at/smartshopper/smartshopper/shoppinglist/ShoppinglistAdapter.java index 1dee8f7..cf751a8 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/shoppinglist/ShoppinglistAdapter.java +++ b/app/src/main/java/at/smartshopper/smartshopper/shoppinglist/ShoppinglistAdapter.java @@ -100,7 +100,7 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter details) { this.details = details; @@ -63,30 +65,42 @@ public class DetailsAdapter extends RecyclerView.Adapter itemsList = details.get(i).getItems(); ItemAdapter itemAdapter = new ItemAdapter(itemsList); - itemsrecycle.setAdapter(itemAdapter); + final Database db = new Database(); + + + int cardcolor; + try { + cardcolor = Color.parseColor(details.get(i).getGroup().getColor()); + } catch (Exception e) { + cardcolor = Color.parseColor("#FFFFFF"); + } + groupColor.setBackgroundColor(cardcolor); + + groupName.setText(details.get(i).getGroup().getName()); + Picasso.get().load(R.drawable.delete).into(deleteGroup); + Picasso.get().load(R.drawable.add).into(addItem); + Picasso.get().load(R.drawable.bearbeiten).into(editGroup); + + viewHolder.groupCard.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + onCardClicked.onCardClick(details.get(i).getGroup().getGroup_id(), details.get(i).getGroup().getSl_idd(), v); + } + }); + + addItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -109,7 +123,20 @@ public class DetailsAdapter extends RecyclerView.Adapter { private List data; + private OnItemEditClicked onItemEditClick; + private OnItemDelClicked onItemDelClicked; - public ItemAdapter(List data){ + public ItemAdapter(List data) { this.data = data; } /** * Erstellt einen Neuen view holder mit aktueller view + * * @param viewGroup * @param i * @return @@ -40,20 +45,52 @@ public class ItemAdapter extends RecyclerView.Adapter /** * Setzt alle Daten in die View elemente + * * @param myViewHolder Das View Holder Objekt mit allen elementen - * @param i Der Index welcher aus der data list genommen werden soll + * @param i Der Index welcher aus der data list genommen werden soll */ @Override - public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) { - TextView itemName = myViewHolder.itemName; - TextView itemAnzahl = myViewHolder.itemAnzahl; - ImageView itemBearbeiten = myViewHolder.itemBearbeiten; + public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, final int i) { + final TextView itemName = myViewHolder.itemName; + final TextView itemAnzahl = myViewHolder.itemAnzahl; + CheckBox itemErledigt = myViewHolder.erledigtItem; ImageView itemDel = myViewHolder.itemDel; itemName.setText(data.get(i).getName()); itemAnzahl.setText(data.get(i).getCount()); - Picasso.get().load(R.drawable.bearbeiten).into(itemBearbeiten); Picasso.get().load(R.drawable.delete).into(itemDel); + + /* + itemName.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + onItemEditClick.onItemEditClicked(data.get(i).getItem_id(), data.get(i).getGroup_id(), data.get(i).getSl_id(), itemName.getText().toString(), Integer.parseInt(itemAnzahl.getText().toString())); + } + }); + + itemDel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + onItemDelClicked.onItemDelClicked(data.get(i).getItem_id(), data.get(i).getGroup_id(), data.get(i).getSl_id()); + } + }); +*/ + } + + public interface OnItemDelClicked { + void onItemDelClicked(String item_id, String group_id, String sl_id); + } + + public void setItemDelClick(OnItemDelClicked onItemDelClicked){ + this.onItemDelClicked = onItemDelClicked; + } + + public interface OnItemEditClicked { + void onItemEditClicked(String item_id, String group_id, String sl_id, String newname, int newcount); + } + + public void setOnItemEditClick(OnItemEditClicked onItemEditClick) { + this.onItemEditClick = onItemEditClick; } @Override @@ -64,18 +101,19 @@ public class ItemAdapter extends RecyclerView.Adapter /** * Haltet alle elemente. Durch ein Objekt von dem kann jedes Element welches hier drinnen angeführt ist verwendet werden */ - public static class MyViewHolder extends RecyclerView.ViewHolder{ + public static class MyViewHolder extends RecyclerView.ViewHolder { TextView itemName, itemAnzahl; - ImageView itemBearbeiten, itemDel; + ImageView itemDel; + CheckBox erledigtItem; - public MyViewHolder(View itemView){ + public MyViewHolder(View itemView) { super(itemView); - this.itemName = (TextView)itemView.findViewById(R.id.nameItem); - this.itemAnzahl = (TextView)itemView.findViewById(R.id.anzahlItem); - this.itemBearbeiten = (ImageView)itemView.findViewById(R.id.itemBearbeiten); - this.itemDel = (ImageView)itemView.findViewById(R.id.itemDel); + this.itemName = (TextView) itemView.findViewById(R.id.nameItem); + this.itemAnzahl = (TextView) itemView.findViewById(R.id.anzahlItem); + this.itemDel = (ImageView) itemView.findViewById(R.id.itemDel); + this.erledigtItem = (CheckBox) itemView.findViewById(R.id.erledigtItem); } } } diff --git a/app/src/main/res/drawable/rechteck.xml b/app/src/main/res/drawable/rechteck.xml new file mode 100644 index 0000000..f22dcb0 --- /dev/null +++ b/app/src/main/res/drawable/rechteck.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_item_list.xml b/app/src/main/res/layout/activity_item_list.xml new file mode 100644 index 0000000..16be527 --- /dev/null +++ b/app/src/main/res/layout/activity_item_list.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/cardviewgroup.xml b/app/src/main/res/layout/cardviewgroup.xml index 69029b2..5e141a5 100644 --- a/app/src/main/res/layout/cardviewgroup.xml +++ b/app/src/main/res/layout/cardviewgroup.xml @@ -11,14 +11,47 @@ app:cardPreventCornerOverlap="true" app:cardUseCompatPadding="true"> - + android:layout_height="match_parent"> + + + + + android:id="@+id/constraintLayout" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:layout_marginEnd="8dp" + android:padding="8dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="@+id/guideline3" + app:layout_constraintTop_toTopOf="parent"> - - - - - - - + + diff --git a/app/src/main/res/layout/cardviewitem.xml b/app/src/main/res/layout/cardviewitem.xml index 8892c33..29ea3f0 100644 --- a/app/src/main/res/layout/cardviewitem.xml +++ b/app/src/main/res/layout/cardviewitem.xml @@ -3,50 +3,45 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/itemCardView" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + app:cardBackgroundColor="#DBDBDB" + app:cardCornerRadius="8dp"> - + + + android:text="ItemName" /> - - - - + - - + + diff --git a/app/src/main/res/layout/cardviewshoppinglist.xml b/app/src/main/res/layout/cardviewshoppinglist.xml index f030867..340e3d3 100644 --- a/app/src/main/res/layout/cardviewshoppinglist.xml +++ b/app/src/main/res/layout/cardviewshoppinglist.xml @@ -16,18 +16,34 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + + card_view:layout_constraintStart_toStartOf="@+id/guideline4" + card_view:layout_constraintTop_toTopOf="parent" + card_view:layout_constraintVertical_bias="0.436"> + card_view:layout_constraintGuide_begin="111dp" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b9f805..3c8f3a3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,4 +3,5 @@ Dash ShoppinglistDetail ShoppinglistDetails + ItemListActivity