alexstyl / contactstore

A modern, strongly-typed contacts API for Android.
https://alexstyl.github.io/contactstore
Apache License 2.0
440 stars 15 forks source link

Problem with ContactGroups when moving a contact between two accounts #74

Closed fgubler closed 1 year ago

fgubler commented 1 year ago

Hi

I have encountered an interesting problem this weekend:

Does that description make any sense?

If yes, I have two questions / wishes

  1. Would it be possible to add the option to filter contactStore.fetchContactGroups() by Account?
  2. When using contactStore.execute { insertGroup(myGroup) } where is it actually saved? Into the phone's local contacts? Into all the accounts? Into the "default" account? => would be great if it were able to specify exactly into which account to store it
alexstyl commented 1 year ago

thanks for the feature request @fgubler and the detailed issue.

Would it be possible to add the option to filter contactStore.fetchContactGroups() by Account?

I will have a look into this and let you know. If it is something supported by Android i would be more than happy to support it.

When using contactStore.execute { insertGroup(myGroup) } where is it actually saved?

I think it is the phone's (offline), if it follows what saving a contact does without specifying an account

would be great if it were able to specify exactly into which account to store it

seems reasonable. i will need to have a look how it is done from android's side first and will let you know.

fgubler commented 1 year ago

Thanks a lot 😍

alexstyl commented 1 year ago

Just pushed this to 1.6.0.

The way to insert a new group into a specific account is:

contactStore.execute {
      insertGroup(intoAccount = InternetAccount(...)) {
          title = "My Group"
      }
  }

to update a group you can:

val updatedCopy = group.mutableCopy {
    note = "Updated Note"
    title = "Updated Title"
    account = InternetAccount("test@test.com", "test.com")
}
contactStore.execute {
    updateGroup(updatedCopy)
}

I will close this issue once the new version is available on maven

alexstyl commented 1 year ago

This is now live in 1.7.0.

Now the contact groups you fetch are going to include an account property that contains information about which account the contact group is saved into. a null account means the group is stored locally (offline).

Closing this as it is now live

fgubler commented 1 year ago

Great, thank youbl so much :-) I will try it as soon as I get back from vacation.

fgubler commented 1 year ago

Seems to work splendidly, thanks :-)