How to automatically show Progress Bar on each retrofit API call?
<p>How to achieve showing a progress bar on each <code>Retrofit 2.0</code> API call without having to make a progress bar in each activity, showing it and dismissing. Progress bar should show <strong>whenever</strong> an API is hit and it should dismiss when we get a response on <code>onResponse</code> or <code>onFailure</code> is called.</p>

<p>I tried this : </p>

<pre><code>ProgressDialog mProgressDialog = new ProgressDialog(this);
mProgressDialog.setIndeterminate(true);
mProgressDialog.setMessage("Loading...");
mProgressDialog.show();
retrofitService.login(new SignInRequest(email, password),
                new Callback&lt;SignInResponse&gt;() {
         @Override
         public void onResponse(Call&lt;SignInResponse&gt; call, Response&lt;SignInResponse&gt; response) {

              if (mProgressDialog.isShowing())
                  mProgressDialog.dismiss();
          }

         @Override
         public void onFailure(Call&lt;SignInResponse&gt; call, Throwable t) {
              if (mProgressDialog.isShowing())
                  mProgressDialog.dismiss();
          }
 });
</code></pre>

<p>But this code will have to copy pasted everywhere whenever I make an API call. I don;t want duplicate code.</p>