mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Removed featuring artists from the artist's name of downloaded item
This commit is contained in:
parent
ed4dc9fb63
commit
6e715d58a3
3 changed files with 25 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ import androidx.room.Entity;
|
||||||
import androidx.room.PrimaryKey;
|
import androidx.room.PrimaryKey;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.util.MusicUtil;
|
||||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||||
|
|
||||||
@Entity(tableName = "download")
|
@Entity(tableName = "download")
|
||||||
|
|
@ -57,7 +58,7 @@ public class Download {
|
||||||
this.albumId = song.getAlbumId();
|
this.albumId = song.getAlbumId();
|
||||||
this.albumName = song.getAlbumName();
|
this.albumName = song.getAlbumName();
|
||||||
this.artistId = song.getArtistId();
|
this.artistId = song.getArtistId();
|
||||||
this.artistName = song.getArtistName();
|
this.artistName = MusicUtil.normalizedArtistName(song.getArtistName());
|
||||||
this.primary = song.getPrimary();
|
this.primary = song.getPrimary();
|
||||||
this.duration = song.getDuration();
|
this.duration = song.getDuration();
|
||||||
this.server = PreferenceUtil.getInstance(App.getInstance()).getServerId();
|
this.server = PreferenceUtil.getInstance(App.getInstance()).getServerId();
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,16 @@ public class MusicUtil {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String normalizedArtistName(String string) {
|
||||||
|
if (string != null) {
|
||||||
|
if(string.toLowerCase().contains(" feat.")) return Pattern.compile(" feat.", Pattern.CASE_INSENSITIVE).split(string)[0].trim();
|
||||||
|
else if(string.toLowerCase().contains(" featuring")) return Pattern.compile(" featuring", Pattern.CASE_INSENSITIVE).split(string)[0].trim();
|
||||||
|
else return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> getReadableStrings(List<String> strings) {
|
public static List<String> getReadableStrings(List<String> strings) {
|
||||||
List<String> readableStrings = new ArrayList<>();
|
List<String> readableStrings = new ArrayList<>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,14 @@ import com.cappielloantonio.play.model.Album;
|
||||||
import com.cappielloantonio.play.model.Artist;
|
import com.cappielloantonio.play.model.Artist;
|
||||||
import com.cappielloantonio.play.model.Download;
|
import com.cappielloantonio.play.model.Download;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
|
||||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
|
||||||
import com.cappielloantonio.play.repository.DownloadRepository;
|
import com.cappielloantonio.play.repository.DownloadRepository;
|
||||||
import com.cappielloantonio.play.repository.SongRepository;
|
|
||||||
import com.cappielloantonio.play.util.MappingUtil;
|
import com.cappielloantonio.play.util.MappingUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DownloadViewModel extends AndroidViewModel {
|
public class DownloadViewModel extends AndroidViewModel {
|
||||||
private static final String TAG = "HomeViewModel";
|
private static final String TAG = "HomeViewModel";
|
||||||
|
|
@ -36,7 +37,15 @@ public class DownloadViewModel extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Artist>> getDownloadedArtists(LifecycleOwner owner, int size) {
|
public LiveData<List<Artist>> getDownloadedArtists(LifecycleOwner owner, int size) {
|
||||||
downloadRepository.getLiveDownloadSample(size).observe(owner, downloads -> downloadedArtistSample.postValue(MappingUtil.mapDownloadToArtist(downloads)));
|
downloadRepository.getLiveDownloadSample(size).observe(owner, downloads -> {
|
||||||
|
List<Download> unique = downloads
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.collectingAndThen(
|
||||||
|
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Download::getArtistName))), ArrayList::new)
|
||||||
|
);
|
||||||
|
|
||||||
|
downloadedArtistSample.postValue(MappingUtil.mapDownloadToArtist(unique));
|
||||||
|
});
|
||||||
return downloadedArtistSample;
|
return downloadedArtistSample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue