Contacts group GROUP_VISIBLE and GROUP_IS_READ_ONLY ignored? - java

Can someone explain me why this parameters GROUP_IS_READ_ONLY (set to 0) and GROUP_VISIBLE (set to false) are ignored when my group is created?
I can still see group and contacts in it and also I can delete/modify my group and contacts in it.
EDIT
This is how I create a group:
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
ops.add(ContentProviderOperation.newInsert(Groups.CONTENT_URI)
.withValue(Groups.TITLE, groupName)
.withValue(Groups.ACCOUNT_NAME, accountName)
.withValue(Groups.ACCOUNT_TYPE, AccountGeneral.ACCOUNT_TYPE)
.withValue(Groups.GROUP_VISIBLE, false)
.withValue(Groups.GROUP_IS_READ_ONLY, 1)
.build());
mContentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
And this is what official developer android page said:
GROUP_VISIBLE - Flag indicating if the contacts belonging to this group should be visible in any user interface.
GROUP_IS_READ_ONLY - The "read-only" flag: "0" by default, "1" if the row cannot be modified or deleted except by a sync adapter. See ContactsContract.CALLER_IS_SYNCADAPTER.
Thanks!

So, to continue from the comments section, the answer is that your input values are ok, and persisted as requested.
However, the Contacts app (or any other app that reads contacts) can just ignore the values at GROUP_VISIBLE and display all contacts on the phone.
Usually apps provide some filter capabilities to the user, so the user can choose if she wants to see only contacts in visible groups, all contacts on the phone, or a specific group.
If you query for contacts using the IN_VISIBLE_GROUP selection, then you should not get the contacts created under your group in the cursor response.

Related

Save button deletes previous data in firebase

I am new to android studio and firebase. I am trying to save a list of people to firebase like this. Idea is that the logged in user should be able to save information about some people.
String userId = user.getCurrentUser().getUid();
databaseReference.child("users").child(userId).child("savedPersons").child("name").setValue(nameTxt);
databaseReference.child("users").child(userId).child("savedPersons").child("surname").setValue(surnameTxt);
databaseReference.child("users").child(userId).child("savedPersons").child("gender").setValue(genderTxt);
databaseReference.child("users").child(userId).child("savedPersons").child("ageTxt").setValue(ageTxt);
It does not surprise me that it deletes the previous saved person when i save another one but i don't know how to save all of them. I have this in my firebase but i need multiple saved users. How do i do it ?
Firebase screenshot
If you want to save multiple people in a list in the database, you'll want to call push:
String userId = user.getCurrentUser().getUid();
DatabaseReference newRef = databaseReference.child("users").child(userId).child("savedPersons").push(); // 👈
newRef.child("name").setValue(nameTxt);
newRef.child("surname").setValue(surnameTxt);
newRef.child("gender").setValue(genderTxt);
newRef.child("ageTxt").setValue(ageTxt);
This will create a new child node under savedPersons each time you call push(). To learn more on this, see the Firebase documentation on appending data to a list.
Note that calling setValue for each property is wasteful, and may lead to unexpected behavior down the line. I recommend putting all values in a map, and then adding them all with one call to setValue:
Map<String, Object> values = new Map<>();
values.put("name", nameTxt);
values.put("surname", surnameTxt);
values.put("gender", genderTxt);
values.put("ageTxt", ageTxt);
newRef.setValue(values);

How to retrieve values from a node in firebase and display in a recycler view?

- Orders
|-1234567898(phoneno)
|-march13,202117:33:52PM(orderid)
|-name
|-address
|-phoneno
|-orderid
|-1231231231(phoneno)
|-march10,202117:33:52PM(orderid)
|-name
|-address
|-phoneno
|-orderid
|-1212121212(phoneno)
|-march9,20211:33:52PM(orderid)
|-name
|-address
|-phoneno
|-orderid
I need to display all orders in a recycler view with values name, phoneno.
How can i get the phoneno s?
Several issues in one question . It is quite impossible to have a complete answer in one go .I would advise you to create custom class like Order for example with all data mandatory .Then if you just need to display all orders , i don t think the database structure is the best . You could have Orders:order (with id inside the order class) , or orderBy customerID if you need to handle researches

How can I change this filter from a specific AD Group to All AD Groups in the Organization?

This filterString gets all AD users from a specific AD group, I need to change this to get ALL users from ALL groups in my organization. I have read through dozens of similar questions and changed this string around several times and cannot find the solution.
String filterString = "(&(objectCategory=user)(memberOf=cn=" + this.ldapUserSearch + ",ou=Groups,OU=Organization,dc=organizationsoftware,dc=com))";
You can try the following filter, which includes an attribute presence clause:
(&(objectCategory=user)(memberOf=*))
This will return every user whose memberOf attribute is set to any value. This should have the effect of retrieving all users from all groups.

Organizing firebase data

I am using Firebase Auth and Firebase Database to store student's profiles and students reports.
When the user signs up they input email, password, school name, school year, school discipline. I use the email and password for the Auth but the rest of the info is stored in the Database with a unique ID as shown below:
For the reports, each students can input many entries, each with its unique ID as shown below:
Here are my questions:
Once a student logs in, how can I find their profile info since the parent is a unique ID. In other words is there a way to search through the database for that students email (for example, mido4#hotmail.com, in the image) and from that get the students name (in this case, Emina Osman)?
Once you get the student's name, how can you search for all the entries that student has saved in the database? For each entry the student has, the student name is saved.
Not sure if the way I setup the database is ideal so is there a better way?
Thanks for your time! Any help would be really appreciated!
Yes, it is. The simplest way to achieve this, is to change your database structure a little bit. So instead of using as a unique identifier, the pushed key, generated by the push() method, i suggets you using the email address. It's also unique and easy to use. The benefit is, that is allows you to search your database for that particular email. Your database structure should look like this:
flashscreen-1d252
|
--- Users
|
--- mido4#hotmail,com
| |
| --- //User Details
|
--- mido5#hotmail,com
|
--- //User Details
Note, that Firebase does not allow symbols as . (dot) to be used in a key. So as you probably see, i have changed the . dot with a , (comma). I have achieved this using the below method:
String encodeUserEmail(String userEmail) {
return userEmail.replace(".", ",");
}
To search for an user and get the name, simply add a listener on Users node like this:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference userRef = rootRef.child("Users").child("mido4#hotmail,com");
ValueEventListener eventListener = new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()) {
String firstName = dataSnapshot.child("firstname").getValue(String.class);
String lastName = dataSnapshot.child("lastname").getValue(String.class);
Log.d("TAG", firstName + " " + lastName);
}
}
#Override
public void onCancelled(DatabaseError databaseError) {}
};
usersRef.addListenerForSingleValueEvent(eventListener);
The output will be: Emina Osman
You'll have to search after the email address and not after the name.
Already answered above. This database structure is more efficient.
Edit: There 2 additional questions regarding this answer based on using the email address vs. uid.
What if a user decides to delete his account and after a while decides to return and tries to sign-in again? If we are using the email address, nothing happens. If we are using the uid, when the user signs in for the second time, another uid is generated, which is obvious that is different from the first one and this the moment in which you are in trouble, because even he is the same user, he is treated as a new one.
What if the users email address changes? IMHO, an email can be changed only if you decide to change it. Personally, I haven't changed my email address in years but I have deleted hundreds of accounts from hundreds of applications. Even if you change your email address, there's no much of a problem. You login in your application, change the email address and that's it. You'll have also all your history within that application. Having a unique identifier a uid, in case you delete the account and you come back again, you start from zero.
Once a student logs in, how can I find their profile info since the
parent is a unique ID.
Super easy! When a users account is created initially, Firebase assigns the user a 'random' and unchanging user uid (uid). That uid is what identified that specific user to Firebase. That's what you should store there info under within the users node like this:
users
uid_0
name: "users name"
Then when they authenticate in the future, firebase provides that uid to you in the authentication process. You can then simply get their user information from the users node via that uid. i.e. read the node /users/uid_0
Once you get the student's name, how can you search for all the
entries that student has saved in the database?
Again, super simple. For every entry you make in Firebase, reference that uid. For example, say you want to keep track of each users reports
reports
uid_0
-9i9sdjj3i0a09djads //create with push() or childByAutoId() in swift
reportName: "some report"
-ua9sd9i9i3i0idsfi
reportName: "another report"
Then to get all of their reports, read the node /reports/uid_0
conversely, you can store the reports and then a link to the user
reports
-9i9sdjj3i0a09djads
reportName: "some report"
report_by: "uid_0"
and with that structure a query can be done where report_by is equal to "uid_0" to return all of uid_0's reports.
Not sure if the way I setup the database is ideal so is there a better
way?
there's a number of different ways to achieve what you want but the above is a very common design pattern.

JDO - List of Strings not being retrieved from database

On my User class I have a field that is a list of strings:
#Persistent
private List<String> openIds;
When I create a new user I do this:
User user = new User();
user.openIds.add(openid);
pm.makePersistent(user);
When I break after that last line and look, the openIds contains the openid I put in there.
But, when I later call User user = pm.getObjectById(User.class, id); with the correct id, the openIds field is an empty list.
Anyone know what could cause that?
EDIT: BTW I'm running on the Google App Engine
UPDATE: Looking at the datastore viewer, I can see the openid was correctly stored in the database. So its just not getting it out correctly...
UPDATE 2: Its working fine now. I'm pretty sure I didn't change anything. I think what must have happened is that there was an old version of the user object being pulled from the database. A user object that was put in before I had the code that saves the openid. Once I wiped the database things worked fine.
Not putting that field in the fetch plan ?
Accessing persistent fields directly, rather than going via setters ?

Categories

Resources