feat: Ability to toggle visibility of artist biography (#338)

This commit is contained in:
eddyizm 2026-01-08 21:25:54 -08:00 committed by GitHub
commit 5ef5731fe3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 68 additions and 15 deletions

View file

@ -9,6 +9,8 @@ import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import android.widget.ToggleButton; import android.widget.ToggleButton;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -39,6 +41,7 @@ import com.cappielloantonio.tempo.ui.adapter.ArtistCatalogueAdapter;
import com.cappielloantonio.tempo.ui.adapter.SongHorizontalAdapter; import com.cappielloantonio.tempo.ui.adapter.SongHorizontalAdapter;
import com.cappielloantonio.tempo.util.Constants; import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.MusicUtil; import com.cappielloantonio.tempo.util.MusicUtil;
import com.cappielloantonio.tempo.util.Preferences;
import com.cappielloantonio.tempo.viewmodel.ArtistPageViewModel; import com.cappielloantonio.tempo.viewmodel.ArtistPageViewModel;
import com.cappielloantonio.tempo.viewmodel.PlaybackViewModel; import com.cappielloantonio.tempo.viewmodel.PlaybackViewModel;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -119,6 +122,10 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
ToggleButton favoriteToggle = view.findViewById(R.id.button_favorite); ToggleButton favoriteToggle = view.findViewById(R.id.button_favorite);
favoriteToggle.setChecked(artistPageViewModel.getArtist().getStarred() != null); favoriteToggle.setChecked(artistPageViewModel.getArtist().getStarred() != null);
favoriteToggle.setOnClickListener(v -> artistPageViewModel.setFavorite(requireContext())); favoriteToggle.setOnClickListener(v -> artistPageViewModel.setFavorite(requireContext()));
Button bioToggle = view.findViewById(R.id.button_toggle_bio);
bioToggle.setOnClickListener(v ->
Toast.makeText(getActivity(), R.string.artist_no_artist_info_toast, Toast.LENGTH_SHORT).show());
} }
private void initAppBar() { private void initAppBar() {
@ -136,13 +143,6 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
if (artistInfo == null) { if (artistInfo == null) {
if (bind != null) bind.artistPageBioSector.setVisibility(View.GONE); if (bind != null) bind.artistPageBioSector.setVisibility(View.GONE);
} else { } else {
String normalizedBio = MusicUtil.forceReadableString(artistInfo.getBiography());
if (bind != null)
bind.artistPageBioSector.setVisibility(!normalizedBio.trim().isEmpty() ? View.VISIBLE : View.GONE);
if (bind != null)
bind.bioMoreTextViewClickable.setVisibility(artistInfo.getLastFmUrl() != null ? View.VISIBLE : View.GONE);
if (getContext() != null && bind != null) { if (getContext() != null && bind != null) {
ArtistID3 currentArtist = artistPageViewModel.getArtist(); ArtistID3 currentArtist = artistPageViewModel.getArtist();
String primaryId = currentArtist.getCoverArtId() != null && !currentArtist.getCoverArtId().trim().isEmpty() String primaryId = currentArtist.getCoverArtId() != null && !currentArtist.getCoverArtId().trim().isEmpty()
@ -192,15 +192,43 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
.into(bind.artistBackdropImageView); .into(bind.artistBackdropImageView);
} }
if (bind != null) bind.bioTextView.setText(normalizedBio); if (bind != null) {
String normalizedBio = MusicUtil.forceReadableString(artistInfo.getBiography()).trim();
String lastFmUrl = artistInfo.getLastFmUrl();
if (bind != null) bind.bioMoreTextViewClickable.setOnClickListener(v -> { if (normalizedBio.isEmpty()) {
bind.bioTextView.setVisibility(View.GONE);
} else {
bind.bioTextView.setText(normalizedBio);
}
if (lastFmUrl == null) {
bind.bioMoreTextViewClickable.setVisibility(View.GONE);
} else {
bind.bioMoreTextViewClickable.setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(artistInfo.getLastFmUrl())); intent.setData(Uri.parse(artistInfo.getLastFmUrl()));
startActivity(intent); startActivity(intent);
}); });
bind.bioMoreTextViewClickable.setVisibility(View.VISIBLE);
}
if (bind != null) bind.artistPageBioSector.setVisibility(View.VISIBLE); if (!normalizedBio.isEmpty() || lastFmUrl != null) {
View view = bind.getRoot();
Button bioToggle = view.findViewById(R.id.button_toggle_bio);
bioToggle.setOnClickListener(v -> {
if (bind != null) {
boolean displayBio = Preferences.getArtistDisplayBiography();
Preferences.setArtistDisplayBiography(!displayBio);
bind.artistPageBioSector.setVisibility(displayBio ? View.GONE : View.VISIBLE);
}
});
boolean displayBio = Preferences.getArtistDisplayBiography();
bind.artistPageBioSector.setVisibility(displayBio ? View.VISIBLE : View.GONE);
}
}
} }
}); });
} }

View file

@ -82,6 +82,7 @@ object Preferences {
private const val DEFAULT_ALBUM_SORT_ORDER = Constants.ALBUM_ORDER_BY_NAME private const val DEFAULT_ALBUM_SORT_ORDER = Constants.ALBUM_ORDER_BY_NAME
private const val ARTIST_SORT_BY_ALBUM_COUNT= "artist_sort_by_album_count" private const val ARTIST_SORT_BY_ALBUM_COUNT= "artist_sort_by_album_count"
private const val SORT_SEARCH_CHRONOLOGICALLY= "sort_search_chronologically" private const val SORT_SEARCH_CHRONOLOGICALLY= "sort_search_chronologically"
private const val ARTIST_DISPLAY_BIOGRAPHY= "artist_display_biography"
@JvmStatic @JvmStatic
fun getServer(): String? { fun getServer(): String? {
@ -680,4 +681,14 @@ object Preferences {
fun isSearchSortingChronologicallyEnabled(): Boolean { fun isSearchSortingChronologicallyEnabled(): Boolean {
return App.getInstance().preferences.getBoolean(SORT_SEARCH_CHRONOLOGICALLY, false) return App.getInstance().preferences.getBoolean(SORT_SEARCH_CHRONOLOGICALLY, false)
} }
@JvmStatic
fun getArtistDisplayBiography(): Boolean {
return App.getInstance().preferences.getBoolean(ARTIST_DISPLAY_BIOGRAPHY, true)
}
@JvmStatic
fun setArtistDisplayBiography(displayBiographyEnabled: Boolean) {
App.getInstance().preferences.edit().putBoolean(ARTIST_DISPLAY_BIOGRAPHY, displayBiographyEnabled).apply()
}
} }

View file

@ -124,6 +124,19 @@
android:textOff="" android:textOff=""
android:textOn="" /> android:textOn="" />
<Button
android:id="@+id/button_toggle_bio"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="0dp"
android:background="@drawable/ic_info_stream"
android:foreground="?android:attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:text=""
android:textOff=""
android:textOn="" />
</LinearLayout> </LinearLayout>
<View <View

View file

@ -39,6 +39,7 @@
<string name="artist_list_page_downloaded">Downloaded artists</string> <string name="artist_list_page_downloaded">Downloaded artists</string>
<string name="artist_list_page_starred">Starred artists</string> <string name="artist_list_page_starred">Starred artists</string>
<string name="artist_list_page_title">Artists</string> <string name="artist_list_page_title">Artists</string>
<string name="artist_no_artist_info_toast">No additional artist info</string>
<string name="artist_page_radio_button">Radio</string> <string name="artist_page_radio_button">Radio</string>
<string name="artist_page_shuffle_button">Shuffle</string> <string name="artist_page_shuffle_button">Shuffle</string>
<string name="artist_page_switch_layout_button">Switch layout</string> <string name="artist_page_switch_layout_button">Switch layout</string>