Пример #1
0
    @Override
    protected Void doInBackground(Void... params) {
      // Create the array
      photoarraylist = new ArrayList<PhotoList>();
      try {
        // Locate the class table named "ImageUpload" in Parse.com
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("ImageUpload");
        // Locate the column named "position" in Parse.com and order list
        // by descending order of created.
        query.orderByDescending("createdAt");
        query.setLimit(15);
        ob = query.find();
        for (ParseObject po : ob) {
          // retrieve objectID and Title
          String stringTitle = (String) po.get("Title");
          String stringObjectID = po.getObjectId();

          // retrieve the image file
          ParseFile image = (ParseFile) po.get("Photo");
          PhotoList map = new PhotoList();
          map.setPhoto(image.getUrl());
          map.setObjectID(stringObjectID);
          map.setTitle(stringTitle);
          photoarraylist.add(map);
        }
      } catch (ParseException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
      }
      return null;
    }
Пример #2
0
  // TODO: What to do with strings? leave it of clean it
  public void getNewPosts(final NewsFeedAdapter adapter) {

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");
    query.setLimit(2);
    query.orderByDescending("createdAt");
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> list, ParseException e) {
            if (e == null) {
              ArrayList<News> news = new ArrayList<News>();
              for (ParseObject item : list) {
                News n = new News();

                n.setTitle(item.getString("title"));
                n.setLocation(item.getString("location"));
                n.setTime(item.getString("time"));
                n.setText(item.getString("text"));
                n.setIndicator((ArrayList<String>) item.get("icons"));
                n.setType(item.getString("type"));
                n.setDate(item.getDate("date"));
                n.setAuthor(item.getString("Author"));
                n.setCreatedAt(item.getCreatedAt());
                Log.d("CREATEDAT", item.getCreatedAt().toString());
                news.add(n);
              }
              mLast = list.get(list.size() - 1).getInt("number");
              adapter.addItems(news);
            } else {
              e.printStackTrace();
            }
          }
        });
  }
Пример #3
0
 private void startManageContent() {
   // if you're logged
   if (app.logged()) {
     findViewById(R.id.progress).setVisibility(View.VISIBLE);
     manageNotLoggedText.setVisibility(View.GONE);
     ParseQuery<ParseObject> query = ParseQuery.getQuery(Consts.PROTEST);
     query.whereEqualTo(Consts.P_ADMIN, app.getUsername());
     query.orderByDescending("createdAt");
     query.findInBackground(
         new FindCallback<ParseObject>() {
           public void done(List<ParseObject> retrievedProtestList, ParseException e) {
             if (e == null) {
               manageProtestArrList = Protest.convertList(retrievedProtestList);
               manageProtestAdapter =
                   new ProtestsAdapter(con, R.layout.row_protest, manageProtestArrList);
               manageProtestList.setAdapter(manageProtestAdapter);
               showHideNoProtestsMsg(retrievedProtestList);
             } else {
               Log.v(TAG, "Error: " + e.getMessage());
             }
             findViewById(R.id.progress).setVisibility(View.GONE);
           }
         });
   } else {
     notLogged("view protests you manage ", getString(R.string.unregistered_manage));
   }
 }
  public void getQuotes(final Context context) {
    row_quotes = new ArrayList<RowQuote>();

    query.whereExists("createdAt");
    query.orderByDescending("createdAt");
    query.setLimit(1000);

    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> quoteList, ParseException e) {
            if (e == null) {
              for (int i = 0; i < quoteList.size(); i++) {
                String quote = quoteList.get(i).getString("Quote");
                String name = quoteList.get(i).getString("Name");
                row_quotes.add(new RowQuote(name, quote));

                //						if (i == quoteList.size()-1) {
                //							last_item_date = quoteList.get(i).getCreatedAt();
                //						}
              }
            } else {
              row_quotes.add(
                  new RowQuote(
                      "Justin",
                      "hm, either you don't have internet connection or my database is down"));
            }

            row_adapter = new RowQuoteAdapter(context, row_quotes);
            list = (ListView) getActivity().findViewById(R.id.list);
            list.setAdapter(row_adapter);
          }
        });
  }
