예제 #1
0
  private void retrieveMessages() {
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstant.CLASS_MESSAGE);
    query.whereEqualTo(ParseConstant.KEY_RECIPIENT_IDS, ParseUser.getCurrentUser().getObjectId());
    query.addDescendingOrder(ParseConstant.KEY_CREATED_AT);
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> list, ParseException e) {
            getActivity().setProgressBarIndeterminateVisibility(false);
            if (mSwipeRefreshLayout.isRefreshing()) {
              mSwipeRefreshLayout.setRefreshing(false);
            }

            if (e == null) {
              // No found message
              mMessages = list;
              String[] usernames = new String[mMessages.size()];
              int i = 0;
              for (ParseObject message : mMessages) {
                usernames[i] = message.getString(ParseConstant.KEY_SENDER_NAME);
                i++;
              }
              if (getListView().getAdapter() == null) {
                MessageAdapter adapter = new MessageAdapter(getListView().getContext(), mMessages);
                setListAdapter(adapter);
              } else {
                // refill the adapter
                ((MessageAdapter) getListView().getAdapter()).refill(mMessages);
              }
            }
          }
        });
  }
예제 #2
0
  private void retrieveMessages() {
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_MESSAGES);
    query.whereEqualTo(ParseConstants.KEY_RECIPIENT_IDS, ParseUser.getCurrentUser().getObjectId());
    query.addDescendingOrder(ParseConstants.KEY_CREATED_AT);
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> messages, ParseException e) {

            if (mSwipe.isRefreshing()) {
              mSwipe.setRefreshing(false);
            }

            if (e == null) {
              // We found the message
              mMessages = messages;
              String[] usernames = new String[mMessages.size()];
              int i = 0;
              for (ParseObject message : mMessages) {
                usernames[i] = message.getString(ParseConstants.KEY_SENDER_NAME);
                i++;
              }
              if (getListView().getAdapter() == null) {
                MessageAdapter adapter = new MessageAdapter(getListView().getContext(), mMessages);
                setListAdapter(adapter);
              } else {
                // Refill listview
                ((MessageAdapter) getListView().getAdapter()).refill(mMessages);
              }
            }
          }
        });
  }
예제 #3
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);

    listView = (ListView) getActivity().findViewById(R.id.listView1);
    dates = new ArrayList<String>();
    steps = new ArrayList<Integer>();

    statsList1 = new ArrayList<Stats>();
    statsList2 = new ArrayList<Stats>();
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Walking");
    query.whereEqualTo("user", ParseUser.getCurrentUser());
    query.addDescendingOrder("date");
    query.findInBackground(
        new FindCallback<ParseObject>() {

          @Override
          public void done(List<ParseObject> arg0, ParseException arg1) {
            // TODO Auto-generated method stub
            Log.d("demo", "Parse Objects size " + arg0.size());
            if (arg1 == null) {
              Log.d("score", "Retrieved " + arg0.size() + " scores");
              for (ParseObject p : arg0) {
                Log.d("demonew", p.getString("date") + " " + p.get("steps"));
                stats = new Stats();
                dates.add(p.getString("date"));
                steps.add(p.getInt("steps"));
                stats.setDate(p.getString("date"));
                stats.setStep(p.getInt("steps"));
                Log.d("demo", stats.toString());
                if (!statsList1.contains(stats)) {
                  statsList1.add(stats);
                }
                Log.d("demo", statsList1.toString());
              }

            } else {
              Log.d("score", "Error: " + arg1.getMessage());
            }

            for (int i = 0, j = (statsList1.size() - 1);
                i < statsList1.size() && j >= 0;
                i++, j--) {
              statsList2.add(statsList1.get(j));
            }

            Log.d("demo", "dates " + dates + "");
            Log.d("demo", "steps " + steps + "");
            Log.d("demo", "StatsList1 " + statsList1 + "");
            Log.d("demo", "StatsList2 " + statsList1 + "");

            adapter = new ListAdapater(getActivity(), R.layout.list_view_row, statsList2);
            listView.setAdapter(adapter);
            adapter.setNotifyOnChange(true);
          }
        });
  }
 public static void findUsersWithRecognition(
     Recognition recognition, final FindCallback<UserRecognition> callback) {
   ParseQuery<UserRecognition> userRecognitionQuery = ParseQuery.getQuery(UserRecognition.class);
   userRecognitionQuery.include("achievedBy");
   userRecognitionQuery.whereEqualTo("recognition", recognition);
   userRecognitionQuery.addDescendingOrder("dateAchieved");
   userRecognitionQuery.findInBackground(
       new FindCallback<UserRecognition>() {
         @Override
         public void done(List<UserRecognition> objects, ParseException e) {
           callback.done(objects, null);
         }
       });
 }
 public static void findLatestUserRecognitionInBackground(
     ParseUser user, final GetCallback<UserRecognition> callback) {
   ParseQuery<UserRecognition> userRecognitionQuery = ParseQuery.getQuery(UserRecognition.class);
   userRecognitionQuery.include("achievedBy");
   userRecognitionQuery.whereEqualTo("achievedBy", user);
   userRecognitionQuery.addDescendingOrder("dateAchieved");
   userRecognitionQuery.getFirstInBackground(
       new GetCallback<UserRecognition>() {
         @Override
         public void done(UserRecognition userRecognition, ParseException e) {
           if (e == null) {
             callback.done(userRecognition, null);
           } else {
             callback.done(null, e);
           }
         }
       });
 }
  @Override
  protected void onResume() {
    super.onResume();
    setProgressBarIndeterminateVisibility(true);
    ParseUser currentuser = ParseUser.getCurrentUser();
    if (currentuser == null) return;
    String currbranch, curryear;

    currbranch = currentuser.getString(ParseConstants.KEY_BRANCH);
    curryear = currentuser.getString(ParseConstants.KEY_YEAR);
    Integer endyear = new Integer(curryear);
    Integer startyear;

    if (currbranch.contentEquals("ARCHI") == false) startyear = endyear - 4;
    else startyear = endyear - 5;

    String channel = currbranch + curryear;
    publicchannel = channel;

    group.setText(currbranch + " " + startyear + " - " + endyear);

    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(channel);
    query.addDescendingOrder(ParseConstants.KEY_CREATED_AT);

    boolean isInCache = query.hasCachedResult();

    if (isNetworkAvailable() == true)
      query.setCachePolicy(ParseQuery.CachePolicy.CACHE_THEN_NETWORK);
    else if (isNetworkAvailable() == false && isInCache == true) {
      query.setCachePolicy(ParseQuery.CachePolicy.CACHE_ONLY);
      noInternetAccess();
    } else {
      noInternetAccess();
      return;
    }

    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> messages, ParseException e) {
            setProgressBarIndeterminateVisibility(false);
            mMessages = messages;
            if (e == null) {
              // We found messages!
              ArrayList<String> usernames = new ArrayList<String>();
              ArrayList<String> time = new ArrayList<String>();
              for (ParseObject mMessage : messages) {
                usernames.add(mMessage.getString(ParseConstants.KEY_SENDER_NAME));
                String str =
                    mMessage.getDate("sent_date").getHours()
                        + ":"
                        + mMessage.getDate("sent_date").getMinutes();
                if (str != null) time.add(str);
                else time.add("00:00");
              }

              lv.setAdapter(new VersionAdapterRumour(RumourActivity.this, usernames, time));
              lv.setScrollingCacheEnabled(false);
            }
          }
        });
  }
예제 #7
0
  public void getNewsList(String userName) {
    ParseQuery<ParseObject> parseQuery = new ParseQuery<ParseObject>("story");
    // parseQuery.whereEqualTo("userName", "Jeny Zheng Lan");
    parseQuery.setLimit(LIMIT);

    parseQuery.whereEqualTo("userName", userName);
    parseQuery.addDescendingOrder("createdAt");
    parseQuery.findInBackground(
        new FindCallback<ParseObject>() {

          @Override
          public void done(List<ParseObject> objects, ParseException e) {
            // TODO Auto-generated method stub
            if (!objects.isEmpty()) {
              for (int i = 0; i < objects.size(); i++) {
                ParseObject parseObject = objects.get(i);
                final String objectIdString = parseObject.getObjectId();
                final String userNameString = parseObject.getString("userName");
                final String userUuidString = parseObject.getString("userUuid");
                final String titleString = parseObject.getString("title");
                final int score = parseObject.getInt("score");
                final String contentString = parseObject.getString("content");

                final double latitude = parseObject.getDouble("latitude");
                final double longitude = parseObject.getDouble("longitude");
                final String stateString = parseObject.getString("State");
                final boolean toTop = parseObject.getBoolean("toTop");
                final Date createdAtDate = parseObject.getCreatedAt();

                ParseFile imageFile = (ParseFile) parseObject.get("image");
                if (imageFile != null) {
                  imageFile.getDataInBackground(
                      new GetDataCallback() {

                        @Override
                        public void done(byte[] data, ParseException e) {
                          if (e == null) {
                            // Log.d(tag, "parseFile done");
                            Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
                            newsList.add(
                                new News(
                                    objectIdString,
                                    userNameString,
                                    userUuidString,
                                    titleString,
                                    score,
                                    bmp,
                                    contentString,
                                    latitude,
                                    longitude,
                                    stateString,
                                    toTop,
                                    createdAtDate));

                            // redo if data change
                            newsAdt.notifyDataSetChanged();
                          }
                        }
                      });
                }
              }
            }
          }
        });
  }