Skip to content

Conversation

@CDRussell
Copy link
Member

@CDRussell CDRussell commented Feb 6, 2018

Asana Issue URL: https://app.asana.com/0/414730916066338/538612605030335

Description

Add ability to long press on an image in a WebView and see a context menu allowing for the image to be downloaded

Note, images won't be able to be downloaded from DDG SERP yet due to an ongoing issue there.

Steps to Test this PR:

  1. Visit a site which contains images, such as http://www.bbc.co.uk/news/business-42957834
  2. Check that you can long press on an image (such as the FTSE 100 chart 📉) and see an option to download the image. Do so.
  3. Verify you are prompted for the runtime permission for writing to storage.
  4. Deny the permission, and ensure the app handles it gracefully enough.
  5. Try again, this time grant the permission, and ensure the image downloads successfully.
  6. Check that you cannot long press on the video on the page.
  7. Check that you can long press on the BBC icon (very top left of the page) and that you can download this image - this is a different type of image from the FTSE chart but both should download successfully.
  8. Also, check an image from theguardian.com as these images were previously not being named sensibly - it should name them sensibly now.

From here, it would be wise to revoke the storage permission, and test that PDFs still download successfully (using espc.com for instance, and clicking on a property, and then "schedule" to trigger a PDF download)

@CDRussell CDRussell requested a review from subsymbolic February 6, 2018 10:57
Copy link
Contributor

@subsymbolic subsymbolic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, I really like the long press menu.

A couple of requests
• Can we update the pdf download to also be a long press menu operation for consistency?
• Can we give the images better names? I am seeing 'downloadfile.bin' for all of them

override fun onContextItemSelected(item: MenuItem): Boolean {
webView.hitTestResult?.let {
var url = it.extra
if(viewModel.userSelectedItemFromLongPressMenu(url, item)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up formatting

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What site/image are you seeing that's giving you downloadfile.bin? I'm seeing sensible filenames by default when I'm testing.

screen shot 2018-02-07 at 09 41 57

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had tried a few images on espc.com and the guardian.co.uk and they are all downloadfile.bin in our app but fine in Chrome. I just tried bbc and that looks good in our app too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; will investigate

}

fun userLongPressedInWebView(target: WebView.HitTestResult, menu: ContextMenu) {
Timber.i("Long pressed on %s, (extra=%s)", target.type, target.extra)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use kotlin style strings? It is the project standard and I'd rather not mix styles. I know it's slightly less efficient but on the upside they are more readable and if efficiency becomes an issue we can fix it with some proguard config.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed other instances of the Timber style in favour of the Kotlin style too.

@CDRussell
Copy link
Member Author

Can we update the pdf download to also be a long press menu operation for consistency?

I'm not sure if we can? it looks like the PDF download is a more integral action whereby the WebView just tells us it can't handle some content; i don't see a way to hook into that.

We could perhaps start whitelisting types we suspect the browser can't handle (and PDF would be one) and handle that in a special way, but seems like a bigger thing than should be done in this task.

@subsymbolic
Copy link
Contributor

subsymbolic commented Feb 7, 2018

I'm not sure if we can? it looks like the PDF download is a more integral action

It was just a thought, I should have marked it as optional as it really goes beyond the scope of this task.

@CDRussell
Copy link
Member Author

CDRussell commented Feb 7, 2018

@subsymbolic I've added code to save the images to "public external storage directory" so that it will outlive the system's download cache as well as attempting to name the files better. Doing so requires the runtime permission for WRITE_EXTERNAL_STORAGE so that's also included.

Re-review please

Copy link
Contributor

@subsymbolic subsymbolic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

@CDRussell CDRussell merged commit 11fd7e4 into develop Feb 7, 2018
@CDRussell CDRussell deleted the feature/image_downloading branch February 7, 2018 17:17
aitorvs pushed a commit that referenced this pull request Nov 18, 2021
…rom DB (#179)

Co-authored-by: Craig Russell <CDRussell@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants