Skip to content

Commit 9fa4a9a

Browse files
committed
Changes per PR feedback
1 parent b59822a commit 9fa4a9a

17 files changed

Lines changed: 111 additions & 139 deletions

File tree

app/src/main/java/com/amaze/filemanager/asynchronous/services/ftp/AppFtpReceiver.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
package com.amaze.filemanager.asynchronous.services.ftp
2222

2323
import com.amaze.filemanager.ftpserver.service.FtpReceiver
24+
import com.amaze.filemanager.ftpserver.service.FtpServerService
2425

2526
/**
2627
* Concrete implementation of FtpReceiver for the Amaze File Manager app.
2728
*
2829
* This receiver handles start/stop intents for the FTP server service.
2930
*/
3031
class AppFtpReceiver : FtpReceiver() {
31-
override fun getFtpServiceClass(): Class<*> = AppFtpService::class.java
32+
override fun getFtpServiceClass(): Class<out FtpServerService> = AppFtpService::class.java
3233
}

app/src/main/java/com/amaze/filemanager/asynchronous/services/ftp/AppFtpService.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,19 @@ import java.io.InputStream
3838
import java.security.GeneralSecurityException
3939

4040
/**
41-
* Concrete implementation of FtpServerService for the Amaze File Manager app.
41+
* Concrete implementation of [FtpServerService].
4242
*
4343
* This class provides app-specific implementations for notifications, keystore access,
4444
* password decryption, and error messages.
4545
*/
4646
class AppFtpService : FtpServerService() {
47+
companion object {
48+
@JvmStatic
49+
private val log: Logger = LoggerFactory.getLogger(AppFtpService::class.java)
50+
}
51+
4752
private val serverNotification
48-
get() = ServerRegistry.getProvider(ServerType.FTP)!!.getNotification()
53+
get() = requireNotNull(ServerRegistry.getProvider(ServerType.FTP)).getNotification()
4954

5055
override fun getNotificationId(): Int = serverNotification.getNotificationId()
5156

@@ -109,9 +114,4 @@ class AppFtpService : FtpServerService() {
109114
override fun getFeatResponse(): String {
110115
return getString(R.string.ftp_command_FEAT)
111116
}
112-
113-
companion object {
114-
@JvmStatic
115-
private val log: Logger = LoggerFactory.getLogger(AppFtpService::class.java)
116-
}
117117
}

app/src/main/java/com/amaze/filemanager/database/typeconverters/JsonTypeConverter.kt

Lines changed: 0 additions & 47 deletions
This file was deleted.

app/src/main/java/com/amaze/filemanager/ui/fragments/FtpServerFragment.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ class FtpServerFragment : Fragment(R.layout.fragment_ftp) {
425425
ServerRegistry.getProvider(ServerType.FTP)
426426
?.getNotification()
427427
?.updateRunningNotification(
428-
context ?: return,
428+
requireContext() ?: return,
429429
FtpServerEvent.StartedFromTile == signal,
430430
)
431431
}
@@ -646,7 +646,7 @@ class FtpServerFragment : Fragment(R.layout.fragment_ftp) {
646646
statusText.text = spannedStatusNotRunning
647647
ftpBtn.isEnabled = true
648648
}
649-
url.text = "URL: "
649+
url.text = getString(com.amaze.filemanager.ftpserver.R.string.ftpmod_url_label, "")
650650
ftpBtn.text = resources.getString(R.string.start_ftp).uppercase()
651651
} else {
652652
accentColor = mainActivity.accent
@@ -740,9 +740,12 @@ class FtpServerFragment : Fragment(R.layout.fragment_ftp) {
740740

741741
private fun resetFTPPath() {
742742
mainActivity.prefs
743-
.edit()
744-
.putString(FtpPreferences.KEY_PREFERENCE_PATH, FtpPreferences.defaultPath(requireContext()))
745-
.apply()
743+
.edit {
744+
putString(
745+
FtpPreferences.KEY_PREFERENCE_PATH,
746+
FtpPreferences.defaultPath(requireContext()),
747+
)
748+
}
746749
}
747750

748751
/** Updates the status spans */
@@ -766,7 +769,7 @@ class FtpServerFragment : Fragment(R.layout.fragment_ftp) {
766769
)
767770
spannedStatusUrl =
768771
HtmlCompat.fromHtml(
769-
"URL:&nbsp;$ftpAddress",
772+
getString(com.amaze.filemanager.ftpserver.R.string.ftpmod_url_label, ftpAddress),
770773
FROM_HTML_MODE_COMPACT,
771774
)
772775
spannedStatusNoConnection =
@@ -791,11 +794,6 @@ class FtpServerFragment : Fragment(R.layout.fragment_ftp) {
791794
"${resources.getString(R.string.ftp_status_secure_connection)}</font></b>",
792795
FROM_HTML_MODE_COMPACT,
793796
)
794-
spannedStatusUrl =
795-
HtmlCompat.fromHtml(
796-
"URL:&nbsp;$ftpAddress",
797-
FROM_HTML_MODE_COMPACT,
798-
)
799797
}
800798

801799
private fun initLoginDialogViews(loginDialogView: DialogFtpLoginBinding) {

app/src/main/java/com/amaze/filemanager/ui/fragments/preferencefragments/PreferencesConstants.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ object PreferencesConstants {
8686
const val PREFERENCE_REGEX = "regex"
8787
const val PREFERENCE_REGEX_MATCHES = "matches"
8888

89-
// ftp preferences (shared key with FtpPreferences in ftpserver module)
89+
// ftp preferences
9090
const val PREFERENCE_FTP_BATTERY_OPTIMIZATION_ASKED = "ftp_battery_optimization_asked"
9191

9292
// security_prefs.xml

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,10 @@
701701
<string name="choose_folder">Choose This Folder</string>
702702
<string name="folder_go_up_one_level" translatable="false">..</string>
703703
<string name="some_files_failed_invalid_operation">Some files failed due to invalid operation</string>
704+
<string name="ftp_readonly">Read-only access</string>
704705
<string name="ftp_server_prompt_connect_to_network">Connect to a network or enable AP</string>
705706
<string name="ftp_server_open_settings">Open settings</string>
707+
<string name="ftp_prompt_restart_server">You will need to restart the FTP server for changes to take effect.</string>
706708
<string name="move">Move</string>
707709
<string name="select_save_location">Select location to save</string>
708710
<string name="scp_default_path">Default Path (Optional)</string>
@@ -735,11 +737,9 @@
735737
<string name="choose_different_app">Choose different application</string>
736738
<string name="clear_open_file">Clear cache</string>
737739
<string name="clear_open_file_summary">Clears selected default file opening apps</string>
738-
<string name="ftp_readonly">Read-only access</string>
739740
<string name="legacy_listing_title">Use legacy listing for root</string>
740741
<string name="legacy_listing_summary">If enabled, uses legacy method to list files</string>
741742
<string name="error_unsupported_v5_rar">RAR archive \"%s\" is unsupported RAR v5 archive.</string>
742-
<string name="ftp_prompt_restart_server">You will need to restart the FTP server for changes to take effect.</string>
743743
<string name="error_permission_denied">Permission denied</string>
744744
<string name="error_archive_password_incorrect">Wrong archive password.</string>
745745
<string name="error_archive_cannot_extract">Cannot extract archive entry \"%s\" to \"%s\".</string>
@@ -766,7 +766,7 @@ You only need to do this once, until the next time you select a new location for
766766
<string name="ftp_battery_optimization_action_settings">Open Settings</string>
767767
<string name="ftp_battery_optimization_action_skip">Skip</string>
768768
<string name="ftp_battery_optimization_action_dont_ask">Don\'t ask again</string>
769-
<string name="ftp_battery_optimization_tile_warning">Battery optimization is enabled — FTP server may be stopped by the OS</string>
769+
<string name="ftp_battery_optimization_tile_warning">Battery optimization is enabled. You may experience lower transfer speeds when using the FTP server.</string>
770770
<string name="ftp_battery_optimization_pref_title">Disable battery optimization prompt</string>
771771
<string name="ftp_battery_optimization_pref_summary">Skip battery optimization reminder when starting the FTP server</string>
772772
<string name="ftp_server_preferences">FTP Server</string>

ftpserver/src/main/java/com/amaze/filemanager/ftpserver/commands/AVBL.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
package com.amaze.filemanager.ftpserver.commands
2222

2323
import com.amaze.filemanager.ftpserver.filesystem.AndroidFileSystemFactory
24+
import com.amaze.filemanager.ftpserver.filesystem.RootFileSystemFactory
2425
import org.apache.ftpserver.command.AbstractCommand
26+
import org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory
2527
import org.apache.ftpserver.ftplet.DefaultFtpReply
2628
import org.apache.ftpserver.ftplet.FtpFile
2729
import org.apache.ftpserver.ftplet.FtpReply.REPLY_213_FILE_STATUS
@@ -38,7 +40,7 @@ import java.io.File
3840
/**
3941
* Implements FTP extension AVBL command, to answer device remaining space in FTP command.
4042
*
41-
* Only supports RootFileSystemFactory and NativeFileSystemFactory. Otherwise will simply return
43+
* Only supports [RootFileSystemFactory] and [NativeFileSystemFactory]. Otherwise will simply return
4244
* 550 Access Denied.
4345
*
4446
* See [Draft spec](https://www.ietf.org/archive/id/draft-peterson-streamlined-ftp-command-extensions-10.txt)

ftpserver/src/main/java/com/amaze/filemanager/ftpserver/commands/FEAT.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import org.apache.ftpserver.impl.FtpIoSession
2828
import org.apache.ftpserver.impl.FtpServerContext
2929

3030
/**
31-
* Custom FEAT command to add AVBL command to the list.
31+
* Custom [org.apache.ftpserver.command.impl.FEAT] command to add [AVBL] command to the list.
3232
*/
3333
class FEAT(
3434
private val featResponseProvider: () -> String,

ftpserver/src/main/java/com/amaze/filemanager/ftpserver/service/FtpCommandFactoryFactory.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import org.apache.ftpserver.command.CommandFactory
2727
import org.apache.ftpserver.command.CommandFactoryFactory
2828

2929
/**
30-
* Custom CommandFactory factory with custom commands.
30+
* Custom [CommandFactory] factory with custom commands.
3131
*/
3232
object FtpCommandFactoryFactory {
3333
/**
34-
* Encapsulate custom CommandFactory construction logic. Append custom AVBL and PWD command,
35-
* as well as feature flag in FEAT command if not using AndroidFtpFileSystemView.
34+
* Encapsulate custom [CommandFactory] construction logic. Append custom [AVBL] and [PWD] command,
35+
* as well as feature flag in [FEAT] command if not using AndroidFtpFileSystemView.
3636
*/
3737
fun create(
3838
useAndroidFileSystem: Boolean,

ftpserver/src/main/java/com/amaze/filemanager/ftpserver/service/FtpEventBus.kt

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,22 @@ import kotlinx.coroutines.flow.MutableSharedFlow
2424
import kotlinx.coroutines.flow.asSharedFlow
2525

2626
/**
27-
* Event bus for FTP server events using Kotlin's Flow.
27+
* Replacement event bus to handle [FtpServerService] events using Kotlin's Flow.
28+
*
29+
* Original idea: https://mirchev.medium.com/its-21st-century-stop-using-eventbus-3ff5d9c6a00f
30+
*
31+
* @see [FtpServerService]
2832
*/
2933
object FtpEventBus {
3034
private val _events = MutableSharedFlow<FtpServerEvent>(replay = 0)
3135
val events = _events.asSharedFlow()
3236

3337
/**
3438
* Emit the event signal to the event bus.
39+
*
40+
* @param event The event to be emitted.
3541
*/
3642
suspend fun emit(event: FtpServerEvent) {
3743
_events.emit(event)
3844
}
3945
}
40-
41-
/**
42-
* Events broadcast when FTP server state changes.
43-
*/
44-
sealed class FtpServerEvent {
45-
data object Started : FtpServerEvent()
46-
47-
data object StartedFromTile : FtpServerEvent()
48-
49-
data object Stopped : FtpServerEvent()
50-
51-
data object FailedToStart : FtpServerEvent()
52-
}

0 commit comments

Comments
 (0)