@NonNull
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {

    binding =
        DataBindingUtil.inflate(
            LayoutInflater.from(getContext()), R.layout.set_location_dialog, null, false);
    binding.locationEdit.addTextChangedListener(
        new SimpleTextWatcher() {
          @Override
          public void afterTextChanged(Editable s) {
            updateFreeSpace(s.toString());
          }
        });
    binding.locationEdit.setText(initialLocation);

    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle(R.string.choose_location);
    builder.setView(binding.getRoot());
    builder.setPositiveButton(
        R.string.apply,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            if (listener != null) {
              listener.onLocationSelected(
                  binding.locationEdit.getText().toString(), binding.moveDataCheckbox.isChecked());
            }
          }
        });
    builder.setNegativeButton(android.R.string.cancel, null);

    return builder.create();
  }
  private void updateFreeSpace(String path) {
    if (runningFreeSpaceRequest != null) runningFreeSpaceRequest.cancel();
    binding.setLoadingInProgress(true);
    runningFreeSpaceRequest = new FreeSpaceRequest(path);

    getTransportManager()
        .doRequest(
            runningFreeSpaceRequest,
            new RequestListener<FreeSpace>() {
              @Override
              public void onRequestSuccess(FreeSpace freeSpace) {
                runningFreeSpaceRequest = null;
                binding.setLoadingInProgress(false);
                binding.freeSpaceText.setText(
                    getString(
                        R.string.free_space,
                        TextUtils.displayableSize(freeSpace.getSizeInBytes())));
              }

              @Override
              public void onRequestFailure(SpiceException spiceException) {
                if (spiceException.getCause() instanceof ResponseFailureException) {
                  runningFreeSpaceRequest = null;
                  binding.setLoadingInProgress(false);
                  String failureMessage =
                      ((ResponseFailureException) spiceException.getCause()).getFailureMessage();
                  binding.freeSpaceText.setText(failureMessage);
                } else if (!(spiceException
                    instanceof RequestCancelledException)) { // Retry if not canceled
                  getTransportManager().doRequest(runningFreeSpaceRequest, this);
                }
              }
            });
  }