예제 #1
0
  private void finishVoting() {
    if (closing) {
      finishClosing();

      return;
    }

    if (!modified) {
      // Come back to the previous activity since the event is not modified
      dialogResponded();

      return;
    }

    // Get the current selected event
    Event event = imin.getUser().getCurrentEvent();

    // Get the event proposals
    List<Proposal> proposals = event.getProposals();

    // Analyze the responses
    List<Response> responses = new ArrayList<Response>();

    // Analyze the poll table
    for (Proposal proposal : proposals) {
      if (proposal.getProposalType() == Proposal.PROPOSAL_TYPE_LOCATION) {
        // Look up the table and get the response of the user for that
        Response response = proposal.getContactResponse(imin.getUser().getPublicUserId());

        if (response != null) {
          // Add to the list of responses
          responses.add(response);
        }
      }
    }

    showRespondDialog();

    // Add the datetime responses
    responses.addAll(imin.dateTimeResponses);

    // At this point, we have the list of responses
    configurationInstance.taskRespondEvent = new TaskRespondEvent(this);
    TaskRespondEventParams params =
        new TaskRespondEventParams(imin.getUser().getPrivateUserId(), event, responses);
    configurationInstance.taskRespondEvent.execute(params);
  }
예제 #2
0
  private void paintCounters() {
    // Iterate through the counters
    for (int k = 0; k < layoutPollUserVotes.getChildCount(); ++k) {
      // Get the user response
      View layoutPollUserVote = layoutPollUserVotes.getChildAt(k);
      Button btnViewPollVote = (Button) layoutPollUserVote.findViewById(R.id.btnViewPollVote);
      Proposal proposal = (Proposal) btnViewPollVote.getTag();

      View layoutPollCounter = layoutPollCounters.getChildAt(k);
      Button btnPollCounter = (Button) layoutPollCounter.findViewById(R.id.btnPollCounter);

      // Get the response of ourselves
      Response response = proposal.getContactResponse(imin.getUser().getPublicUserId());

      // Get number of votes
      List<Contact> attendingContacts = proposal.getContacts(Response.RESPONSE_TYPE_ATTENDING);

      // Set the counter text
      int num_attending_contacts = attendingContacts.size();
      String counter = String.valueOf(num_attending_contacts);
      btnPollCounter.setText(counter);

      if (closing) {
        btnPollCounter.setEnabled(false);
        btnPollCounter.setTextColor(getResources().getColor(R.color.black));
      } else {
        if (response != null && response.getResponseType() == Response.RESPONSE_TYPE_ATTENDING) {
          btnPollCounter.setEnabled(true);
          btnPollCounter.setTextColor(getResources().getColor(R.color.white));
        } else {
          btnPollCounter.setEnabled(false);
          btnPollCounter.setTextColor(getResources().getColor(R.color.black));
        }
      }
    }
  }
예제 #3
0
  // Get the current selected event
  private void eventClose() {
    Event event = imin.getUser().getCurrentEvent();

    // Go ahead with event closing
    showCloseDialog();

    Proposal finalDateTimeProposal = event.getFinalDateTimeProposal();
    Proposal finalLocationProposal = event.getFinalLocationProposal();
    String finalDateTimeProposalId = finalDateTimeProposal.getPublicProposalId();
    String finalLocationProposalId = finalLocationProposal.getPublicProposalId();
    event.setFinalDateTimeProposalId(finalDateTimeProposalId);
    event.setFinalLocationProposalId(finalDateTimeProposalId);

    // Run an asynchronous task to retrieve the single event
    configurationInstance.taskCloseEvent = new TaskCloseEvent(this);
    TaskCloseEventParams params =
        new TaskCloseEventParams(
            imin.getUser().getPrivateUserId(),
            event.getId(),
            true,
            finalDateTimeProposalId,
            finalLocationProposalId);
    configurationInstance.taskCloseEvent.execute(params);
  }
예제 #4
0
  private void fillValues() {
    // Animator animator;

    // Clear the poll before recreating it
    layoutPollLocations.removeAllViews();
    layoutPollPoll.removeAllViews();
    layoutPollCounters.removeAllViews();
    layoutPollUserVotes.removeAllViews();

    // Get the current selected event
    Event event = imin.getUser().getCurrentEvent();

    if (!event.isResponded()) {
      modified = true;
    }

    // Get the list of proposals
    List<Proposal> proposals = event.getProposals();

    // =================================================== //
    // FILL LOCATION NAMES ON THE TOP

    // Retrieve the possible days of all the proposals
    List<Location> locations = event.getProposalLocations();

    // Sort the locations
    Collections.sort(locations);

    for (Location location : locations) {
      // For each day, create all the layouts
      String locationName = location.getName();

      // Find the corresponding proposal
      boolean found = false;
      Proposal proposal = null;
      for (Proposal proposalToFind : proposals) {
        if (proposalToFind.getLocation() == location) {
          // Found
          found = true;
          proposal = proposalToFind;
          break;
        }
      }

      if (found) {
        // Get the list of attending contacts for this proposal
        List<Contact> attendingContacts = proposal.getContacts(Response.RESPONSE_TYPE_ATTENDING);

        // ==================================================
        // HEADER ON THE TOP SHOWING DATE AND TIME

        // Inflate location layout
        View layoutPollLocation = inflater.inflate(R.layout.layout_poll_location, null);
        Button btnViewPollLocation =
            (Button) layoutPollLocation.findViewById(R.id.btnViewPollLocation);

        btnViewPollLocation.setText(locationName);

        btnViewPollLocation.setTag(proposal);
        btnViewPollLocation.setOnLongClickListener(
            new OnLongClickListener() {
              @Override
              public boolean onLongClick(View view) {
                Proposal proposal = (Proposal) view.getTag();
                contactsDialog(proposal);
                return true;
              }
            });

        // Finally, add the location to the list of locations
        layoutPollLocations.addView(layoutPollLocation);

        // Inflate votes linear layout
        LinearLayout layoutPollVotes =
            (LinearLayout) inflater.inflate(R.layout.layout_poll_votes, null);

        // ==================================================
        // USER RESPONSES

        int responseType;

        // Find user response
        String publicUserId = imin.getUser().getPublicUserId();
        Response response = proposal.getContactResponse(publicUserId);

        if (response != null) {
          // Responded, let's see which response has the user voted
          if (response.getResponseType() == Response.RESPONSE_TYPE_ATTENDING) {
            responseType = Response.RESPONSE_TYPE_ATTENDING;
          } else if (response.getResponseType() == Response.RESPONSE_TYPE_NOT_ATTENDING) {
            responseType = Response.RESPONSE_TYPE_NOT_ATTENDING;
          } else {
            responseType = Response.RESPONSE_TYPE_NOT_ATTENDING;
          }
        } else {
          // Not responded
          responseType = Response.RESPONSE_TYPE_NOT_ATTENDING;
        }

        // Inflate the option view
        View layoutPollUserVote = inflater.inflate(R.layout.layout_poll_location_user_vote, null);
        Button btnViewPollVote = (Button) layoutPollUserVote.findViewById(R.id.btnViewPollVote);

        if (closing) {
          btnViewPollVote.setBackgroundResource(
              R.drawable.button_poll_option_not_attending_background);
        } else {
          // Set the background of the view
          paintResponse(btnViewPollVote, responseType);
        }

        // Set the button clickable
        btnViewPollVote.setTag(proposal);
        btnViewPollVote.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View view) {
                if (!closing) {
                  // Set the modified flag
                  modified = true;

                  // Get the proposal of the view
                  Proposal proposal = (Proposal) view.getTag();

                  // Get the response of ourselves
                  Response response = proposal.getContactResponse(imin.getUser().getPublicUserId());

                  if (response != null) {
                    // Increment the response type
                    response.incrementResponseType();
                  } else {
                    // Create
                    response =
                        new Response(
                            imin.getUser().getContact(),
                            Response.RESPONSE_TYPE_ATTENDING,
                            proposal);

                    // Finally, add the user response
                    proposal.addResponse(response);
                  }

                  int responseType = response.getResponseType();

                  // Paint the response
                  Button btnVote = (Button) view;
                  paintResponse(btnVote, responseType);

                  // Paint the counters
                  paintCounters();
                } else {
                  // Save the proposal of the view
                  imin.getUser().setSelectedLocationProposal((Proposal) view.getTag());

                  proposalSelected = true;

                  // Reset user votes and counters
                  paintUserVotes();
                  paintCounters();

                  view.setBackgroundResource(R.drawable.button_poll_option_attending_background);
                }
              }
            });

        // So, add the option
        layoutPollUserVotes.addView(layoutPollUserVote);

        // ==================================================
        // COUNTERS

        // Inflate the option view
        View layoutPollCounter = inflater.inflate(R.layout.layout_poll_location_counter, null);

        layoutPollCounters.addView(layoutPollCounter);

        // ==================================================
        // RESPONSES FROM THE REST OF CONTACTS

        for (Contact contact : attendingContacts) {
          // Inflate the option view
          View layoutPollVote = inflater.inflate(R.layout.layout_poll_location_vote, null);
          ResizableImageView imageViewPollContact =
              (ResizableImageView) layoutPollVote.findViewById(R.id.imageViewPollContact);
          TextView textViewPollContact =
              (TextView) layoutPollVote.findViewById(R.id.textViewPollContact);

          // Handle click
          imageViewPollContact.setTag(contact);
          imageViewPollContact.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View view) {
                  Contact contact = (Contact) view.getTag();
                  Imin.showContactProfile(context, contact);
                }
              });

          textViewPollContact.setTag(contact);
          textViewPollContact.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View view) {
                  Contact contact = (Contact) view.getTag();
                  Imin.showContactProfile(context, contact);
                }
              });

          // Set the contact photo
          Bitmap contactPhoto = contact.getPhoto();
          if (contactPhoto != null) {
            imageViewPollContact.setImageBitmap(contactPhoto);
            imageViewPollContact.setVisibility(View.VISIBLE);
            textViewPollContact.setVisibility(View.GONE);
          } else {
            // Capital letter in the box
            String contactName = contact.getName();
            if (contactName.length() > 0) {
              textViewPollContact.setText(contactName.substring(0, 1));
              textViewPollContact.setBackgroundColor(contact.getColor());
            }

            imageViewPollContact.setVisibility(View.GONE);
            textViewPollContact.setVisibility(View.VISIBLE);
          }

          // So, add the option
          layoutPollVotes.addView(layoutPollVote);
        }

        // Inflate the option view
        View layoutPollHiddenContact =
            inflater.inflate(R.layout.layout_poll_location_hidden_contact, null);

        // Add a hidden layout just for filling the list
        layoutPollVotes.addView(layoutPollHiddenContact);

        // Finally, add the list of contacts who are attending
        layoutPollPoll.addView(layoutPollVotes);
      }
    }

    paintCounters();

    // Set fonts
    Imin.overrideFonts(layoutPollLocations, Imin.fontRegular);
    Imin.overrideFonts(layoutPollCounters, Imin.fontRegular);
    Imin.overrideFonts(layoutPollPoll, Imin.fontRegular);
    Imin.overrideFonts(layoutPollUserVotes, Imin.fontRegular);
  }