Exemplo n.º 1
0
  public void initializeView(
      int newFitLogId, String workoutName, String referenceId, boolean editable, View button) {
    mFitLogId = newFitLogId;
    if (referenceId == null) {
      mRootFitLog = new FitLog(mFitLogId, 0);
    } else {
      ParseQuery<FitLog> refQuery = new ParseQuery<FitLog>("FitLog");
      refQuery.whereEqualTo("objectId", referenceId);
      ParseQuery<FitLog> query = new ParseQuery<FitLog>("FitLog");
      query.whereMatchesKeyInQuery("user", "user", refQuery);
      query.whereMatchesKeyInQuery("fitLogId", "fitLogId", refQuery);
      query.addAscendingOrder(FitLog.INDEX);
      try {
        List<FitLog> list = query.find();
        List<FitLog> newList = new LinkedList<FitLog>();
        Iterator<FitLog> it = list.iterator();
        while (it.hasNext()) {
          newList.add(it.next().getNewFitLog(newFitLogId));
        }

        mRootFitLog = FitLog.buildHierarchy(newList);
      } catch (Exception e) {
        // TODO
        e.printStackTrace();
      }
    }
    mRootFitLog.put(FitLog.EXERCISE, workoutName);
    addView(mRootFitLog.createView(getContext(), editable));
    setVisibility(View.VISIBLE);
    button.setVisibility(View.GONE);

    this.addOnLayoutChangeListener(this);
  }
  @Override
  public void onResume() {
    super.onResume();

    mCurrentUser = ParseUser.getCurrentUser();

    mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);

    mProgressBar.setVisibility(View.VISIBLE);

    ParseQuery<ParseUser> query = mFriendsRelation.getQuery();

    query.addAscendingOrder(ParseConstants.KEY_USERNAME);

    query.findInBackground(
        new FindCallback<ParseUser>() {
          @Override
          public void done(List<ParseUser> friends, ParseException e) {

            mProgressBar.setVisibility(View.INVISIBLE);

            if (e == null) {
              mFriends = friends;
              String[] usernames = new String[mFriends.size()];

              // For loop to iterate through the list of users
              int i = 0;
              for (ParseUser user : mFriends) {

                usernames[i] = user.getUsername();
                i++;
              }

              ArrayAdapter<String> adapter =
                  new ArrayAdapter<String>(
                      mListView.getContext(), android.R.layout.simple_list_item_checked, usernames);
              mListView.setAdapter(adapter);
              mListView.setEmptyView(mTextView); // Set the EmptyTextView
            } else {
              Log.e(TAG, e.getMessage());
              AlertDialog.Builder builder = new AlertDialog.Builder(RecipientsActivity.this);
              builder
                  .setMessage(e.getMessage())
                  .setTitle(R.string.error_title)
                  .setPositiveButton(android.R.string.ok, null);
              AlertDialog dialog = builder.create();
              dialog.show();
            }
          }
        });
  }
Exemplo n.º 3
0
  @Override
  public void onResume() {
    super.onResume();

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

    getActivity().setProgressBarIndeterminateVisibility(true);

    ParseQuery<ParseUser> query = mFriendsRelation.getQuery();
    query.addAscendingOrder(ParseConstants.KEY_USERNAME);
    query.findInBackground(
        new FindCallback<ParseUser>() {
          @Override
          public void done(List<ParseUser> friends, ParseException e) {
            getActivity().setProgressBarIndeterminateVisibility(false);

            if (e == null) {
              mFriends = friends;

              String[] usernames = new String[mFriends.size()];
              int i = 0;
              for (ParseUser user : mFriends) {
                usernames[i] = user.getUsername();
                i++;
              }
              if (mGridView.getAdapter() == null) {
                UserAdapter adapter = new UserAdapter(getActivity(), mFriends);
                mGridView.setAdapter(adapter);
              } else {
                ((UserAdapter) mGridView.getAdapter()).refill(mFriends);
              }
            } else {
              Log.e(TAG, e.getMessage());
              AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
              builder
                  .setMessage(e.getMessage())
                  .setTitle(R.string.error_title)
                  .setPositiveButton(android.R.string.ok, null);
              AlertDialog dialog = builder.create();
              dialog.show();
            }
          }
        });
  }
