Exemple #1
0
 private List<RegistrationDTO> getFilteredResults(CharSequence constraint) {
   List<RegistrationDTO> list = new ArrayList<RegistrationDTO>();
   for (RegistrationDTO attendant : attendants) {
     PersonDTO person = attendant.getPerson();
     if (person.getName().toLowerCase().contains(constraint.toString().toLowerCase())
         && (attendant.getStatus() == 0)) {
       list.add(attendant);
     }
   }
   return list;
 }
Exemple #2
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
      LayoutInflater vi =
          (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      v = vi.inflate(R.layout.person_list_item, null);
    }
    RegistrationDTO attendant = getItem(position);
    if (attendant != null) {
      PersonDTO person = attendant.getPerson();
      TextView tt = (TextView) v.findViewById(R.id.toptext);
      TextView bt = (TextView) v.findViewById(R.id.bottomtext);
      if (tt != null) {
        tt.setText(person.getName());
      }
      if (bt != null) {
        bt.setText(person.getEmailAddress());
      }
      CheckBox cb = (CheckBox) v.findViewById(R.id.checkBox1);
      cb.setTag(attendant);
      cb.setOnCheckedChangeListener(null);
      cb.setChecked(attendant.getStatus() == 1);
      cb.setOnCheckedChangeListener(this);

      ImageView imageView = (ImageView) v.findViewById(R.id.icon);
      if (gravatars.containsKey(attendant)) {
        imageView.setImageBitmap(gravatars.get(attendant));
      } else {
        imageView.setImageResource(R.drawable.icon);
        new DownloadImageTask(imageView).execute(attendant);
      }
    }
    v.setTag(attendant.getPerson());
    v.setOnLongClickListener(
        new OnLongClickListener() {

          @Override
          public boolean onLongClick(View v) {
            final PersonDTO person = (PersonDTO) v.getTag();

            AlertDialog.Builder builder;

            Context mContext = getContext();
            getContext();
            LayoutInflater inflater =
                (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout =
                inflater.inflate(
                    R.layout.custom_dialog, (ViewGroup) v.findViewById(R.id.custom_dialog));

            final EditText editText = (EditText) layout.findViewById(R.id.nameFld);
            editText.setText(person.getName());

            builder = new AlertDialog.Builder(mContext);
            builder.setView(layout);
            final AlertDialog alertDialog = builder.create();

            final Button saveBtn = (Button) layout.findViewById(R.id.savePoiNameBtn);
            final Button cancelBtn = (Button) layout.findViewById(R.id.cancelPoiNameBtn);

            saveBtn.setOnClickListener(
                new OnClickListener() {

                  @Override
                  public void onClick(View v) {
                    person.setName(editText.getText().toString());

                    // RestClient rc = new RestClient(AttendItActivity.URL
                    // + "/attendit/rest/registration/person/"
                    // + person.getId());
                    // GsonBuilder builder = new GsonBuilder();
                    // Gson gson = builder.create();
                    //
                    // String json = gson.toJson(person, PersonDTO.class);
                    // Log.i("PersonAdapter", "Person JSON: " + json);
                    // rc.AddParam("person", json);
                    // try {
                    // rc.Execute(RestClient.RequestMethod.POST);
                    // Toast.makeText(getContext(),
                    // "Successfully updated person",
                    // Toast.LENGTH_SHORT).show();
                    // alertDialog.dismiss();
                    // } catch (Exception e) {
                    // Toast.makeText(getContext(),
                    // "An error occured saving person: " + e.getMessage(),
                    // Toast.LENGTH_LONG).show();
                    // }
                    Toast.makeText(getContext(), "Successfully updated person", Toast.LENGTH_SHORT)
                        .show();
                    alertDialog.dismiss();
                  }
                });

            cancelBtn.setOnClickListener(
                new OnClickListener() {

                  @Override
                  public void onClick(View v) {
                    alertDialog.dismiss();
                  }
                });

            alertDialog.show();

            return false;
          }
        });
    return v;
  }