Merge pull request #3587 from ByteHamster/remove-commons-text
Removed commons text library that was just used 2 times
This commit is contained in:
commit
3c0489890c
|
@ -49,7 +49,6 @@ project.ext {
|
|||
awaitilityVersion = "3.1.6"
|
||||
commonsioVersion = "2.5"
|
||||
commonslangVersion = "3.6"
|
||||
commonstextVersion = "1.3"
|
||||
eventbusVersion = "3.1.1"
|
||||
glideVersion = "4.8.0"
|
||||
glideOkhttpIntegrationVersion = "4.8.0"
|
||||
|
|
|
@ -62,7 +62,6 @@ dependencies {
|
|||
implementation "android.arch.work:work-runtime:$workManagerVersion"
|
||||
implementation "androidx.media:media:1.1.0"
|
||||
implementation "org.apache.commons:commons-lang3:$commonslangVersion"
|
||||
implementation "org.apache.commons:commons-text:$commonstextVersion"
|
||||
implementation "commons-io:commons-io:$commonsioVersion"
|
||||
implementation "org.jsoup:jsoup:$jsoupVersion"
|
||||
implementation "com.github.bumptech.glide:glide:$glideVersion"
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package de.danoeh.antennapod.core.syndication.namespace.atom;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.runners.Parameterized.Parameter;
|
||||
import static org.junit.runners.Parameterized.Parameters;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit test for {@link AtomText}.
|
||||
*/
|
||||
@SmallTest
|
||||
@RunWith(Parameterized.class)
|
||||
public class AtomTextTest {
|
||||
|
||||
@Parameter(value = 0)
|
||||
public String input;
|
||||
|
||||
@Parameter(value = 1)
|
||||
public String expectedOutput;
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> initParameters() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{">", ">"},
|
||||
{">", ">"},
|
||||
{"<Français>", "<Français>"},
|
||||
{"ßÄÖÜ", "ßÄÖÜ"},
|
||||
{""", "\""},
|
||||
{"ß", "ß"},
|
||||
{"’", "’"},
|
||||
{"‰", "‰"},
|
||||
{"€", "€"},
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessingHtml() {
|
||||
final AtomText atomText = new AtomText("", new NSAtom(), AtomText.TYPE_HTML);
|
||||
atomText.setContent(input);
|
||||
assertEquals(expectedOutput, atomText.getProcessedContent());
|
||||
}
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
package de.danoeh.antennapod.core.syndication.namespace.atom;
|
||||
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.Html;
|
||||
import de.danoeh.antennapod.core.syndication.namespace.Namespace;
|
||||
import de.danoeh.antennapod.core.syndication.namespace.SyndElement;
|
||||
|
||||
/** Represents Atom Element which contains text (content, title, summary). */
|
||||
public class AtomText extends SyndElement {
|
||||
public static final String TYPE_TEXT = "text";
|
||||
private static final String TYPE_HTML = "html";
|
||||
public static final String TYPE_HTML = "html";
|
||||
private static final String TYPE_XHTML = "xhtml";
|
||||
|
||||
private final String type;
|
||||
|
@ -24,7 +24,11 @@ public class AtomText extends SyndElement {
|
|||
if (type == null) {
|
||||
return content;
|
||||
} else if (type.equals(TYPE_HTML)) {
|
||||
return StringEscapeUtils.unescapeHtml4(content);
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
return Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
} else {
|
||||
return Html.fromHtml(content).toString();
|
||||
}
|
||||
} else if (type.equals(TYPE_XHTML)) {
|
||||
return content;
|
||||
} else { // Handle as text by default
|
||||
|
|
|
@ -3,17 +3,16 @@ package de.danoeh.antennapod.core.util;
|
|||
import android.text.TextUtils;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.text.RandomStringGenerator;
|
||||
|
||||
|
||||
/** Generates valid filenames for a given string. */
|
||||
public class FileNameGenerator {
|
||||
|
||||
private static final char[] validChars = (
|
||||
"abcdefghijklmnopqrstuvwxyz" +
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
|
||||
"0123456789" +
|
||||
" _-").toCharArray();
|
||||
private static final char[] validChars =
|
||||
("abcdefghijklmnopqrstuvwxyz"
|
||||
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
+ "0123456789"
|
||||
+ " _-").toCharArray();
|
||||
|
||||
private FileNameGenerator() {
|
||||
}
|
||||
|
@ -26,7 +25,8 @@ public class FileNameGenerator {
|
|||
StringBuilder buf = new StringBuilder();
|
||||
for (int i = 0; i < string.length(); i++) {
|
||||
char c = string.charAt(i);
|
||||
if(Character.isSpaceChar(c) && (buf.length() == 0 || Character.isSpaceChar(buf.charAt(buf.length()-1)))) {
|
||||
if (Character.isSpaceChar(c)
|
||||
&& (buf.length() == 0 || Character.isSpaceChar(buf.charAt(buf.length() - 1)))) {
|
||||
continue;
|
||||
}
|
||||
if (ArrayUtils.contains(validChars, c)) {
|
||||
|
@ -34,14 +34,17 @@ public class FileNameGenerator {
|
|||
}
|
||||
}
|
||||
String filename = buf.toString().trim();
|
||||
if(TextUtils.isEmpty(filename)) {
|
||||
return new RandomStringGenerator.Builder()
|
||||
.withinRange('0', 'z')
|
||||
.filteredBy(Character::isLetterOrDigit)
|
||||
.build()
|
||||
.generate(8);
|
||||
if (TextUtils.isEmpty(filename)) {
|
||||
return randomString(8);
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
private static String randomString(int length) {
|
||||
StringBuilder sb = new StringBuilder(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
sb.append(validChars[(int) (Math.random() * validChars.length)]);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue