How to filter some places in onPlaceChangeRequest in ActivityManager?

70 views
Skip to first unread message

Anton Mityagin

unread,
Mar 26, 2015, 6:35:42 AM3/26/15
to google-we...@googlegroups.com

Hi

There is need to filter some places in onPlaceChangeRequest in ActivityManager to prevent call mayStop of currentActivity.

for example, I have ListEditActivity where I can edit list items. This activity managed by ActivityManager this CachingActivityMapper and FilteredActivityMapper.
Also I have ListSelectionItemPlace which indicates currently selected item in the list

After a list item has been edited and selected another item in the list, there is an attempt to change the place to ListSelectionItemPlace
and fired event PlaceChangeRequestEvent. Handler onPlaceChangeRequest in ActivityManager calls mayStop method of ListEditActivity it is returns some message
because item has been edited.

I need to ignore such places change, but I cannot to do it.

method mayStop has no any parameters.

Handle PlaceChangeRequestEvent in ListEditActivity gets no result because event handler is still called in ActivityManager before.

I can subclass ActivityManager for ListEditActivity and override onPlaceChangeRequest method, but I have no access to currentActivity to ask it ignor or not this call.


Have any ideas?

Jens

unread,
Mar 26, 2015, 6:57:05 AM3/26/15
to google-we...@googlegroups.com
ListEditActivity.mayStop() should not return a message if it is valid to change list items. 

mayStop() is normally used for dirty checking, e.g. someone edits an item and has not yet saved the edits. In that case mayStop() should return a warning message which allows the user to decide to actually do the place change and discard edits or stay at the current place and save his edits. If the item is saved and everything is good to go then mayStop() should return null.

Anyways you can always implement your own ActivityManager, but before doing so I would think hard if your mayStop() implementation is really what you want. To me it sounds like you have a bad mayStop() method and because of this you need further workarounds in a custom ActivityManager.

-- J.

Anton Mityagin

unread,
Mar 26, 2015, 8:14:39 AM3/26/15
to google-we...@googlegroups.com

I can not agree with you.

ListEditActivity works with ListEditViev which has ListEditor editing a set of items.

it ListEditActivity responsibility for what to save all edited items in the editor.

mayStop returns a message only when trying to change, for example, to another ListEditPlace.

I want to note that ListEditActivity managed by ActivityManager with CachingActivityMapper and FilteredActivityMapper and it wouldn't stopped when placeController go to place ListSelectionItemPlace.
In this way we no need to ask ListEditActivity about mayStop - only when going to ListSelectionItemPlace

If I have a legal way to bypass stopping activity (CachingActivityMapper and FilteredActivityMapper) then a need to have a way to not ask this activity to may stop any way it wouldn't be stopped.

did you agree with me.

Yes, now I see only one way is to implement ActivityManager - no good solution.

Eric Ponthiaux

unread,
Mar 26, 2015, 1:27:25 PM3/26/15
to google-we...@googlegroups.com

Anton Mityagin

unread,
Mar 26, 2015, 1:57:40 PM3/26/15
to google-we...@googlegroups.com

Why it's look like a design problem?

Can I create ActivityManager with CachingActivityMapper and FilteredActivityMapper?

Somthing like this:

public CachingHorizontalMasterActivityMapper(HorizontalMasterActivityMapper horizontalMasterActivityMapper) {

    FilteredActivityMapper.Filter filter = new FilteredActivityMapper.Filter() {
      @Override
      public Place filter(Place place) {
        return place instanceof MailDetailPlace ? new MailListPlace() : place;
      }
    };

    CachingActivityMapper cachingActivityMapper = new CachingActivityMapper(horizontalMasterActivityMapper);
    filteredActivityMapper = new FilteredActivityMapper(filter, cachingActivityMapper);
  }

  @Override
  public Activity getActivity(Place place) {
    return filteredActivityMapper.getActivity(place);
  }

This ActivityManager does not stop currently started activity MailListActivity if new place is MailDetailPlace, right?

If, so, why ActivityManager ask current MailListActivity mayStop, if it will not stop it?

Is there in my words any logic?

Or you mean that my ListEditActivity has design problem? 

ListEditActivity is responsible for saving all changed list items in one server call, each item has been changed by ItemDetailActivity (but not actually sended to server for save).
for this functionality there is ListEditView which implements IsEditor<ListEditor<T, E>>

and ListEditActivity.mayStop is performed then user go from one item to edit another item in list - trying to change ItemDetailPlace - this place stops current ItemDetailActivity and starts new ItemDetailActivity
this call of ListEditActivity.mayStop not need because ListEditActivity will not stopped. Only ItemDetailActivity will be stopped in ItemDetailActivity.mayStop needt to call.

And call ListEditActivity.mayStop need only when place ListEditPlace is changed, then ListEditActivity will be stopped

very kind of you to send me those links ))))

Jens

unread,
Mar 26, 2015, 3:37:33 PM3/26/15
to google-we...@googlegroups.com


Am Donnerstag, 26. März 2015 18:57:40 UTC+1 schrieb Anton Mityagin:

Why it's look like a design problem?

Can I create ActivityManager with CachingActivityMapper and FilteredActivityMapper?

Somthing like this:

public CachingHorizontalMasterActivityMapper(HorizontalMasterActivityMapper horizontalMasterActivityMapper) {

    FilteredActivityMapper.Filter filter = new FilteredActivityMapper.Filter() {
      @Override
      public Place filter(Place place) {
        return place instanceof MailDetailPlace ? new MailListPlace() : place;
      }
    };

    CachingActivityMapper cachingActivityMapper = new CachingActivityMapper(horizontalMasterActivityMapper);
    filteredActivityMapper = new FilteredActivityMapper(filter, cachingActivityMapper);
  }

  @Override
  public Activity getActivity(Place place) {
    return filteredActivityMapper.getActivity(place);
  }

This ActivityManager does not stop currently started activity MailListActivity if new place is MailDetailPlace, right?

If, so, why ActivityManager ask current MailListActivity mayStop, if it will not stop it?

Good question, probably a design decision or its simply a bug/oversight. I think it would be fine to add the "currentActivity.equals(nextActivity) return" check for PlaceChangeRequestEvents as well to avoid the mayStop() call. 

However others might already depend on that behavior of calling mayStop() on cached activities so its generally a breaking change although I think it won't affect a lot of people, if any at all.

Feel free to open a bug for it.


 
Is there in my words any logic?

Yes of course once I figured out that your ListEditActivity should save a list of items with one server request. 


As a workaround, if you don't want to implement your own ActivityManager, you could probably do the following in your ListEditActivity:

public String mayStop() {
  return null; // always return null.
}

public void start(AcceptsOneWidget panel, EventBus eventBus) {
  eventBus.addHandler(PlaceChangeRequestEvent.TYPE, this);
}

// implement PlaceChangeRequestEvent.Handler in your Activity
public void onPlaceChangeRequest(PlaceChangeRequestEvent e) {
  Place newPlace = e.getNewPlace();
  if (/* check that newPlace would really cause this Activity to be stopped and not reused from cache */) {
   if (unsavedChanges) {
     e.setWarning("your warning message");
   }
  }
}

I think that should work as the mayStop() method should be called before your onPlaceChangeRequest() method is called. That means mayStop() won't reset the message back to null.

But a patched ActivityManager would be a cleaner solution, especially if you have that case more than once.

-- J.

Anton Mityagin

unread,
Mar 26, 2015, 4:28:58 PM3/26/15
to google-we...@googlegroups.com


On Thursday, March 26, 2015 at 10:37:33 PM UTC+3, Jens wrote:


Am Donnerstag, 26. März 2015 18:57:40 UTC+1 schrieb Anton Mityagin:



If, so, why ActivityManager ask current MailListActivity mayStop, if it will not stop it?

Good question, probably a design decision or its simply a bug/oversight. I think it would be fine to add the "currentActivity.equals(nextActivity) return" check for PlaceChangeRequestEvents as well to avoid the mayStop() call. 

But in PlaceChangeRequestEvent handled before PlaceChangeEvent and there is no nextActivity in handler PlaceChangeRequestEvent.

I think that problem in ActivityMapper. It has a logic to get next activity, but it is used only on handler of PlaceChangeEvent.

It needs to resuse it some way in handler of PlaceChangeRequestEvent to prevent unnecessary call of mayStop and duplicate logic of ActivityMapper in some workaround


Feel free to open a bug for it.

 

 
Is there in my words any logic?

Yes of course once I figured out that your ListEditActivity should save a list of items with one server request. 


As a workaround, if you don't want to implement your own ActivityManager, you could probably do the following in your ListEditActivity:

public String mayStop() {
  return null; // always return null.
}

public void start(AcceptsOneWidget panel, EventBus eventBus) {
  eventBus.addHandler(PlaceChangeRequestEvent.TYPE, this);
}

// implement PlaceChangeRequestEvent.Handler in your Activity
public void onPlaceChangeRequest(PlaceChangeRequestEvent e) {
  Place newPlace = e.getNewPlace();
  if (/* check that newPlace would really cause this Activity to be stopped and not reused from cache */) {
   if (unsavedChanges) {
     e.setWarning("your warning message");
   }
  }
}

I think that should work as the mayStop() method should be called before your onPlaceChangeRequest() method is called. That means mayStop() won't reset the message back to null.

But a patched ActivityManager would be a cleaner solution, especially if you have that case more than once.


Your idea is perfect and it's works!!!

My first post was for this good idea! Thank you
 
-- J.

Jens

unread,
Mar 26, 2015, 6:11:38 PM3/26/15
to google-we...@googlegroups.com

Feel free to open a bug for it.



Yes. 


--- J.
Reply all
Reply to author
Forward
0 new messages