From 6fa8c901fc222703689b50e62c48f102a23f4d22 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 7 Jan 2021 21:22:01 +0100 Subject: [PATCH] Decode the title of sources containing special html characters (#326) #325 --- .../java/apps/amine/bou/readerforselfoss/HomeActivity.kt | 2 +- .../bou/readerforselfoss/adapters/ItemCardAdapter.kt | 4 ++-- .../bou/readerforselfoss/adapters/ItemListAdapter.kt | 4 ++-- .../bou/readerforselfoss/adapters/SourcesListAdapter.kt | 6 +++--- .../bou/readerforselfoss/api/selfoss/SelfossModels.kt | 8 ++++++++ .../apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt | 2 +- .../readerforselfoss/utils/persistence/EntitiesUtils.kt | 4 ++-- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt index d6a053a..0e39688 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -604,7 +604,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { } else { for (tag in maybeSources) { val item = PrimaryDrawerItem() - .withName(tag.title) + .withName(tag.getTitleDecoded()) .withIdentifier(tag.id.toLong()) .withOnDrawerItemClickListener { _, _, _ -> allItems = ArrayList() diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt index aa431c8..4393993 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt @@ -90,13 +90,13 @@ class ItemCardAdapter( } if (itm.getIcon(c).isEmpty()) { - val color = generator.getColor(itm.sourcetitle) + val color = generator.getColor(itm.getSourceTitle()) val drawable = TextDrawable .builder() .round() - .build(itm.sourcetitle.toTextDrawableString(c), color) + .build(itm.getSourceTitle().toTextDrawableString(c), color) holder.mView.sourceImage.setImageDrawable(drawable) } else { c.circularBitmapDrawable(config, itm.getIcon(c), holder.mView.sourceImage) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt index 7f958c0..c2b0386 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt @@ -81,13 +81,13 @@ class ItemListAdapter( if (itm.getThumbnail(c).isEmpty()) { if (itm.getIcon(c).isEmpty()) { - val color = generator.getColor(itm.sourcetitle) + val color = generator.getColor(itm.getSourceTitle()) val drawable = TextDrawable .builder() .round() - .build(itm.sourcetitle.toTextDrawableString(c), color) + .build(itm.getSourceTitle().toTextDrawableString(c), color) holder.mView.itemImage.setImageDrawable(drawable) } else { diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt index 635bdd5..505ef32 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt @@ -46,19 +46,19 @@ class SourcesListAdapter( config = Config(c) if (itm.getIcon(c).isEmpty()) { - val color = generator.getColor(itm.title) + val color = generator.getColor(itm.getTitleDecoded()) val drawable = TextDrawable .builder() .round() - .build(itm.title.toTextDrawableString(c), color) + .build(itm.getTitleDecoded().toTextDrawableString(c), color) holder.mView.itemImage.setImageDrawable(drawable) } else { c.circularBitmapDrawable(config, itm.getIcon(c), holder.mView.itemImage) } - holder.mView.sourceTitle.text = itm.title + holder.mView.sourceTitle.text = itm.getTitleDecoded() } override fun getItemCount(): Int = items.size diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossModels.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossModels.kt index 516c78f..8a2399e 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossModels.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossModels.kt @@ -64,6 +64,10 @@ data class Source( } return constructUrl(config, "favicons", icon) } + + fun getTitleDecoded(): String { + return Html.fromHtml(title).toString() + } } data class Item( @@ -167,6 +171,10 @@ data class Item( return Html.fromHtml(title).toString() } + fun getSourceTitle(): String { + return Html.fromHtml(sourcetitle).toString() + } + // TODO: maybe find a better way to handle these kind of urls fun getLinkDecoded(): String { var stringUrl: String diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt index 3f3eac3..2f7c562 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt @@ -32,7 +32,7 @@ fun Item.sourceAndDateText(): String { "" } - return this.sourcetitle + formattedDate + return this.getSourceTitle() + formattedDate } fun Item.toggleStar(): Item { diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/persistence/EntitiesUtils.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/persistence/EntitiesUtils.kt index 7bd7aef..d9efb40 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/persistence/EntitiesUtils.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/persistence/EntitiesUtils.kt @@ -28,7 +28,7 @@ fun SourceEntity.toView(): Source = fun Source.toEntity(): SourceEntity = SourceEntity( this.id, - this.title, + this.getTitleDecoded(), this.tags.tags, this.spout, this.error, @@ -68,6 +68,6 @@ fun Item.toEntity(): ItemEntity = this.thumbnail, this.icon, this.link, - this.sourcetitle, + this.getSourceTitle(), this.tags.tags ) \ No newline at end of file