Exemplo n.º 4
0
  @Override
  public void onResume() {
    super.onResume();
    mCurrentUser = ParseUser.getCurrentUser();
    mFriendRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIEND_RELATION);

    getActivity().setProgressBarIndeterminateVisibility(true);
    ParseQuery<ParseUser> query = mFriendRelation.getQuery();
    query.addAscendingOrder(ParseConstants.KEY_USERNAME);
    query.findInBackground(
        new FindCallback<ParseUser>() {

          @Override
          public void done(List<ParseUser> friends, ParseException e) {
            getActivity().setProgressBarIndeterminateVisibility(false);
            if (e == null) {
              mFriends = friends;

              String[] usernames = new String[mFriends.size()];
              int i = 0;
              for (ParseUser friend : mFriends) {
                usernames[i] = friend.getUsername();
                i++;
              }
              // setting the adapter
              ArrayAdapter<String> adapter =
                  new ArrayAdapter<String>(
                      getListView().getContext(), android.R.layout.simple_list_item_1, usernames);
              setListAdapter(adapter);

            } else {
              Log.i(TAG, e.getMessage());
              // Building an alert dialog
              AlertDialog.Builder UserBuilder = new AlertDialog.Builder(getListView().getContext());
              UserBuilder.setTitle(e.getMessage());
              UserBuilder.setMessage(R.string.error_title);
              UserBuilder.setPositiveButton(android.R.string.ok, null);
              UserBuilder.create();
              UserBuilder.show();
            }
          }
        });
  }
Exemplo n.º 5
0
  @Override
  public void onResume() {
    super.onResume();

    mCurrentUser = ParseUser.getCurrentUser();
    // get relations for the current user if the column exists it is returned else it is created.
    mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);
    // we are querying into parse relational object.
    // get the list of parse user objects which are in relation with the current parse user.
    mProgressBar.setVisibility(View.VISIBLE);
    ParseQuery<ParseUser> query = mFriendsRelation.getQuery();
    query.addAscendingOrder(ParseConstants.KEY_USERNAME);
    query.findInBackground(
        new FindCallback<ParseUser>() {
          @Override
          public void done(List<ParseUser> friends, ParseException e) {
            mProgressBar.setVisibility(View.INVISIBLE);
            mFriends = friends;
            if (e == null) {
              if (mGridView.getAdapter() == null) {
                UserAdapter adapter = new UserAdapter(getActivity(), mFriends);
                mGridView.setAdapter(adapter);
              } else {
                ((UserAdapter) mGridView.getAdapter()).refill(mFriends);
              }
            } else if (e.getMessage()
                .equals(
                    "java.lang.ClassCastException: java.lang.String cannot be cast to org.json.JSONObject")) {
              // Do nothing since friends are not yet added.
              // ignore
            } else {
              // Log.e(TAG, e.getMessage());
              AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
              builder.setTitle(R.string.error_title);
              builder.setMessage(e.getMessage());
              builder.setPositiveButton(android.R.string.ok, null);
              AlertDialog dialog = builder.create();
              dialog.show();
            }
          }
        });
  }