Пример #5
0
  static float[] updateGraph() {
    long timeStep = 1445214540000L;
    float[] results = new float[numData];

    ParseQuery<ParseObject> query = ParseQuery.getQuery("data");
    query.whereEqualTo("flag", 1);
    try {
      ParseObject flagged = query.getFirst();
      timeStep = flagged.getLong("unixTimeStamp");
      flagged.put("flag", 0);
      flagged.saveInBackground();
      Log.d("Find Flag", flagged.getObjectId());
    } catch (ParseException e) {
      Log.d("Find Flag", "Error: " + e.getMessage());
    }
    query = ParseQuery.getQuery("data");
    query.orderByAscending("unixTimeStamp");
    query.whereGreaterThan("unixTimeStamp", timeStep);
    try {
      ParseObject nextFlag = query.getFirst();
      nextFlag.put("flag", 1);
      nextFlag.saveInBackground();
      Log.d("Set Next Flag", nextFlag.getObjectId() + " is " + nextFlag.getInt("flag"));
    } catch (ParseException e) {
      Log.d("Set Next Flag", "Error: " + e.getMessage());
    }
    query = ParseQuery.getQuery("data");
    query.orderByDescending("unixTimeStamp");
    query.whereLessThan("unixTimeStamp", timeStep);
    for (int i = 0; i < numData; i++) {
      try {
        ParseObject data = query.getFirst();
        results[numData - i - 1] = (float) data.getInt("Bg");
        query.whereLessThan("unixTimeStamp", data.getLong("unixTimeStamp"));
      } catch (ParseException e) {
        Log.d("Fill Results Array", "Failed");
      }
    }
    /*query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> data, ParseException e) {
            int i = 0;

            if (e == null) {
                Log.d("Blood Glucose", "Retrieved " + data.size() + " Blood Glucose Data Points");
                for(ParseObject person : data) {
                    results[i] = person.getInt("Bg");
                    i++;
                }
            }
            else {
                Log.d("Blood Glucose", "Error: " + e.getMessage());
            }
        }
    });*/
    return results;
  }
 @Override
 public List<UserLikeComment> getMostRecentlyLikedComments(
     ParseUser user, int numberOfRetunredRows) throws ParseException {
   ParseQuery<UserLikeComment> query = ParseQuery.getQuery("UserLikeComment");
   query.whereEqualTo("user", user);
   query.setLimit(numberOfRetunredRows);
   query.orderByDescending("createdAt");
   return query.find();
 }
Пример #7
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.e("nicat", "tebrikler");
    View rootView = inflater.inflate(R.layout.admin_fragment_friends, container, false);

    final ProgressDialog ProgressDialog = new ProgressDialog(rootView.getContext());
    ProgressDialog.setTitle("Yüklənir");
    ProgressDialog.setMessage("Loading Please Wait");
    ProgressDialog.show();

    //        final List<String> foods = new ArrayList<String>();
    //        final ArrayAdapter buckyAdapter = new
    // ArrayAdapter<String>(rootView.getContext(),R.layout.allorderslist,R.id.textView2,foods);

    final dataListAdapter dataListAdapter = new dataListAdapter();
    final ArrayList<String> quantity = new ArrayList<String>();
    final ArrayList<String> tarix = new ArrayList<String>();
    final ArrayList<String> otaq = new ArrayList<String>();
    final ArrayList<String> ad = new ArrayList<String>();

    final ListView buckyList = (ListView) rootView.findViewById(R.id.listView2);

    ParseQuery query = new ParseQuery("Orders");
    final ParseUser nicat = new ParseUser();
    query.whereEqualTo("buildingId", nicat.getCurrentUser().getString("buildingId"));
    query.orderByDescending("createdAt");
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> objects, com.parse.ParseException e) {
            if (e == null) {
              for (ParseObject dealsObject : objects) {
                Date date = dealsObject.getCreatedAt();
                SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
                String formattedDate = df.format(date);
                tarix.add(formattedDate);
                quantity.add(dealsObject.get("quantity").toString());
                otaq.add(dealsObject.get("roomId").toString());
                ad.add(dealsObject.get("Name").toString());
              }
              dataListAdapter.notifyDataSetChanged();
              buckyList.setAdapter(new dataListAdapter(quantity, tarix, i1, otaq, ad));
              ProgressDialog.dismiss();

            } else {
              Log.d("Brand", "Error: " + e.getMessage());
            }
          }
        });

    Log.d("nicat", ParseUser.getCurrentUser().getObjectId().toString());

    return rootView;
  }
