-
Notifications
You must be signed in to change notification settings - Fork 145
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
Using System.getProperty("line.separator") instead of '\n' and adding pre-caching of licenses text #35
Conversation
@@ -64,9 +64,10 @@ protected String getContent(final Context context, final int contentResourceId) | |||
|
|||
private String toString(final BufferedReader reader) throws IOException { | |||
final StringBuilder builder = new StringBuilder(); | |||
String lineSeparator = System.getProperty("line.separator"); |
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.
Make that a constant
Thank you for your contribution. Could you please take a look at my comments and fix them? Also, I feel like the caching mechanism produces a lot of duplicate code, maybe you could move it to the base class? |
Sure, I'll add the changes. I was not sure about adding the cached Strings to the License class in case you wanted to keep it implementation-independent. But if you don't mind, I'll try to pull the cache code to the parent License class |
That would be better I think :) |
Done. Could you review my changes? I had to rename some methods in the license subclasses in order to maintain compatibility with the previously existing ones in the License base class. |
Done, just three little things and then it's good to go. |
…ext re-defined to be final in order to prevent overriding
Using System.getProperty("line.separator") instead of '\n' and adding pre-caching of licenses text
Good, that was a pretty fast PR :) |
Yep, holiday here ;) |
In some Android versions using '\n' does not lead to a new line on TextViews. Instead, the standard System.getProperty("line.separator") must be used. This was affecting licenses text, since the method for reading them was adding '\n' characters that were not being shown in the licenses dialog (see the following image from a screenshot on a Nexus 5 running Android 4.4.4)
Also, when a license's text was requested, either by using 'getSummaryText' or 'getFullText', a fresh new read from the raw resource was performed. This can slow down the dialog when multiple instances of the same license are used, which is quite common (most licenses on our projects are apache 2.0). I added some changes to read the raw resource once and store the resulting String, so subsequent calls to the previous methods would return the cached String.