Added DestinationPathName to DownloadFile#94
Added DestinationPathName to DownloadFile#94SimonSimCity merged 5 commits intodevelopfrom unknown repository
Conversation
|
Thanks for the support here, but it only fixes half of the problem ... I'll need to take a look at how this can be fixed permanently also when using the temporary location ... |
|
Maybe I didn't look that clear to the code and also without looking at the code now: but doesn't this also fill the new property with the location when it's a temporary one? This PR is actually not a solution for the referenced issue, since that's a bit more complicated. Edit: Edit2: It's not that great, but it's at least something. The reason for this PR is actually because I'm showing a notification with action when the download has been completed. The action opens the file, but for that I need the have the file path where the file was located. Because the |
|
You're right in that the native Android download manager doesn't have a way to get notified if a property has changed. That's why I've implemented a timer to update the properties of all running downloads. In this way we could just set the property after updating the status. On Android I have to set the path before the download starts, which is the reason why it's downloaded directly to the desired destination. If the download is finished, publish the destination you get from the native download manager. On iOS there is a method which gets called when the download is finished and it also gives you the full destination path. Here's the excerpt of the code where I move the file to the desired destination after a successful download: Here you either have to publish As it's very likely that UWP will stick around for quite a while, it'd be good if you could also find a way there. Maybe this excerpt from the samples already helps you getting on track: Xamarin-CrossDownloadManager/Sample/UWP/MainPage.xaml.cs Lines 81 to 86 in 6833954 To be consistent, the variable on the Please let me know if you disagree in any of the details I wrote. I let you know this because I won't have the time to test these changes ... Please test it and report back. I'll merge it when the changes are useful for all the cases. |
…emporary locations.
|
Sounds good. Could you review the last commit I made? Android iOS UWP I got the following back: How about that? |
… temporary location.
|
I've added another commit which only sets the |
SimonSimCity
left a comment
There was a problem hiding this comment.
Looks good! There's just a quick change on the iOS implementation and a request for change on the UWP version ...
| var success = true; | ||
| var destinationPathName = Controller.PathNameForDownloadedFile?.Invoke (file); | ||
| if (destinationPathName != null) { | ||
| file.DestinationPathName = destinationPathName; |
There was a problem hiding this comment.
Please set the path after the file has been moved. This way if a person only listens on a change on DestinationPathName his closure will be triggered when the file is available there.
| file = await folder.CreateFileAsync(downloadUrl.Segments.Last(), CreationCollisionOption.GenerateUniqueName); | ||
| } | ||
|
|
||
| DestinationPathName = file.Path; |
There was a problem hiding this comment.
This would now be the only instance where this value is set before the download is started ... can we get this consistent? All other platforms should also report the destination when the download is complete (but before the status is updated).
Another question is: Could you please check and confirm how this behaves if the app crashes? Does the download still continue or does it (unlike in the implementation on iOS or Android) stop?
If it continues, is this path still available if the download finishes then?
There was a problem hiding this comment.
I tried, but the ProgressChanged method actually kicked in after the Status property changed... Though I just noticed that way my mistake, lol. Fixed.
There was a problem hiding this comment.
Do you have a way for me to crash the app whilst running?
There was a problem hiding this comment.
This should create a null-reference exception. Put it at the right place and it will get the app to crash 😉
object o = null;
DateTime d = (DateTime)o;There was a problem hiding this comment.
I know, but that instantly kills the process since Visual Studio doesn't want to continue. I thought you had a way to crash and keep the process running. Or was that the question? Well then no, the app crashes and the download does not complete. At least in Debug mode.
I published the app with the Release configuration and side-loaded it to see whether the download would continue or stop. I added to the code that it would create a text file containing the download location, but it never shows up. So I guess it's safe to assume that the answer is no.
| switch ((DownloadStatus)cursor.GetInt (cursor.GetColumnIndex (Android.App.DownloadManager.ColumnStatus))) { | ||
| case DownloadStatus.Successful: | ||
| downloadFile.StatusDetails = default(string); | ||
| if (string.IsNullOrEmpty(downloadFile.DestinationPathName)) |
There was a problem hiding this comment.
I've found I can also do
downloadFile.DestinationPathName = cursor.GetString(cursor.GetColumnIndex("local_uri"));
instead of the if statement and line 70.
I get a file:// uri back when using a custom location, content:// for temp locations. What do you think?
There was a problem hiding this comment.
Oh and your comment had to be in the Mac file, didn't it? :P
There was a problem hiding this comment.
I thought the condition to be good to prevent triggering the change multiple times, but you've already done that in the IDownloadFile implementation...
There was a problem hiding this comment.
I think the new way you've added here, using cursor.GetString(cursor.GetColumnIndex("local_uri")) is the one which is best to use.
There was a problem hiding this comment.
Oh so that's what you meant. The setter checks if the value is the same as the new one, so pretty much I guess.
CHANGELOG.md
Outdated
| @@ -1,5 +1,9 @@ | |||
| ## Changes | |||
|
|
|||
| ### 1.3.7 | |||
There was a problem hiding this comment.
Please call it Unreleased for now. It will at least be 1.4.0 as this is a feature, but let's see what we'll get in at this version.
There was a problem hiding this comment.
Sure thing. Will you be releasing this as a preview, though? I want to be able to use this feature 😄
iOS: Set DestinationPathName after the file has moved. Android: Changed the way the file path is received. Changed version in changelog.
|
See last commit for the Code Review changes. Feel free to redo the review. Code quality first! |
|
Looks very good, Thanks! I'll have a look at what else I will take into this release and then push it out. Please bare with me if it takes a while since I'll be on holiday for 2 weeks from today on and this is a project purely developed in my spare-time 😊 |
|
Thank you. I understand. For now I'll just use my own DLLs and switch to the new NuGet release whenever you are ready. Have a great holiday! |
Ref #93