mirror of
https://github.com/antebudimir/tempus.git
synced 2026-04-15 16:27:26 +00:00
feat: Ability to toggle visibility of artist biography (#338)
This commit is contained in:
commit
5ef5731fe3
4 changed files with 68 additions and 15 deletions
|
|
@ -9,6 +9,8 @@ import android.util.Log;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
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.util.Constants;
|
||||
import com.cappielloantonio.tempo.util.MusicUtil;
|
||||
import com.cappielloantonio.tempo.util.Preferences;
|
||||
import com.cappielloantonio.tempo.viewmodel.ArtistPageViewModel;
|
||||
import com.cappielloantonio.tempo.viewmodel.PlaybackViewModel;
|
||||
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);
|
||||
favoriteToggle.setChecked(artistPageViewModel.getArtist().getStarred() != null);
|
||||
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() {
|
||||
|
|
@ -136,13 +143,6 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
|
|||
if (artistInfo == null) {
|
||||
if (bind != null) bind.artistPageBioSector.setVisibility(View.GONE);
|
||||
} 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) {
|
||||
ArtistID3 currentArtist = artistPageViewModel.getArtist();
|
||||
String primaryId = currentArtist.getCoverArtId() != null && !currentArtist.getCoverArtId().trim().isEmpty()
|
||||
|
|
@ -192,15 +192,43 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
|
|||
.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 -> {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(artistInfo.getLastFmUrl()));
|
||||
startActivity(intent);
|
||||
});
|
||||
if (normalizedBio.isEmpty()) {
|
||||
bind.bioTextView.setVisibility(View.GONE);
|
||||
} else {
|
||||
bind.bioTextView.setText(normalizedBio);
|
||||
}
|
||||
|
||||
if (bind != null) bind.artistPageBioSector.setVisibility(View.VISIBLE);
|
||||
if (lastFmUrl == null) {
|
||||
bind.bioMoreTextViewClickable.setVisibility(View.GONE);
|
||||
} else {
|
||||
bind.bioMoreTextViewClickable.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(artistInfo.getLastFmUrl()));
|
||||
startActivity(intent);
|
||||
});
|
||||
bind.bioMoreTextViewClickable.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ object Preferences {
|
|||
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 SORT_SEARCH_CHRONOLOGICALLY= "sort_search_chronologically"
|
||||
private const val ARTIST_DISPLAY_BIOGRAPHY= "artist_display_biography"
|
||||
|
||||
@JvmStatic
|
||||
fun getServer(): String? {
|
||||
|
|
@ -680,4 +681,14 @@ object Preferences {
|
|||
fun isSearchSortingChronologicallyEnabled(): Boolean {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
|
@ -124,6 +124,19 @@
|
|||
android:textOff=""
|
||||
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>
|
||||
|
||||
<View
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
<string name="artist_list_page_downloaded">Downloaded artists</string>
|
||||
<string name="artist_list_page_starred">Starred 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_shuffle_button">Shuffle</string>
|
||||
<string name="artist_page_switch_layout_button">Switch layout</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue