mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Force replace html dirty text from biography
This commit is contained in:
parent
522323073a
commit
0edd09569e
4 changed files with 38 additions and 20 deletions
|
|
@ -34,6 +34,7 @@ public class Artist implements Parcelable {
|
|||
public boolean favorite;
|
||||
public String bio;
|
||||
public String imageUrl;
|
||||
public String lastfm;
|
||||
|
||||
public Artist(ArtistID3 artistID3) {
|
||||
this.id = artistID3.getId();
|
||||
|
|
@ -67,6 +68,7 @@ public class Artist implements Parcelable {
|
|||
this.similarArtists = MappingUtil.mapSimilarArtist(artistInfo2.getSimilarArtists());
|
||||
this.bio = artistInfo2.getBiography();
|
||||
this.imageUrl = artistInfo2.getLargeImageUrl();
|
||||
this.lastfm = artistInfo2.getLastFmUrl();
|
||||
}
|
||||
|
||||
public Artist(String id, String name) {
|
||||
|
|
@ -170,6 +172,14 @@ public class Artist implements Parcelable {
|
|||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public String getLastfm() {
|
||||
return lastfm;
|
||||
}
|
||||
|
||||
public void setLastfm(String lastfm) {
|
||||
this.lastfm = lastfm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package com.cappielloantonio.play.ui.fragment;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.graphics.BlendMode;
|
||||
import android.graphics.BlendModeColorFilter;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
|
|
@ -110,13 +112,23 @@ public class ArtistPageFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void initArtistInfo() {
|
||||
|
||||
artistPageViewModel.getArtistInfo(artistPageViewModel.getArtist().getId()).observe(requireActivity(), artist -> {
|
||||
if (bind != null) bind.artistPageBioSector.setVisibility(artist.getBio() != null ? View.VISIBLE : View.GONE);
|
||||
if (bind != null) bind.bioMoreTextViewClickable.setVisibility(artist.getLastfm() != null ? View.VISIBLE : View.GONE);
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(requireContext(), null, CustomGlideRequest.ARTIST_PIC, artist.getImageUrl())
|
||||
.build()
|
||||
.into(bind.artistBackdropImageView);
|
||||
|
||||
bind.bioTextView.setText(MusicUtil.HTMLParser(artist.getBio()));
|
||||
bind.bioTextView.setText(MusicUtil.forceReadableString(artist.getBio()));
|
||||
|
||||
bind.bioMoreTextViewClickable.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(artist.getLastfm()));
|
||||
startActivity(intent);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.cappielloantonio.play.model.Song;
|
|||
import com.google.android.exoplayer2.MediaItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
|
@ -61,6 +62,17 @@ public class MusicUtil {
|
|||
return "";
|
||||
}
|
||||
|
||||
public static String forceReadableString(String string) {
|
||||
if (string != null) {
|
||||
return getReadableString(string)
|
||||
.replaceAll(""", "\"")
|
||||
.replaceAll("'", "'")
|
||||
.replaceAll("<a[\\s]+([^>]+)>((?:.(?!</a>))*.)</a>", "");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static List<String> getReadableStrings(List<String> strings) {
|
||||
List<String> readableStrings = new ArrayList<>();
|
||||
|
||||
|
|
@ -93,21 +105,4 @@ public class MusicUtil {
|
|||
String uri = MusicUtil.getSongFileUri(song);
|
||||
return MediaItem.fromUri(uri);
|
||||
}
|
||||
|
||||
public static CharSequence HTMLParser(String toParse) {
|
||||
if (toParse != null && containsHTML(toParse)) {
|
||||
return Html.fromHtml(toParse, Html.FROM_HTML_MODE_LEGACY);
|
||||
}
|
||||
else {
|
||||
return toParse;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean containsHTML(String toParse) {
|
||||
String HTML_PATTERN = "<(\"[^\"]*\"|'[^']*'|[^'\">])*>";
|
||||
Pattern pattern = Pattern.compile(HTML_PATTERN);
|
||||
|
||||
Matcher matcher = pattern.matcher(toParse);
|
||||
return matcher.find();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@
|
|||
android:layout_weight="1"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="Bio" />
|
||||
android:text="Biography" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bio_more_text_view_clickable"
|
||||
|
|
@ -152,7 +152,8 @@
|
|||
android:layout_height="match_parent"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="More" />
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Label and button -->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue