Move cleanText method to api package

This commit is contained in:
Shinokuni 2020-09-13 12:38:51 +02:00
parent 8e5900833b
commit 15e1723893
6 changed files with 27 additions and 28 deletions

View File

@ -23,7 +23,7 @@ class RSSItemsAdapter : XmlAdapter<List<Item>> {
val item = Item().apply {
allChildrenAutoIgnore(names) {
when (tagName) {
"title" -> title = nonNullText()
"title" -> title = LibUtils.cleanText(nonNullText())
"link" -> link = nonNullText()
"author" -> author = nullableText()
"dc:creator" -> creators += nullableText()

View File

@ -6,6 +6,8 @@ import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.jsoup.Jsoup;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Scanner;
@ -61,4 +63,14 @@ public final class LibUtils {
return null;
}
}
/**
* Remove html tags and trim the text
*
* @param text string to clean
* @return cleaned text
*/
public static String cleanText(String text) {
return Jsoup.parse(text).text().trim();
}
}

View File

@ -16,4 +16,10 @@ class LibUtilsTest {
assertEquals(LibUtils.parseContentType("text/xml"),
"text/xml")
}
@Test
fun cleanTextTest() {
val text = " <p>This is a text<br/>to</p> clean "
assertEquals("This is a text to clean", LibUtils.cleanText(text))
}
}

View File

@ -17,8 +17,6 @@ import androidx.annotation.NonNull;
import com.google.android.material.snackbar.Snackbar;
import com.readrops.api.utils.HttpManager;
import org.jsoup.Jsoup;
import java.io.InputStream;
import java.util.Locale;
@ -97,16 +95,6 @@ public final class Utils {
snackbar.show();
}
/**
* Remove html tags and trim the text
*
* @param text string to clean
* @return cleaned text
*/
public static String cleanText(String text) {
return Jsoup.parse(text).text().trim();
}
public static Bitmap getBitmapFromDrawable(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);

View File

@ -1,15 +1,16 @@
package com.readrops.app.utils.matchers;
import com.readrops.api.utils.DateUtils;
import com.readrops.app.utils.Utils;
import com.readrops.db.entities.Feed;
import com.readrops.db.entities.Item;
import com.readrops.api.localfeed.atom.ATOMEntry;
import com.readrops.api.localfeed.json.JSONItem;
import com.readrops.api.localfeed.rss.RSSEnclosure;
import com.readrops.api.localfeed.rss.RSSItem;
import com.readrops.api.localfeed.rss.RSSMediaContent;
import com.readrops.api.utils.DateUtils;
import com.readrops.api.utils.LibUtils;
import com.readrops.api.utils.ParseException;
import com.readrops.app.utils.Utils;
import com.readrops.db.entities.Feed;
import com.readrops.db.entities.Item;
import java.util.ArrayList;
import java.util.List;
@ -26,7 +27,7 @@ public final class ItemMatcher {
newItem.setContent(item.getContent()); // Jsoup.clean(item.getContent(), Whitelist.relaxed())
newItem.setDescription(item.getDescription());
newItem.setGuid(item.getGuid() != null ? item.getGuid() : item.getLink());
newItem.setTitle(Utils.cleanText(item.getTitle()));
newItem.setTitle(LibUtils.cleanText(item.getTitle()));
try {
newItem.setPubDate(DateUtils.stringToLocalDateTime(item.getDate()));
@ -72,7 +73,7 @@ public final class ItemMatcher {
dbItem.setContent(item.getContent()); // Jsoup.clean(item.getContent(), Whitelist.relaxed())
dbItem.setDescription(item.getSummary());
dbItem.setGuid(item.getId());
dbItem.setTitle(Utils.cleanText(item.getTitle()));
dbItem.setTitle(LibUtils.cleanText(item.getTitle()));
try {
dbItem.setPubDate(DateUtils.stringToLocalDateTime(item.getUpdated()));
@ -102,7 +103,7 @@ public final class ItemMatcher {
dbItem.setContent(item.getContent()); // Jsoup.clean(item.getContent(), Whitelist.relaxed())
dbItem.setDescription(item.getSummary());
dbItem.setGuid(item.getId());
dbItem.setTitle(Utils.cleanText(item.getTitle()));
dbItem.setTitle(LibUtils.cleanText(item.getTitle()));
try {
dbItem.setPubDate(DateUtils.stringToLocalDateTime(item.getPubDate()));

View File

@ -7,17 +7,9 @@ import com.readrops.app.utils.Utils;
import org.junit.Test;
import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;
public class UtilsTest {
@Test
public void cleanTextTest() {
String text = " <p>This is a text<br/>to</p> clean ";
assertEquals("This is a text to clean", Utils.cleanText(text));
}
@Test
public void colorTooBrightTest() {
assertTrue(Utils.isColorTooBright(-986896));