Item delete, edit, add, show. All Lists refreshable

Items können gelöscht, bearbeitet, hinzugefügt und angezeigt werden
Alle Card Views können mit Swipe to refresh aktualisiert werden
This commit is contained in:
Georg Reisinger 2019-02-17 20:49:03 +01:00
parent 0d341638ef
commit 6eb0e704d1
17 changed files with 609 additions and 276 deletions

2
.idea/misc.xml generated
View File

@ -5,7 +5,7 @@
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -25,6 +25,7 @@ import at.smartshopper.smartshopper.R;
import android.widget.PopupWindow;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
@ -32,6 +33,7 @@ import com.google.firebase.auth.FirebaseUser;
import com.squareup.picasso.Picasso;
import org.json.JSONException;
import org.w3c.dom.Text;
import java.sql.SQLException;
import java.util.List;
@ -140,7 +142,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte
@Override
public void onClick(View v) {
try {
showShoppinglistEditView(false, null, v);
showShoppinglistEditView(false, null, "Shoppingliste erstellen", v);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
@ -164,13 +166,16 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte
* @param sl_id Muss nur eine sl_id drinnen sein wenn fromDB true ist
* @param v der View auf dem das Popup sein soll
*/
private void showShoppinglistEditView(final boolean fromDB, String sl_id, View v) throws SQLException, JSONException {
private void showShoppinglistEditView(final boolean fromDB, String sl_id, String title, View v) throws SQLException, JSONException {
final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final String username = FirebaseAuth.getInstance().getCurrentUser().getUid();
View customView = inflater.inflate(R.layout.add_shoppinglist_dialog, null);
TextView fensterTitle = (TextView) customView.findViewById(R.id.shoppinglisteAddTitle);
fensterTitle.setText(title);
ImageButton addClose = (ImageButton) customView.findViewById(R.id.addClose);
colorBtn = (Button) customView.findViewById(R.id.addColor);
Button addFertig = (Button) customView.findViewById(R.id.addFertig);
@ -425,7 +430,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte
@Override
public void onChangeItemClick(String sl_id, View v) {
try {
showShoppinglistEditView(true, sl_id, v);
showShoppinglistEditView(true, sl_id, "Shoppingliste bearbeiten", v);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {

View File

@ -1,27 +1,46 @@
package at.smartshopper.smartshopper.activitys;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.TextView;
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.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 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 View colorView;
private SwipeRefreshLayout swipeRefreshLayoutItem;
@Override
@ -32,6 +51,50 @@ public class ItemListActivity extends Activity implements ItemAdapter.OnItemEdit
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"
this.groupNameString = myIntent.getStringExtra("groupNameString"); // will return "SecondKeyValue"
this.groupName = (TextView)findViewById(R.id.groupViewName);
this.groupName.setText(groupNameString);
this.colorView = (View) findViewById(R.id.itemListColorView);
try {
this.colorView.setBackgroundColor(Color.parseColor(db.getGroup(group_id, sl_id).getColor()));
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
this.swipeRefreshLayoutItem = (SwipeRefreshLayout) findViewById(R.id.itemListRefresh);
this.swipeRefreshLayoutItem.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
try {
showItems(group_id, sl_id);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
swipeRefreshLayoutItem.setRefreshing(false);
}
});
this.fabAddItem = (FloatingActionButton)findViewById(R.id.fabItemAdd);
fabAddItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
showPopupItemEdit(false, sl_id, group_id, null, "Item erstellen", v);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
try {
@ -69,11 +132,106 @@ public class ItemListActivity extends Activity implements ItemAdapter.OnItemEdit
@Override
public void onItemDelClicked(String item_id, String group_id, String sl_id) {
try {
swipeRefreshLayoutItem.setRefreshing(true);
db.deleteItem(item_id, group_id, sl_id);
showItems(group_id, sl_id);
swipeRefreshLayoutItem.setRefreshing(false);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onItemEditClicked(String item_id, String group_id, String sl_id, String newname, int newcount) {
public void onItemEditClicked(String item_id, String group_id, String sl_id, View v) {
try {
showPopupItemEdit(true, sl_id, group_id, item_id, "Item bearbeiten", v);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
private void showPopupItemEdit(final boolean fromDB, final String sl_id, final String group_id, final String item_id, String title, View v) throws SQLException, JSONException {
final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View customView = inflater.inflate(R.layout.add_item_dialog, null);
TextView addGroupTitle = (TextView) customView.findViewById(R.id.addItemTitle);
addGroupTitle.setText(title);
ImageButton close = (ImageButton) customView.findViewById(R.id.itemClose);
final EditText name = (EditText) customView.findViewById(R.id.itemName);
final EditText count = (EditText) customView.findViewById(R.id.itemAnzahl);
Button finish = (Button) customView.findViewById(R.id.itemFinish);
Picasso.get().load(R.drawable.close).into(close);
if (fromDB) {
Item dbitem = db.getItem(item_id);
name.setText(dbitem.getName());
count.setText(dbitem.getCount());
} else {
colorString = "ffffff";
}
finish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (fromDB) {
try {
db.editItem(item_id, group_id, sl_id, name.getText().toString(), Integer.parseInt(count.getText().toString()));
showItems(group_id, sl_id);
popupWindowItem.dismiss();
colorString = "ffffff";
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
} else {
try {
db.addItem(group_id, sl_id, name.getText().toString(), Integer.parseInt(count.getText().toString()));
showItems(group_id, sl_id);
popupWindowItem.dismiss();
colorString = "ffffff";
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindowItem.dismiss();
}
});
popupWindowItem = new PopupWindow(customView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
// Set an elevation value for popup window
// Call requires API level 21
if (Build.VERSION.SDK_INT >= 21) {
popupWindowItem.setElevation(5.0f);
}
popupWindowItem.setOutsideTouchable(false);
popupWindowItem.setFocusable(true);
popupWindowItem.showAtLocation(v, Gravity.CENTER, 0, 0);
popupWindowItem.update();
}
}

View File

@ -6,6 +6,7 @@ import android.os.Build;
import android.os.Bundle;
import android.app.Activity;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
@ -16,15 +17,12 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.Toast;
import android.widget.TextView;
import com.google.firebase.auth.FirebaseAuth;
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;
@ -33,9 +31,8 @@ import at.smartshopper.smartshopper.shoppinglist.Shoppinglist;
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, DetailsAdapter.OnCardClicked {
public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGroupEditClicked, DetailsAdapter.OnGroupDeleteClicked, DetailsAdapter.OnCardClicked {
private Database db = new Database();
private FloatingActionButton fab;
@ -43,6 +40,7 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
private PopupWindow popupWindow;
private PopupWindow popupWindowItem;
private Button colorBtn;
private SwipeRefreshLayout detailsSwiperefresh;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -70,7 +68,9 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
@Override
public void onClick(View v) {
try {
showPupupGroupEdit(false, null, finalSl_id, v);
detailsSwiperefresh.setRefreshing(true);
showPupupGroupEdit(false, null, finalSl_id, "Gruppe erstellen", v);
detailsSwiperefresh.setRefreshing(false);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
@ -87,6 +87,22 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
e.printStackTrace();
}
detailsSwiperefresh = (SwipeRefreshLayout) findViewById(R.id.detailsRefreshSwipe);
final String finalSl_id1 = sl_id;
detailsSwiperefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
try {
showDetails(finalSl_id1);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
detailsSwiperefresh.setRefreshing(false);
}
});
}
/**
@ -97,13 +113,15 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
* @param groupid Wenn fromDb true ist wird diese id benötigt um das richtige element zu bearbeiten
* @param v Der view auf dem das popup platziert werden soll
*/
private void showPupupGroupEdit(final boolean fromDB, final String groupid, final String sl_id, View v) throws SQLException, JSONException {
private void showPupupGroupEdit(final boolean fromDB, final String groupid, final String sl_id, String title, View v) throws SQLException, JSONException {
final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final String username = FirebaseAuth.getInstance().getCurrentUser().getUid();
View customView = inflater.inflate(R.layout.add_group_dialog, null);
TextView addGroupTitle = (TextView) customView.findViewById(R.id.addgruppetitle);
addGroupTitle.setText(title);
ImageButton close = (ImageButton) customView.findViewById(R.id.groupClose);
final EditText name = (EditText) customView.findViewById(R.id.groupName);
Button color = (Button) customView.findViewById(R.id.groupColor);
@ -122,7 +140,7 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
colorstring = "#" + dbgroup.getColor();
}
color.setBackgroundColor(Color.parseColor(colorstring));
name.setText(dbgroup.getName());
name.setText(dbgroup.getGroupName());
} else {
colorString = "ffffff";
}
@ -239,92 +257,17 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
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);
View customView = inflater.inflate(R.layout.add_item_dialog, null);
ImageButton close = (ImageButton) customView.findViewById(R.id.itemClose);
final EditText name = (EditText) customView.findViewById(R.id.itemName);
final EditText count = (EditText) customView.findViewById(R.id.itemAnzahl);
Button finish = (Button) customView.findViewById(R.id.itemFinish);
Picasso.get().load(R.drawable.close).into(close);
if (fromDB) {
Item dbitem = db.getItem(item_id);
name.setText(dbitem.getName());
} else {
colorString = "ffffff";
}
finish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (fromDB) {
try {
showDetails(sl_id);
popupWindow.dismiss();
colorString = "ffffff";
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
} else {
try {
db.addItem(group_id, sl_id, name.getText().toString(), Integer.parseInt(count.getText().toString()));
showDetails(sl_id);
popupWindowItem.dismiss();
colorString = "ffffff";
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindowItem.dismiss();
}
});
popupWindowItem = new PopupWindow(customView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
// Set an elevation value for popup window
// Call requires API level 21
if (Build.VERSION.SDK_INT >= 21) {
popupWindowItem.setElevation(5.0f);
}
popupWindowItem.setOutsideTouchable(false);
popupWindowItem.setFocusable(true);
popupWindowItem.showAtLocation(v, Gravity.CENTER, 0, 0);
popupWindowItem.update();
}
@Override
public void onGroupEditClick(String sl_id, String group_id, View v) {
try {
showPupupGroupEdit(true, group_id, sl_id, v);
detailsSwiperefresh.setRefreshing(true);
showPupupGroupEdit(true, group_id, sl_id, "Gruppe bearbeiten", v);
detailsSwiperefresh.setRefreshing(false);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
@ -335,8 +278,10 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
@Override
public void onGroupDeleteClick(String sl_id, String group_id, View v) {
try {
detailsSwiperefresh.setRefreshing(true);
db.deleteGroup(group_id, sl_id);
showDetails(sl_id);
detailsSwiperefresh.setRefreshing(false);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
@ -345,24 +290,12 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr
}
@Override
public void onItemAddClick(String sl_id, String group_id, String item_id, View v) {
try {
showPopupItemEdit(false, sl_id, group_id, item_id, v);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onCardClick(String group_id, String sl_id, View v) {
public void onCardClick(String group_id, String sl_id, String groupName, View v) {
finish();
Intent intent = new Intent(this, ItemListActivity.class);
intent.putExtra("group_id", group_id);
intent.putExtra("sl_id", sl_id);
intent.putExtra("groupNameString", groupName);
startActivity(intent);
}
}

View File

@ -137,7 +137,7 @@ public class Database {
public void editGroup(String sl_id, String group_id, String newname, String newcolor, String newhidden) throws SQLException, JSONException {
Group oldgroup = getGroup(group_id, sl_id);
if (!oldgroup.getName().equals(newname) && newname != null) {
if (!oldgroup.getGroupName().equals(newname) && newname != null) {
sqlUpdate3Param("UPDATE \"Group\" SET name = ? WHERE group_id = ? AND sl_id = ?", newname, group_id, sl_id);
}

View File

@ -1,8 +1,8 @@
package at.smartshopper.smartshopper.shoppinglist.details;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.media.Image;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
@ -11,25 +11,19 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
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.RoundCornersTransformation;
import at.smartshopper.smartshopper.db.Database;
import at.smartshopper.smartshopper.shoppinglist.ShoppinglistAdapter;
import at.smartshopper.smartshopper.shoppinglist.details.item.ItemAdapter;
import at.smartshopper.smartshopper.shoppinglist.details.item.ItemShoppinglistDetailsAdapter;
public class DetailsAdapter extends RecyclerView.Adapter<DetailsAdapter.MyViewHolder> {
public class DetailsAdapter extends RecyclerView.Adapter<DetailsAdapter.MyViewHolder> implements ItemShoppinglistDetailsAdapter.OnItemEditClicked {
private List<Details> details;
private OnGroupEditClicked onGroupEditClicked;
private OnItemAddClicked onItemAddClicked;
private OnGroupDeleteClicked onGroupDeleteClicked;
private OnCardClicked onCardClicked;
@ -62,18 +56,17 @@ public class DetailsAdapter extends RecyclerView.Adapter<DetailsAdapter.MyViewHo
*/
@Override
public void onBindViewHolder(@NonNull MyViewHolder viewHolder, final int i) {
TextView groupName = viewHolder.groupName;
final TextView groupName = viewHolder.groupName;
ImageButton deleteGroup = viewHolder.deleteGroup;
RecyclerView itemsrecycle = viewHolder.itemsrecycle;
View groupColor = viewHolder.grouoColor;
ImageButton editGroup = viewHolder.editGroup;
ImageButton addItem = viewHolder.addItem;
itemsrecycle.setHasFixedSize(true);
itemsrecycle.setLayoutManager(new LinearLayoutManager(new Activity()));
List<at.smartshopper.smartshopper.shoppinglist.details.item.Item> itemsList = details.get(i).getItems();
ItemAdapter itemAdapter = new ItemAdapter(itemsList);
ItemShoppinglistDetailsAdapter itemAdapter = new ItemShoppinglistDetailsAdapter(itemsList);
itemAdapter.setOnItemEditClick(this);
itemsrecycle.setAdapter(itemAdapter);
@ -88,23 +81,14 @@ public class DetailsAdapter extends RecyclerView.Adapter<DetailsAdapter.MyViewHo
}
groupColor.setBackgroundColor(cardcolor);
groupName.setText(details.get(i).getGroup().getName());
groupName.setText(details.get(i).getGroup().getGroupName());
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) {
onItemAddClicked.onItemAddClick(details.get(i).getGroup().getSl_idd(), details.get(i).getGroup().getGroup_id(), db.generateItemId(), v);
onCardClicked.onCardClick(details.get(i).getGroup().getGroup_id(), details.get(i).getGroup().getSl_idd(), details.get(i).getGroup().getGroupName(), v);
}
});
@ -123,11 +107,21 @@ public class DetailsAdapter extends RecyclerView.Adapter<DetailsAdapter.MyViewHo
});
}
@Override
public void onItemEditClicked(String item_id, String group_id, String sl_id, String groupName, View v) {
//v.getContext().finish();
Intent intent = new Intent(v.getContext(), ItemListActivity.class);
intent.putExtra("group_id", group_id);
intent.putExtra("sl_id", sl_id);
intent.putExtra("groupNameString", groupName);
v.getContext().startActivity(intent);
}
/**
* Interface damit onoclick in der Shoppinglistdetails activity ausgeführt werden kann
*/
public interface OnCardClicked {
void onCardClick(String group_id, String sl_id, View v);
void onCardClick(String group_id, String sl_id, String groupName, View v);
}
/**
@ -138,21 +132,6 @@ public class DetailsAdapter extends RecyclerView.Adapter<DetailsAdapter.MyViewHo
this.onCardClicked = onCardClicked;
}
/**
* Interface damit onoclick in der Shoppinglistdetails activity ausgeführt werden kann
*/
public interface OnItemAddClicked {
void onItemAddClick(String sl_id, String group_id, String item_id, View v);
}
/**
* Setzt das OnChangeItemClick event
* @param onItemAddClicked Der Click event Listener
*/
public void setItemAddClick(OnItemAddClicked onItemAddClicked){
this.onItemAddClicked = onItemAddClicked;
}
/**
* Interface damit onoclick in der Shoppinglistdetails activity ausgeführt werden kann
*/
@ -194,7 +173,7 @@ public class DetailsAdapter extends RecyclerView.Adapter<DetailsAdapter.MyViewHo
public static class MyViewHolder extends RecyclerView.ViewHolder {
TextView groupName;
ImageButton deleteGroup, editGroup, addItem;
ImageButton deleteGroup, editGroup;
RecyclerView itemsrecycle;
View grouoColor;
CardView groupCard;
@ -206,7 +185,6 @@ public class DetailsAdapter extends RecyclerView.Adapter<DetailsAdapter.MyViewHo
this.itemsrecycle = (RecyclerView) itemView.findViewById(R.id.itemsRecycle);
this.grouoColor = (View) itemView.findViewById(R.id.groupColorView);
this.editGroup = (ImageButton) itemView.findViewById(R.id.editGroup);
this.addItem = (ImageButton) itemView.findViewById(R.id.addItem);
this.groupCard = (CardView) itemView.findViewById(R.id.cardViewGroup);
}

View File

@ -31,12 +31,18 @@ public class Group {
return this.sl_id;
}
public String getName() {
public String getGroupName() {
return this.name;
}
public String getColor() {
return this.color;
if(color.isEmpty()){
return "#FFFFFF";
}else if (!color.contains("#")){
return "#" + this.color;
}else {
return this.color;
}
}
public String getHidden() {

View File

@ -1,7 +1,10 @@
package at.smartshopper.smartshopper.shoppinglist.details.item;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -11,10 +14,14 @@ import android.widget.TextView;
import com.squareup.picasso.Picasso;
import org.json.JSONException;
import java.sql.SQLException;
import java.util.List;
import at.smartshopper.smartshopper.R;
import at.smartshopper.smartshopper.db.Database;
public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.MyViewHolder> {
@ -55,16 +62,39 @@ public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.MyViewHolder>
final TextView itemAnzahl = myViewHolder.itemAnzahl;
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();
}
*/
itemName.setText(data.get(i).getName());
itemAnzahl.setText(data.get(i).getCount());
Picasso.get().load(R.drawable.delete).into(itemDel);
/*
itemName.setOnClickListener(new View.OnClickListener() {
itemCardView.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()));
onItemEditClick.onItemEditClicked(data.get(i).getItem_id(), data.get(i).getGroup_id(), data.get(i).getSl_id(), v);
}
});
@ -74,19 +104,19 @@ public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.MyViewHolder>
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){
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);
void onItemEditClicked(String item_id, String group_id, String sl_id, View v);
}
public void setOnItemEditClick(OnItemEditClicked onItemEditClick) {
@ -106,6 +136,8 @@ public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.MyViewHolder>
TextView itemName, itemAnzahl;
ImageView itemDel;
CheckBox erledigtItem;
CardView itemCardView;
//View colorBox;
public MyViewHolder(View itemView) {
super(itemView);
@ -114,6 +146,8 @@ public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.MyViewHolder>
this.itemAnzahl = (TextView) itemView.findViewById(R.id.anzahlItem);
this.itemDel = (ImageView) itemView.findViewById(R.id.itemDel);
this.erledigtItem = (CheckBox) itemView.findViewById(R.id.erledigtItem);
this.itemCardView = (CardView) itemView.findViewById(R.id.itemCardView);
//this.colorBox = (View) itemView.findViewById(R.id.itemListColorView);
}
}
}

View File

@ -0,0 +1,112 @@
package at.smartshopper.smartshopper.shoppinglist.details.item;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import org.json.JSONException;
import java.sql.SQLException;
import java.util.List;
import at.smartshopper.smartshopper.R;
import at.smartshopper.smartshopper.db.Database;
public class ItemShoppinglistDetailsAdapter extends RecyclerView.Adapter<ItemShoppinglistDetailsAdapter.MyViewHolder> {
private List<at.smartshopper.smartshopper.shoppinglist.details.item.Item> data;
private OnItemEditClicked onItemEditClick;
public ItemShoppinglistDetailsAdapter(List<at.smartshopper.smartshopper.shoppinglist.details.item.Item> data) {
this.data = data;
}
/**
* Erstellt einen Neuen view holder mit aktueller view
*
* @param viewGroup
* @param i
* @return
*/
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cardviewitemshoppinglistdetails, viewGroup, false);
MyViewHolder myViewHolder = new MyViewHolder(view);
return myViewHolder;
}
/**
* 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
*/
@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, final int i) {
final TextView itemName = myViewHolder.itemName;
TextView itemAnzahl = myViewHolder.itemAnzahl;
CheckBox itemErledigt = myViewHolder.erledigtItem;
CardView itemCardView = myViewHolder.itemCardView;
itemCardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
onItemEditClick.onItemEditClicked(data.get(i).getItem_id(), data.get(i).getGroup_id(), data.get(i).getSl_id(), new Database().getGroup(data.get(i).getGroup_id(), data.get(i).getSl_id()).getGroupName(), v);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
itemName.setText(data.get(i).getName());
itemAnzahl.setText(data.get(i).getCount());
}
public interface OnItemEditClicked {
void onItemEditClicked(String item_id, String group_id, String sl_id, String groupName, View v);
}
public void setOnItemEditClick(OnItemEditClicked onItemEditClick) {
this.onItemEditClick = onItemEditClick;
}
@Override
public int getItemCount() {
return data.size();
}
/**
* 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 {
TextView itemName, itemAnzahl;
CheckBox erledigtItem;
CardView itemCardView;
public MyViewHolder(View itemView) {
super(itemView);
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

@ -6,78 +6,114 @@
android:layout_height="match_parent"
tools:context=".activitys.ItemListActivity">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/itemListRefresh"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<LinearLayout
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content" >
<View
android:id="@+id/groupViewColorView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:src="@drawable/rechteck"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/guideline5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/groupViewName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="GroupName"
android:textAlignment="center"
android:textColor="@android:color/background_dark"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/itemsListRecycler"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="29dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/itemsListRecycler"
android:layout_width="0dp"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline5" />
android:orientation="vertical">
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
<View
android:id="@+id/itemListColorView"
android:layout_width="13dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:src="@drawable/rechteck"
app:layout_constraintBottom_toBottomOf="@+id/itemsListRecycler"
app:layout_constraintEnd_toStartOf="@+id/guideline5"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.v7.widget.CardView>
<TextView
android:id="@+id/groupViewName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="GroupName"
android:textAlignment="center"
android:textColor="@android:color/background_dark"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="29dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/itemsListRecycler"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/groupViewName" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.v7.widget.CardView>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabItemAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:clickable="true"
android:src="@drawable/addoutline"
app:backgroundTint="@color/fui_linkColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>

View File

@ -6,12 +6,28 @@
android:layout_height="match_parent"
tools:context=".activitys.ShoppinglistDetails">
<android.support.v7.widget.RecyclerView
android:id="@+id/groupRecycle"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/detailsRefreshSwipe"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:id="@+id/groupRecycle"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/addGroupFab"
@ -23,6 +39,6 @@
android:clickable="true"
android:src="@drawable/addoutline"
app:backgroundTint="@color/fui_linkColor"
app:layout_constraintBottom_toBottomOf="@+id/groupRecycle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>

View File

@ -41,7 +41,7 @@
android:orientation="vertical">
<TextView
android:id="@+id/textView3"
android:id="@+id/addgruppetitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gruppe Bearbeiten"

View File

@ -41,7 +41,7 @@
android:orientation="vertical">
<TextView
android:id="@+id/textView4"
android:id="@+id/addItemTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Item Bearbeiten"

View File

@ -44,7 +44,7 @@
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:id="@+id/shoppinglisteAddTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Shoppingliste Hinzufügen"

View File

@ -59,12 +59,10 @@
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Name"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/addItem"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -90,17 +88,6 @@
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/bearbeiten" />
<ImageButton
android:id="@+id/addItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:background="@color/fui_transparent"
app:layout_constraintEnd_toStartOf="@+id/editGroup"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/add" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.Guideline

View File

@ -1,6 +1,7 @@
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/itemCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -12,43 +13,71 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:gravity="left"
android:orientation="horizontal"
android:padding="8dp">
<CheckBox
android:id="@+id/erledigtItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="@+id/nameItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ItemName" />
<TextView
android:id="@+id/anzahlItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Anzahl" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:id="@+id/itemDel"
<CheckBox
android:id="@+id/erledigtItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
app:srcCompat="@drawable/delete" />
</LinearLayout>
android:textAlignment="viewStart"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/nameItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
android:text="ItemName"
android:textAlignment="viewStart"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/erledigtItem"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/anzahlItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:text="Anzahl"
android:textAlignment="textEnd" />
<ImageView
android:id="@+id/itemDel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/delete" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</LinearLayout>

View File

@ -0,0 +1,39 @@
<?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:id="@+id/itemCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#DBDBDB"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:id="@+id/nameItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:text="ItemName" />
<TextView
android:id="@+id/anzahlItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:text="Anzahl"
android:textAlignment="textEnd" />
</LinearLayout>
</android.support.v7.widget.CardView>