-
-
Notifications
You must be signed in to change notification settings - Fork 779
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
feat: Add downloader plugin system #2041
Conversation
Eu gostaria que você comentasse um pouco mais sobre como funcionaria esse sistema de plugin para leigos em um texto se fosse possível para eu já ficar sabendo como funciona, acompanhe o projeto de você |
interface DownloaderPlugin<A : DownloaderPlugin.App> { | ||
val pagingConfig: PagingConfig | ||
fun createPagingSource(parameters: SearchParameters): PagingSource<*, A> | ||
suspend fun download(app: A, parameters: DownloadParameters) |
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.
In DSL an API like this would be better:
downloader {
download { it: A -> inputStream to total }
}
* @param packageName The package name to search for. | ||
* @param versionHint The preferred version to search for. It is not mandatory to respect this parameter. | ||
*/ | ||
class SearchParameters(val packageName: String, val versionHint: String?) |
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.
SearchParameters can be converted to direct parameters in createPagingSource function
* @param targetFile The location where the downloaded APK should be saved. | ||
* @param onDownloadProgress A callback for reporting download progress. | ||
*/ | ||
class DownloadParameters( |
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.
DownloadParameters can be converted to direct parameters in download function
* @param onDownloadProgress A callback for reporting download progress. | ||
*/ | ||
class DownloadParameters( | ||
val targetFile: File, |
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.
Probably a stream is better for the API to write to.
val targetFile: File, | |
val output: OutputStream, |
*/ | ||
class DownloadParameters( | ||
val targetFile: File, | ||
val onDownloadProgress: suspend (progress: Pair<BytesReceived, BytesTotal>?) -> Unit |
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.
Two parameters instead of a Pair is simpler, BytesTotal must be nullable in case total can't be reported by downloader. A spinner with current downloaded bytes can be shown.
) | ||
} | ||
|
||
typealias BytesReceived = Int |
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.
Named parameters can be used instead of type alias
|
||
override fun createPagingSource(parameters: DownloaderPlugin.SearchParameters) = | ||
singlePagePagingSource { | ||
val impl = withContext(Dispatchers.IO) { getPackageInfo(parameters.packageName) }?.let { |
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.
The context can be set when calling the createPagingSource function. The implementation can still switch context. This behaviour should be documented in the inline docs of this function so the user knows that this function is called on IO.
override fun createPagingSource(parameters: DownloaderPlugin.SearchParameters) = | ||
singlePagePagingSource { | ||
val impl = withContext(Dispatchers.IO) { getPackageInfo(parameters.packageName) }?.let { | ||
AppImpl( |
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.
Probably PMDownloader and PMApp would be a better name for purpose of an example instead of "AppImpl"
c064800
to
0637365
Compare
0637365
to
c8975f5
Compare
Implements a plugin system for downloaders.