-
-
Notifications
You must be signed in to change notification settings - Fork 693
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
Upload Service 4 Alpha 2 #463
Comments
Sorry for my bad English. I checked the current version from the master branch. And as I understand, there is still no way to localize notifications content and placeholders. As I can see in android-upload-service/uploadservice/src/main/java/net/gotev/uploadservice/Placeholders.kt Lines 42 to 50 in 5fcf509
you use wrong way to format values.
Also
I read wiki, but I still don’t understand whether these values can be localized. Because of this, I can not use placeholders (-> no usefull information), because non-localized text does not look professional. Forgive me if I didn’t find something, and this can be done. |
Hi there @ChristinaGit and thanks for the detailed explanation! Currently, to use localised messages, you can do something like the following (extracted from the demo app).
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="uploading">Uploaded [[UPLOADED_FILES]] of [[TOTAL_FILES]] at [[UPLOAD_RATE]] - [[PROGRESS]]</string>
<string name="upload_success">Upload completed successfully in [[ELAPSED_TIME]]</string>
<string name="upload_error">Error while uploading</string>
<string name="upload_cancelled">Upload has been cancelled</string>
</resources> protected UploadNotificationConfig getNotificationConfig(final String uploadId, @StringRes int title) {
UploadNotificationConfig config = new UploadNotificationConfig(App.CHANNEL);
config.getProgress().setMessage(getString(R.string.uploading));
config.getProgress().setIconResourceID(R.drawable.ic_upload);
config.getProgress().setIconColorResourceID(Color.BLUE);
config.getProgress().getActions().add(new UploadNotificationAction(
R.drawable.ic_cancelled,
getString(R.string.cancel_upload),
NotificationActions.getCancelUploadAction(this, 1, uploadId)));
config.getCompleted().setMessage(getString(R.string.upload_success));
config.getCompleted().setIconResourceID(R.drawable.ic_upload_success);
config.getCompleted().setIconColorResourceID(Color.GREEN);
config.getError().setMessage(getString(R.string.upload_error));
config.getError().setIconResourceID(R.drawable.ic_upload_error);
config.getError().setIconColorResourceID(Color.RED);
config.getCancelled().setMessage(getString(R.string.upload_cancelled));
config.getCancelled().setIconResourceID(R.drawable.ic_cancelled);
config.getCancelled().setIconColorResourceID(Color.YELLOW);
return config;
} Example usage final BinaryUploadRequest request = new BinaryUploadRequest(this, serverUrl)
.setUploadID(uploadId)
.setMethod(httpMethod)
.setNotificationConfig(getNotificationConfig(uploadId, R.string.binary_upload))
.setMaxRetries(MAX_RETRIES)
.setUsesFixedLengthStreamingMode(FIXED_LENGTH_STREAMING_MODE); However, contents of Placeholders are not localisable as you pointed out. I'd love to see a PR with your additions to make them truly localisable! |
I may not have been able to do the localization, but I have a couple more suggestions that I would like to mention. HttpStack for demoI think many will want to see how notifications and callbacks works. But making real requests to a real server (event for local) looks too complicated. So I think it's worth mentioning on the wiki page, or even adding an implementation of I did this for the old version. Don't know how to do it for a new one. class TestHttpStack(
private val _uploadingTime: Long,
private val _shouldThrowError: (String?) -> Boolean
) : HttpStack {
override fun createNewConnection(
method: String?,
url: String?
): HttpConnection = object : HttpConnection {
override fun getResponse(delegate: HttpConnection.RequestBodyDelegate?): ServerResponse {
Thread.sleep(_uploadingTime)
return if (!_shouldThrowError(url)) {
ServerResponse(200, "".toByteArray(Charsets.UTF_8), null)
} else {
ServerResponse(400, "".toByteArray(Charsets.UTF_8), null)
}
}
override fun setTotalBodyBytes(
totalBodyBytes: Long,
isFixedLengthStreamingMode: Boolean
): HttpConnection = this
override fun setHeaders(requestHeaders: MutableList<NameValue>?): HttpConnection = this
override fun close() {
}
}
} Custom thread poolMany libraries use their own thread pools.
And I would like to avoid increasing their number. Perhaps you should add the ability to specify custom thread pool, not just its size. |
@ChristinaGit this is exactly the purpose of this issue. Docs are not ready yet for lack of time, however there are 2 out of the box implementations ready to be used (exactly as previous versions). First one is based in Testing is a good point, because tests are lacking in current implementation. For convenience and acquired knowledge, I would use OkHttp together with its MockWebServer which is easy, stable and already used by many people. Your example may be part of a new Custom ThreadPool is another good point. Definitely going to add it! |
Alpha 2 stage is now complete, Alpha 3 is now open #465 |
Fasten your seatbelt, Upload Service 4 Alpha 02 is here! #450 checkmarks reflects what you will find in this version. Use this issue to provide feedback about this release.
BEAR IN MIND THIS IS A DEVELOPER PREVIEW AND NOT PRODUCTION GRADE VERSION. IF YOU NEED SOMETHING BATTLE TESTED FOR PRODUCTION, USE 3.5.2 UNTIL 4.0.0 IS CERTIFIED STABLE.
For those who wants to experience the new Upload Service, here we go. Upgrade your Gradle (by adding only the artifacts you need):
Docs are not ready yet because APIs have not reached their final form and may be changed based on feedback, but the demo app example is fully functional and can be used as reference. If you're coming from 3.x version, prepare a cup of coffee and enter in refactoring mood.
Feel free to tell here anything about this version.
Changelog since 4.0 Alpha 1
Implemented delegates substitutes. Example usage:
android-upload-service/examples/app/demoapp/src/main/java/net/gotev/uploadservicedemo/MultipartUploadActivity.java
Lines 37 to 114 in 1e64b0a
This uses the newly introduced RequestObserverDelegate:
android-upload-service/uploadservice/src/main/java/net/gotev/uploadservice/observer/request/RequestObserverDelegate.kt
Lines 7 to 53 in 8d45db5
Now the delegate is automatically wrapped inside a standard BroadcastReceiver, called
RequestObserver
which is lifecycle aware (using AndroidX lifecycle) and registers and unregisters itself automatically. As a bonus, you can also intercept the case when you get back to the activity from background and the observed task already completed.The text was updated successfully, but these errors were encountered: