Shared List Member Custom Edit Share

Member können Share
deabonieren
Bearbeiten
und nichtmehr Löschen
This commit is contained in:
Georg Reisinger 2019-02-18 20:30:20 +01:00
parent 6a0649b9ab
commit 8dfa175286
5 changed files with 605 additions and 19 deletions
app/src/main

@ -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<Shoppinglist> 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);
}
}

@ -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
*

@ -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<ShoppinglistSharedAdapter.ShoppinglistViewHolder> {
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> shoppinglist;
private SharedOnShoppinglistClick sharedOnShoppinglistClick;
//getting the context and product list with constructor
public ShoppinglistSharedAdapter(Context mCtx, List<Shoppinglist> 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);
}
}
}

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="utf-8"?>
<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:tools="http://schemas.android.com/tools"
android:id="@+id/ownLists"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="8dp"
card_view:cardElevation="4dp"
card_view:cardUseCompatPadding="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/shoppinglistColor"
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"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toStartOf="@+id/guideline4"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:orientation="vertical"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toStartOf="@+id/guideline"
card_view:layout_constraintStart_toStartOf="@+id/guideline4"
card_view:layout_constraintTop_toTopOf="parent"
card_view:layout_constraintVertical_bias="0.436">
<ImageView
android:id="@+id/shoppinglistOwner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@drawable/common_google_signin_btn_icon_dark" />
<TextView
android:id="@+id/ownerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OwnerName"
android:textSize="10sp"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toBottomOf="@+id/shoppinglistOwner" />
</LinearLayout>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
card_view:layout_constraintGuide_begin="111dp" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:orientation="vertical"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toStartOf="@+id/guideline2"
card_view:layout_constraintStart_toStartOf="@+id/guideline"
card_view:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/shoppinglistName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Name"
android:textSize="18sp"
android:textStyle="bold"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toEndOf="@+id/shoppinglistOwner"
card_view:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/shoppinglistBeschreibung"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Beschreibung"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toEndOf="@+id/shoppinglistOwner"
card_view:layout_constraintTop_toBottomOf="@+id/shoppinglistName" />
</LinearLayout>
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
card_view:layout_constraintGuide_begin="319dp" />
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:gravity="right|top"
android:orientation="horizontal"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toStartOf="@+id/guideline2"
card_view:layout_constraintTop_toTopOf="parent">
<ImageButton
android:id="@+id/shareEditButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/fui_transparent"
card_view:srcCompat="@drawable/share" />
<ImageButton
android:id="@+id/bearbeiteShoppinglist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/fui_transparent"
card_view:srcCompat="@drawable/bearbeiten" />
</LinearLayout>
<android.support.constraint.Guideline
android:id="@+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
card_view:layout_constraintGuide_begin="32dp" />
</android.support.constraint.ConstraintLayout>
</TableRow>
</android.support.v7.widget.CardView>

@ -0,0 +1,71 @@
<?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">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="vertical">
<ImageButton
android:id="@+id/exitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/fui_transparent"
app:srcCompat="@drawable/close" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<EditText
android:id="@+id/linkausgabe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable="false"
android:ems="10"
android:inputType="textPersonName" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<Button
android:id="@+id/copyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="in die zwischenablage kopieren" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<Button
android:id="@+id/delShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Listen Sharing beenden!" />
</TableRow>
</TableLayout>
</android.support.v7.widget.CardView>