private void getAttendedBy() {
   if (hasEmployee && employeeId != null) {
     ParseQuery<ParseUser> query = ParseUser.getQuery();
     query.whereEqualTo("objectId", employeeId);
     query.getFirstInBackground(
         new GetCallback<ParseUser>() {
           @Override
           public void done(ParseUser parseUser, ParseException e) {
             if (e == null) {
               if (parseUser.getParseFile("userImage") != null) {
                 attendedByAvatar = parseUser.getParseFile("userImage").getUrl();
               }
               updateHomeServiceRequestStatus(parseUser);
             } else {
               Log.e("ERROR", "empleado no encontrado: " + e.getMessage());
             }
           }
         });
   } else {
     if (ParseUser.getCurrentUser().getParseFile("userImage") != null) {
       attendedByAvatar = ParseUser.getCurrentUser().getParseFile("userImage").getUrl();
     }
     updateHomeServiceRequestStatus(ParseUser.getCurrentUser());
   }
 }
Exemplo n.º 2
0
    @Override
    protected Void doInBackground(Void... params) {
      // Create the array
      userProfileList = new ArrayList<UserProfile>();
      try {

        // Locate the class table named "Country" in Parse.com
        ParseQuery<ParseUser> query = ParseUser.getQuery();

        Log.d("UserListActivity", "In asynctask.. username - " + currentUser.getUsername());

        query.whereNotEqualTo("username", currentUser.getUsername());

        // by ascending LastName
        query.orderByAscending("lastName");
        ob = query.find();
        for (ParseObject userProfile : ob) {

          UserProfile map = new UserProfile();
          map.setFirstName((String) userProfile.get("firstName"));
          map.setLastName((String) userProfile.get("lastName"));
          map.setDepartment((String) userProfile.get("department"));
          map.setUsername((String) userProfile.get("username"));

          userProfileList.add(map);
        }
      } catch (ParseException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
      }
      return null;
    }
Exemplo n.º 3
0
  public void getUsers(final List<ParseObject> list, final int listSize, final int i) {
    size = listSize;
    if (i == listSize) {
      checkList();
    } else {
      if ((list.get(i).getString("toUser") + "").equals(currentUser.getObjectId() + "")) {
        friendid = list.get(i).getString("fromUser");
      } else {
        friendid = list.get(i).getString("toUser");
      }

      ParseQuery<ParseUser> query = ParseUser.getQuery();
      query.getInBackground(
          friendid,
          new GetCallback<ParseUser>() {

            @Override
            public void done(ParseUser arg0, ParseException arg1) {
              // Toast.makeText(Friends.this, arg0.getObjectId()+"", Toast.LENGTH_SHORT).show();
              addUser(arg0);
              getUsers(list, listSize, i + 1);
            }
          });
    }
  }
Exemplo n.º 4
0
 // load user's profile image from parse - added by alex, edited by Jamie
 public void retrieveImage(String struser) {
   ParseQuery query = ParseUser.getQuery();
   query.whereContains("username", struser);
   query.findInBackground(
       new FindCallback<ParseObject>() {
         public void done(List<ParseObject> objects, ParseException e) {
           if (e == null) {
             // The query was successful.
             // Locate the column named "ImageName" and set
             // the string
             for (ParseObject ob : objects) {
               ParseFile fileObject = (ParseFile) ob.getParseFile("profileImg");
               if (fileObject != null) {
                 profileImg.setParseFile(fileObject);
                 profileImg.loadInBackground(
                     new GetDataCallback() {
                       @Override
                       public void done(byte[] bytes, ParseException e) {
                         // nothing to be done
                       }
                     });
               } else profileImg.setImageResource(R.drawable.no_image);
             }
           } else {
             // Something went wrong. Look at the ParseException to see what's up.
           }
         }
       });
 }
Exemplo n.º 5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    /*
    This line gets the unique id associated with each android device. Can only be reset by wiping the phone
     */
    final String android_id =
        Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
    Log.d("ANDROID ID", android_id);

    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.whereEqualTo(
        "androidID",
        android_id); // If these id's match, an account has already been registered on that account
    query.findInBackground(
        new FindCallback<ParseUser>() {
          public void done(List<ParseUser> scoreList, ParseException e) {
            if (e == null) {
              if (scoreList.size() > 0) {
                Log.d("id", "android_id matches one already in the table");
                // Displays dialog to inform the user the passwords were unequal and they must try
                // again
                AlertDialog.Builder builder = new AlertDialog.Builder(Register.this);
                builder
                    .setMessage(R.string.androidIdAlertMessage)
                    .setTitle(R.string.androidIdAlertTitle);
                builder.setCancelable(
                    false); // Makes it so a user can't click outside of the alert to close the
                            // dialog. They must click the button
                builder.setPositiveButton(
                    "Back to Home",
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
                        // These two lines automatically take the user back to the home page after a
                        // successful registration
                        Intent goHome = new Intent(Register.this, HomePage.class);
                        startActivity(goHome);
                      }
                    });
                AlertDialog alert = builder.create();
                alert.show();
              } else {
                Log.d("No Match", "Android ID does not match any in table");
              }

            } else {
              Log.d("score", "Error: " + e.getMessage());
            }
          }
        });
  }