Пример #8
0
  /**
   * Load the conversation list from Parse server and save the date of last message that will be
   * used to load only recent new messages
   */
  private void loadConversationList() {
    ParseQuery<ParseObject> q = ParseQuery.getQuery(discussionTableName);
    if (messagesList.size() != 0) {
      //			// load all messages...
      //			ArrayList<String> al = new ArrayList<String>();
      //			al.add(discussionTopic);
      //			al.add(MainActivity.user.getParseID());
      //			q.whereContainedIn("sender", al);
      //		}
      //		else {
      // load only newly received message..
      if (lastMsgDate != null)
        // Load only new messages, that weren't send by me
        q.whereGreaterThan(Const.COL_MESSAGE_CREATED_AT, lastMsgDate);
      q.whereNotEqualTo(Const.COL_MESSAGE_SENDER_ID, MainActivity.user.getParseID());
    }
    q.orderByDescending(Const.COL_MESSAGE_CREATED_AT);
    q.setLimit(100);
    q.findInBackground(
        new FindCallback<ParseObject>() {

          @Override
          public void done(List<ParseObject> li, ParseException e) {
            if (li != null && li.size() > 0) {
              for (int i = li.size() - 1; i >= 0; i--) {
                ParseObject po = li.get(i);

                Message message =
                    new Message(
                        po.getString(Const.COL_MESSAGE_CONTENT),
                        po.getCreatedAt(),
                        po.getString(Const.COL_MESSAGE_SENDER_ID),
                        po.getString(Const.COL_MESSAGE_SENDER_NAME));

                message.setStatus(MessageStatus.STATUS_SENT);
                messagesList.add(message);

                if (lastMsgDate == null || lastMsgDate.before(message.getDate())) {
                  lastMsgDate = message.getDate();
                }
                chatAdapter.notifyDataSetChanged();
              }
            }
            handler.postDelayed(
                new Runnable() {

                  @Override
                  public void run() {
                    if (isRunning) loadConversationList();
                  }
                },
                1000);
          }
        });
  }
Пример #9
0
 public static void getAllQuestions() {
   ParseQuery<ParseObject> query = ParseQuery.getQuery(Common.OBJECT_POST);
   query.orderByDescending("updatedAt");
   query.findInBackground(
       new FindCallback<ParseObject>() {
         public void done(List<ParseObject> questionList, ParseException e) {
           if (e == null) {
             Log.d("questions", "Retrieved " + questionList.size() + " questions");
             sortByPopularity(questionList);
             EventBus.getDefault().post(new QuestionEvent(questionList));
           } else {
             Log.d("questions", "Error: " + e.getMessage());
           }
         }
       });
 }
Пример #10
0
 public static void getAllCommunities() {
   ParseQuery<ParseObject> query = ParseQuery.getQuery("Community");
   // exclude taiwan community
   query.whereNotEqualTo("objectId", "wtgxgSpmNH");
   query.orderByDescending("updatedAt");
   query.findInBackground(
       new FindCallback<ParseObject>() {
         public void done(List<ParseObject> communityList, ParseException e) {
           if (e == null) {
             Log.d("communities", "Retrieved " + communityList.size() + " communities");
             EventBus.getDefault().post(new CommunityEvent(communityList));
           } else {
             Log.d("communities", "Error: " + e.getMessage());
           }
         }
       });
 }
  private void getBookingList() {
    ParseUser currentUser = ParseUser.getCurrentUser();

    ParseQuery<ParseObject> userbookingQuery = ParseQuery.getQuery("UserBooking");
    userbookingQuery.whereEqualTo("User", currentUser);
    userbookingQuery.include("BookedHotel");
    userbookingQuery.orderByDescending("ReservationTime");
    userbookingQuery.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> bookings, ParseException e) {
            for (int i = 0; i < bookings.size(); ++i) {
              userboookingAdapter.add(bookings.get(i));
            }
          }
        });
  }
Пример #12
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));
             }
           }
         }
       });
 }
Пример #13
0
  public static void getMyQuestions(ParseUser user) {
    ParseQuery<ParseObject> query = user.getRelation(Common.OBJECT_USER_MY_QUESTIONS).getQuery();
    // ParseQuery<ParseObject> query = ParseQuery.getQuery("Colleciton");

    query.orderByDescending("updatedAt");
    // query.whereEqualTo("uid",uid);
    query.findInBackground(
        new FindCallback<ParseObject>() {
          public void done(List<ParseObject> myQuestionsList, ParseException e) {
            if (e == null) {
              Log.d("myQuesions", "Retrieved " + myQuestionsList.size() + " collections");
              EventBus.getDefault().post(new MyQuestionsEvent(myQuestionsList));
            } else {
              Log.d("myQuesions", "Error: " + e.getMessage());
            }
          }
        });
  }
Пример #14
0
  public void getMorePosts(final NewsFeedAdapter adapter) {
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");
    query.setLimit(2);
    if (mLast != -1 && mPrevious != mLast) {

      query.orderByDescending("createdAt");
      query.whereLessThan("number", mLast);
      mPrevious = mLast;
    } else {
      Toast.makeText(adapter.getContext(), "No more posts", Toast.LENGTH_SHORT).show();
      return;
    }

    final int count = adapter.getCount();
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> list, ParseException e) {
            if (e == null) {
              ArrayList<News> news = new ArrayList<News>();
              for (ParseObject item : list) {
                News n = new News();

                n.setTitle(item.getString("title"));
                n.setLocation(item.getString("location"));
                n.setTime(item.getString("time"));
                n.setText(item.getString("text"));
                n.setIndicator((ArrayList<String>) item.get("icons"));
                n.setType(item.getString("type"));
                n.setDate(item.getDate("date"));
                n.setAuthor(item.getString("Author"));
                n.setCreatedAt(item.getCreatedAt());
                news.add(n);
              }

              adapter.addItems(news);
            } else {
              e.printStackTrace();
            }
          }
        });
  }
Пример #15
0
  private void loadInfoDataFromServer() {
    ParseQuery<Info> query = Info.getQuery();
    query.orderByDescending("createdAt");
    query.getFirstInBackground(
        new GetCallback<Info>() {

          @Override
          public void done(Info info, ParseException e) {
            if (info == null) {
              Log.d("Parse", "The getFirst request failed.");
            } else {
              // got the most recently modified object... do something with it here
              info.pinInBackground();
              title.setText(info.getTitle());
              content.setText(info.getContent() + info.getCreatedAt().toString());
              contact.setText("Contact: " + info.getEmail());
            }
          }
        });
  }
Пример #16
0
  public static void getCommunityQuestions(ParseObject community) {

    if (community == null) {
      getAllQuestions();
      return;
    }

    ParseRelation<ParseObject> relation = community.getRelation(Common.OBJECT_COMMUNITY_POSTS);
    ParseQuery<ParseObject> query = relation.getQuery();
    query.orderByDescending("updatedAt");
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> list, ParseException e) {
            if (e == null) {
              Log.d("questions", "Retrieved " + list.size() + " community questions");
              EventBus.getDefault().post(new QuestionEvent(list));
            }
          }
        });
  }
Пример #17
0
 private void getAllAlbums() {
   ParseQuery<Album> queryAuthor = ParseQuery.getQuery("Album");
   queryAuthor.whereEqualTo("author", ParseUser.getCurrentUser());
   ParseQuery<Album> queryCollaborator = ParseQuery.getQuery("Album");
   queryCollaborator.whereEqualTo("collaborators", ParseUser.getCurrentUser());
   List<ParseQuery<Album>> queries = new ArrayList<>();
   queries.add(queryAuthor);
   queries.add(queryCollaborator);
   ParseQuery<Album> mainQuery = ParseQuery.or(queries);
   mainQuery.orderByDescending("createdAt");
   mainQuery.findInBackground(
       new FindCallback<Album>() {
         public void done(List<Album> results, ParseException e) {
           if (e == null) {
             mAllAlbums = results;
             mAdapter.setAlbums(mAllAlbums);
             mResultsView.scrollToPosition(0);
           }
         }
       });
 }
