How to populate recyclerview with data from parse server? - android

Is it possible to retrieve all the data present in a specific class in the parse server in the form of a news feed similar to facebook using recyclerView?

in order to do it you need to do the following:
I recommend you to use Parse SDK for android. You can read the docs in here . This SDK will make your life easy with performing all CRUD operations in front of your parse server instance. So the thing that you need to do is to execute query on your class like the following (taken from parse server docs):
ParseQuery<ParseObject> query = ParseQuery.getQuery("<YOUR_CLASS_NAME>");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
Log.d("score", "Retrieved " + scoreList.size() + " scores");
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
From the code above you can see that we first create a query object on class and then use findInBackground in order to retrieve all objects.
Inside that findInBackground callback what you need to do is to iterate on all results and map them to your recyclerView adapter and finally refresh it and see the results
From the answer above you can see that's its pretty simple task if you use Parse Android SDK. As much as I know there is no out of the box solution that will create recyclerView from parse query results.

Related

ParseQuery finding object null

I am using the following code to search through my Data Browser. The columns are Location and Weather and the class is called Nowcast.
If my Data Browser has New York in it and the weather "sunny", the TextView showWeather displays "The weather in New York is sunny".
However, if I search Los Angeles and it is not in the Data Browser, it shows "The weather in Los Angeles is null" whereas it should not enter the if condition at all according to the code. What am I doing wrong?
public void getData(){
searchText = searchTextView.getText().toString();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Nowcast");
query.whereEqualTo("Location", searchText);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> object, ParseException e) {
if (e == null) {
for (ParseObject weatherObject : object) {
weatherData = weatherObject.getString("Weather");
}
showWeather.setText("The weather in " + searchTextToString + " is " + weatherData);
} else {
Toast.makeText(NowcastSearch.this, "No such location found",Toast.LENGTH_LONG).show();
}
}
});
}
whereas it should not enter the if condition at all according to the code
It shouldn't enter only if the ParseException isn't null. In other words it shouldn't enter the if condition (the first branch of it) only if there's been a problem with your query (e.g. you passed the wrong type of argument for a field condition).
There's no problem with your query. So no exception has been thrown. The query in which not a single record matches your conditions can still be a valid query. The object list is just empty but there hasn't been any errors with the whole process.
ParseException e
this exception is represeting if there is a problem while parsing whole data to objects. So you can check if parsing operation is successful or not by null checking it.
There was no exception parsing your data. That means you dont have corrupted datas or something another.
You are just getting null object because there is no data about it. You should null check your "weatherData".

Parse: how to get pinned object without id

Ive got application on android which should work without internet and with parse database when internet is on.
Also I faced with problem of getting of pinned ParseObject which not saved in online database before.
So what I do:
ParseObject car = new ParseObject("cat");
cat.put("name","Pussy");
cat.pinInBackground();
So, now I want to get this cat by query with query.getInBackground but, I cant do it because I haven't objectId, which automatically generated only after saving in online database.
You can search for cats (objects) with given properties in the local datastore:
ParseQuery<ParseObject> query = ParseQuery.getQuery("cat");
query.fromLocalDatastore();
query.whereEqualTo("name", "Pussy");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> catList, ParseException e) {
if (e == null) {
Log.d("cat", "Retrieved " + catList.size() + " cats");
} else {
Log.d("cat", "Error: " + e.getMessage());
}
}
});
However, if name is the only property, you'll likely get a list of objects with more than one entry. Here, you may add other properties (e.g. an owner) to limit the number of possible matches.

Android parse.com setObjectId