Exemplo n.º 6
0
  public void onResume() {
    super.onResume();

    mCurrentUser = ParseUser.getCurrentUser();
    mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);
    ParseQuery<ParseUser> query = mFriendsRelation.getQuery();
    query.addAscendingOrder(ParseConstants.KEY_USERNAME);
    mFriendsRelation
        .getQuery()
        .findInBackground(
            new FindCallback<ParseUser>() {
              @Override
              public void done(List<ParseUser> friends, ParseException e) {

                if (e == null) {
                  mFriends = friends;

                  String[] usernames = new String[mFriends.size()];
                  int i = 0;
                  for (ParseUser user : mFriends) {
                    usernames[i] = user.getUsername();
                    i++;
                  }
                  ArrayAdapter<String> adapter =
                      new ArrayAdapter<String>(
                          getListView().getContext(),
                          android.R.layout.simple_list_item_1,
                          usernames);
                  setListAdapter(adapter);
                } else {
                  Log.e(TAG, e.getMessage());
                  AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext());
                  builder
                      .setMessage(e.getMessage())
                      .setTitle(R.string.error_title)
                      .setPositiveButton(R.string.ok, null);
                  AlertDialog dialog = builder.create();
                  dialog.show();
                }
              }
            });
  }
Exemplo n.º 7
0
  // get a list of all your friends - this code is copied from the onResume() method in the
  // FriendsFragment with some additions
  @Override
  public void onResume() {
    super.onResume();

    // get the current user using the getCurrentUser() method
    mCurrentUser = ParseUser.getCurrentUser();
    // for the relation, from this user we want to call a method called getRelation()
    mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);

    // start the progress indicator before we run our query
    // use the getActivity() to get a reference to the activity in which the fragment is running (as
    // setProgressBarIndeterminateVisibility() is an Activity method)
    // note: Window provided Progress Bars are now deprecated with Toolbar.
    // see:
    // http://stackoverflow.com/questions/27788195/setprogressbarindeterminatevisibilitytrue-not-working
    // getActivity().setProgressBarIndeterminateVisibility(true);

    // the first thing we need is a list of the users friends...
    // we have the friend relation, but this doesn't give us a list of users to work with
    // the list itself is still on the back end, we need to use the ParseRelation to retrieve it
    // use the build in query to retrieve it - this gets us the query associated with this
    // ParseRelation
    ParseQuery<ParseUser> query = mFriendsRelation.getQuery();

    // sort the list by username before calling it
    query.addAscendingOrder(ParseConstants.KEY_USERNAME);

    query.findInBackground(
        new FindCallback<ParseUser>() {
          @Override
          public void done(List<ParseUser> friends, ParseException e) {

            // getActivity().setProgressBarIndeterminateVisibility(false);

            // include an if statement to check the exception
            if (e == null) {

              // set the mFriends variable based on the list of friends that is returned
              mFriends = friends;

              // now we need to use mFriends as the data source for the list view in our fragments
              // we need to create an adapter and set it as the list adapter, just like we do for
              // lost activities
              // this is very similar to what we are ding for all users in the EditFriends activity,
              // so copy and paste that code

              // create an array of strings to store the usernames and set the size equal to that of
              // the list returned
              String[] usernames = new String[mFriends.size()];
              // enhanced for loop to go through the list of parse users and create an array of
              // usernames
              int i = 0;
              for (ParseUser user : mFriends) {
                usernames[i] = user.getUsername();
                i++;
              }
              // create an array adapter and set it as the adapter for this activity
              ArrayAdapter<String> adapter =
                  new ArrayAdapter<String>(
                      // for the first parameter here, need to get the context of a fragment through
                      // the list view itself
                      // the list view knows which context it is in because of its layout in the
                      // fragment and in the activity that contains the fragment, so use...
                      getListView().getContext(),
                      android.R.layout.simple_list_item_checked,
                      usernames);
              // need to call setListAdapter for this activity.  This method is specifically from
              // the ListActivity class
              setListAdapter(adapter);
            } else {
              // display a message to the user (copied from EditFriendsActivity)
              // there was an error - log the message
              Log.e(TAG, e.getMessage());
              // display an alert to the user
              // if there is a parse exception then...
              AlertDialog.Builder builder = new AlertDialog.Builder(RouteRecipientsActivity.this);
              // set the message from the exception
              builder
                  .setMessage(e.getMessage())
                  .setTitle(R.string.error_title)
                  .setPositiveButton(android.R.string.ok, null);
              AlertDialog dialog = builder.create();
              dialog.show();
            }
          }
        });
  }
Exemplo n.º 8
0
  public void downloadLatestThumbnails() {
    File folder = new File(Environment.getExternalStorageDirectory() + "/galleryandupload");
    if (!folder.exists()) {
      folder.mkdir();
    }
    File folder2 = new File(Environment.getExternalStorageDirectory() + "/galleryandupload/large");
    if (!folder2.exists()) {
      folder2.mkdir();
    }

    if (checkConnection()) {
      dialog1 = ProgressDialog.show(this, null, "Just a moment...", true);
      final ParseQuery<ParseObject> query = ParseQuery.getQuery("PhotoTable");
      // query.addDescendingOrder("createdAt");
      query.addAscendingOrder("createdAt");
      query.findInBackground(
          new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> objects, ParseException e) {
              ParseObject lastObject = null;
              try {
                lastObject = objects.get(objects.size() - 1);
              } catch (ArrayIndexOutOfBoundsException ex) {
                Toast.makeText(GalleryActivity.this, "No images in Cloud!", Toast.LENGTH_LONG)
                    .show();
                dialog1.dismiss();
                GalleryActivity.this.finish();
                return;
              }
              // 'd' - latest photo date from Parse
              Date d = lastObject.getCreatedAt();
              Cursor cursor = db.rawQuery("SELECT thetime FROM latestphototime;", null);
              cursor.moveToFirst();
              String currentlatesttime = cursor.getString(0);
              DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US);
              // 'dd' - latest photo date from sqlite
              Date dd = null;
              try {
                dd = dateFormat.parse(currentlatesttime);
              } catch (Exception ee) {
              }
              if (dd.toString().equals(d.toString())) {
                displayThumbnails();
              } else {
                File dir =
                    new File(Environment.getExternalStorageDirectory() + "/galleryandupload");
                File[] filelist = dir.listFiles();
                int pos = filelist.length;

                if (filelist.length == 1) {
                  for (int i = 0; i < objects.size(); ++i) {
                    if (objects.get(i).getCreatedAt().toString().equals(currentlatesttime)) {
                      break;
                    }
                    ParseFile myFile = objects.get(i).getParseFile("pic_thumbnail");
                    byte[] data = null;
                    try {
                      data = myFile.getData();
                    } catch (Exception eee) {
                    }
                    String fn = String.valueOf(pos) + "_th.jpg";
                    pos++;
                    writeFile(data, fn);
                  }
                } else {
                  boolean flag = true;
                  for (int i = 0; i < objects.size(); ++i) {
                    if (flag
                        && objects.get(i).getCreatedAt().toString().equals(currentlatesttime)) {
                      flag = false;
                    } else if (!flag) {
                      ParseFile myFile = objects.get(i).getParseFile("pic_thumbnail");
                      byte[] data = null;
                      try {
                        data = myFile.getData();
                      } catch (Exception eee) {
                      }
                      String fn = String.valueOf(pos) + "_th.jpg";
                      pos++;
                      writeFile(data, fn);
                    }
                  }

                  /*for (int i = objects.size()-1; i >=0 ; --i) {
                      if (objects.get(i).getCreatedAt().toString().equals(currentlatesttime)) {
                          break;
                      }
                      ParseFile myFile = objects.get(i).getParseFile("pic_thumbnail");
                      byte[] data = null;
                      try {
                          data = myFile.getData();
                      } catch (Exception eee) {
                      }
                      String fn = String.valueOf(pos) + "_th.jpg";
                      pos++;
                      writeFile(data, fn);
                  }*/
                }

                displayThumbnails();
                db.execSQL("UPDATE latestphototime SET thetime='" + d.toString() + "';");
              }

              // One more case left out. When some row is deleted from Parse db, the latest date
              // stored locally could be AFTER the latest date from Parse in which case we will have
              // to delete a couple of photos from the local storage.

              dialog1.dismiss();
            }
          });

    } else {
      Toast.makeText(this, "Check your Internet Connection!", Toast.LENGTH_LONG).show();
      displayThumbnails();
    }
  }