mardi 5 mai 2015

How to edit one complex object in multiple screens in Android?

I'm trying to figure out best/correct way to edit one complex object on multiple screens in Android. I have Event which has a collection of Invites. Event is edited on one screen and Invites list is composed on another. User first edits event data then goes to address book like screen to add/remove invites then goes back to event screen and send all changes to server.

I'm using Xamarin and want to have same business logic code on both iOS and Android. On iOS I have Event object with InvitesList inside it. I pass InvitesList to InvitesController and it edits this list and this is basically it. Everything works as intended. Sample code:

public class Event {
  InvitesList Invites { get; private set; }
  public async Task Save() {
    await service.SaveEvent(this);
    await service.SyncContacts(Invites.New, Invites.Removed);
  }
}

My problem is that above scenario does not work with Android if I want to edit InvitesList in a separate activity. InvitesList knows how to load it data from server and it also tracks additions and deletions so Event object could figure out what server API calls it need to do later on. AFAIK my options are

  1. Create InviteListMemento and pass it back and forth between activities. I don't like it because I'll will have to serialize potentially large list of added Contacts or Contact object might be large (for example have images inside or maybe dozen of strings).
  2. Save InvitesList in static variable. This is ugly and I'd like to avoid this solution.

I don't like any of above solutions. Can anyone suggest a solution which would allow me to keep my business objects intact? I'd like to have Event object with InvitesList inside and also to be able to edit InvitesList in separate activity. Ideally I also would like to keep changes required only for Android to a minimum.

Aucun commentaire:

Enregistrer un commentaire