Exemplo n.º 6
0
  @Override
  protected void onResume() {
    super.onResume();

    mCurrentUser = ParseUser.getCurrentUser();
    mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);

    setProgressBarIndeterminateVisibility(true);

    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.orderByAscending(ParseConstants.KEY_USERNAME);
    query.setLimit(1000);
    query.findInBackground(
        new FindCallback<ParseUser>() {
          @Override
          public void done(List<ParseUser> users, ParseException e) {
            setProgressBarIndeterminateVisibility(false);

            if (e == null && users != null) {
              // Success
              mUsers = users;
              String[] userNames = new String[mUsers.size()];
              int i = 0;
              for (ParseUser user : mUsers) {
                userNames[i] = user.getUsername();
                i++;
              }

              ArrayAdapter<String> adapter =
                  new ArrayAdapter<String>(
                      EditFriendsActivity.this,
                      android.R.layout.simple_list_item_checked,
                      userNames);
              setListAdapter(adapter);

              addFriendCheckMarks();

            } else {

              Tools.displayErrorDialog(
                  e.getMessage(), getString(R.string.ERROR_TITLE), EditFriendsActivity.this);
              Log.e(TAG, e.getMessage());
            }
          }
        });
  }
    @Override
    protected Void doInBackground(Void... params) {
      // Create the array
      /* mItems = new ArrayList<Leader>();
      try {
          ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Point");
          query.include("User");
          query.orderByDescending("pointslead");
          ob = query.find();
          final Leader map = new Leader();

          for (final ParseObject img : ob) {
              Log.e("1", img.getInt("pointslead") + "");
              map.setpLead(img.getInt("pointslead"));*/

      ParseQuery<ParseUser> queryuser = ParseUser.getQuery();
      queryuser.getInBackground(
          g,
          new GetCallback<ParseUser>() {
            public void done(ParseUser object, ParseException e) {
              if (e == null) {
                Log.e("--:--", "-- yes --");
                name = object.getUsername();
                url = object.getParseFile("img").getUrl();
                idobj = object.getObjectId();

                Log.e("--:--", name);
                Log.e("--:--", url);
                Log.e("--:--", idobj);
                map.setUsername(name);
                map.setUrl(url);
                if (ParseUser.getCurrentUser().getObjectId().equals(idobj)) {
                  map.setMe(true);
                } else {
                  map.setMe(false);
                }
                mItems.add(map);

              } else {
                Log.e("Error", e.getMessage());
              }
            }
          });

      return null;
    }
Exemplo n.º 8
0
  public String fetchGroups() {
    // this code fetches the data in the background thread
    ParseUser.getQuery()
        .whereEqualTo("username", ParseUser.getCurrentUser().getUsername())
        .findInBackground(
            new FindCallback<ParseUser>() {

              @Override
              public void done(List<ParseUser> arg0, ParseException arg1) {
                // TODO Auto-generated method stub
                assoclist = new ArrayList<String>();
                for (int i = 0; i < arg0.size(); i++) {
                  groupnames = arg0.get(i).getString("L_G");
                  if (!(arg0.get(i).getString("L_G") == null)) {
                    String[] names = groupnames.split(",");
                    for (int j = 0; j < names.length; j++) {
                      if (names[j] != null) assoclist.add(names[j]);
                    }
                  }
                }
                listview.setAdapter(qa);
                qa.notifyDataSetChanged();

                // listview.setOnItemClickListener(new View.)

              }
            });
    // this codes fetches the data on main thread
    /*
     * try { List<ParseUser>
     * list=ParseUser.getQuery().whereEqualTo("username",
     * ParseUser.getCurrentUser().getUsername()).find(); for (int i = 0; i <
     * list.size(); i++) { groupnames = list.get(i).getString("L_G");
     * System.out.println("the final 123 final is "+groupnames); String[]
     * names = groupnames.split(","); assoclist = new ArrayList<String>();
     * for (int j = 0; j < names.length; j++) { assoclist.add(names[j]); } }
     * listview.setAdapter(new QueryAdapter());
     *
     *
     * } catch (ParseException e) { // TODO Auto-generated catch block
     * e.printStackTrace(); }
     */

    return groupnames;
  }
