-
-
Notifications
You must be signed in to change notification settings - Fork 32
Server path completion for download path on AddTorrentScreen #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| } | ||
|
|
||
| searchDirectoriesJob = viewModelScope.launch { | ||
| kotlinx.coroutines.delay(300) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to use the fully qualified name here. Import kotlinx.coroutines.delay and call it as delay(300).
| var savePathExpanded by remember { mutableStateOf(false) } | ||
|
|
||
| // Hide suggestions when IME is folded | ||
| val density = androidx.compose.ui.platform.LocalDensity.current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as previous one.
|
|
||
| fun searchDirectories(serverId: Int, path: String) { | ||
| searchDirectoriesJob?.cancel() | ||
| if (path.isBlank() || !path.startsWith("/")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (path.isBlank() || !path.startsWith("/")) { | |
| if (path.isBlank()) { |
You also need to consider Windows users. It’s also possible that they are using network drives on Windows, which start with \\, etc. I think it’s better to remove this check altogether.
| // if path doesn't ends with a slash, we need to also check the parent directory for suggestions | ||
| // e.g. for /downloads/m, check if there's a directory's name under /downloads starts with "m" | ||
| if (!path.endsWith("/")) { | ||
| val lastSeparatorIndex = path.lastIndexOf('/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to handle the Windows case here as well. I don’t think there’s a way to get the operating system from the API, so you can check whether the path contains / and treat it as Unix in that case.
| is RequestResult.Success -> { | ||
| suggestions.addAll(result.data) | ||
| } | ||
| else -> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| else -> {} | |
| is RequestResult.Error -> {} |
| is RequestResult.Success -> { | ||
| suggestions.addAll(result.data) | ||
| } | ||
| else -> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| else -> {} | |
| is RequestResult.Error -> {} |
| onClick = { | ||
| savePath = TextFieldValue( | ||
| text = suggestion, | ||
| selection = androidx.compose.ui.text.TextRange(suggestion.length), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this fully qualified name as well.
|
|
||
| fun searchDirectories(serverId: Int, path: String) { | ||
| searchDirectoriesJob?.cancel() | ||
| if (path.isBlank() || !path.startsWith("/")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getDirectoryContent was added in qBittorrent 5.0.0, so you need to account for that. Inject RequestManager in the constructor, then you can check the version like this:
val version = requestManager.getQBittorrentVersion(serverId)
if (version >= QBittorrentVersion(5, 0, 0)) {
// ..
}| when (val result = repository.getDirectoryContent(serverId, path)) { | ||
| is RequestResult.Success -> { | ||
| suggestions.addAll(result.data) | ||
| } | ||
| else -> {} | ||
| } | ||
|
|
||
| // if path doesn't ends with a slash, we need to also check the parent directory for suggestions | ||
| // e.g. for /downloads/m, check if there's a directory's name under /downloads starts with "m" | ||
| if (!path.endsWith("/")) { | ||
| val lastSeparatorIndex = path.lastIndexOf('/') | ||
| val parent = path.take(lastSeparatorIndex + 1) | ||
| when (val result = repository.getDirectoryContent(serverId, parent)) { | ||
| is RequestResult.Success -> { | ||
| suggestions.addAll(result.data) | ||
| } | ||
| else -> {} | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s better to run these network requests in parallel. Launch two more coroutines, one for each request, have both return lists, then combine the results.
Inspired by Vuetorrent similar feature: VueTorrent/VueTorrent#2501
Uses getDirectoryContent API
Screenshots: