Exemplo n.º 1
0
 public void updateData() {
   ParseQuery<Task> query = ParseQuery.getQuery(Task.class);
   query.whereEqualTo("user", ParseUser.getCurrentUser());
   query.setCachePolicy(CachePolicy.CACHE_THEN_NETWORK);
   query.orderByDescending("createdAt");
   query.findInBackground(
       new FindCallback<Task>() {
         @Override
         public void done(List<Task> tasks, ParseException error) {
           if (tasks != null) {
             mAdapter.clear();
             for (int i = 0; i < tasks.size(); i++) {
               mAdapter.add(tasks.get(i));
             }
           }
         }
       });
 }
  @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);
            }
          }
        });
  }