final String name = getIntent().getStringExtra("name");
ParseQuery<ParseObject> query = ParseQuery.getQuery("Info");
query.whereEqualTo("user", name);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null){
ArrayList<String> barbers = new ArrayList<String>();
for (ParseObject object : objects){
barbers.add(String.valueOf(object.get("times")));
}
ArrayAdapter arrayAdaptar = new ArrayAdapter<String>(Barbers.this, android.R.layout.simple_list_item_1, barbers);
list.setAdapter(arrayAdaptar);
}
}
});
I am making a app where people put times and then other people can see all their times when they click their name. I have made this query to get all the times from that certain person that they clicked on but when the app runs it only gets me the newest time and if the person that you clicked is not the newest will not retrieve anything. Thank you, here are some screenshots of my Parse Server and of the query.
Related
I am currently trying to make a friendlist with Firestore. My coding is owrking but not the right way.
So I am have a friendlist in my database which looks like this: Databse pic
So Document is saved under my ID which saves otherIDs from users, who accepted a friend request.
So right now it looks like this in the app: new database picture
It shows me that i have 3 friends, which is correct and when i click on one of the profiles it shows me my friend the rght way.
This is how it should look: here
My important code lokks like this right now:
mFirestore.collection("users").document(usid).collection("friends").addSnapshotListener(new EventListener<QuerySnapshot>() {
#Override
public void onEvent(#Nullable QuerySnapshot queryDocumentSnapshots, #Nullable FirebaseFirestoreException e) {
if (e != null) {
}
for(DocumentChange doc : queryDocumentSnapshots.getDocumentChanges()) {
if (doc.getType() == DocumentChange.Type.ADDED){
String user_id = doc.getDocument().getId();
//Toast.makeText(yourFriends.this, fAuth.getUid(), Toast.LENGTH_SHORT).show();
System.out.println(user_id);
System.out.println(fAuth.getUid());
if (fAuth.getUid().equals(user_id)){
Map map = doc.getDocument().getData();
System.out.println(map.size());
//Toast.makeText(yourFriends.this, map.size(), Toast.LENGTH_SHORT).show();
for(Object friendid : map.values()){
friendid.toString();
Users users = doc.getDocument().toObject(Users.class).withId((String)friendid);
//Toast.makeText(yourFriends.this, (String)friendid, Toast.LENGTH_SHORT).show();
usersList.add(users);
}
}
usersListAdapter.notifyDataSetChanged();
}
}
}
});
So I am getting my friendlist but it does not load the information in my userlist.
Your Database structure is wrong. You have to start one more collection under a user and within that you need to store the documnet and under that store the friends data. After this get that collection to the Listview or Recyclerview It will come.
I'm currently working on a basic application that makes a query to parse (back4app) backend, the aim is to retrive ParseGeoPoint from every row in the class "Annuncio" and display them in the google map.
The query works fine, I have an ArrayList that is populated after the query:
ParseQuery<ParseObject> query = ParseQuery.getQuery(Keys.CLASS_NAME);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
for(ParseObject object : objects){
createAnnuncio(object);
}
progressDialog.hide();
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
the createAnnuncio method is this:
private void createAnnuncio(ParseObject object) {
Azienda azienda = new Azienda();
azienda.setWebSite(object.getString(Keys.SITO_WEB));
azienda.setEmail(object.getString(Keys.EMAIL));
azienda.setPhoneNumber(object.getString(Keys.TELEFONO));
azienda.setLocation(object.getParseGeoPoint(Keys.LOCATION));
azienda.setNomeAzienda(object.getString(Keys.NOME_AZIENDA));
azienda.setDescAzienda(object.getString(Keys.DESC_AZIENDA));
Annuncio annuncio = new Annuncio();
annuncio.setAzienda(azienda);
annuncio.setCompleteText(object.getString(Keys.TESTO_ANNUNCIO));
annuncio.setJobKind(object.getString(Keys.TIPO_LAVORO));
annuncio.setSettore(object.getString(Keys.SETTORE));
annuncio.setTitolo(object.getString(Keys.TITOLO_ANNUNCIO));
annuncio.setFineAnnuncio(object.getDate(Keys.FINE_ANNUNCIO));
mAnnunci.add(annuncio);
}
Basically mAnnunci is a global variable:
public List<Annuncio> mAnnunci = new ArrayList<>();
Even the debug works fine, i have just 2 rows and the mAnnunci.size() is 2 after the for cycle in the query, but then the debugger takes me to some native code of parse sdk and i don't know why but after the query mAnnunci is empty.
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
showSpinner();
getAllPostsFromParse(); // retrive all posts from parse backend
//inside getAllPostsFromParse the size is 2
setUpMarkers(); // here the size is 0 (the debug print is the first instruction, so I don't modify it)
}
And most of all sorry for my bad english!
What I've essentially built is an EditTextView that collects a String, which when input by the user attempts to communicate with the back-end in order to pull the user's "objectId", this being a column in my User database.
The showProfileActivity() function shown below simply works, and I've excluded it because it isn't relevant to the problem. It takes the user's "objectId" and shows the user's profile.
What I want is for "String userId", which is the User's "objectId" in the database to be generated dynamically. I know that the showProfileActivity() function works because I can literally just input a String with the hard-coded objectId and it brings me to that user's profile.
My question is, based on the String input by the user into the search field, how can I retrieve the value in the relevant "objectId" column?
findViewById(R.id.submitSearch).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText searchUserTextField = (EditText) findViewById(R.id.searchUserTextField);
// Value input to search field
final String searchInput = searchUserTextField.getText().toString();
// System.out.println(searchInput);
// Initiate ParseQuery
final ParseQuery<ParseUser> query = ParseQuery.getQuery("username");
// Look for the username that was typed into the search field
query.whereEqualTo("username", searchInput);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
// This works but clearly always loads the exact same user profile. I need this string to be loaded dynamically as a function of the user's search query.
String userId = "dj16qsXPle";
// System.out.println(userId);
showProfileActivity(userId);
} else {
// Something went wrong.
}
}
});
// Execute RemoteDataTask AsyncTask
new RemoteDataTask().execute();
}
});
}
I am not sure what showProfileActivity does, but since you are passing it a userId I am assuming it does another query? Why not do the following:
Assuming usernames are unique (in this case it seems you are also assuming that) Then the findInBackground method should return just a single user.
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
if(objects.size() > 0){
ParseUser user = objects.get(0);
showProfileActivity(user);
}
} else {
// Something went wrong.
}
}
});
And in showProfileActivity, use the user data do whatever showProfileActivity does.
Or, if you are using the objectId for something else, you can do this:
ParseUser user = objects.get(0);
showProfileActivity(user.getObjectId());
and this gives you the id you are looking for instead of the hardcoded one. Again, doing in showProfileActivity whatever it is you do with the objectId. This could mean retrieving from a separate table using objectId, etc..
Ultimately figured it out. I granted you the answer because you definitely provided the core of the correct solution. My error was in initiating my ParseQuery as such: final ParseQuery query = ParseQuery.getQuery("username");. It should have just been ParseQuery query = ParseUser.getQuery();
// Initiate ParseQuery
ParseQuery query = ParseUser.getQuery();
query.whereEqualTo("username", searchInput);
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
System.out.println(objects);
ParseUser user = objects.get(0);
String userId = user.getObjectId();
showProfileActivity(userId);
} else {
// Something went wrong. Look at the ParseException to see what's up.
}
}
});
As a preface, I'll apologize : I'm french, so there are French words in my queries and my tables.
Anyways, I've been having problem with the queries frome Parse4J (which is using the base model of the Android API from Parse.com).
In my data on Parse.com, I have Themes and SubThemes in the same table, but Themes have as RootTheme "Root", while SubThemes have as RootTheme another Theme.
I've been trying to add the results of a query into a ComboBox, but the Query has been returning me 5 times the same result, instead of the 5 RootThemes.
Here's my code :
private ParseQuery<ParseObject> themeQuery;
private ObservableList<String> themeComboData;
#Override
public void initialize(URL location, ResourceBundle resources) {
themeComboData = FXCollections.observableArrayList();
themeQuery = ParseQuery.getQuery("Theme").whereEqualTo("RootThemeID", "DBWw03ygSv");
themeQuery.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> themeList, ParseException e) {
if (e == null) {
for(int i = 0; i < themeList.size(); i++){
ParseObject themeTemp;
themeTemp = new ParseObject("Theme");
themeTemp = themeList.get(i);
themeComboData.add(themeTemp.getString("Name"));
}
} else {
Logger.getLogger(AmIApp.class.getName()).log(Level.SEVERE, null, e);
}
}
});
themeCombo.setItems(themeComboData);
}
But all it does is filling my Combo Box themeCombo with 5 times "Affinités", instead of the 5 different RootThemes.
Any advice ? Thanks in advance :)
Edit : Here's a crop of the Table I'm using :
http://imgur.com/USpinhE
Edit :
here is the query done with the ios
PFQuery * themeQuery = [PFQuery queryWithClassName:#"Theme"];
[themeQuery whereKey:#"RootThemeID" equalTo:#"DBWw03ygSv"];
[themeQuery findObjectsInBackgroundWithBlock:^(NSArray* themes, NSError* error) {
if (!error) {
for (PFObject *th in themes ) {
NSLog(#"theme is : %#", th[#"Name"]);
}
}else {
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
It returns 5 different themes as expected, I’d like to do the same with Parse4J in java.
Really struggling with this query, all I want to do is run a query through my Routines table selecting Routines that belong to a certain user. Running a normal query would require something query.whereEqualTo("routineIcon", "1") would bring up the the first and third row. However, the tricky bit is querying the user (Point<_user>) field, this is a reference to a user (objectId) from the User class. Initially I tried query.whereEqualTo("user", "RE1bvmzyPk"), but this came out blank so I looked into querying Pointers, I've trie d a few things but can't get it to work. Anyone got any tips?
private void retrieveRoutines() {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Routine");
query.whereEqualTo("user", "RE1bvmzyPk");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> routines, ParseException e) {
if (e==null){
mRoutines = routines;
String[] routineNames = new String[mRoutines.size()];
int i = 0;
for (ParseObject routine : mRoutines) {
routineNames[i] = routine.getString("routineName");
Log.d("OK", routineNames[i]);
i++;
}
}
else {
//error
}
}
});
}
The Routine Class is in the format:
objectId (string) | routineIcon (string) | routinesName (string) | user (Pointer<_User>
You can create the user pointer by using the objectid of the user
ParseUser user=new ParseUser();
user.setObjectId("RE1bvmzyPk");
ParseQuery<ParseObject> query = ParseQuery.getQuery("Routine");
query.whereEqualTo("user", user);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> routines, ParseException e) {
if (e==null){
}
else {
//error
}
}
});
if you want routines that point back to ( were created by a User )
Add the pointer field to Routines:
"createdBy" type=pointer
And then query for it using the User Obj.
ParseQuery<ParseObject> query = ParseQuery.getQuery("Routine");
query.whereEqualTo("createdBy", $userObj);