Exemplo n.º 9
0
  @Override
  protected void onResume() {
    super.onResume();
    // getting the current user
    mCurrentUser = ParseUser.getCurrentUser();
    // now the relation
    mFriendRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);
    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.orderByAscending(ParseConstants.KEY_USERNAME);
    query.setLimit(1000);
    query.findInBackground(
        new FindCallback<ParseUser>() {
          @Override
          public void done(List<ParseUser> users, ParseException e) {
            if (e == null) {
              // it worked. create list and adapter
              mUsers = users;
              String[] usernames = new String[mUsers.size()];
              int i = 0;
              for (ParseUser user : mUsers) {
                usernames[i] = user.getUsername();
                i++;
              }
              ArrayAdapter<String> adapter =
                  new ArrayAdapter<String>(
                      EditFriendsActivity.this,
                      android.R.layout.simple_list_item_checked,
                      usernames);
              setListAdapter(adapter);
              // method to add checkmarks next friends
              addFriendCheckmarks();

            } else {
              // something didnt work well. show alert message.
              AlertDialog.Builder builder = new AlertDialog.Builder(EditFriendsActivity.this);
              builder.setTitle(R.string.title_error);
              builder.setMessage(e.getMessage());
              builder.setPositiveButton(android.R.string.ok, null);
              AlertDialog alertDialog = builder.create();
              alertDialog.show();
            }
          }
        });
  }
Exemplo n.º 10
0
  private void queryFromUsername(String username) {
    if (username == null) {
      populateFromUser(null);
      return;
    }

    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.whereEqualTo(Constants.kUsernameKey, username);
    query.getFirstInBackground(
        new GetCallback<ParseUser>() {
          @Override
          public void done(ParseUser parseUser, ParseException e) {
            if (e != null) {
              Log.d("BOOM", "Exception" + e);
            }
            populateFromUser(parseUser);
          }
        });
  }
Exemplo n.º 11
0
  // query current user and load about me and location data to activity. added by Jamie
  public void getUserInfo() {

    ParseQuery query = ParseUser.getQuery();
    query.findInBackground(
        new FindCallback<ParseObject>() {
          public void done(List<ParseObject> objects, ParseException e) {
            if (e == null) {

              for (ParseObject ob : objects) {
                aboutMe = (TextView) findViewById(R.id.aboutText);
                aboutMe.setText(ob.getString("AboutMe"));

                location = (TextView) findViewById(R.id.locationText);
                location.setText(ob.getString("location"));
              }

            } else {
              // Something went wrong. Look at the ParseException to see what's up.
            }
          }
        });
  }
  /** Load list of users. */
  private void loadUserList() {
    final ProgressDialog dia = ProgressDialog.show(this, null, getString(R.string.alert_loading));
    ParseUser.getQuery()
        .whereNotEqualTo("username", user.getUsername())
        .findInBackground(
            new FindCallback<ParseUser>() {

              @Override
              public void done(List<ParseUser> li, ParseException e) {
                dia.dismiss();
                if (li != null) {
                  if (li.size() == 0)
                    Toast.makeText(
                            UserListActivity.this, R.string.msg_no_user_found, Toast.LENGTH_SHORT)
                        .show();

                  uList = new ArrayList<ParseUser>(li);
                  ListView list = (ListView) findViewById(R.id.list);
                  list.setAdapter(new UserAdapter());
                  list.setOnItemClickListener(
                      new AdapterView.OnItemClickListener() {

                        @Override
                        public void onItemClick(
                            AdapterView<?> arg0, View arg1, int pos, long arg3) {

                          startActivity(
                              new Intent(UserListActivity.this, ChatActivity.class)
                                  .putExtra(Const.EXTRA_DATA, uList.get(pos).getUsername()));
                        }
                      });
                } else {
                  Utils.showDialog(
                      UserListActivity.this, getString(R.string.err_users) + " " + e.getMessage());
                  e.printStackTrace();
                }
              }
            });
  }
 private void listPotentialPlayers() {
   final ParseQuery<ParseUser> query = ParseUser.getQuery();
   final Context context = this;
   query.selectKeys(Arrays.asList("username"));
   query.findInBackground(
       new FindCallback<ParseUser>() {
         public void done(List<ParseUser> userList, ParseException e) {
           if (e == null) {
             if (userList != null) {
               List<String> usernameList = new ArrayList<String>();
               for (int i = 0; i < userList.size(); i++) {
                 try {
                   usernameList.add(userList.get(i).getString("username"));
                 } catch (Exception exc) {
                   Log.d(
                       "ScavengerHuntApp",
                       "Problem building user list: " + Log.getStackTraceString(exc));
                 }
               }
               playerList = userList;
               final ArrayAdapter<String> adapter =
                   new ArrayAdapter<String>(
                       context, android.R.layout.simple_list_item_multiple_choice, usernameList);
               final ListView playerListView = (ListView) findViewById(R.id.gamePlayersListView);
               playerListView.setAdapter(adapter);
               playerListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
             }
           } else {
             CharSequence text = "Sorry, there was a problem. Just a sec.";
             int duration = Toast.LENGTH_SHORT;
             Toast.makeText(context, text, duration).show();
             finish();
             startActivity(getIntent());
           }
         }
       });
 }
