robospice icon indicating copy to clipboard operation
robospice copied to clipboard

Add way to detect if pending listener connected successfully

Open cavey79 opened this issue 11 years ago • 8 comments

It would be very useful to have the counterpart of onRequestNotFound, something like onRequestFound that would receive the request for such cases when you need to display a progress bar or do other things in case there's a pending request. Currently have to resort to trickery like showing a progress bar anyway and dismissing it in onRequestNotFound which results in flickering. It would also help in storing state in the request so that the newly attached listener can access that instead of storing it somewhere else.

cavey79 avatar Jul 09 '14 14:07 cavey79

Please provide a more detailed suggestion, or even better a PR, or an API design.

Issue is marked 'till then. It will be closed if there is no further activity in this thread.

stephanenicolas avatar Sep 06 '14 11:09 stephanenicolas

How about this:

public interface PendingRequestListener<RESULT> extends RequestListener<RESULT> {        
    void onRequestNotFound();
    void onRequestFound(Request request);
}

Having the request as a parameter would allow easily making the onSuccess/onFailure dependent on the inner state of the request - for example (not the greatest example, but bear with me), you have LoginRequest with a username field:

LoginRequest loginRequest = new LoginRequest("username", "password");

and later, after rotation, trying to reconnect (while no longer having access to the original request or its listener (see how knowing what request this connected to allows the success and failure callbacks to do what they need to do - as opposed to what's happening right now, which would force storing this extra state somewhere else rather than the request):

        PendingRequestListener listener = new PendingRequestListener(){
            void onRequestNotFound(){}//do nothing
            void onRequestFound(Request request){
                this.foundLoginRequest = request;
            }
            void onRequestSuccess(){
                alert("Logged in as:"+foundLoginRequest.getUserName());
            }
            void onRequestFailure(){
                //etc
            }
        }
    }

cavey79 avatar Sep 08 '14 14:09 cavey79

As an exercise I recommend you look at doing the changes as cleanly as possible as it should be relatively straight forward (ish).

As a clue look at the addRequest method of RequestProcessor

On 8 September 2014 15:28:29 BST, Radu Muresan [email protected] wrote:

How about this:

public interface PendingRequestListener<RESULT> extends
RequestListener<RESULT> {        
   void onRequestNotFound();
   void onRequestFound(Request request);
}

Having the request as a parameter would allow easily making the onSuccess/onFailure dependent on the inner state of the request - for example (not the greatest example, but bear with me), you have LoginRequest with a username field:

LoginRequest loginRequest = new LoginRequest("username", "password");

and later, after rotation, trying to reconnect (while no longer having access to the original request or its listener (see how knowing what request this connected to allows the success and failure callbacks to do what they need to do - as opposed to what's happening right now, which would force storing this extra state somewhere else rather than the request):

       PendingRequestListener listener = new PendingRequestListener(){
           void onRequestNotFound(){}//do nothing
           void onRequestFound(Request request){
               this.foundLoginRequest = request;
           }
           void onRequestSuccess(){
               alert("Logged in as:"+foundLoginRequest.getUserName());
           }
           void onRequestFailure(){
               //etc
           }
       }
   }

Reply to this email directly or view it on GitHub: https://github.com/stephanenicolas/robospice/issues/335#issuecomment-54826816

Sent from my Android device with K-9 Mail. Please excuse my brevity.

softwaremaverick avatar Sep 08 '14 17:09 softwaremaverick

Go for a PR, please, base on master, not release.

S.

2014-09-08 13:10 GMT-04:00 softwaremaverick [email protected]:

As an exercise I recommend you look at doing the changes as cleanly as possible as it should be relatively straight forward (ish).

As a clue look at the addRequest method of RequestProcessor

On 8 September 2014 15:28:29 BST, Radu Muresan [email protected] wrote:

How about this:

public interface PendingRequestListener<RESULT> extends
RequestListener<RESULT> {
void onRequestNotFound();
void onRequestFound(Request request);
}

Having the request as a parameter would allow easily making the onSuccess/onFailure dependent on the inner state of the request - for example (not the greatest example, but bear with me), you have LoginRequest with a username field:

LoginRequest loginRequest = new LoginRequest("username", "password");

and later, after rotation, trying to reconnect (while no longer having access to the original request or its listener (see how knowing what request this connected to allows the success and failure callbacks to do what they need to do - as opposed to what's happening right now, which would force storing this extra state somewhere else rather than the request):

PendingRequestListener listener = new PendingRequestListener(){
void onRequestNotFound(){}//do nothing
void onRequestFound(Request request){
this.foundLoginRequest = request;
}
void onRequestSuccess(){
alert("Logged in as:"+foundLoginRequest.getUserName());
}
void onRequestFailure(){
//etc
}
}
}

Reply to this email directly or view it on GitHub:

https://github.com/stephanenicolas/robospice/issues/335#issuecomment-54826816

Sent from my Android device with K-9 Mail. Please excuse my brevity.

— Reply to this email directly or view it on GitHub https://github.com/stephanenicolas/robospice/issues/335#issuecomment-54853253 .

stephanenicolas avatar Sep 09 '14 15:09 stephanenicolas

Could i suggest that it should be onListenerAttached instead of request found.

This way it sounds more typical of similar concepts. .

softwaremaverick avatar Sep 10 '14 21:09 softwaremaverick

So, how is the development of this issue right now? Will it be added, or is there any better way to know if there is a request which has been executed?

fikr4n avatar Oct 07 '14 03:10 fikr4n

We're waiting for you to implement the change! :-)

On 7 October 2014 04:47:09 BST, fikr4n [email protected] wrote:

So, how is the development of this issue right now? Will it be added, or is there any better way to know if there is a request which has been executed?


Reply to this email directly or view it on GitHub: https://github.com/stephanenicolas/robospice/issues/335#issuecomment-58132849

Sent from my Android device with K-9 Mail. Please excuse my brevity.

softwaremaverick avatar Oct 07 '14 17:10 softwaremaverick

I implemented the hack I described when I opened this issue. I'm off that project for now so don't have the time to implement this. I'd still think it's a valuable feature though.

cavey79 avatar Oct 07 '14 17:10 cavey79