Пример #18
0
  public void refreshNotesList(boolean showLoadingProgress) {
    if (showLoadingProgress) {
      listLoadingProgressBar.setVisibility(View.VISIBLE);
    }

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");
    query.whereEqualTo("author", ParseUser.getCurrentUser());
    query.orderByDescending("updatedAt");

    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> parseObjects, ParseException e) {
            if (e == null) {
              notes.clear();
              for (ParseObject noteObject : parseObjects) {
                Note note =
                    new Note(
                        noteObject.getObjectId(),
                        noteObject.getString("title"),
                        noteObject.getString("content"));
                notes.add(note);
              }
              listLoadingProgressBar.setVisibility(View.GONE);
              notesAdapter.notifyDataSetChanged();

              if (notes.isEmpty()) {
                showEmptyView();
              }
            } else {
              showEmptyView();
              Log.e(LOG_TAG, e.getMessage());
            }
          }
        });
  }
Пример #19
0
  private void retrieveData() {
    //
    // Retreive data from Parse
    //

    final ProgressDialog progressDialog =
        ProgressDialog.show(getActivity(), "Retreiving Data", "Please wait...");
    ParseQuery<ParseObject> query = ParseQuery.getQuery("CustomerRequest");
    query.whereEqualTo("owner", ParseUser.getCurrentUser());
    query.whereEqualTo("status", buyer.post.NewCJActivity.PENDING);
    query.orderByDescending("createdAt");
    query.findInBackground(
        new FindCallback<ParseObject>() {
          public void done(List<ParseObject> requestList, ParseException e) {
            if (e == null) {

              if (requestList.size() > 0) {
                ListingsAdapter adapter =
                    new ListingsAdapter(
                        getActivity(), R.layout.adapter_buyer_listings_item, requestList);
                mListViewPendingJob.setAdapter(adapter);
              } else {
                mListViewPendingJob.setEmptyView(mTextViewNoJobs);
              }

            } else {
              Toast.makeText(
                      getActivity(),
                      "Failed to retrieve data\n\nPlease try again later",
                      Toast.LENGTH_LONG)
                  .show();
            }
            progressDialog.dismiss();
          }
        });
  }
