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 392a1c4..4e4c6b8 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java +++ b/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java @@ -64,6 +64,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte private Button colorBtn; //Für Double Back press to exit private boolean doubleBackToExitPressedOnce = false; + private TabHost host; /** * Convertiert eine int farbe in eine hexa dezimale Farbe @@ -159,6 +160,16 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte // Erstellt die Tabs tabHoster(uid); + // Get the transferred data from source activity. + Intent intent = getIntent(); + String message = intent.getStringExtra("tab2"); + String wahr = "true"; + if(message != null){ + if(message.equals(wahr)) { + host.setCurrentTab(1); + } + } + try { try { showOwnShoppingList(uid); @@ -337,6 +348,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte colorBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + finish(); Intent intent = new Intent(Dash.this, Colorpicker.class); startActivityForResult(intent, 1); @@ -526,7 +538,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte * Hier wird auch der Name der Tabs gesetzt */ private void tabHoster(final String uid) { - final TabHost host = (TabHost) findViewById(R.id.tabHost1); + host = (TabHost) findViewById(R.id.tabHost1); host.setup(); //Tab 1 @@ -574,6 +586,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte * Schickt an die Login Activity einen intend mit dem extra EXIT. Um die app zu schließen */ private void exit() { + finish(); Intent intent = new Intent(Dash.this, LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("EXIT", true); @@ -604,10 +617,12 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte popupaddInvite(); return true; case R.id.doneEinkauf: + finish(); Intent intent = new Intent(Dash.this, DoneItemActivity.class); startActivity(intent); return true; case R.id.editUser: + finish(); Intent intent2 = new Intent(Dash.this, EditUser.class); startActivity(intent2); return true; @@ -765,6 +780,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte } private void onShoppinglistClickContainer(String sl_id, View v) { + finish(); Intent intent = new Intent(this, ShoppinglistDetails.class); intent.putExtra("sl_id", sl_id); diff --git a/app/src/main/java/at/smartshopper/smartshopper/activitys/DoneItemActivity.java b/app/src/main/java/at/smartshopper/smartshopper/activitys/DoneItemActivity.java index 0a07fe1..cfc3d53 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/activitys/DoneItemActivity.java +++ b/app/src/main/java/at/smartshopper/smartshopper/activitys/DoneItemActivity.java @@ -1,10 +1,14 @@ package at.smartshopper.smartshopper.activitys; +import android.content.Intent; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import org.json.JSONException; @@ -13,6 +17,7 @@ import java.util.List; import at.smartshopper.smartshopper.R; import at.smartshopper.smartshopper.customViews.SpaceItemDecoration; +import at.smartshopper.smartshopper.customViews.ToolbarHelper; import at.smartshopper.smartshopper.db.Database; import at.smartshopper.smartshopper.shoppinglist.details.item.Item; import at.smartshopper.smartshopper.shoppinglist.details.item.ItemShoppinglistDetailsAdapter; @@ -20,12 +25,89 @@ import at.smartshopper.smartshopper.shoppinglist.details.item.ItemShoppinglistDe public class DoneItemActivity extends AppCompatActivity { private Database db; + private String from, sl_id; + private String groupname; + private String group_id; + + /** + * Menu item Action listener + * + * @param item Action Item + * @return True wenn erfolgreich + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + ToolbarHelper th = new ToolbarHelper(getApplicationContext(), getWindow().getDecorView()); + switch (item.getItemId()) { + case R.id.logoutBtn: + th.logout(); + return true; + + case R.id.addInvite: + th.popupaddInvite(); + return true; + case R.id.editUser: + finish(); + Intent intent2 = new Intent(this, EditUser.class); + startActivity(intent2); + return true; + default: + // If we got here, the user's action was not recognized. + // Invoke the superclass to handle it. + return super.onOptionsItemSelected(item); + + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + + MenuInflater inflater = getMenuInflater(); + + inflater.inflate(R.menu.done_items_menu, menu); + + return true; + + } + + @Override + public void onBackPressed() { + finish(); + Intent intent = new Intent(this, ShoppinglistDetails.class); + if (from != null) { + switch (from) { + case "shpdetails": + intent = new Intent(this, ShoppinglistDetails.class); + intent.putExtra("sl_id", sl_id); + + break; + case "itemlist": + intent = new Intent(this, ItemListActivity.class); + intent.putExtra("sl_id", sl_id); + intent.putExtra("groupNameString", groupname); + intent.putExtra("group_id", group_id); + break; + } + } else { + intent = new Intent(this, Dash.class); + } + + + startActivity(intent); + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_done_item); + Intent intent = getIntent(); + from = intent.getStringExtra("from"); + sl_id = intent.getStringExtra("sl_id"); + groupname = intent.getStringExtra("groupNameString"); + group_id = intent.getStringExtra("group_id"); + + db = new Database(); final SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.doneItemListRefresh); diff --git a/app/src/main/java/at/smartshopper/smartshopper/activitys/ItemListActivity.java b/app/src/main/java/at/smartshopper/smartshopper/activitys/ItemListActivity.java index 5784d53..ad6bdf5 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/activitys/ItemListActivity.java +++ b/app/src/main/java/at/smartshopper/smartshopper/activitys/ItemListActivity.java @@ -7,12 +7,16 @@ import android.os.Build; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.Editable; import android.text.TextWatcher; import android.view.Gravity; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.Button; @@ -32,12 +36,13 @@ import java.util.List; import at.smartshopper.smartshopper.R; import at.smartshopper.smartshopper.customViews.SpaceItemDecoration; +import at.smartshopper.smartshopper.customViews.ToolbarHelper; import at.smartshopper.smartshopper.db.Database; import at.smartshopper.smartshopper.messaging.MyFirebaseSender; 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, ItemAdapter.OnItemCheckClicked { +public class ItemListActivity extends AppCompatActivity implements ItemAdapter.OnItemEditClicked, ItemAdapter.OnItemDelClicked, ItemAdapter.OnItemCheckClicked { private String group_id, groupNameString; private String sl_id; private PopupWindow popupWindowItem; @@ -116,6 +121,50 @@ public class ItemListActivity extends Activity implements ItemAdapter.OnItemEdit } + /** + * Menu item Action listener + * + * @param item Action Item + * @return True wenn erfolgreich + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + ToolbarHelper th = new ToolbarHelper(getApplicationContext(),getWindow().getDecorView()); + switch (item.getItemId()) { + case R.id.logoutBtn: + th.logout(); + return true; + + case R.id.addInvite: + th.popupaddInvite(); + return true; + case R.id.doneEinkauf: + th.doneEinkauf("itemlist", sl_id, group_id, groupNameString); + return true; + case R.id.editUser: + finish(); + Intent intent2 = new Intent(this, EditUser.class); + startActivity(intent2); + return true; + default: + // If we got here, the user's action was not recognized. + // Invoke the superclass to handle it. + return super.onOptionsItemSelected(item); + + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + + MenuInflater inflater = getMenuInflater(); + + inflater.inflate(R.menu.dash_menu, menu); + + return true; + + } + private void showItems(String group_id, String sl_id) throws SQLException, JSONException { RecyclerView itemsListRecycler = findViewById(R.id.itemsListRecycler); int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.item_spacing); 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 434a17e..6b72b47 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/activitys/ShoppinglistDetails.java +++ b/app/src/main/java/at/smartshopper/smartshopper/activitys/ShoppinglistDetails.java @@ -8,11 +8,16 @@ 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.app.AppCompatActivity; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.TextWatcher; import android.view.Gravity; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.Button; @@ -32,6 +37,7 @@ import java.util.List; import at.smartshopper.smartshopper.R; import at.smartshopper.smartshopper.customViews.SpaceItemDecoration; +import at.smartshopper.smartshopper.customViews.ToolbarHelper; import at.smartshopper.smartshopper.db.Database; import at.smartshopper.smartshopper.messaging.MyFirebaseSender; import at.smartshopper.smartshopper.shoppinglist.Shoppinglist; @@ -40,15 +46,67 @@ 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.OnCardClicked { +public class ShoppinglistDetails extends AppCompatActivity implements DetailsAdapter.OnGroupEditClicked, DetailsAdapter.OnGroupDeleteClicked, DetailsAdapter.OnCardClicked { private Database db; private FloatingActionButton fab; - private String colorString; + private String colorString, sl_id; private PopupWindow popupWindow; private Button colorBtn; private SwipeRefreshLayout detailsSwiperefresh; + + /** + * Menu item Action listener + * + * @param item Action Item + * @return True wenn erfolgreich + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + ToolbarHelper th = new ToolbarHelper(getApplicationContext(),getWindow().getDecorView()); + switch (item.getItemId()) { + case R.id.logoutBtn: + th.logout(); + return true; + + case R.id.addInvite: + th.popupaddInvite(); + return true; + case R.id.doneEinkauf: + th.doneEinkauf("shpdetails", sl_id, " ", " "); + return true; + case R.id.editUser: + finish(); + Intent intent2 = new Intent(this, EditUser.class); + startActivity(intent2); + return true; + default: + // If we got here, the user's action was not recognized. + // Invoke the superclass to handle it. + return super.onOptionsItemSelected(item); + + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + + MenuInflater inflater = getMenuInflater(); + + inflater.inflate(R.menu.dash_menu, menu); + + return true; + + } + + @Override + public void onBackPressed() { + finish(); + Intent intent = new Intent(this, Dash.class); + startActivity(intent); + } + /** * Convertiert eine int farbe in eine hexa dezimale Farbe * @@ -63,11 +121,12 @@ public class ShoppinglistDetails extends Activity implements DetailsAdapter.OnGr protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shoppinglist_details); + fab = findViewById(R.id.addGroupFab); db = new Database(); colorBtn = (Button) findViewById(R.id.groupColor); Intent intent = getIntent(); - String sl_id = intent.getStringExtra("sl_id"); + sl_id = intent.getStringExtra("sl_id"); try { diff --git a/app/src/main/java/at/smartshopper/smartshopper/customViews/ToolbarHelper.java b/app/src/main/java/at/smartshopper/smartshopper/customViews/ToolbarHelper.java new file mode 100644 index 0000000..810f316 --- /dev/null +++ b/app/src/main/java/at/smartshopper/smartshopper/customViews/ToolbarHelper.java @@ -0,0 +1,151 @@ +package at.smartshopper.smartshopper.customViews; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageButton; +import android.widget.PopupWindow; +import android.widget.TextView; + +import com.google.firebase.auth.FirebaseAuth; +import com.squareup.picasso.Picasso; + +import org.json.JSONException; + +import java.sql.SQLException; + +import at.smartshopper.smartshopper.R; +import at.smartshopper.smartshopper.activitys.Dash; +import at.smartshopper.smartshopper.activitys.DoneItemActivity; +import at.smartshopper.smartshopper.activitys.LoginActivity; +import at.smartshopper.smartshopper.db.Database; + +public class ToolbarHelper extends Activity { + + private PopupWindow popupAddShare; + private Database db = new Database(); + private Context context; + private View decor; + + public ToolbarHelper(Context context, View decor) { + this.context = context; + this.decor = decor; + } + + /** + * Logt den User aus und geht zur Login Activity + */ + public void logout() { + finish(); + FirebaseAuth.getInstance().signOut(); + Intent intent = new Intent(context, LoginActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + + public void doneEinkauf(String from, String sl_id,String group_id, String groupname) { + finish(); + Intent intent = new Intent(context, DoneItemActivity.class); + intent.putExtra("from", from); + intent.putExtra("sl_id", sl_id); + intent.putExtra("groupNameString", groupname); + intent.putExtra("group_id", group_id); + + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + + /** + * Öffnet ein popup in dem ein invite link eingegeben werden kann. Diese Shoppingliste wird dann hinzugefügt + */ + public void popupaddInvite() { + final LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); + View popupContentView = inflater.inflate(R.layout.add_share_link, null); + + final TextView linkEingabe = (TextView) popupContentView.findViewById(R.id.addShareLinkInput); + + ImageButton exitButton = (ImageButton) popupContentView.findViewById(R.id.addShareExit); + Picasso.get().load(R.drawable.close).into(exitButton); + exitButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + popupAddShare.dismiss(); + } + }); + final Button finish = (Button) popupContentView.findViewById(R.id.shareAddFinish); + + if (!linkEingabe.getText().toString().isEmpty()) { + finish.setEnabled(true); + } else { + finish.setEnabled(false); + } + linkEingabe.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + if (!linkEingabe.getText().toString().isEmpty()) { + finish.setEnabled(true); + } else { + finish.setEnabled(false); + } + } + }); + + + finish.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String invite = linkEingabe.getText().toString(); + + + try { + db.addInviteLink(invite, FirebaseAuth.getInstance().getCurrentUser().getUid()); + } catch (SQLException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + + popupAddShare.dismiss(); + + + finish(); + Intent intent = new Intent(context, Dash.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra("tab2", "true"); + context.startActivity(intent); + } + }); + + popupAddShare = new PopupWindow(popupContentView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + popupAddShare.setOutsideTouchable(false); + popupAddShare.setFocusable(true); + // Set an elevation value for popup window + // Call requires API level 21 + if (Build.VERSION.SDK_INT >= 21) { + popupAddShare.setElevation(5.0f); + } + popupAddShare.setAnimationStyle(R.style.popup_window_animation_phone); + + + popupAddShare.showAtLocation(decor.findViewById(android.R.id.content), Gravity.CENTER, 0, 0); + popupAddShare.update(); + } +} diff --git a/app/src/main/res/menu/done_items_menu.xml b/app/src/main/res/menu/done_items_menu.xml new file mode 100644 index 0000000..f3de385 --- /dev/null +++ b/app/src/main/res/menu/done_items_menu.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file