title: Display and hide progress bar using MVVM pattern
body: <p>I am working with <em>MVVM</em> pattern. I have just started it and i have done it successfully.</p>
  
  <p>But I don't understand how to add progress bar for showing and hide as we normally do for API calls.</p>
  
  <p>I am not using data binding. So how can i use progress bar for showing and hide it.</p>
  
  <p><strong>For Login</strong></p>
  
  <pre><code>public class LoginRepository {
  
  private DATAModel dataModel = new DATAModel();
  private MutableLiveData&lt;DATAModel&gt; mutableLiveData = new MutableLiveData&lt;&gt;();
  private Application application;
  
  public LoginRepository(Application application) {
      this.application = application;
  }
  
  public MutableLiveData&lt;DATAModel&gt; getMutableLiveData(String username, String password) {
  
      APIRequest apiRequest = RetrofitRequest.getRetrofit().create(APIRequest.class);
  
      JsonLogin jsonLogin = new JsonLogin(Constants.DEVICE_TYPE, Functions.getDeviceId(application.getApplicationContext()), Constants.APP_VERSION, Constants.API_VERSION, Functions.getTimeStamp(), Functions.getDeviceModel(), Build.VERSION.RELEASE, username, password);
  
      Call&lt;APIResponseLogin&gt; call = apiRequest.getUsersDetails(jsonLogin);
      call.enqueue(new Callback&lt;APIResponseLogin&gt;() {
          @Override
          public void onResponse(Call&lt;APIResponseLogin&gt; call, Response&lt;APIResponseLogin&gt; response) {
              APIResponseLogin apiResponse = response.body();
              if (apiResponse != null &amp;&amp; apiResponse.getStatuscode() == 0) {
                  if (apiResponse.getDataModel() != null) {
                      dataModel = apiResponse.getDataModel();
                      mutableLiveData.setValue(dataModel);
                  }
  
              } else if (apiResponse != null &amp;&amp; apiResponse.getStatuscode() == 1) {
  
                  Log.v("AAAAAAAAA", apiResponse.getStatusmessage());
              }
          }
  
          @Override
          public void onFailure(Call&lt;APIResponseLogin&gt; call, Throwable t) {
  
              Log.v("ErrorResponse", t.getMessage() + " : " + call.request().toString());
          }
      });
      return mutableLiveData;
  }
  </code></pre>
  
  <p><strong>Activity Code</strong></p>
  
  <pre><code>void loginCall() {
      loginViewModel.getUserDetails(editTextUsername.getText().toString().trim(), editTextPassword.getText().toString().trim()).observe(this, new Observer&lt;DATAModel&gt;() {
          @Override
          public void onChanged(@Nullable DATAModel dataModel) {
              if (dataModel != null) {
                  Userdetails userdetails = dataModel.getUserdetails();
                  List&lt;ContactTypes&gt; contactTypes = dataModel.getContactTypes();
                  if (userdetails != null) {
  
                      MySharedPreferences.setCustomPreference(LoginActivity.this, Constants.SHAREDPREFERENCE_USERDETAILS, userdetails);
                      MySharedPreferences.setStringPreference(LoginActivity.this, Constants.SHAREDPREFERENCE_USER_ID, userdetails.getUserId());
                  }
  
                  if (contactTypes != null) {
                      MySharedPreferences.setCustomArrayList(LoginActivity.this, Constants.SHAREDPREFERENCE_CONTACTTYPES, contactTypes);
                  }
  
                  Intent i = new Intent(LoginActivity.this, MainActivity.class);
                  startActivity(i);
                  finish();
              }
          }
      });
  }
  </code></pre>
  
  <p>Advanced help would be appreciated!</p>