How set objectId with Parse.com with primary key.Can you help me ?
When i create new row, i want setObjectId of row.
final ParseObject parseObject = new ParseObject(ChapsModel.PARSE_OBJECT);
parseObject.put(ChapsModel.PARSE_FIELD_NAME_CHAPS,
chapsModel.get(i)
.getNamChap());
parseObject.put(ChapsModel.PARSE_FIELD_LINK_CHAP,
chapsModel.get(i)
.getLinkChap());
parseObject.put(ChapsModel.PARSE_FILED_TEAM_TRANSLATE,
chapsModel.get(i)
.getTeamTranslate());
parseObject.put(ChapsModel.PARSE_FIELD_OBJECT_MANGA,
ParseObject.createWithoutData(MangaModel.PARSE_OBJECT,
chapsModel.get(i)
.getObjectManga()));
parseObject.saveInBackground(new SaveCallback() {
#Override
public void done(final ParseException e) {
if (e == null) {
Log.e(">>>>>",
"done" + ojectId);
// parseObject.setObjectId(ojectId);
} else {
Log.e(">>>>>",
"else" + e.getMessage());
}
}
});
Log
java.lang.RuntimeException: objectIds cannot be changed in offline mode.
Log:
Sorry my english. thank
It's not possible to set objectId with Parse.com with primary key.
Although parse.com doesn't allow us to set the objectId of a row, you can create a new column named anything you want and you can set that new column to any objectId you want. For example, you can create a new column named myObjectId and set it to a string.
From the parse.com website at https://www.parse.com/docs/js/guide#cloud_code
The Data Browser
The Data Browser is the web UI where you can update and create objects in each of your apps. Here, you can see the raw JSON values that are saved that represents each object in your class.
When using the interface, keep in mind the following:
The objectId, createdAt, updatedAt fields cannot be edited (these are set automatically).

Parse local datastore query takes time on Android

I have pinned object for first time. Next time i try to fetch same object it takes time sometimes like 5 to 6 second in this the screen turns blank.
Here is my code for pinning. (Both pinning and querying data from local store is done on same table in parse)
ParseQuery<ParseObject> query = ParseQuery.getQuery(PARSE_IMAGE_TABLE);
List<ParseObject> images = query.find();
for each image i get i do following:
parseObject.pinInBackground(PARSE_PIN_WALLPAPER_INFO,
new SaveCallback() {
#Override
public void done(ParseException arg0) {
System.out.println();
}
});
When querying:
ParseQuery<ParseObject> query = ParseQuery.getQuery(PARSE_IMAGE_TABLE);
query.whereEqualTo(PARSE_IMAGE_THUMB_URL, imageURL);
query.fromLocalDatastore();
query.fromPin();
List<ParseObject> images = query.find(); -- this call takes time
Yes their is a lot of performance tweaks you can do in your code.
Pinning a list of objects is faster and better approach.
Instead of using find query use findInBackground.
Also start using pin(String name) and fromPin(String name) instead of fromPin() and fromPin(String name). This has a huge advantage if you have a lot of rows in your parse local storage.

how to Parse Query search case insensitive in android?

I am using the parse cloud to store data .
in this case I have a table "MyUser" in this table I want to search user by name in case insensitive.
Search is working fine but the search operation is not case insensitive
I have to search case insensitive
here is my code.:-
ParseQuery<ParseObject> query = ParseQuery.getQuery("BetsUpUser");
query.whereContains("name", searchData);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objList,ParseException e) {
if (e == null) {
Log.d("score","####Retrieved " + objList.size()+ " scores");
} else {
Log.d("score", "###Error: " + e.getMessage());
}
}
});
Thanks in advance.
I Solve the problem of case insensitive string Parse Query
replace the line
query.whereContains("name", searchData);
with
query.whereMatches("name", "("+searchData+")", "i");
I also came across with this question and realized there are no much ways to do this simple thing. Another interesting approach from #ardrian by using JavaScript. For Java it will almost the same. He suggests to create one more field with lowercase version of the searchable one. It look like below:
ParseObject gameScore = new ParseObject("BetsUpUser");
gameScore.put("name", name);
gameScore.put("name_lowercase", name.toLowerCase());
gameScore.saveInBackground();
And while searching we transform input text to lower case. This way we still can use whereContains() method and it will not affect us much.
ParseQuery<ParseObject> query = ParseQuery.getQuery("BetsUpUser");
query.whereContains("name_lowercase", searchData.toLowerCase()); // the only one change
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objList,ParseException e) {
if (e == null) {
Log.d("ParseQuery", objList.get(0).get("name"));//name in actual case
} else {
Log.d("ParseQuery", e.getMessage());
}
}
});
See this post on the Parse Blog about implementing scalable search.
http://blog.parse.com/2013/03/19/implementing-scalable-search-on-a-nosql-backend/
Basically you can use an afterSave event to save a searchable field (i.e. lower-cased name) on the object.

Categories

Resources