Advertisement
Guest User

PeopleAttendingActivity

a guest
Jul 23rd, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 54.52 KB | None | 0 0
  1. package com.swarmerapp.swarmer.PeopleAttendingEventTable.ui;
  2.  
  3. import android.app.Activity;
  4.  
  5. import android.app.FragmentManager;
  6. import android.content.ComponentName;
  7. import android.content.Intent;
  8. import android.content.pm.LabeledIntent;
  9. import android.content.pm.PackageManager;
  10. import android.content.pm.ResolveInfo;
  11. import android.graphics.Paint;
  12. import android.net.Uri;
  13. import android.os.Bundle;
  14. import android.support.v4.app.ShareCompat;
  15. import android.support.v4.content.ContextCompat;
  16. import android.support.v4.view.ViewPager;
  17. import android.support.v4.widget.NestedScrollView;
  18. import android.support.v4.widget.SwipeRefreshLayout;
  19. import android.support.v7.app.AppCompatActivity;
  20. import android.text.Html;
  21. import android.view.View;
  22. import android.view.animation.AnimationUtils;
  23. import android.webkit.WebView;
  24. import android.widget.Button;
  25. import android.widget.ImageView;
  26. import android.widget.LinearLayout;
  27. import android.widget.RelativeLayout;
  28. import android.widget.TableLayout;
  29. import android.widget.TableRow;
  30. import android.widget.TextView;
  31. import android.widget.Toast;
  32.  
  33. import com.google.android.gms.maps.GoogleMap;
  34. import com.google.android.gms.maps.OnMapReadyCallback;
  35. import com.google.android.gms.maps.SupportMapFragment;
  36. import com.google.android.gms.maps.model.LatLng;
  37. import com.google.gson.Gson;
  38. import com.squareup.picasso.Picasso;
  39. import com.swarmerapp.swarmer.App;
  40. import com.swarmerapp.swarmer.BookTableActivity;
  41. import com.swarmerapp.swarmer.BookedEventDetailsActivity;
  42. import com.swarmerapp.swarmer.BookingConfirmationActivity;
  43. import com.swarmerapp.swarmer.ImagesPreviewPagerActivity;
  44. import com.swarmerapp.swarmer.LocationDisplayActivity;
  45. import com.swarmerapp.swarmer.PeopleAttendingEventTable.PeopleAttendingEventTableContract;
  46. import com.swarmerapp.swarmer.PeopleAttendingEventTable.PeopleAttendingEventTablePresenter;
  47. import com.swarmerapp.swarmer.VideoActivity;
  48. import com.swarmerapp.swarmer.R;
  49. import com.swarmerapp.swarmer.activityFeed.presenter.StickyResponseOnRequest;
  50. import com.swarmerapp.swarmer.createTable.ListOfPeopleAttending;
  51. import com.swarmerapp.swarmer.createTable.VenueInfo;
  52.  
  53. import java.io.Serializable;
  54. import java.lang.ref.WeakReference;
  55. import java.text.DecimalFormat;
  56. import java.text.SimpleDateFormat;
  57. import java.util.ArrayList;
  58. import java.util.Calendar;
  59. import java.util.Collections;
  60. import java.util.Date;
  61. import java.util.HashSet;
  62. import java.util.List;
  63. import java.util.Objects;
  64. import java.util.Set;
  65. import java.util.TimeZone;
  66.  
  67. import adapters.RequestsRecyclerViewAdapter;
  68. import adapters.UserGalleryAdapter;
  69. import butterknife.BindView;
  70. import butterknife.ButterKnife;
  71. import butterknife.OnClick;
  72. import customViews.AcceptDenyBottomView;
  73. import customViews.MultiSwipeRefreshLayout;
  74. import customViews.PeopleTableSeatView;
  75. import de.greenrobot.event.EventBus;
  76. import io.reactivex.SingleObserver;
  77. import io.reactivex.android.schedulers.AndroidSchedulers;
  78. import io.reactivex.disposables.Disposable;
  79. import io.reactivex.schedulers.Schedulers;
  80.  
  81. import com.swarmerapp.swarmer.login.ui.LoginDialog;
  82. import com.trekeye.swarmer_sdk_library.modules.AppUser;
  83. import models.Booking;
  84. import models.BookingInnerItem;
  85. import com.trekeye.swarmer_sdk_library.modules.Event;
  86. import models.Receipt;
  87. import models.Recipient;
  88. import com.trekeye.swarmer_sdk_library.modules.Table;
  89. import com.trekeye.swarmer_sdk_library.modules.TableSeat;
  90. import models.busEvents.connectionEvents.Errors.ErrorServerResponse;
  91. import models.busEvents.connectionEvents.Errors.ErrorWatchTable;
  92. import models.busEvents.connectionEvents.RequestBookedTable;
  93. import models.busEvents.connectionEvents.RequestCheckTableWatched;
  94. import models.busEvents.connectionEvents.RequestInviteOnTableResponse;
  95. import models.busEvents.connectionEvents.RequestResponseOnTableInvitation;
  96. import models.busEvents.connectionEvents.RequestSocialiteTableBooking;
  97. import models.busEvents.connectionEvents.RequestSocialiteTableRequestConfirmation;
  98. import models.busEvents.connectionEvents.RequestUnwatchTable;
  99. import models.busEvents.connectionEvents.RequestWatchTable;
  100. import models.busEvents.connectionEvents.connectionResponse.ResponseCheckWatched;
  101. import models.busEvents.connectionEvents.connectionResponse.ResponseInviteOnTableConfirmation;
  102. import models.busEvents.connectionEvents.connectionResponse.ResponseOnSocialiteTableRequest;
  103. import models.busEvents.connectionEvents.connectionResponse.ResponseWatchTable;
  104. import services.RxMessagingService;
  105. import services.RxNetworkLayer;
  106. import com.trekeye.swarmer_sdk_library.utils.AppConstants;
  107. import com.trekeye.swarmer_sdk_library.utils.BaseUtils;
  108.  
  109. import utils.Common;
  110. import utils.GeoUtils;
  111. import utils.GsonFactory;
  112. import utils.PageIndicator;
  113. import utils.SwipeRefreshLayoutOptions;
  114. import utils.Utils;
  115. import utils.bus_events.TableInvitationTempHolder;
  116. import utils.bus_events.TableRequestsWrapper;
  117.  
  118.  
  119. /**
  120.  * Created by Blagoj Bojcevski on 8/15/2017.
  121.  */
  122.  
  123. public class PeopleAttendingActivity extends AppCompatActivity implements PeopleAttendingEventTableContract.PeopleAttendingEventTableView, SwipeRefreshLayout.OnRefreshListener,Serializable, OnMapReadyCallback , PeopleTableSeatView.PeopleTableSeatActionListener{
  124.  
  125.  
  126.     private String eventId;
  127.     private String tableId = null;
  128.     private Table table;
  129.     private String userType;
  130.     private GoogleMap googleMap;
  131.     private PeopleAttendingEventTablePresenter presenter;
  132.     private UserGalleryAdapter eventPhotosAdapter;
  133.     private ViewPager imagesPager;
  134.     private ImageView venuePhoto;
  135.     private static final int REQ_CODE_BOOK = 1;
  136.     private static final int CONFIRM_BOOKING = 1153;
  137.     private static final int BOOKED_EVENT_DETAILS = 1154;
  138.     private final RxNetworkLayer rxNetwork = Common.getInstance().getRxNetworkLayer();
  139.  
  140.     @BindView(R.id.swipeRefresh)
  141.     MultiSwipeRefreshLayout mSwipeRefreshLayout;
  142.  
  143.     @BindView(R.id.noContent)
  144.     View noContent;
  145.  
  146.     @BindView(R.id.scrlMainContainer)
  147.     NestedScrollView scrlMainContainer;
  148.  
  149.     @BindView(R.id.join_table_name)
  150.     TextView tvTableName;
  151.  
  152.     @BindView(R.id.people_attending_info_dress_code_label)
  153.     View txtDressCode;
  154.  
  155.     @BindView(R.id.people_attending_bottle_allocation)
  156.     TextView txtBottleAllocation;
  157.  
  158.     @BindView(R.id.people_attending_need_to_know)
  159.     TextView txtNeedToKnow;
  160.  
  161.     @BindView(R.id.people_attending_bottle_allocation_label)
  162.     View txtBottleAllocationLabel;
  163.  
  164.     @BindView(R.id.join_table_event_name)
  165.     TextView txtEventName;
  166.  
  167.     @BindView(R.id.join_table_event_date)
  168.     TextView txtEventDate;
  169.  
  170.     @BindView(R.id.join_table_details_table_type)
  171.     TextView txtEventTableType;
  172.  
  173.     @BindView(R.id.people_attending_details_price)
  174.     TextView txtEventSeatPrice;
  175.  
  176.     @BindView(R.id.joint_table_details_rseats)
  177.     TextView txtEventRemainigSeats;
  178.  
  179.     @BindView(R.id.join_table_info_event_name)
  180.     TextView tvInfoEventName;
  181.  
  182.     @BindView(R.id.join_table_info_venue_name)
  183.     TextView tvInfoVenueName;
  184.  
  185.     @BindView(R.id.join_table_info_street)
  186.     TextView tvInfoStreet;
  187.  
  188.     @BindView(R.id.join_table_info_city_state)
  189.     TextView tvInfoStateZip;
  190.  
  191.     @BindView(R.id.people_attending_info_dress_code)
  192.     TextView tvInfoDressCode;
  193.  
  194.     @BindView(R.id.people_attending_need_to_know_label)
  195.     TextView tvNeedToKnow;
  196.  
  197.     @BindView(R.id.event_time)
  198.     TextView eventTime;
  199.  
  200.     @BindView(R.id.join_table_info_event_description_label)
  201.     View txtEventDescriptionLabel;
  202.  
  203.     @BindView(R.id.join_table_info_event_description)
  204.     TextView txtEventDescription;
  205.  
  206.     @BindView(R.id.join_table_info_important_info)
  207.     TextView txtImportantInfo;
  208.  
  209.     @BindView(R.id.join_table_important_info)
  210.     TextView txtImportantEventInfo;
  211.  
  212.     @BindView(R.id.event_pictures_page_indicator)
  213.     PageIndicator eventsPicturesPageIndicator;
  214.  
  215.     @BindView(R.id.accept_deny_view)
  216.     AcceptDenyBottomView acceptDenyView;
  217.  
  218.     @BindView(R.id.tblFemaleGuests)
  219.     TableLayout tblFemaleGuests;
  220.  
  221.     @BindView(R.id.imageBottleAllocation)
  222.     ImageView imageBottleAllocation;
  223.  
  224.     @BindView(R.id.imageWhatToWear)
  225.     ImageView imageWhatToWear;
  226.  
  227.     @BindView(R.id.imageImpInfo)
  228.     ImageView imageImpInfo;
  229.  
  230.     @BindView(R.id.imageEventDesciption)
  231.     ImageView imageEventDesciption;
  232.  
  233.     @BindView(R.id.imageneed_to_know)
  234.     ImageView imageneedToKnow;
  235.  
  236.     @BindView(R.id.watch_table_btn)
  237.     ImageView btnWatchTable;
  238.  
  239.     @BindView(R.id.joint_table_join_btn)
  240.     Button btnJoinNow;
  241.  
  242.     @BindView(R.id.join_table_num_of_socialites)
  243.     TextView txtNumOfSocialites;
  244.  
  245.     @BindView(R.id.not_seats_left)
  246.     TextView notSeatsLeftTv;
  247.  
  248.  
  249.     @BindView(R.id.descriton_table)
  250.     LinearLayout descritonTable;
  251.  
  252.     @BindView(R.id.showMore)
  253.     TextView showmore;
  254.  
  255.     @BindView(R.id.ll_transparent1)
  256.     View line1;
  257.  
  258.     @BindView(R.id.ll_transparent2)
  259.     View line2;
  260.  
  261.     private Event event;
  262.     private List<TableSeat> getSeats;
  263.     private TableRequestsWrapper tempWrapper;
  264.     private String eventOrTableType;
  265.     private boolean socialitesJoined = false;
  266.     private Gson gson;
  267.     private final static int NUMBER_OF_ICONS_IN_ROW = 4;
  268.     private int numSwarmerSeatsTaken, numSocialiteSeatsTaken;
  269.     private boolean isWatched = false;
  270.     private ImageView videoView;
  271.     private ImageView playButton;
  272.  
  273.     @Override
  274.     protected void onCreate(Bundle savedInstanceState) {
  275.         super.onCreate(savedInstanceState);
  276.         setContentView(R.layout.people_attending);
  277.  
  278.         ButterKnife.bind(this);
  279.  
  280.         uiRef();
  281.         eventId = getIntent().getStringExtra("eventId");
  282.         Intent intent = getIntent();
  283.         String action = intent.getAction();
  284.         Uri data = intent.getData();
  285.         if(data!=null){
  286.             String link = data.toString();
  287.             String [] parsed = link.split("/");
  288.             eventId = parsed[4];
  289.             tableId = parsed[6];
  290.         }
  291.         userType = Common.getInstance().getPref().getUserType();
  292.         presenter = new PeopleAttendingEventTablePresenter(this, this);
  293.         presenter.getEvent(eventId);
  294.         venuePhoto = findViewById(R.id.join_table_venue_info_image);
  295.         tempWrapper = GsonFactory.getInstance().fromJson(getIntent().getExtras().getString("wrapper"), TableRequestsWrapper.class);
  296.  
  297.         userType = Common.getInstance().getPref().getUserType();
  298.         gson = new Gson();
  299.  
  300.         if (userType != null) {
  301.             if (userType.equals(getResources().getString(R.string.u_type_socialite))) {
  302.                 socialitesJoined = true;
  303.             }
  304.         }
  305.     }
  306.  
  307.     private void uiRef(){
  308.         mSwipeRefreshLayout.setSwipeableChildren(R.id.join_table_photos);
  309.         imagesPager = findViewById(R.id.join_table_photos);
  310.         videoView = findViewById(R.id.join_table_video);
  311.         playButton = findViewById(R.id.play_button);
  312.         mSwipeRefreshLayout.setOnRefreshListener(this);
  313.         SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.join_table_map_view);
  314.         mapFragment.getMapAsync(this);
  315.     }
  316.  
  317.     private void showContent() {
  318.         hideNoContent();
  319.         btnJoinNow.setVisibility(View.VISIBLE);
  320.         scrlMainContainer.setVisibility(View.VISIBLE);
  321.     }
  322.     @Override
  323.     public void onItemClick(int pos, String uri) {
  324.         Intent i = new Intent(PeopleAttendingActivity.this, ImagesPreviewPagerActivity.class);
  325.         i.putExtra("images", getImagesFromEvent(event));
  326.         i.putExtra("position", pos);
  327.         startActivity(i);
  328.     }
  329.  
  330.     private void fillSeats() {
  331.  
  332.         tblFemaleGuests.removeAllViews();
  333.         final List<String> socialiteSeats = new ArrayList<>();
  334.         final List<String> swarmerSeats = new ArrayList<>();
  335.         for (TableSeat ts : table.getSeats()) {
  336.             if(ts.getUserType().equals(getResources().getString(R.string.u_type_swarmer)))
  337.                 swarmerSeats.add(ts.getFacebookId());
  338.             else
  339.                 socialiteSeats.add(ts.getFacebookId());
  340.         }
  341.  
  342.         final Set<TableSeat> tempSocialiteSeats = new HashSet<>();
  343.         final Set<TableSeat> tempswarmerSeats = new HashSet<>();
  344.         for (TableSeat ts : table.getSeats()) {
  345.             ts.setSwarmerSeats(numSwarmerSeatsTaken);
  346.             ts.setSocialiteSeats(numSocialiteSeatsTaken);
  347.             ts.setPeopleSeats(table.getPeopleSeats());
  348.             ts.setSwarmerSeats(table.getSwarmerSeats());
  349.             ts.setSocialiteSeats(table.getSocialiteSeats());
  350.             int occurrences = 0;
  351.             if(ts.getUserType().equals(getResources().getString(R.string.u_type_swarmer))) {
  352.                 occurrences = Collections.frequency(swarmerSeats, ts.getFacebookId());
  353.                 ts.setNumberOfReservedSeats(occurrences);
  354.                 tempswarmerSeats.add(ts);
  355.             }else {
  356.                 occurrences = Collections.frequency(socialiteSeats, ts.getFacebookId());
  357.                 ts.setNumberOfReservedSeats(occurrences);
  358.                 tempSocialiteSeats.add(ts);
  359.             }
  360.         }
  361.         getSeats = new ArrayList<>(tempSocialiteSeats);
  362.         getSeats.addAll(tempswarmerSeats);
  363.  
  364.         int chunkEnd = NUMBER_OF_ICONS_IN_ROW;
  365.         TableRow row = new TableRow(this);
  366.         for (int j = 0; j < chunkEnd; j++) {
  367.             PeopleTableSeatView seatView = new PeopleTableSeatView(getApplicationContext());
  368.             seatView.setActionListener(this);
  369.             if (j > getSeats.size() - 1) {
  370.                 break;
  371.             }else {
  372.                 final TableSeat seat = getSeats.get(j);
  373.                 seatView.setModel(seat);
  374.                 row.addView(seatView);
  375.             }
  376.         }
  377.         int num = chunkEnd-getSeats.size();
  378.         if (getSeats.size() < 4) {
  379.             for (int c = 0; c < num; c++) {
  380.                 PeopleTableSeatView t2 = new PeopleTableSeatView(getApplicationContext());
  381.                 t2.setEmptySeat();
  382.                 row.addView(t2);
  383.             }
  384.         }
  385.         tblFemaleGuests.addView(row);
  386.     }
  387.  
  388.     private void hideNoContent() {
  389.         noContent.setVisibility(View.GONE);
  390.     }
  391.  
  392.     /**
  393.      * Function that returns the desired suffix for a given day of month
  394.      *
  395.      * @param day
  396.      * @return the correct suffix
  397.      */
  398.     private String getSuffixForDay(int day) {
  399.         if (day >= 1 && day <= 31) {
  400.             if (day >= 11 && day <= 13) {
  401.                 return "th";
  402.             }
  403.             switch (day % 10) {
  404.                 case 1:
  405.                     return "st";
  406.                 case 2:
  407.                     return "nd";
  408.                 case 3:
  409.                     return "rd";
  410.                 default:
  411.                     return "th";
  412.             }
  413.         } else {
  414.             return "";
  415.         }
  416.     }
  417.  
  418.     private void initMap(GoogleMap googleMap) {
  419.         boolean mapSuccess = GeoUtils.displayVenueLocationOnMap(event, googleMap, new OnMapClickListener(this));
  420.     }
  421.  
  422.     @Override
  423.     public void onMapReady(GoogleMap googleMap) {
  424.         this.googleMap = googleMap;
  425.     }
  426.  
  427.     @Override
  428.     public void displayError(String err) {
  429.         Toast.makeText(this, err, Toast.LENGTH_SHORT).show();
  430.     }
  431.  
  432.  
  433.  
  434.     @OnClick(R.id.showMore)
  435.     public void setShowmore() {
  436.         RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
  437.         params.setMargins(0, 10, 0, 0);
  438.         descritonTable.setLayoutParams(params);
  439.         line1.setVisibility(View.GONE);
  440.         line2.setVisibility(View.GONE);
  441.         showmore.setVisibility(View.GONE);
  442.  
  443.     }
  444.  
  445.     @OnClick(R.id.see_all_people_btn)
  446.     public void submit() {
  447.         if (!Common.getInstance().getPref().getToken().equals(""))
  448.         {
  449.             if(table != null){
  450.                 Intent intent = new Intent(PeopleAttendingActivity.this, ListOfPeopleAttending.class);
  451.                 intent.putExtra("list", (Serializable) getSeats);
  452.                 if(table.isGenderNeutral()){
  453.                     intent.putExtra("genderNeutral", table.isGenderNeutral());
  454.                     intent.putExtra("peopleSeats", table.getPeopleSeats());
  455.                     startActivity(intent);
  456.                 }else {
  457.                     intent.putExtra("genderNeutral", table.isGenderNeutral());
  458.                     intent.putExtra("peopleSeats", table.getSwarmerSeats());
  459.                     intent.putExtra("numberOfSocialiteSeatsLeft", table.getSocialiteSeats());
  460.                     startActivity(intent);
  461.                 }
  462.             }
  463.         }else
  464.         {
  465.             FragmentManager fm = getFragmentManager();
  466.             LoginDialog dialog = new LoginDialog();
  467.             dialog.setRetainInstance(true);
  468.             dialog.show(fm, "loginDialog");
  469.         }
  470.  
  471.     }
  472.     @OnClick(R.id.join_table_info_venue_name)
  473.     public void info() {
  474.         Intent i = new Intent(PeopleAttendingActivity.this, VenueInfo.class);
  475.         i.putExtra("venueId", event.getVenueId());
  476.         startActivity(i);
  477.     }
  478.  
  479.     @OnClick(R.id.backBtn)
  480.     public void onBackClick(){
  481.         finish();
  482.     }
  483.  
  484.     @OnClick(R.id.share_btn)
  485.     public void onShareClick(){
  486.         openEmailApp();
  487.     }
  488.  
  489.     @OnClick(R.id.joint_table_join_btn)
  490.     public void joinBt(){
  491.         if (!Common.getInstance().getPref().getToken().equals(""))
  492.         {
  493.             joinTable();
  494.         }else
  495.         {
  496.             android.app.FragmentManager fm = getFragmentManager();
  497.             LoginDialog dialog = new LoginDialog();
  498.             dialog.setRetainInstance(true);
  499.             dialog.show(fm, "loginDialog");
  500.         }
  501.  
  502.     }
  503.  
  504.     @Override
  505.     public void openTableDetails(Event res) {
  506.         mSwipeRefreshLayout.post(new SwipeRefreshLayoutOptions(new WeakReference<SwipeRefreshLayout>(mSwipeRefreshLayout), false));
  507.         showContent();
  508.         if(tableId==null){
  509.             tableId = getIntent().getStringExtra("tableId");
  510.         }
  511.         event = res;
  512.  
  513.  
  514.         if (event != null) {
  515.             for (Table t : event.getTables()) {
  516.                 if (t.getId().equals(tableId)) {
  517.                     table = t;
  518.                 }
  519.             }
  520.             if (table != null) {
  521.                 if(table.getType() != null && table.getType().length() > 0){
  522.                     eventOrTableType = table.getType();
  523.                 }else{
  524.                     eventOrTableType = event.getType();
  525.                 }
  526.                 DecimalFormat decimalFormatter = new DecimalFormat("0.#");
  527.                 if (userType.equals(getResources().getString(R.string.u_type_swarmer))) {
  528.                     txtEventSeatPrice.setText("$" + decimalFormatter.format(table.getSwarmerSeatPrice()));
  529.                 } else {
  530.                     txtEventSeatPrice.setText("$" + decimalFormatter.format(table.getSocialiteSeatPrice()));
  531.                 }
  532.  
  533.                 if (event.getDescription() != null && !"".equals(event.getDescription())) {
  534.                     String [] parsedDescription = event.getDescription().split("\\r?\\n");
  535.                     String bulletDescription = "";
  536.                     String circle = "\u25CF";
  537.                     for (int i = 0; i < parsedDescription.length; i++) {
  538.                         bulletDescription = circle + "  " + parsedDescription[i] + "\n";
  539.                     }
  540.                     txtEventDescription.setText(bulletDescription);
  541.                 } else {
  542.                     txtEventDescription.setVisibility(View.GONE);
  543.                     txtEventDescriptionLabel.setVisibility(View.GONE);
  544.                     imageEventDesciption.setVisibility(View.GONE);
  545.                 }
  546.  
  547.                 if (event.getImportantInfo() != null && !"".equals(event.getImportantInfo())) {
  548.                     txtImportantInfo.setText(event.getImportantInfo());
  549.                 } else {
  550.                     txtImportantInfo.setVisibility(View.GONE);
  551.                     txtImportantEventInfo.setVisibility(View.GONE);
  552.                     imageImpInfo.setVisibility(View.GONE);
  553.                 }
  554.  
  555.                 if (table.getLocation() != null) {
  556.                     tvTableName.setText(table.getLocation());
  557.                     txtEventTableType.setText(table.getLocation());
  558.                 }
  559.                 if (userType.equals(getResources().getString(R.string.u_type_socialite))) {
  560.                     txtEventRemainigSeats.setText(String.format("%d seats remaning", (table.getSocialiteSeatsLeft())));
  561.                 } else {
  562.                     txtEventRemainigSeats.setText(String.format("%d seats remaning", (table.getSwarmerSeatsLeft())));
  563.                 }
  564.  
  565.                 txtEventName.setText(event.getName());
  566.                 tblFemaleGuests = findViewById(R.id.tblFemaleGuests);
  567.  
  568.                 tvInfoVenueName.setPaintFlags(tvInfoVenueName.getPaintFlags() |   Paint.UNDERLINE_TEXT_FLAG);
  569.  
  570.                 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, MMMM d");
  571.                 simpleDateFormat.setTimeZone(TimeZone.getTimeZone(event.getVenueTimezone()));
  572.                 Date tmp = null;
  573.                 try {
  574.                     tmp = BaseUtils.getDateWithSpecificTimeZone(event.getOpen(), event.getVenueTimezone());
  575.                 } catch (Exception ex) {
  576.                     ex.printStackTrace();
  577.                 }
  578.                 Calendar c = Calendar.getInstance();
  579.                 c.setTime(tmp);
  580.                 String formattedDate = simpleDateFormat.format(tmp);
  581.                 formattedDate += getSuffixForDay(c.get(Calendar.DAY_OF_MONTH));
  582.                 txtEventDate.setText(formattedDate);
  583.  
  584.                 if (event.getVenueArea() != null) {
  585.                     tvInfoEventName.setText(event.getVenueArea().toUpperCase());
  586.                 }
  587.  
  588.                 if (event.getVenueName() != null) {
  589.                     tvInfoVenueName.setText(event.getVenueName().toUpperCase());
  590.                 }
  591.  
  592.                 if (event.getVenueLine1() != null) {
  593.                     tvInfoStreet.setText(event.getVenueLine1());
  594.                 }
  595.  
  596.  
  597.                 if (event.getOpen() != null) {
  598.                     //Date d = BaseUtils.getDateWithSpecificTimeZone(event.getOpen(), event.getVenueTimezone());
  599.                     eventTime.setText("Event Start Time : " + Utils.formatEventTime(event.getOpen(), event.getVenueTimezone()));
  600.                 }
  601.  
  602.                 if (event.getVenueState() != null && event.getVenueCity() != null && event.getVenueZip() != null) {
  603.                     String s = event.getVenueLine1() + ", " + event.getVenueCity() + ", " + event.getVenueState() + ", " + event.getVenueZip();
  604.                     tvInfoStateZip.setText(s);
  605.                 }
  606.  
  607.                 if (event.getDressCode() != null && !"".equals(event.getDressCode())) {
  608.                     tvInfoDressCode.setText(event.getDressCode());
  609.                 } else {
  610.                     txtDressCode.setVisibility(View.GONE);
  611.                     tvInfoDressCode.setVisibility(View.GONE);
  612.                     imageWhatToWear.setVisibility(View.GONE);
  613.                 }
  614.  
  615.                 if (event.getVenueNeedToKnow() != null && !"".equals(event.getVenueNeedToKnow())) {
  616.                     txtNeedToKnow.setText(event.getVenueNeedToKnow());
  617.                 } else {
  618.                     txtNeedToKnow.setVisibility(View.GONE);
  619.                     tvNeedToKnow.setVisibility(View.GONE);
  620.                     imageneedToKnow.setVisibility(View.GONE);
  621.                 }
  622.  
  623.                 if (table != null && table.getRefundPolicy() != null && !"".equals(table.getRefundPolicy())) {
  624.                     txtBottleAllocation.setText(table.getRefundPolicy());
  625.                 } else {
  626.                     txtBottleAllocation.setVisibility(View.GONE);
  627.                     txtBottleAllocationLabel.setVisibility(View.GONE);
  628.                     imageBottleAllocation.setVisibility(View.GONE);
  629.                 }
  630.                 numSwarmerSeatsTaken = table.getSwarmerSeats() - table.getSwarmerSeatsLeft();
  631.                 numSocialiteSeatsTaken = table.getSocialiteSeats() - table.getSocialiteSeatsLeft();
  632.                 int numGenderNeutralSeatsTaken = table.getPeopleSeats() - table.getPeopleSeatsLeft();
  633.  
  634.                 if(table.isGenderNeutral()){
  635.                     txtNumOfSocialites.setText(String.format("%d/%d", numGenderNeutralSeatsTaken, table.getPeopleSeats()));
  636.                     if(numGenderNeutralSeatsTaken ==table.getPeopleSeats()){
  637.                         notSeatsLeftTv.setVisibility(View.VISIBLE);
  638.                         notSeatsLeftTv.setText(getResources().getString(R.string.no_more_seats_left).toUpperCase());
  639.                     }
  640.  
  641.                 }else {
  642.                     int numOfAllPeopleSeats = numSwarmerSeatsTaken + numSocialiteSeatsTaken;
  643.                     txtNumOfSocialites.setText(String.format("%d/%d", numOfAllPeopleSeats, table.getSocialiteSeats()+table.getSwarmerSeats()));
  644.                     if(userType.equals(getResources().getString(R.string.u_type_swarmer)) && table.getSwarmerSeatsLeft() == 0){
  645.                         notSeatsLeftTv.setVisibility(View.VISIBLE);
  646.                         notSeatsLeftTv.setText(getResources().getString(R.string.table_closed_for_gentlemens).toUpperCase());
  647.                     } else if(userType.equals(getResources().getString(R.string.u_type_socialite)) && table.getSocialiteSeatsLeft() == 0){
  648.                         notSeatsLeftTv.setVisibility(View.VISIBLE);
  649.                         notSeatsLeftTv.setText(getResources().getString(R.string.table_closed_for_ladies).toUpperCase());
  650.                     }
  651.                 }
  652.  
  653.                 if (event.getPhotos() != null || event.getVideos() != null) {
  654.                     eventPhotosAdapter = new UserGalleryAdapter(this, getImagesFromEvent(event), (pos, uri) -> {
  655.                         Intent i = new Intent(PeopleAttendingActivity.this, ImagesPreviewPagerActivity.class);
  656.                         i.putExtra("images", getImagesFromEvent(event));
  657.                         i.putExtra("position", pos);
  658.                         startActivity(i);
  659.                     });
  660.                     imagesPager.setAdapter(eventPhotosAdapter);
  661.                     if(event.getPhotos().size() > 1){
  662.                         eventsPicturesPageIndicator.setViewPager(imagesPager);
  663.                     }
  664.                 }
  665.  
  666.                 imagesPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  667.                     @Override
  668.                     public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  669.                         if(position >= event.getVideos().size()){
  670.                             videoView.setVisibility(View.INVISIBLE);
  671.                             playButton.setVisibility(View.INVISIBLE);
  672.                         }else {
  673.                             playButton.setVisibility(View.VISIBLE);
  674.                             playButton.setBackground(null);
  675.                             videoView.setVisibility(View.VISIBLE);
  676.                             if(!Objects.equals(event.getVideos().get(position).getThumbnailUrl(), ""))
  677.                             Picasso.with(getApplicationContext()).load(event.getVideos().get(position).getThumbnailUrl()).fit().centerCrop().into(videoView);
  678.                         }
  679.                         playButton.setOnClickListener(new View.OnClickListener() {
  680.                             @Override
  681.                             public void onClick(View view) {
  682.                                 Intent i = new Intent(PeopleAttendingActivity.this, VideoActivity.class);
  683.                                 i.putExtra("video", event.getVideos().get(position).getUrl());
  684.                                 startActivity(i);
  685.                             }
  686.                         });
  687.                     }
  688.  
  689.                     @Override
  690.                     public void onPageSelected(int position) {
  691.                     }
  692.  
  693.                     @Override
  694.                     public void onPageScrollStateChanged(int state) {
  695.                     }
  696.  
  697.                 });
  698.  
  699.                 if (tempWrapper != null) {
  700.                     btnJoinNow.setVisibility(View.GONE);
  701.                     acceptDenyView.setVisibility(View.VISIBLE);
  702.                     acceptDenyView.setOnActionListener(new PeopleAttendingActivity.AcceptDenyTableInvitationListener(this));
  703.  
  704.                     if(AcceptDenyBottomView.ACCEPTDENYSCREEN.equals("GONE")){
  705.                         checkAcceptDenyScreen();
  706.                     }
  707.                 }else{
  708.                     acceptDenyView.setVisibility(View.GONE);
  709.                     btnJoinNow.setVisibility(View.VISIBLE);
  710.                 }
  711.  
  712.                 if (event.getVenuePhotoUrl() != null) {
  713.                     Picasso.with(this).load(event.getVenuePhotoUrl()).fit().centerCrop().into(venuePhoto);
  714.                 }
  715.                 fillSeats();
  716.                 updateJoinTableButton();
  717.  
  718.                 EventBus.getDefault().post(new RequestCheckTableWatched(table.getEventId(), table.getId()));
  719.                 initMap(googleMap);
  720.  
  721.                 if(txtImportantInfo.getVisibility()==View.GONE && txtEventDescription.getVisibility()==View.GONE && txtDressCode.getVisibility()==View.GONE && txtBottleAllocationLabel.getVisibility()==View.GONE){
  722.                     showmore.setVisibility(View.GONE);
  723.                     descritonTable.setVisibility(View.GONE);
  724.                 }
  725.  
  726.             }
  727.         }
  728.     }
  729.  
  730.     @OnClick(R.id.watch_table_btn)
  731.     public void setBtnWatchTable() {
  732.         if (isWatched) {
  733.             EventBus.getDefault().post(new RequestUnwatchTable(table.getId()));
  734.             btnWatchTable.setSelected(false);
  735.             isWatched=false;
  736.         } else {
  737.             EventBus.getDefault().post(new RequestWatchTable(table.getEventId(), table.getId()));
  738.             btnWatchTable.setSelected(true);
  739.             isWatched=true;
  740.         }
  741.     }
  742.  
  743.     public void onEventMainThread(ResponseCheckWatched res) {
  744.         isWatched = res.isWatched();
  745.         btnWatchTable.setSelected(isWatched);
  746.  
  747.         btnWatchTable.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
  748.     }
  749.  
  750.     public void onEventMainThread(ResponseWatchTable res) {
  751.         Toast.makeText(this, isWatched ? "Event added to Favourites" : "Event removed from Favourites", Toast.LENGTH_SHORT).show();
  752.         isWatched = res.isWatched();
  753.         btnWatchTable.setSelected(isWatched);
  754.         btnWatchTable.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
  755.  
  756.     }
  757.  
  758.     public void onEventMainThread(ErrorWatchTable error) {
  759.         Toast.makeText(this, "Error happened, Try again", Toast.LENGTH_SHORT).show();
  760.         btnWatchTable.setSelected(isWatched);
  761.         btnWatchTable.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
  762.     }
  763.  
  764.     private void checkAcceptDenyScreen(){
  765.         acceptDenyView.setVisibility(View.GONE);
  766.         btnJoinNow.setVisibility(View.VISIBLE);
  767.     }
  768.  
  769.     private String[] getImagesFromEvent(Event event) {
  770.         final String[] imgVideoUris = new String[event.getPhotos().size()+event.getVideos().size()];
  771.         int index = event.getVideos().size();
  772.  
  773.         for (int i = 0; i < event.getVideos().size(); i++) {
  774.             if(!event.getVideos().get(i).getUrl().equals(AppConstants.EMPTY_VIDEO)){
  775.                 imgVideoUris[i] = event.getVideos().get(i).getUrl();
  776.             }
  777.         }
  778.         for (int i = 0; i < event.getPhotos().size(); i++) {
  779.             if(!event.getPhotos().get(i).getUrl().equals(AppConstants.EMPTY_IMAGE)){
  780.                 imgVideoUris[i+index] = event.getPhotos().get(i).getUrl();
  781.             }
  782.         }
  783.         return imgVideoUris;
  784.     }
  785.  
  786.     @Override
  787.     public void onPeopleTableEmptySeatClick() {
  788.  
  789.     }
  790.  
  791.     @Override
  792.     public void onSeatClick(TableSeat seat) {
  793.         if (Common.getInstance().getPref().getToken().equals(""))
  794.         {
  795.             android.app.FragmentManager fm = getFragmentManager();
  796.             LoginDialog dialog = new LoginDialog();
  797.             dialog.setRetainInstance(true);
  798.             dialog.show(fm, "loginDialog");
  799.         }else{
  800.             Intent intent = new Intent(this, com.swarmerapp.swarmer.userProfile.ui.UserProfileActivity.class);
  801.             intent.putExtra("facebookId", seat.getFacebookId());
  802.             startActivity(intent);
  803.         }
  804.     }
  805.  
  806.     private void updateJoinTableButton(/*Event event, Table table*/) {
  807.  
  808.         if (event == null || table == null) {
  809.             return;
  810.         }
  811.         btnJoinNow.setEnabled(true);
  812.  
  813.         String closed = "";
  814.         if (table.getLabelType() != null) {
  815.  
  816.             switch (table.getLabelType()) {
  817.                 case Table.LABEL_TYPE_TABLE:
  818.                     closed = getResources().getString(R.string.table_closed_t).toLowerCase();
  819.                     break;
  820.                 case Table.LABEL_TYPE_STANDARD:
  821.                     closed = getResources().getString(R.string.sold_out).toLowerCase();
  822.                     break;
  823.                 case Table.LABEL_TYPE_PACKAGE:
  824.                     closed = getResources().getString(R.string.sold_out).toLowerCase();
  825.                     break;
  826.             }
  827.  
  828.         }else{
  829.             closed = getResources().getString(R.string.table_closed_t);
  830.         }
  831.  
  832.         int sNumOfSeats = 0;
  833.         int numOfGenderNeutralSeats = table.getPeopleSeatsLeft();
  834.         boolean isEventPassed = Utils.checkIfEventIsPassed(event.getClose());
  835.         if (table.isGenderNeutral()){
  836.             sNumOfSeats = numOfGenderNeutralSeats;
  837.         } else {
  838.             if (Common.getInstance().getPref().getUserType().equals(getResources().getString(R.string.u_type_swarmer))) {
  839.                 sNumOfSeats = table.getSwarmerSeatsLeft();
  840.             } else {
  841.                 sNumOfSeats = table.getSocialiteSeatsLeft();
  842.             }
  843.         }
  844.  
  845.         if (sNumOfSeats != 0 && !isEventPassed ) {
  846.  
  847.             if(userType.equals(getResources().getString(R.string.u_type_socialite))){
  848.                 if(isUserAlreadyOnTable(table)){
  849.                     if(table.getSocialiteSeatPrice() > 0){
  850.                         if (eventOrTableType.equals(Event.EVENT_TYPE_OPEN)){
  851.                             btnJoinNow.setText( getString(R.string.purchase_additional_seats));
  852.                             btnJoinNow.setBackgroundColor(ContextCompat.getColor(this, R.color.light_green_pressed));
  853.                         }
  854.                     } else {
  855.                         btnJoinNow.setText(getResources().getString(R.string.invite_friends).toUpperCase());
  856.                     }
  857.                 }else{
  858.                     if(eventOrTableType.equals(Event.EVENT_TYPE_INVITE)){
  859.                         btnJoinNow.setText(getResources().getString(R.string.request_to_join).toUpperCase());
  860.                     } else if (eventOrTableType.equals(Event.EVENT_TYPE_OPEN)){
  861.                         String txt = "";
  862.                         if(table.getSocialiteSeatPrice() > 0){
  863.                             txt = getResources().getString(R.string.join_event).toUpperCase() + " | " + String.valueOf(Utils.formatAmountWithComma(table.getSocialiteSeatPrice()));
  864.                         }else{
  865.                             txt = getResources().getString(R.string.join_event).toUpperCase();
  866.                         }
  867.  
  868.                         if(table.getLabelType().equals(Table.LABEL_TYPE_PACKAGE)){
  869.                             txt = getResources().getString(R.string.purchase);
  870.                         } else  if(table.getLabelType().equals(Table.LABEL_TYPE_TABLE)){
  871.                             txt = getResources().getString(R.string.join_table_btn).toUpperCase() + " | " + String.valueOf(Utils.formatAmountWithComma(table.getSocialiteSeatPrice()));
  872.                             txt = table.getSocialiteSeatPrice()==0 ? getString(R.string.join_table_btn).toUpperCase() : txt;
  873.                         }
  874.  
  875.                         btnJoinNow.setText(txt);
  876.                     }
  877.                 }
  878.             }else{
  879.                 String txt;
  880.                 switch (table.getLabelType()) {
  881.                     case Table.LABEL_TYPE_PACKAGE:
  882.                         txt = getResources().getString(R.string.purchase);
  883.                         btnJoinNow.setText(isUserAlreadyOnTable(table) ? getString(R.string.invite_friends) : txt);
  884.                         break;
  885.                     case Table.LABEL_TYPE_TABLE:
  886.                         txt = getResources().getString(R.string.join_table_btn).toUpperCase() + " | " + String.valueOf(Utils.formatAmountWithComma(table.getSwarmerSeatPrice()));
  887. //                    btnJoinNow.setText(isUserAlreadyOnTable(table) ? getString(R.string.purchase_additional_seats) : table.getSwarmerSeatPrice()==0 ? getString(R.string.join_table_btn).toUpperCase() : txt);
  888.  
  889.                         if (isUserAlreadyOnTable(table)) {
  890.                             isFreeTable();
  891.                         } else {
  892.                             if (table.getSwarmerSeatPrice() == 0) {
  893.                                 btnJoinNow.setText(getString(R.string.join_table_btn).toUpperCase());
  894.                             } else {
  895.                                 btnJoinNow.setText(txt);
  896.                             }
  897.                         }
  898.                         break;
  899.                     default:
  900.                         txt = getResources().getString(R.string.join_event).toUpperCase() + " | " + String.valueOf(Utils.formatAmountWithComma(table.getSwarmerSeatPrice()));
  901.                         if (isUserAlreadyOnTable(table)) {
  902.                             isFreeTable();
  903.                         } else {
  904.                             btnJoinNow.setText(txt);
  905.                         }
  906.                         break;
  907.                 }
  908.  
  909.                 btnJoinNow.setBackgroundColor(ContextCompat.getColor(this, R.color.light_green_pressed));
  910.             }
  911.  
  912.         } else {
  913.             if(isEventPassed){
  914.                 btnJoinNow.setText(getResources().getString(R.string.event_expired));
  915.             }else {
  916.                 btnJoinNow.setText(closed);
  917.             }
  918.             btnJoinNow.setBackgroundColor(getResources().getColor(R.color.material_red));
  919.             btnJoinNow.setEnabled(false);
  920.         }
  921.     }
  922.  
  923.     private void isFreeTable(){
  924.         if(isUserAlreadyOnTable(table) && table.getSwarmerSeatPrice()==0){
  925.             btnJoinNow.setText(getString(R.string.invite_friends));
  926.         }else {
  927.             btnJoinNow.setText(getString(R.string.purchase_additional_seats));
  928.  
  929.             if(table.getLabelType().equals(Table.LABEL_TYPE_STANDARD)){
  930.                 btnJoinNow.setText(getString(R.string.purchase_additional_tickets));
  931.             }
  932.         }
  933.     }
  934.     private boolean isUserAlreadyOnTable(Table t) {
  935.         for (TableSeat seat : t.getSeats()) {
  936.             if (seat.getFacebookId().equals(Common.getInstance().getPref().getSocialId())) {
  937.                 return true;
  938.             }
  939.         }
  940.         return false;
  941.     }
  942.  
  943.     private static class OnMapClickListener implements GoogleMap.OnMapClickListener {
  944.         final WeakReference<PeopleAttendingActivity> peopleAttendingActivityWeakReference;
  945.  
  946.         OnMapClickListener(PeopleAttendingActivity activity) {
  947.             peopleAttendingActivityWeakReference = new WeakReference<>(activity);
  948.         }
  949.  
  950.         @Override
  951.         public void onMapClick(LatLng latLng) {
  952.             PeopleAttendingActivity activity = peopleAttendingActivityWeakReference.get();
  953.             if (activity != null) {
  954.                 final double lat = activity.event.getVenueGeoLocation().getCoordinates()[1];
  955.                 final double lon = activity.event.getVenueGeoLocation().getCoordinates()[0];
  956.                 Intent i = new Intent(activity, LocationDisplayActivity.class);
  957.                 i.putExtra("lon", lon);
  958.                 i.putExtra("lat", lat);
  959.                 i.putExtra("venueName", activity.event.getVenueName());
  960.                 activity.startActivity(i);
  961.             }
  962.  
  963.         }
  964.     }
  965.     private void joinTable(){
  966.         Intent intent = new Intent(this, BookTableActivity.class);
  967.         String txt = (String) btnJoinNow.getText();
  968.         int price = (int) table.getSocialiteSeatPrice();
  969.         if (socialitesJoined && !table.isGenderNeutral()) {
  970.             if (table.getSocialiteSeatsLeft() > 0) {
  971.                 if ((eventOrTableType.equals(Event.EVENT_TYPE_OPEN) && price > 0 ) && txt.equals(R.string.join_table_btn)) {
  972.                     Bundle b = new Bundle();
  973.                     b.putString("table", gson.toJson(table));
  974.                     b.putString("Event", gson.toJson(event));
  975.                     b.putInt(BookTableActivity.INTENT_SEATS_LEFT, table.getSocialiteSeatsLeft());
  976.                     intent.putExtras(b);
  977.                     startActivityForResult(intent, REQ_CODE_BOOK);
  978.                 } else {
  979.                     if (isUserAlreadyOnTable(table)||  txt.equals(R.string.invite_friends)) {
  980.                         if (table.getSeats().size() > 0) {
  981.                             openEmailApp();
  982.                         } else {
  983.                             Toast.makeText(this, "There is no swarmers present on this table to approve your request!", Toast.LENGTH_SHORT).show();
  984.                         }
  985.                     } else {
  986.                         if (table.getSeats().size() > 0 ) {
  987.                             if (table.getSocialiteSeatsLeft() > 0 && price == 0) {
  988.                                 navigateToBookingConfirmation();
  989.                             } else {
  990.                                 onRequestToJoin(event.getId(), table.getId());
  991.                             }
  992.  
  993.                         } else {
  994.                             Toast.makeText(this, "There is no swarmers present on this table to approve your request!", Toast.LENGTH_SHORT).show();
  995.                         }
  996.                     }
  997.  
  998.                 }
  999.             }else{
  1000.                 Toast.makeText(PeopleAttendingActivity.this, "There are no seats left to join.", Toast.LENGTH_SHORT).show();
  1001.             }
  1002.         } else if (table.isGenderNeutral()){
  1003.             if (table.getPeopleSeatsLeft() > 0 && table.getSwarmerSeatPrice() != 0 && table.getSocialiteSeatPrice() != 0) {
  1004.                 Bundle b = new Bundle();
  1005.                 b.putString("table", gson.toJson(table));
  1006.                 b.putString("Event", gson.toJson(event));
  1007.                 b.putInt(BookTableActivity.INTENT_SEATS_LEFT, table.getPeopleSeatsLeft());
  1008.                 intent.putExtras(b);
  1009.                 startActivityForResult(intent, REQ_CODE_BOOK);
  1010.             } else if (table.getPeopleSeatsLeft() > 0 && table.getSwarmerSeatPrice() == 0 && table.getSocialiteSeatPrice() == 0) {
  1011.                 navigateToBookingConfirmation();
  1012.             } else {
  1013.                 Toast.makeText(PeopleAttendingActivity.this, "There are no seats left to join.", Toast.LENGTH_SHORT).show();
  1014.             }
  1015.         } else {
  1016.             if (table.getSwarmerSeatsLeft() > 0 && table.getSwarmerSeatPrice() != 0) {
  1017.                 Bundle b = new Bundle();
  1018.                 b.putString("table", gson.toJson(table));
  1019.                 b.putString("Event", gson.toJson(event));
  1020.                 b.putInt(BookTableActivity.INTENT_SEATS_LEFT, table.getSwarmerSeatsLeft());
  1021.                 intent.putExtras(b);
  1022.                 startActivityForResult(intent, REQ_CODE_BOOK);
  1023.             } else if (table.getSwarmerSeatsLeft() > 0 && table.getSwarmerSeatPrice() == 0 && !btnJoinNow.getText().equals(txt)) {
  1024.                 navigateToBookingConfirmation();
  1025.             } else {
  1026.                 if (isUserAlreadyOnTable(table) || btnJoinNow.getText().equals(txt)) {
  1027.                     if (table.getSeats().size() > 0) {
  1028.                         openEmailApp();
  1029.                     } else {
  1030.                         Toast.makeText(PeopleAttendingActivity.this, "There are no seats left to join.", Toast.LENGTH_SHORT).show();
  1031.                     }
  1032.                 }
  1033.             }
  1034.         }
  1035.     }
  1036.  
  1037.     private void navigateToBookingConfirmation() {
  1038.         Intent i1 = new Intent(PeopleAttendingActivity.this, BookingConfirmationActivity.class);
  1039.         i1.putExtra("event", gson.toJson(event));
  1040.         i1.putExtra("table", gson.toJson(table));
  1041.         i1.putExtra("price", String.valueOf(0));
  1042.  
  1043.         startActivityForResult(i1, CONFIRM_BOOKING);
  1044.  
  1045.     }
  1046.  
  1047.     @Override
  1048.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  1049.         super.onActivityResult(requestCode, resultCode, data);
  1050.         if (resultCode == Activity.RESULT_OK) {
  1051.             switch (requestCode) {
  1052.                 case CONFIRM_BOOKING:
  1053.                     startPayment();
  1054.                     break;
  1055.             }
  1056.         } else {
  1057.             if (requestCode == BOOKED_EVENT_DETAILS) {
  1058.                 finishPayment();
  1059.             }
  1060.         }
  1061.     }
  1062.  
  1063.     private void startPayment() {
  1064.         List<BookingInnerItem> items = new ArrayList<>();
  1065.         BookingInnerItem item = new BookingInnerItem();
  1066.         item.setType("TableSeat");
  1067.         item.setPrice(0);
  1068.         item.setQty(1);
  1069.         item.setItemName(table.getLocation());
  1070.         item.setItemId(table.getId());
  1071.         items.add(item);
  1072.  
  1073.         String promoCode = "";
  1074.  
  1075.         EventBus.getDefault().post(new RequestBookedTable(event.getId(), promoCode, "Free Of Charge", items));
  1076.     }
  1077.     private void finishPayment() {
  1078.         if (event != null) {
  1079.             List<Table> tmpTables = event.getTables();
  1080.             Table toReturn = null;
  1081.  
  1082.             for (Table t : tmpTables) {
  1083.                 if (t.getId().equals(table.getId())) {
  1084.                     toReturn = t;
  1085.                 }
  1086.             }
  1087.             Intent backToJoin = new Intent();
  1088.             Bundle b = new Bundle();
  1089.             b.putString("table", gson.toJson(toReturn));
  1090.             b.putString("Event", gson.toJson(event));
  1091.             backToJoin.putExtras(b);
  1092.             setResult(RESULT_OK, backToJoin);
  1093.             finish();
  1094.         }
  1095.  
  1096.     }
  1097.  
  1098.     public void onEventMainThread(Booking res) {
  1099.  
  1100.         rxNetwork.getEventById(res.getEventId())
  1101.                 .subscribeOn(Schedulers.io())
  1102.                 .observeOn(AndroidSchedulers.mainThread())
  1103.                 .subscribeWith(new OnGetEventByIdObserver(this));
  1104.  
  1105.         TableInvitationTempHolder invitation = EventBus.getDefault().getStickyEvent(TableInvitationTempHolder.class);
  1106.         if (invitation != null) {
  1107.             EventBus.getDefault().post(new RequestResponseOnTableInvitation(invitation.getFacebookId(), invitation.getInviteId(), invitation.isAccept()));
  1108.             EventBus.getDefault().removeStickyEvent(invitation);
  1109.         }
  1110.         Toast.makeText(this, "Table successfully booked", Toast.LENGTH_SHORT).show();
  1111.     }
  1112.  
  1113.     public void onEventMainThread(ErrorServerResponse error) {
  1114.         Toast.makeText(this, error.getMessage(), Toast.LENGTH_SHORT).show();
  1115.     }
  1116.  
  1117.     private Receipt createReceipt() {
  1118.         Receipt receipt = new Receipt();
  1119.         receipt.setPromoCode("");
  1120.         receipt.setFee(0);
  1121.         receipt.setGratuity(0);
  1122.         receipt.setTax(0);
  1123.         receipt.setSubtotal(0);
  1124.         receipt.setDiscount(0);
  1125.         receipt.setTotal(0);
  1126.         receipt.setSeatSinglePrice(0);
  1127.  
  1128.         return receipt;
  1129.     }
  1130.     private void openEmailApp() {
  1131.         String text = "Hey, I'm going to "+ event.getName() + " @ " + event.getVenueName().toUpperCase() + ". Wanna join? ";
  1132.         String link = AppConstants.DEVELOPMENT_BASE_URL + "events/" + event.getId() + "/tables/" +
  1133.                 table.getId() + "/share";
  1134.         PackageManager pm = getPackageManager();
  1135.         Intent basicIntent = new Intent();
  1136.         basicIntent.setAction(Intent.ACTION_SEND);
  1137.         basicIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  1138.         basicIntent.putExtra(Intent.EXTRA_TEXT, link);
  1139.         basicIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, text);
  1140.         basicIntent.setType("text/plain");
  1141.         List<ResolveInfo> resInfo = pm.queryIntentActivities(basicIntent, 0);
  1142.  
  1143.         startActivity(Intent.createChooser(basicIntent, "Share"));
  1144.     }
  1145.  
  1146.     @Override
  1147.     protected void onResume() {
  1148.         super.onResume();
  1149.         if(!EventBus.getDefault().isRegistered(this)){
  1150.             EventBus.getDefault().register(this);
  1151.         }
  1152.         getData();
  1153.     }
  1154.     private void getData() {
  1155.         presenter.getEvent(eventId);
  1156.     }
  1157.     @Override
  1158.     public void onRefresh() {
  1159.         getData();
  1160.     }
  1161.  
  1162.     @Override
  1163.     protected void onPause() {
  1164.         super.onPause();
  1165.         EventBus.getDefault().unregister(this);
  1166.     }
  1167.  
  1168.     @Override
  1169.     protected void onDestroy() {
  1170.         super.onDestroy();
  1171.  
  1172.         if (eventPhotosAdapter != null) {
  1173.             eventPhotosAdapter.setOnItemClickListener(null);
  1174.         }
  1175.  
  1176.         if (btnJoinNow != null) {
  1177.             btnJoinNow.setOnClickListener(null);
  1178.         }
  1179.  
  1180.         if (mSwipeRefreshLayout != null) {
  1181.             mSwipeRefreshLayout.setOnRefreshListener(null);
  1182.         }
  1183.         acceptDenyView.unbindViews();
  1184.         App.watchReference(this);
  1185.     }
  1186.  
  1187.     private void onRequestToJoin(String eventId, String tableId){
  1188.         Recipient u = new Recipient();
  1189.         AppUser user = Common.getInstance().getPref().getUser();
  1190.         List<Recipient> from = new ArrayList<>();
  1191.         u.setFirstName(user.getFirstName());
  1192.         u.setLastName(user.getLastName());
  1193.         u.setProfilePhotoUrl(user.getProfilePhotoUrl());
  1194.         u.setFacebookId(user.getFacebookId());
  1195.         u.setUserType(user.getUserType());
  1196.         from.add(u);
  1197.         EventBus.getDefault().post(new RequestSocialiteTableBooking(eventId, tableId, from));
  1198.     }
  1199.  
  1200.     public void onEventMainThread(ResponseOnSocialiteTableRequest res){
  1201.         if(res.isSuccess()){
  1202.             Toast.makeText(PeopleAttendingActivity.this, "Request to join the table has been sent", Toast.LENGTH_SHORT).show();
  1203.         }else{
  1204.             if(res.getError() != null){
  1205.                 Toast.makeText(PeopleAttendingActivity.this, res.getError(), Toast.LENGTH_SHORT).show();
  1206.             }else{
  1207.                 Toast.makeText(PeopleAttendingActivity.this, "Error sending request", Toast.LENGTH_SHORT).show();
  1208.             }
  1209.         }
  1210.     }
  1211.     public void onEventMainThread(ResponseInviteOnTableConfirmation res){
  1212.         if (res.isSuccess()) {
  1213.             tempWrapper = null;
  1214.             EventBus.getDefault().postSticky(new StickyResponseOnRequest(res.getInviteId()));
  1215.             getData();
  1216.         }else{
  1217.             Toast.makeText(this, "Something went wrong!", Toast.LENGTH_SHORT).show();
  1218.         }
  1219.     }
  1220.  
  1221.     private static class AcceptDenyTableInvitationListener implements AcceptDenyBottomView.OnActionListener{
  1222.  
  1223.         private final WeakReference<PeopleAttendingActivity> weakAct;
  1224.  
  1225.  
  1226.         AcceptDenyTableInvitationListener(PeopleAttendingActivity act) {
  1227.             weakAct = new WeakReference<PeopleAttendingActivity>(act);
  1228.         }
  1229.  
  1230.         @Override
  1231.         public void onResponse(boolean accepted) {
  1232.             PeopleAttendingActivity act = weakAct.get();
  1233.             if (act != null) {
  1234.                 Table table = act.table;
  1235.                 TableRequestsWrapper wrapper = act.tempWrapper;
  1236.  
  1237.                 if (wrapper != null) {
  1238.  
  1239.                     if(wrapper.getType() == RequestsRecyclerViewAdapter.SOCIALITE_REQUEST_TYPE){
  1240.                         EventBus.getDefault().post(new RequestSocialiteTableRequestConfirmation(accepted, wrapper.getRequest().get_id()));
  1241.                         AcceptDenyBottomView.ACCEPTDENYSCREEN="GONE";
  1242.                         act.checkAcceptDenyScreen();
  1243.                     }
  1244.                     else if(wrapper.getType() == RequestsRecyclerViewAdapter.INVITE_TABLE_TYPE){
  1245.                         if (accepted) {
  1246.                             if (table.getType().equals(Event.EVENT_TYPE_INVITE) && act.userType.equals(act.getResources().getString(R.string.u_type_socialite))) {
  1247.                                 EventBus.getDefault().post(new RequestInviteOnTableResponse(wrapper.getInvitation().getInvitedByFacebookId(), wrapper.getInvitation().get_id(), accepted));
  1248.                             } else {
  1249.                                 TableInvitationTempHolder invitation = new TableInvitationTempHolder(wrapper.getInvitation().getInvitedByFacebookId(), wrapper.getInvitation().get_id(), accepted);
  1250.                                 EventBus.getDefault().post(new RequestInviteOnTableResponse(wrapper.getInvitation().getInvitedByFacebookId(), wrapper.getInvitation().get_id(), accepted));
  1251.                                 //Utils.removeCachedInvitation(invitation.getInviteId(), table.getId());
  1252.                                 //                                EventBus.getDefault().postSticky(new RequestResponseOnTableInvitation(wrapper.getInvitation().getInvitedByFacebookId(), wrapper.getInvitation().get_id(), accepted));
  1253.                                 act.joinTable();
  1254.                             }
  1255.                             AcceptDenyBottomView.ACCEPTDENYSCREEN="GONE";
  1256.                             act.checkAcceptDenyScreen();
  1257.                             act.onRefresh();
  1258.                         } else {
  1259.                             AcceptDenyBottomView.ACCEPTDENYSCREEN="GONE";
  1260.                             act.checkAcceptDenyScreen();
  1261.                             EventBus.getDefault().post(new RequestInviteOnTableResponse(wrapper.getInvitation().getInvitedByFacebookId(), wrapper.getInvitation().get_id(), accepted));
  1262.                         }
  1263.                     }
  1264.                 }
  1265.             }
  1266.         }
  1267.     }
  1268.  
  1269.     private static class OnGetEventByIdObserver implements SingleObserver<Event> {
  1270.  
  1271.         private final WeakReference<PeopleAttendingActivity> weakAct;
  1272.         private Disposable d;
  1273.  
  1274.         OnGetEventByIdObserver(PeopleAttendingActivity act) {
  1275.             weakAct = new WeakReference<PeopleAttendingActivity>(act);
  1276.         }
  1277.  
  1278.         @Override
  1279.         public void onSubscribe(Disposable d) {
  1280.             this.d = d;
  1281.         }
  1282.  
  1283.         @Override
  1284.         public void onSuccess(Event e) {
  1285.             PeopleAttendingActivity act = weakAct.get();
  1286.  
  1287.             if (act != null) {
  1288.                 act.event = e;
  1289.                 RxMessagingService.startService(act);
  1290.                 Intent i = new Intent(act, BookedEventDetailsActivity.class);
  1291.                 String event = GsonFactory.getInstance().toJson(act.event);
  1292.                 i.putExtra("event", event);
  1293.                 i.putExtra("receipt", act.createReceipt());
  1294.                 i.putExtra("tableId", act.table.getId());
  1295.                 act.startActivityForResult(i, BOOKED_EVENT_DETAILS);
  1296.             }
  1297.  
  1298.             if (d != null && d.isDisposed()) {
  1299.                 d.dispose();
  1300.             }
  1301.         }
  1302.  
  1303.         @Override
  1304.         public void onError(Throwable e) {
  1305.             if (d != null && d.isDisposed()) {
  1306.                 d.dispose();
  1307.             }
  1308.         }
  1309.     }
  1310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement