Skip to content

Text file preview - #707

Closed
stoyicker wants to merge 39 commits into
owncloud:developfrom
owncloudChalmers:us4_view_text_files
Closed

stoyicker wants to merge 39 commits into
owncloud:developfrom
owncloudChalmers:us4_view_text_files

Conversation

@stoyicker

Copy link
Copy Markdown
Contributor

This PR adds support for previewing text files.

Depends on #661.

…roid into us4_view_text_files

Conflicts:
	src/com/owncloud/android/datamodel/OCFile.java
	src/com/owncloud/android/ui/activity/FileDisplayActivity.java
Comment thread SETUP.md Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You are overwriting this SETUP.md (from Oct 12) with an old version! Did you merge develop into your branch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is an issue coming from #661 rather. We're looking into it.

Edit1: We have merged develop and reapplied the commit on #661. We'll be updating this and other PRs depending on #661 during these days.

Edit2: Solved.

@davivel davivel added this to the 1.8-current milestone Jul 22, 2015
@masensio

masensio commented Aug 6, 2015

Copy link
Copy Markdown

This PR has a lot of conflicts because the branch is outdated. It should be necessary to updated with the last version of the develop branch.
@stoyicker, no worries I've created the branch text_file_preview_pr_707_with_develop for testing.
@purigarcia the branch text_file_preview_pr_707_with_developis ready to be test. :)

@purigarcia

Copy link
Copy Markdown
Contributor

There is a bug when you rotate the device
STEPS TO REPRODUCE IT

  1. Download a txt file
  2. once it is downloaded and file is previewed, change the orientation of the device

CURRENT BEHAVIOR
-- Loading is shown and it is there forever. You need to kill the app to keep on using it

  • EXPECTED BEHAVIOR
    -- Loading is not there forever.
  • DEVICE
    -- It has been checked in Nexus 5 v.5.0.1 and Samsung Galaxy s3 v.4.1.2

@stoyicker could you take a look? thank you

@stoyicker

Copy link
Copy Markdown
Contributor Author

@purigarcia can't replicate on real Nexus 4, nor Nexus 5, Galaxy S3 and Galaxy S5 emulators (everything I've tried so far). Can you share the exact file you are able to trigger the issue with?

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

I could replicate it with a nexus 5 emulator:
download file, after that it shows text file content, after that ctrl + f12, modal "wait a moment" appears.

Text file is 0.txt with only content "laptop".

@purigarcia

Copy link
Copy Markdown
Contributor

@stoyicker , I have updated the steps indicating the you should be seen the preview of the file.
I reproduce it with a txt created from the web with a word, for instance

@stoyicker

Copy link
Copy Markdown
Contributor Author

Are you testing this branch or text_file_preview_pr_707_with develop?

@purigarcia

Copy link
Copy Markdown
Contributor

I am testing text_file_preview_pr_707_with develop
Because it is up to date.

@purigarcia

Copy link
Copy Markdown
Contributor

Maybe the bug is affected with new code, but we should fix it anyway.
Thank for the effort

@stoyicker

Copy link
Copy Markdown
Contributor Author

It has to be that. My attempts have been with us4_view_text_files and the bug is not there.

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

I have fixed the bug.
The main problem was that the "wait a moment" dialog was added twice, instead of just being shown the second time.
And as there were existing two dialogs, but only one was removed, the other still blocked the UI.

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

I have pushed the fix to text_file_preview_pr_707_with develop

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

I think this one can be closed and therefore I open a PR for the new branch.
If I am wrong, please revert.

@purigarcia

Copy link
Copy Markdown
Contributor

Great, @tobiasKaminsky !
I think pushing the fix to branch ext_file_preview_pr_707_with develop is correct.
But I am not sure if this pr should be closed. @davivel ?

@davivel

davivel commented Aug 14, 2015

Copy link
Copy Markdown
Contributor

It's OK. History is kept, and a single PR for a single feature.

Let's follow the work in #1095 .

Thanks to everybody.

@purigarcia

Copy link
Copy Markdown
Contributor

I find another issue

_rtf files are not been shown correctly_

  • STEPS TO REPRODUCE IT
  • select to download a .rtf
  • CURRENT BEHAVIOR
    -- It is seen with a lot of strange characters
  • EXPECTED BEHAVIOR
    -- Try to showing it correctly and if it is not possible, not preview it
  • DEVICE
    -- It has been checked in Nexus 5 v.5.0.1

@stoyicker ,@tobiasKaminsky could any of you take a look of it? Thanks

@stoyicker

Copy link
Copy Markdown
Contributor Author

RTF is a proprietary format by Microsoft that describes a file that contains information which is not plain text. I don't know if it is possible to properly read the file (the results would probably be something similar to what you get when you open a .docx file with LibreOffice), but even if it is, the effort and the likely overhead added to the app just for this is huge, and makes the feature completely infeasible in my opinion.

The fact that the file attempts to be previewed is just because the interpretation of its type depends on its mime type, and this is defined by ownCloud, not in the PR.

Note how the same problem occurs with non-text files. For example, take this PSD file and upload it to your server, then open the app and, when it's synced, download it. You'll see how it tries to show the preview, because of the recognized mime type, but is unable to do so because the format is not "understandable" and shows an error instead.

In conclusion, this is a "problem" of the policy on how you identify file types, not preview text files itself. Furthermore, and since there is always the option of opening the file with an external app (Word or Photoshop for example in the described cases) I would not even identify it as a problem. Mime types are a more reliable way to identify a file type than extension parsing as extensions can easily be edited.

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

Yeah.
I would also disable it for RTF and show preview just for plain txt files.
Should we?

@stoyicker

Copy link
Copy Markdown
Contributor Author

I would say that's inconsistent in practice. In the case that you want to reliably identify RTF files you would probably need to look for certain bytes that show that structure; otherwise you could be facing, for example, a plain text file that got its extension manually changed to .rtf, and although since it is a plain text file it should be previewable, the .rtf extension would filter it out. And, even if the filtering is applied, what happens then with .doc, .docx, .odt, etc? I say let's not touch it.

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

According to http://www.sitepoint.com/web-foundations/mime-types-complete-list/
the mimetypes should be different:
txt -> text/plain
rtf -> text/richtext

So this should work.

Of course there is still the function mimetypeByName which should be dropped for the reason you mentioned.

@stoyicker

Copy link
Copy Markdown
Contributor Author

The point is it is precisely because of that it doesn't work. The filtering method implemented in OCFile only cares about the file being text, and not whether it is or not plain, which causes the issue here.
Even if we drop getMimeTypeByName for this functionality and decide to make a different implementation for it, we would have to consider all 99 text mimetypes, and the criteria to identify supported ones would probably end up being rather floffy (for example, HTML files can be displayed as source, but does the user expect them to be interpreted instead? It's the same problem that with RTFs). For this I believe the current approach serves as a good-enough solution. Let's also not forget that this mimetype identification was already being used before this PR, so it is not like sticking to it is bad as long as it continues to be good enough for the purposes that it was being used before, whichever they were.

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

Hmm. Maybe I am not understanding you correctly.
My idea was to use the text preview only for mimetype "text/plain".
What are you suggesting? Keep it the way it is currently and displaying even rtfs as "corrupted" preview?

@stoyicker

Copy link
Copy Markdown
Contributor Author

In summary, I strongly want to keep the "corrupted" preview. I'll use an example to try to better explain why. Think of your suggestion: let's imagine that we decide that this functionality only applies to purely plain text files. This is already arguable by the fact that a user downloading, let's say, an HTML (text/html) file, probably expects to be able to see the contents, but instead the functionality would not support it. But even if we decide to go through all 99 text/something types and filter in those that are properly readable even if not typed as plain, like text/html, this is inconsistent with the current behaviour of the app.
Take a look at the image previewing procedure: it should be pretty similar (actually the text preview is designed in strict accordance with it). Any file that is considered an image by the app - like, for example, PSD files - will be attempted to preview. However, trying to preview a PSD will result in an "improper" preview. Therefore, the same should apply to other types of previews.
Making a proper fix for this is, in my opinion, an application-level issue, that is independent of this PR; this is, filtering only concrete, fully-qualified mimetypes in all UCs where a file type needs to be identified, this is, by rewriting the is*() methods in OCFile. If this is not seen as an independent problem and we decide to fix it here instead, the behaviour will not beg consistent with other previews.

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

Ok. thanks for your very detailed explanation.
To compare it with a "normal" computer: it is like we open all text files with notepad/kwrite/etc.
A normal user should also know that this is not meaningful in every situation.

This is fine for me.

@davivel

davivel commented Aug 19, 2015

Copy link
Copy Markdown
Contributor

I'm sorry, @stoyicker, but I disagree.

I love consistency in code, but it cannot be more important than providing the user with a right functionality. I cannot imagine a situation where rendering the non-printable characters of an RTF file is a nice result for a regular user.

I agree that trying to render RTF correctly is too hard with our resources and current knowledge. Too much for this PR, that brings a very valuable functionality and doesn't need to increase its scope due to problems found in QA. Due to this, the best decision to take is not rendering the file. The user will be able to open it with other apps installed in the device, as for any other file that the OC app is not able to preview (that are a lot).

The filtering method implemented in OCFile only cares about the file being text

Sorry, but that's not the filtering method, it's a (helper) method about a property of the file. The filtering method is

https://github.com/owncloud/android/pull/1095/files#diff-d2ee4c2ecc1b4aee74165cb73d21bbcdR391

, that may be as complex as necessary.

So, please, let's change this before merging. It's the last pending point, if I'm not wrong.

Thanks.

@stoyicker

Copy link
Copy Markdown
Contributor Author

Sure, will get into it later.

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.

8 participants