private void complete() {
    status = STATUS_COMPLETE;
    manager.incrementDownloadsToReview();

    if (completeFile.getAbsoluteFile().exists()) {
      Librarian.instance().scan(getSavePath().getAbsoluteFile());
      String sha1 = Digests.sha1(completeFile);
      Engine.instance().notifyDownloadFinished(getDisplayName(), completeFile, sha1);
    } else {
      Engine.instance().notifyDownloadFinished(getDisplayName(), getSavePath());
    }

    cleanupIncomplete();
  }
  public void refresherOnTime() {
    CoreMediaPlayer mp = Engine.instance().getMediaPlayer();
    if (mp != null) {
      FileDescriptor fd = mp.getCurrentFD();

      String status = "";
      refreshPlayerStateIndicator();
      if (fd != null) {
        status = fd.artist + " - " + fd.title;
        if (getVisibility() == View.GONE) {
          setVisibility(View.VISIBLE);
          startAnimation(showNotifierAnimation);
        }
      } else {
        if (getVisibility() == View.VISIBLE) {
          startAnimation(hideNotifierAnimation);
          setVisibility(View.GONE);
        }
      }
      if (!status.equals(lastStatusShown)) {
        statusText.setText(status);
        lastStatusShown = status;
        statusContainer.startAnimation(fromRightAnimation);
      }
    }
  }
  private void start(final LinkInfo inf, final File temp) {
    if (status == STATUS_SAVE_DIR_ERROR
        || status == STATUS_ERROR_DISK_FULL
        || status == STATUS_ERROR) {
      return;
    }

    status = STATUS_WAITING;

    Engine.instance()
        .getThreadPool()
        .execute(
            new Runnable() {
              @Override
              public void run() {
                try {
                  status = STATUS_DOWNLOADING;
                  httpClient.save(inf.link, temp, false);
                } catch (IOException e) {
                  e.printStackTrace();
                  httpClientListener.onError(httpClient, e);
                }
              }
            });
  }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   if (Engine.instance().getMediaPlayer().getCurrentFD() != null) {
     Intent i = new Intent(getContext(), AudioPlayerActivity.class);
     i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
     getContext().startActivity(i);
   }
   return true;
 }
  private void mainResume() {
    syncSlideMenu();

    if (firstTime) {
      firstTime = false;
      Engine.instance().startServices(); // it's necessary for the first time after wizard
    }

    SoftwareUpdater.instance().checkForUpdate(this);
  }
 private void refreshPlayerStateIndicator() {
   CoreMediaPlayer mediaPlayer = Engine.instance().getMediaPlayer();
   if (mediaPlayer == null) {
     return;
   }
   ImageView notifierIconImageView = (ImageView) findViewById(R.id.view_player_notifier_icon);
   int notifierResourceId = R.drawable.playernotifier_icon_play;
   if (!mediaPlayer.isPlaying()) {
     notifierResourceId = R.drawable.playernotifier_icon_pause;
   }
   notifierIconImageView.setBackgroundResource(notifierResourceId);
 }
  @Override
  public void refresh() {
    List<Peer> peers = PeerManager.instance().getPeers();
    adapter.updateList(peers);

    refreshUPnPCount++;

    if (refreshUPnPCount % 5 == 0) {
      if (Engine.instance().isStarted()
          && ConfigurationManager.instance().getBoolean(Constants.PREF_KEY_NETWORK_USE_UPNP)) {
        UPnPManager.instance().refreshRemoteDevices();
      }
    }
  }
  private void handleDesktopUploadRequest(Intent intent) {
    String action = intent.getAction();

    if (durToken == null && action.equals(Constants.ACTION_DESKTOP_UPLOAD_REQUEST)) {
      durToken = intent.getStringExtra(Constants.EXTRA_DESKTOP_UPLOAD_REQUEST_TOKEN);
    }

    final DesktopUploadManager dum = Engine.instance().getDesktopUploadManager();

    if (dum == null) {
      return;
    }

    DesktopUploadRequest dur = dum.getRequest(durToken);

    if (durToken != null && dur != null && dur.status == DesktopUploadRequestStatus.PENDING) {
      DesktopUploadRequestDialog dlg =
          new DesktopUploadRequestDialog(
              this,
              dur,
              new DesktopUploadRequestDialog.OnDesktopUploadListener() {
                @Override
                public void onResult(
                    DesktopUploadRequestDialog dialog, DesktopUploadRequestDialogResult result) {
                  switch (result) {
                    case ACCEPT:
                      dum.authorizeRequest(durToken);
                      if (ConfigurationManager.instance().showTransfersOnDownloadStart()) {
                        Intent i = new Intent(Constants.ACTION_SHOW_TRANSFERS);
                        MainActivity.this.startActivity(
                            i.setClass(MainActivity.this, MainActivity.class));
                      }
                      break;
                    case REJECT:
                      dum.rejectRequest(durToken);
                      break;
                    case BLOCK:
                      dum.blockComputer(durToken);
                      break;
                  }
                  durToken = null;
                }
              });

      trackDialog(dlg).show();
    }
  }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    setRetainInstance(true);

    if (Engine.instance().isStarted()
        && ConfigurationManager.instance().getBoolean(Constants.PREF_KEY_NETWORK_USE_UPNP)) {
      UPnPManager.instance().resume();
    }

    setupAdapter();

    if (getActivity() instanceof AbstractActivity) {
      ((AbstractActivity) getActivity()).addRefreshable(this);
    }
  }
 public void shutdown() {
   Offers.stopAdNetworks(this);
   finish();
   Engine.instance().shutdown();
 }
 private Fragment getWifiSharingFragment() {
   return Engine.instance().isStarted()
           && ConfigurationManager.instance().getBoolean(Constants.PREF_KEY_NETWORK_USE_UPNP)
       ? peers
       : peersDisabled;
 }