Exemplo n.º 14
0
 public void isUser(final String username) {
   ParseQuery<ParseUser> query = ParseUser.getQuery();
   query.whereEqualTo("username", username);
   query.findInBackground(
       new FindCallback<ParseUser>() {
         public void done(List<ParseUser> userList, ParseException e) {
           if (e == null && userList.size() == 0) {
             findViewById(R.id.LoadingIcon).setVisibility(View.INVISIBLE);
             new AlertDialog.Builder(Friends.this)
                 .setTitle("That User Doesn't Exist!")
                 .setPositiveButton(
                     "OK",
                     new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int which) {
                         add.setEnabled(true);
                       }
                     })
                 .show();
           } else if (userList.size() > 0) {
             areFriends(userList.get(0));
           }
         }
       });
 }
Exemplo n.º 15
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
      switch (requestCode) {
        case REQUEST_ADDITION_FRIEND:
          if (data == null) {
            return;
          }
          String phoneNumber = data.getStringExtra("PHONE_NUMBER");
          if (phoneNumber.equals(((GlobalApplication) this.getApplication()).getPhoneNumber())) {
            Snackbar.make(
                    coordinator, "You can not make friends with yourself", Snackbar.LENGTH_LONG)
                .setAction("ACTION", null)
                .show();
            return;
          }
          final ProgressDialog progressDialog = new ProgressDialog(this);
          progressDialog.setTitle("Addition Friend");
          progressDialog.setMessage("Please wait...");
          progressDialog.setCanceledOnTouchOutside(false);
          progressDialog.show();

          final ParseUser currentUser = ParseUser.getCurrentUser();
          ParseQuery<ParseUser> query = ParseUser.getQuery();
          query.whereEqualTo("username", phoneNumber);
          query.getFirstInBackground(
              new GetCallback<ParseUser>() {
                @Override
                public void done(ParseUser parseUser, ParseException e) {
                  if (e != null) {
                    e.printStackTrace();
                    progressDialog.dismiss();
                    Snackbar.make(coordinator, "Error", Snackbar.LENGTH_LONG)
                        .setAction("ACTION", null)
                        .show();
                    return;
                  }
                  if (parseUser == null) {
                    progressDialog.dismiss();
                    Snackbar.make(coordinator, "That account does not exist", Snackbar.LENGTH_LONG)
                        .setAction("ACTION", null)
                        .show();
                    return;
                  }
                  ArrayList<String> listFriend = (ArrayList<String>) currentUser.get("listFriend");
                  String newUserId = parseUser.getObjectId();
                  if (listFriend == null) {
                    listFriend = new ArrayList<String>();
                  } else {
                    if (listFriend.contains(newUserId)) {
                      progressDialog.dismiss();
                      Snackbar.make(
                              coordinator, "That account has been identical", Snackbar.LENGTH_LONG)
                          .setAction("ACTION", null)
                          .show();
                      return;
                    }
                  }
                  listFriend.add(newUserId);
                  currentUser.put("listFriend", listFriend);
                  currentUser.saveInBackground();
                  MainActivity.this.createNewFriend(parseUser);
                  progressDialog.dismiss();
                  Snackbar snackbar =
                      Snackbar.make(
                              coordinator, "Addition friend successfully", Snackbar.LENGTH_LONG)
                          .setAction("ACTION", null);
                  View snackbarView = snackbar.getView();
                  snackbarView.setBackgroundColor(Color.parseColor("#4caf50"));
                  snackbar.show();
                }
              });
          break;
      }
    }
    super.onActivityResult(requestCode, resultCode, data);
  }
