From 8dfa17528641f7e15eb5a4c1c1665d33f192ff85 Mon Sep 17 00:00:00 2001 From: Georg Reisinger <43533139+GeorgReisinger@users.noreply.github.com> Date: Mon, 18 Feb 2019 20:30:20 +0100 Subject: [PATCH] Shared List Member Custom Edit Share MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Member können Share deabonieren Bearbeiten und nichtmehr Löschen --- .../smartshopper/activitys/Dash.java | 148 +++++++++-- .../smartshopper/db/Database.java | 11 + .../ShoppinglistSharedAdapter.java | 230 ++++++++++++++++++ .../res/layout/cardviewshoppinglistshared.xml | 164 +++++++++++++ app/src/main/res/layout/edit_share_member.xml | 71 ++++++ 5 files changed, 605 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/at/smartshopper/smartshopper/shoppinglist/ShoppinglistSharedAdapter.java create mode 100644 app/src/main/res/layout/cardviewshoppinglistshared.xml create mode 100644 app/src/main/res/layout/edit_share_member.xml 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 dfba286..04ec27a 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java +++ b/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java @@ -55,14 +55,15 @@ import at.smartshopper.smartshopper.customViews.SpaceItemDecoration; import at.smartshopper.smartshopper.db.Database; import at.smartshopper.smartshopper.shoppinglist.Shoppinglist; import at.smartshopper.smartshopper.shoppinglist.ShoppinglistAdapter; +import at.smartshopper.smartshopper.shoppinglist.ShoppinglistSharedAdapter; -public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnItemClicked, ShoppinglistAdapter.OnShoppinglistClick, ShoppinglistAdapter.OnChangeItemClick, ShoppinglistAdapter.OnShareClick { +public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnItemClicked, ShoppinglistAdapter.OnShoppinglistClick, ShoppinglistAdapter.OnChangeItemClick, ShoppinglistAdapter.OnShareClick, ShoppinglistSharedAdapter.SharedOnItemClicked, ShoppinglistSharedAdapter.SharedOnChangeItemClick, ShoppinglistSharedAdapter.SharedOnShareClick, ShoppinglistSharedAdapter.SharedOnShoppinglistClick { private final Database db = new Database(); private SwipeRefreshLayout ownswiperefresh, sharedswiperefresh; private FloatingActionButton addShoppinglistFab; - private PopupWindow popupWindowAdd, popupShare, popupAddShare; + private PopupWindow popupWindowAdd, popupShare, popupAddShare, popupEditShare; private String color; private Button colorBtn; @@ -343,7 +344,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte sharedRecycler.setHasFixedSize(true); sharedRecycler.setLayoutManager(new LinearLayoutManager(this)); List ownListsList = db.getSharedShoppinglists(uid); - ShoppinglistAdapter shpAdapter = new ShoppinglistAdapter(Dash.this, ownListsList, db); + ShoppinglistSharedAdapter shpAdapter = new ShoppinglistSharedAdapter(Dash.this, ownListsList, db); shpAdapter.setOnDelClick(Dash.this); shpAdapter.setOnChangeClick(Dash.this); shpAdapter.setOnShareClick(Dash.this); @@ -545,8 +546,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte * * @param sl_id Die Shoppingliste dieser Id wird gelöscht */ - @Override - public void onItemClick(String sl_id) { + private void onItemClickContainer(String sl_id){ try { db.delShoppinglist(sl_id); refreshOwnShoppinglist(FirebaseAuth.getInstance().getCurrentUser().getUid()); @@ -560,8 +560,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte * * @param sl_id Die Shoppinglist die bearbeitet werden soll */ - @Override - public void onChangeItemClick(String sl_id, View v) { + private void onChangeItemClickContainer(String sl_id, View v){ try { showShoppinglistEditView(true, sl_id, "Shoppingliste bearbeiten", v); } catch (SQLException e) { @@ -571,9 +570,39 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte } } + private void onShoppinglistClickContainer(String sl_id, View v){ + Intent intent = new Intent(this, ShoppinglistDetails.class); + intent.putExtra("sl_id", sl_id); + + startActivity(intent); + } + + /** + * Das ist der Onclick für die einzelnen shoppinglists. Löscht eine shoppinglist und refreshed alle anderen + * + * @param sl_id Die Shoppingliste dieser Id wird gelöscht + */ @Override - public void onShareClick(String sl_id, View v) { - Log.d("ShareClick test", "Workt sl_id: " + sl_id); + public void onItemClick(String sl_id) { + onItemClickContainer(sl_id); + } + + /** + * Das ist der oncklick für eine einzelen Shoppinglist. Bearbeitet eine Shoppinglist + * + * @param sl_id Die Shoppinglist die bearbeitet werden soll + */ + @Override + public void onChangeItemClick(String sl_id, View v) { + onChangeItemClickContainer(sl_id, v); + } + + /** + * Holt den Invitelink einer Shoppingliste + * @param sl_id Die Shoppingliste von der der invitelink gewünscht ist + * @return + */ + private String getInviteLink(String sl_id){ String link = null; try { if (db.isShared(sl_id)) { @@ -587,6 +616,12 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte } catch (JSONException e) { e.printStackTrace(); } + return link; + } + + @Override + public void onShareClick(String sl_id, View v) { + final String link = getInviteLink(sl_id); final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE); View popupContentView = inflater.inflate(R.layout.add_share, null); @@ -603,13 +638,11 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte } }); - Button copyButton = (Button) popupContentView.findViewById(R.id.shareCopy); + final Button copyButton = (Button) popupContentView.findViewById(R.id.shareCopy); copyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("SmartShopper", linkausgabe.getText().toString()); - clipboard.setPrimaryClip(clip); + copyText(linkausgabe.getText().toString()); popupShare.dismiss(); } }); @@ -657,12 +690,89 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte 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); + /** + * Kopiert einen Text in die Zwischenablage + * @param text Der Text, welcher zu kopieren ist + */ + private void copyText(String text){ + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("SmartShopper", text); + clipboard.setPrimaryClip(clip); } + @Override + public void onShoppinglistClick(String sl_id, View v) { + onShoppinglistClickContainer(sl_id, v); + } + + @Override + public void sharedOnItemClick(String sl_id) { + onItemClickContainer(sl_id); + } + + @Override + public void sharedOnChangeItemClick(String sl_id, View v) { + onChangeItemClickContainer(sl_id, v); + } + + @Override + public void sharedOnShareClick(String sl_id, View v) { + final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE); + View popupContentView = inflater.inflate(R.layout.edit_share_member, null); + + ImageButton exitBtn = popupContentView.findViewById(R.id.exitButton); + Picasso.get().load(R.drawable.close).into(exitBtn); + final TextView linkAusgabe = popupContentView.findViewById(R.id.linkausgabe); + Button copyBtn = popupContentView.findViewById(R.id.copyButton); + Button stopShareBtn = popupContentView.findViewById(R.id.delShare); + + + linkAusgabe.setText("www.smartshopper.cf/invite/" + getInviteLink(sl_id)); + exitBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + popupEditShare.dismiss(); + } + }); + copyBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + copyText(linkAusgabe.getText().toString()); + popupEditShare.dismiss(); + } + }); + stopShareBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + db.stopInvite(linkAusgabe.getText().toString(), FirebaseAuth.getInstance().getCurrentUser().getUid()); + popupEditShare.dismiss(); + } catch (SQLException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }); + + + popupEditShare = new PopupWindow(popupContentView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + popupEditShare.setOutsideTouchable(false); + popupEditShare.setFocusable(true); + // Set an elevation value for popup window + // Call requires API level 21 + if (Build.VERSION.SDK_INT >= 21) { + popupEditShare.setElevation(5.0f); + } + popupEditShare.setAnimationStyle(R.style.popup_window_animation_phone); + + + popupEditShare.showAtLocation(v, Gravity.CENTER, 0, 0); + popupEditShare.update(); + } + + @Override + public void sharedOnShoppinglistClick(String sl_id, View v) { + onShoppinglistClickContainer(sl_id, v); + } } 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 2613ddb..872b10e 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/db/Database.java +++ b/app/src/main/java/at/smartshopper/smartshopper/db/Database.java @@ -131,6 +131,17 @@ public class Database { sqlUpdate("Update \"Shoppinglist\" set invitelink=null where sl_id=?", sl_id); } + /** + * Stopt eine Einladung, indem der Member die liste nichtmehr sehen kann + * @param invitelink Der invitelink + * @throws SQLException + * @throws JSONException + */ + public void stopInvite(String invitelink, String uid) throws SQLException, JSONException { + String sl_id = getSlIdFromInvite(invitelink); + sqlUpdate2Param("DELETE FROM \"Shoppinglist_member\" WHERE sl_id = ? AND username = ?", sl_id, uid); + } + /** * Gibt den Invite link einer Shoppingliste zurück, wenn keiner vorhanden ist --> null * diff --git a/app/src/main/java/at/smartshopper/smartshopper/shoppinglist/ShoppinglistSharedAdapter.java b/app/src/main/java/at/smartshopper/smartshopper/shoppinglist/ShoppinglistSharedAdapter.java new file mode 100644 index 0000000..46a5302 --- /dev/null +++ b/app/src/main/java/at/smartshopper/smartshopper/shoppinglist/ShoppinglistSharedAdapter.java @@ -0,0 +1,230 @@ +package at.smartshopper.smartshopper.shoppinglist; + +import android.content.Context; +import android.graphics.Color; +import android.net.Uri; +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.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.squareup.picasso.Picasso; + +import java.util.List; + +import at.smartshopper.smartshopper.R; +import at.smartshopper.smartshopper.customViews.RoundCornersTransformation; +import at.smartshopper.smartshopper.db.Database; + +public class ShoppinglistSharedAdapter extends RecyclerView.Adapter { + + private SharedOnChangeItemClick sharedOnChangeClick; + private SharedOnItemClicked sharedOnClick; + private SharedOnShareClick sharedOnShareClick; + 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; + private SharedOnShoppinglistClick sharedOnShoppinglistClick; + + //getting the context and product list with constructor + public ShoppinglistSharedAdapter(Context mCtx, List shoppinglist, Database db) { + this.mCtx = mCtx; + this.shoppinglist = shoppinglist; + this.db = db; + } + + /** + * Erstellt einen Neuen view holder mit aktueller view + * + * @param parent + * @param viewType + * @return + */ + @Override + public ShoppinglistViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + //inflating and returning our view holder + LayoutInflater inflater = LayoutInflater.from(mCtx); + View view = inflater.inflate(R.layout.cardviewshoppinglistshared, parent, false); + return new ShoppinglistViewHolder(view); + } + + /** + * Setzt alle Daten in die View elemente + * + * @param holder Das View Holder Objekt mit allen elementen + * @param position Der Index welcher aus der data list genommen werden soll + */ + @Override + public void onBindViewHolder(ShoppinglistViewHolder holder, final int position) { + //getting the product of the specified position, + final Shoppinglist shoppinglist = this.shoppinglist.get(position); + final ImageButton shareButton = holder.share; + TextView beschreibung = holder.textViewBeschreibung; + beschreibung.setText(shoppinglist.getdescription()); + Picasso.get().load(R.drawable.share).into(shareButton); + + //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) { + sharedOnShoppinglistClick.sharedOnShoppinglistClick(shoppinglist.getSlId(), v); + } + }); + holder.bearbeiten.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + sharedOnChangeClick.sharedOnChangeItemClick(shoppinglist.getSlId(), v); + } + }); + shareButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String sl_id = shoppinglist.getSlId(); + Toast.makeText(v.getContext(), "LISTENER im ADAPTER geht: " + sl_id, Toast.LENGTH_LONG); + sharedOnShareClick.sharedOnShareClick(sl_id, v); + } + }); + + int cardcolor; + try { + cardcolor = Color.parseColor(shoppinglist.getcolor()); + } catch (Exception e) { + cardcolor = Color.parseColor("#FFFFFF"); + } + + holder.shoppinglistColor.setBackgroundColor(cardcolor); + + FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); + if (user != null) { + // Name, email address, and profile photo Url + String name = user.getDisplayName(); + Uri photoUrl = user.getPhotoUrl(); + holder.ownerName.setText(name); + Picasso.get().load(photoUrl).resize(250, 250).transform(new RoundCornersTransformation(30, 30, true, true)).into(holder.imageView); + // holder.imageView.setImageDrawable(Drawable.createFromPath("@drawable/common_google_signin_btn_icon_dark")); + + // Check if user's email is verified + + // The user's ID, unique to the Firebase project. Do NOT use this value to + // authenticate with your backend server, if you have one. Use + // FirebaseUser.getIdToken() instead. + } + + + } + + + /** + * Holt die anzahl der items in dem Adapter + * @return Anzahl der Items in dem Adapter + */ + @Override + public int getItemCount() { + return shoppinglist.size(); + } + + /** + * Interface damit onoclick in der dash activity ausgeführt werden kann + */ + public interface SharedOnItemClicked { + void sharedOnItemClick(String sl_id); + } + + /** + * Interface damit onoclick in der dash activity ausgeführt werden kann + */ + public interface SharedOnChangeItemClick{ + void sharedOnChangeItemClick(String sl_id, View v); + } + + /** + * Setzt das OnChangeItemClick event + * @param onChangeClick Der Click event Listener + */ + public void setOnChangeClick(SharedOnChangeItemClick onChangeClick){ + this.sharedOnChangeClick = onChangeClick; + } + + /** + * Setzt das OnItemClicked event + * @param onClick Der Click Listener + */ + public void setOnDelClick(SharedOnItemClicked onClick) + { + this.sharedOnClick=onClick; + } + + /** + * Interface damit onoclick in der dash activity ausgeführt werden kann + */ + public interface SharedOnShareClick{ + void sharedOnShareClick(String sl_id, View v); + } + + /** + * Setzt das OnChangeItemClick event + * @param onShareClick Der Click event Listener + */ + public void setOnShareClick(SharedOnShareClick onShareClick){ + this.sharedOnShareClick = onShareClick; + } + + /** + * Interface damit onoclick in der dash activity ausgeführt werden kann + */ + public interface SharedOnShoppinglistClick{ + void sharedOnShoppinglistClick(String sl_id, View v); + } + + /** + * Setzt das OnChangeItemClick event + * @param onShoppinglistClick Der Click event Listener + */ + public void setOnShoppinglistClick(SharedOnShoppinglistClick onShoppinglistClick){ + this.sharedOnShoppinglistClick = onShoppinglistClick; + } + + + + + /** + * Haltet alle elemente. Durch ein Objekt von dem kann jedes Element welches hier drinnen angeführt ist verwendet werden + */ + class ShoppinglistViewHolder extends RecyclerView.ViewHolder { + + TextView textViewTitle, textViewBeschreibung, ownerName; + ImageView imageView; + CardView ownList; + ImageButton bearbeiten, share; + View shoppinglistColor; + + public ShoppinglistViewHolder(View itemView) { + super(itemView); + + textViewTitle = itemView.findViewById(R.id.shoppinglistName); + textViewBeschreibung = itemView.findViewById(R.id.shoppinglistBeschreibung); + imageView = itemView.findViewById(R.id.shoppinglistOwner); + ownerName = itemView.findViewById(R.id.ownerName); + ownList = itemView.findViewById(R.id.ownLists); + bearbeiten = itemView.findViewById(R.id.bearbeiteShoppinglist); + shoppinglistColor = itemView.findViewById(R.id.shoppinglistColor); + share = itemView.findViewById(R.id.shareEditButton); + + } + + + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/cardviewshoppinglistshared.xml b/app/src/main/res/layout/cardviewshoppinglistshared.xml new file mode 100644 index 0000000..3577bd5 --- /dev/null +++ b/app/src/main/res/layout/cardviewshoppinglistshared.xml @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/edit_share_member.xml b/app/src/main/res/layout/edit_share_member.xml new file mode 100644 index 0000000..3196338 --- /dev/null +++ b/app/src/main/res/layout/edit_share_member.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + +