diff --git a/app/src/main/java/com/amaze/filemanager/asynchronous/services/ftp/FtpTileService.java b/app/src/main/java/com/amaze/filemanager/asynchronous/services/ftp/FtpTileService.java index 5272aa36cd..b6023ad231 100644 --- a/app/src/main/java/com/amaze/filemanager/asynchronous/services/ftp/FtpTileService.java +++ b/app/src/main/java/com/amaze/filemanager/asynchronous/services/ftp/FtpTileService.java @@ -46,21 +46,21 @@ public void onStopListening() { @Override public void onClick() { - super.onClick(); - - if (getQsTile().getState() == Tile.STATE_ACTIVE) { - getApplicationContext().sendBroadcast(new Intent(FtpService.ACTION_STOP_FTPSERVER).setPackage(getPackageName())); - } else { - if (FtpService.isConnectedToWifi(getApplicationContext()) - || FtpService.isConnectedToLocalNetwork(getApplicationContext()) - || FtpService.isEnabledWifiHotspot(getApplicationContext())) { - Intent i = new Intent(FtpService.ACTION_START_FTPSERVER).setPackage(getPackageName()); - i.putExtra(FtpService.TAG_STARTED_BY_TILE, true); - getApplicationContext().sendBroadcast(i); + unlockAndRun(()->{ + if (FtpService.isRunning()) { + getApplicationContext().sendBroadcast(new Intent(FtpService.ACTION_STOP_FTPSERVER).setPackage(getPackageName())); } else { - Toast.makeText(getApplicationContext(), getString(R.string.ftp_no_wifi), Toast.LENGTH_LONG).show(); + if (FtpService.isConnectedToWifi(getApplicationContext()) + || FtpService.isConnectedToLocalNetwork(getApplicationContext()) + || FtpService.isEnabledWifiHotspot(getApplicationContext())) { + Intent i = new Intent(FtpService.ACTION_START_FTPSERVER).setPackage(getPackageName()); + i.putExtra(FtpService.TAG_STARTED_BY_TILE, true); + getApplicationContext().sendBroadcast(i); + } else { + Toast.makeText(getApplicationContext(), getString(R.string.ftp_no_wifi), Toast.LENGTH_LONG).show(); + } } - } + }); } private void updateTileState() {