Пример #20
0
    public void runLoadDropItemsFromParse() {

      if (pageNumber != 0) {
        int pageMultiplier = pageNumber - 1;
        skipNumber = pageMultiplier * queryLimit;
        // Otherwise, clear the list, because this is a default(refresh) query
      } else {
        if (mDropListFromParse != null) {
          mDropListFromParse.clear();
        }
      }

      ParseUser user = ParseUser.getCurrentUser();

      ParseRelation relation = user.getRelation("todoDrops");

      ParseQuery query = relation.getQuery();

      query.setLimit(queryLimit);
      query.setSkip(skipNumber);
      query.include("authorPointer");
      query.orderByDescending("createdAt");
      query.findInBackground(
          new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> list, ParseException e) {

              if (e != null) {
                Log.i("KEVIN", "error error");

              } else {

                for (int i = 0; i < list.size(); i++) {

                  // Collects Drop Objects
                  //                        dropObjectsList.add(list.get(i));

                  final DropItem dropItem = new DropItem();

                  // Drop Author Data//////////////////////////////////////////////////////////
                  ParseObject authorData = (ParseObject) list.get(i).get("authorPointer");

                  ParseFile parseProfilePicture = (ParseFile) authorData.get("parseProfilePicture");
                  if (parseProfilePicture != null) {
                    parseProfilePicture.getDataInBackground(
                        new GetDataCallback() {
                          @Override
                          public void done(byte[] data, ParseException e) {
                            if (e == null) {
                              Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
                              Bitmap resized = Bitmap.createScaledBitmap(bmp, 100, 100, true);
                              dropItem.setParseProfilePicture(resized);
                              if (pageNumber != 0) {
                                mDropAdapter.notifyDataSetChanged();
                              } else {

                                if (mDropListFromParse != null) {
                                  updateRecyclerView(mDropListFromParse);
                                }
                              }
                            }
                          }
                        });
                  }

                  // dropItemAll.setAuthorName(authorName);
                  dropItem.setAuthorName((String) authorData.get("displayName"));
                  // Author id
                  dropItem.setAuthorId(authorData.getObjectId());
                  // Author Rank
                  dropItem.setAuthorRank(authorData.getString("userRank"));
                  // Author Riple Count
                  dropItem.setAuthorRipleCount(String.valueOf(authorData.getInt("userRipleCount")));
                  // Author Info
                  dropItem.setAuthorInfo(authorData.getString("userInfo"));

                  // Drop Data////////////////////////////////////////////////////////////////
                  // DropObjectId
                  dropItem.setObjectId(list.get(i).getObjectId());
                  // Drop description
                  dropItem.setDescription(list.get(i).getString("description"));

                  // Get created at from parse and convert it to friendly String
                  Format formatter = new SimpleDateFormat("MMM dd, yyyy @ h a");
                  String dateAfter = formatter.format(list.get(i).getCreatedAt());
                  dropItem.setCreatedAt(dateAfter);

                  // Riple Count
                  int ripleCount = (list.get(i).getInt("ripleCount"));
                  if (ripleCount == 1) {
                    dropItem.setRipleCount(
                        String.valueOf(list.get(i).getInt("ripleCount") + " Riple"));
                  } else {
                    dropItem.setRipleCount(
                        String.valueOf(list.get(i).getInt("ripleCount") + " Riples"));
                  }

                  // Comment Count
                  int commentCount = (list.get(i).getInt("commentCount"));
                  if (commentCount == 1) {
                    dropItem.setCommentCount(
                        String.valueOf(list.get(i).getInt("commentCount") + " Comment"));
                  } else {
                    dropItem.setCommentCount(
                        String.valueOf(list.get(i).getInt("commentCount") + " Comments"));
                  }

                  mDropListFromParse.add(dropItem);
                }
              }

              Log.d(TAG, "DropList = " + mDropListFromParse.size());
              dropTabInteractionList = mDropListFromParse;
            }
          });
    }
    @Override
    protected Void doInBackground(Void... arg0) {
      if (isHoneycomb) {
        final ParseQuery query = new ParseQuery(Preferences.PARSE_TABLE_SMS);
        // Sort the Parse Object so only the username of the current
        // user can be accessed.
        query.whereEqualTo(Preferences.PARSE_USERNAME_ROW, Util.getUsernameString());
        // The most recent message added will be on top.
        query.orderByDescending("createdAt");
        // Only need to get one message from the server, each message
        // will be from a push
        query.setLimit(1);
        try {
          List<ParseObject> messageList = query.find();
          for (ParseObject messageObject : messageList) {
            // Open up the database
            // Get the parse object id
            String objectId = messageObject.objectId();
            // with the objectid you can query the server
            ParseObject message = query.get(objectId);
            // Get the time the message was added to the server
            Date time = message.createdAt();
            // Format the time to (Fri Jan 13 12:00)
            SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd hh:mm");
            String formatedTime = sdf.format(time);
            String timeDB = formatedTime.toString();
            String addressDB = message.getString("address");
            String bodyDB = message.getString("body");
            int readDB = message.getInt("read");
            int smsIdDB = message.getInt("smsId");
            String subjectDB = message.getString("subject");
            int threadIdDB = message.getInt("threadId");
            int typeDB = message.getInt("type");
            int onDeviceDB = message.getInt("onDevice");
            String usernameDB = message.getString("username");
            // Display the total message queryed for
            // logging
            String totalMessage =
                "Sent: "
                    + timeDB
                    + "\n"
                    + "Address: "
                    + addressDB
                    + "\n"
                    + "Message : "
                    + bodyDB
                    + "\n";
            Log.d(TAG, "New message is: " + totalMessage);
            // Get the MessageItem object so you can
            // create the db entry.
            MessageItem item =
                new MessageItem(
                    timeDB,
                    addressDB,
                    bodyDB,
                    readDB,
                    smsIdDB,
                    subjectDB,
                    threadIdDB,
                    typeDB,
                    onDeviceDB,
                    usernameDB);
            // Insert the MessageItem into the sms2honeycomb.db.
            dbAdapter.insertMessageItem(item);

            // TODO update the listadapter to display the new
            // message via an intent/ service?

            String intentString = "com.asa.texttotab.UPDATE_LIST";
            Intent updateIntent = new Intent();
            updateIntent.setAction(intentString);
            mContext.sendBroadcast(updateIntent);

            // TODO NOTICIFATIONS
          }
        } catch (ParseException e) {
          // TODO - Handle situation where querying server failed
          dbAdapter.close();
          Log.e(TAG, "querying server failed");
          e.printStackTrace();
        }
      } else {
        Log.e(TAG, "The device is not honeycomb is its a phone.");
        // If the device is not a tablet it is a phone so you pull from
        // the
        // server, but then send a sms message from the data recived.
        // We want to query the sms table
        final ParseQuery query = new ParseQuery(Preferences.PARSE_TABLE_SMS);
        // Sort the Parse Object so only the username of the current
        // user
        // can be accessed.
        query.whereEqualTo(Preferences.PARSE_USERNAME_ROW, Util.getUsernameString());
        // The most recent message added will be on top.
        query.orderByDescending("createdAt");
        // Only need to get one message from the server, each message
        // will be from a push
        query.setLimit(1);
        try {
          List<ParseObject> messageList = query.find();
          // For the ParseObjects quering get all that needs
          // to be done.
          for (ParseObject messageObject : messageList) {
            // Get the parse object id
            String objectId = messageObject.objectId();
            // with the objectid you can query the
            // server
            ParseObject message = query.get(objectId);
            // Get the time the message was created at
            // for
            // logging, do not need a time to send a
            // message.
            Date time = message.createdAt();
            String timeString = time.toString();
            // Get who the message is coming from
            // (phonenumber).
            String address = message.getString(Preferences.PARSE_SMS_ADDRESS);
            // Get the body of the message
            String body = message.getString(Preferences.PARSE_SMS_BODY);
            // Display the total message queryed for
            // logging
            String totalMessage =
                "Sent: " + timeString + "\n" + "To: " + address + "\n" + "Message : " + body + "\n";
            Log.d(TAG, "New message is: " + totalMessage);
            // get the smsmanager as sms
            SmsManager sms = SmsManager.getDefault();
            // If the message is over the 160 Char limit
            // it
            // will be choped up.
            if (body.length() > 160) {
              // Chops up the message
              sms.divideMessage(body);
              // Send the sms message in its parts
              sms.sendMultipartTextMessage(address, null, sms.divideMessage(body), null, null);
            } else {
              // Sends the message without cutting it
              sms.sendTextMessage(address, null, body, null, null);
            }
          }
        } catch (ParseException e) {
          // TODO - Handle situation where querying server failed
          e.printStackTrace();
        }
      }
      return null;
    }
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {

    x = x + 1;

    if (x == 6) {

      x = 0;
    }

    String[] toastSort = new String[8];
    toastSort[0] = "Sorted by name Ascending";
    toastSort[1] = "by name descending";
    toastSort[2] = "by A.B.V ascending";
    toastSort[3] = "by A.B.V descending";
    toastSort[4] = "by where from ascending";
    toastSort[5] = "by where from descending";

    String tm = toastSort[x];

    Toast sort = Toast.makeText(getActivity(), tm, Toast.LENGTH_LONG);
    sort.setGravity(Gravity.CENTER, 0, 0);
    sort.show();

    List<ParseObject> ob;

    try {
      // Locate the class table named "stansbeers" in Parse.com
      ParseQuery<ParseObject> query = new ParseQuery<>("capitolbeers").fromLocalDatastore();
      // Locate the column named "name" in Parse.com and order list
      // by ascending

      query.orderByAscending("name").whereEqualTo("group", "IMPORT_BOTTLES_CANS");

      switch (x) {
        case 0:
          query.orderByAscending("name");
          break;
        case 1:
          query.orderByDescending("name");
          break;
        case 2:
          query.orderByAscending("abvinteger");
          break;
        case 3:
          query.orderByDescending("abvinteger");
          break;
        case 4:
          query.orderByAscending("wherefrom");
          break;
        case 5:
          query.orderByDescending("wherefrom");
          break;
      }

      ob = query.find();

      beerObject = new ArrayList<>();

      for (ParseObject beers : ob) {
        // Locate images in flag column

        //   ParseFile image = (ParseFile) stansbeers.get("image");

        BeerListObject beer = new BeerListObject();
        beer.setBeerName((String) beers.get("name"));
        beer.setBeerWhereFrom((String) beers.get("wherefrom"));
        beer.setBeerAbv(beers.getDouble("abvinteger"));
        beer.setBeerGroup((String) beers.get("group"));
        beer.setBeerAbout((String) beers.get("about"));
        beer.setBeerPrice((String) beers.get("price"));
        beer.setBeerSize((String) beers.get("size"));
        beerObject.add(beer);
      }
    } catch (ParseException e) {
      Log.e("Error", e.getMessage());
      e.printStackTrace();
    }

    adapter = new BeersListViewAdapter(getActivity(), beerObject);
    setListAdapter(adapter);

    adapter.notifyDataSetChanged();
  }