Exemplo n.º 16
0
  public void deleteItem(String name1) {
    final String nameInside = name1;
    System.out.println("the name to be deleted is" + nameInside);

    // Bundle extras = getIntent().getExtras();
    // final int i = extras.getInt("itemposition");
    System.out.println("the name of the user is");

    System.out.println("the value received is4321ee" + nameInside);

    String str1 = ParseUser.getCurrentUser().getString("L_G");
    try {
      List<ParseUser> po =
          ParseUser.getCurrentUser()
              .getQuery()
              .whereEqualTo("username", ParseUser.getCurrentUser().getUsername())
              .find();
      ParseUser po1 = po.get(0);
      mainString = po1.getString("L_G");
      System.out.println("the username for first user is" + mainString);

    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    System.out.println("the value of the names string is" + mainString);

    ParseUser.getQuery()
        .whereEqualTo("L_G", mainString)
        .findInBackground(
            new FindCallback<ParseUser>() {

              @Override
              public void done(List<ParseUser> result, ParseException arg1) {
                // TODO Auto-generated method stub
                ParseObject po = result.get(0);
                String previousData = po.getString("L_G");
                System.out.println("the main main main data is " + previousData);
                String[] tempData = previousData.split(",");
                String temp1;
                String finalTemp = null;
                for (int k = 0; k < tempData.length; k++) {
                  temp1 = tempData[k];
                  if (!nameInside.equals(temp1)) {
                    if (finalTemp == null) {
                      finalTemp = temp1;
                    } else {
                      finalTemp = finalTemp + "," + temp1;
                    }
                  }
                }

                if (finalTemp == null) {

                  System.out.println("null executed");
                  po.put("L_G", JSONObject.NULL);
                } else {
                  po.put("L_G", finalTemp);
                }

                System.out.println("The updated data in the database is" + finalTemp);
                po.saveInBackground();
              }
            });
    fetchGroups();
    // qa.notifyDataSetChanged();
    Intent restart = new Intent(getApplicationContext(), CreateGroup.class);
    startActivity(restart);
    isConfirmed = false;
  }
Exemplo n.º 17
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);

    ButterKnife.bind(this);

    String user = getIntent().getStringExtra("username");

    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.whereEqualTo("username", user);

    mProgressBar.setVisibility(View.VISIBLE);
    query.findInBackground(
        new FindCallback<ParseUser>() {

          @Override
          public void done(List<ParseUser> user_found, ParseException e) {
            mProgressBar.setVisibility(View.INVISIBLE);

            if (e == null) {
              mUserFound = user_found.get(0);
              mUserHeadLabel.setText(mUserFound.getUsername().toString());
              mUserField.setText(mUserFound.getUsername().toString());
              if (mUserFound.get(ParseConstants.KEY_FIRSTNAME) != null)
                mFirstNameField.setText(mUserFound.get(ParseConstants.KEY_FIRSTNAME).toString());
              if (mUserFound.get(ParseConstants.KEY_LASTNAME) != null)
                mLastNameField.setText(mUserFound.get(ParseConstants.KEY_LASTNAME).toString());
              mEmailField.setText(mUserFound.getEmail().toString());
              if (mUserFound.get(ParseConstants.KEY_HOMETOWN) != null)
                mHomeTownField.setText(mUserFound.get(ParseConstants.KEY_HOMETOWN).toString());

              String email = mUserFound.getEmail().toLowerCase();

              // Obtenemos la imagen de gravatar

              if (email.equals("")) {
                mAvatar.setImageResource(R.drawable.avatar_empty);
              } else {
                // Para obtener la imagen de gravatar obtenemos el hash del email
                // Despues pasamos la url con el hash y los modificadores s= para tamaño
                // y d404 para que nos de un error 404 si no tiene imagen asociada
                String gravatarHash = MD5Util.md5Hex(email);
                String gratavarURL =
                    "http://www.gravatar.com/avatar/" + gravatarHash + "?s=204" + "&d=404";

                Picasso.with(getApplicationContext())
                    .load(gratavarURL)
                    .placeholder(
                        R.drawable.avatar_empty) // Si nos devuelve error 404 usamos esta imagen por
                    // defecto
                    .into(mAvatar);
              }

            } else {

              AlertDialog.Builder builder = new AlertDialog.Builder(ProfileActivity.this);
              builder.setMessage(e.getMessage());
              builder.setTitle(getString(R.string.title_error_message));
              builder.setPositiveButton(android.R.string.ok, null);
              AlertDialog dialog = builder.create();
              dialog.show();
            }
          }
        });

    mCancelButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            finish();
          }
        });
  }