Make Songlist more beautiful

This commit is contained in:
sebastian 2024-11-01 17:29:11 +01:00
parent a7fcaa0ea7
commit c724905027
3 changed files with 84 additions and 11 deletions

View File

@ -15,6 +15,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
@ -53,6 +54,9 @@ public class HomeFragment extends Fragment {
recyclerView.setAdapter(noteSongAdapter); recyclerView.setAdapter(noteSongAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), LinearLayoutManager.VERTICAL);
recyclerView.addItemDecoration(dividerItemDecoration);
homeViewModel.getNoteTitles().observe(getViewLifecycleOwner(), songs -> { homeViewModel.getNoteTitles().observe(getViewLifecycleOwner(), songs -> {
noteSongAdapter.updateSongTitles(songs); noteSongAdapter.updateSongTitles(songs);
}); });

View File

@ -41,6 +41,8 @@ public class NoteSongAdapter extends RecyclerView.Adapter<NoteSongAdapter.NoteVi
@Override @Override
public void onBindViewHolder(@NonNull NoteViewHolder holder, int position) { public void onBindViewHolder(@NonNull NoteViewHolder holder, int position) {
holder.titleTextView.setText(noteTitles.get(position).getTitle()); holder.titleTextView.setText(noteTitles.get(position).getTitle());
holder.yearTextView.setText(String.valueOf(noteTitles.get(position).getYear()));
holder.compositionTextView.setText(noteTitles.get(position).getComposer());
} }
@Override @Override
@ -56,11 +58,14 @@ public class NoteSongAdapter extends RecyclerView.Adapter<NoteSongAdapter.NoteVi
public class NoteViewHolder extends RecyclerView.ViewHolder{ public class NoteViewHolder extends RecyclerView.ViewHolder{
TextView titleTextView; TextView titleTextView;
TextView yearTextView;
TextView compositionTextView;
NoteViewHolder(View itemView) { NoteViewHolder(View itemView) {
super(itemView); super(itemView);
titleTextView = itemView.findViewById(R.id.note_title); titleTextView = itemView.findViewById(R.id.text_title);
yearTextView = itemView.findViewById(R.id.text_year);
compositionTextView = itemView.findViewById(R.id.text_composition);
titleTextView.setOnClickListener(v -> { titleTextView.setOnClickListener(v -> {
int position = getAdapterPosition(); int position = getAdapterPosition();
if(position != RecyclerView.NO_POSITION) { if(position != RecyclerView.NO_POSITION) {

View File

@ -1,13 +1,77 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:orientation="vertical" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="16dp"> android:orientation="horizontal"
android:padding="8dp"
android:gravity="center_vertical">
<TextView <!-- Text Section -->
android:id="@+id/note_title" <LinearLayout
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="18sp" /> android:layout_weight="1"
android:orientation="vertical">
<!-- First Row: Year and Composition -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/text_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Year"
android:textSize="14sp"
android:textColor="@android:color/darker_gray" />
<TextView
android:id="@+id/text_composition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Composition"
android:textSize="14sp"
android:layout_marginStart="8dp"
android:textColor="@android:color/darker_gray" />
</LinearLayout>
<!-- Second Row: Title -->
<TextView
android:id="@+id/text_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="16sp"
android:textColor="@android:color/black"
android:paddingTop="4dp"/>
</LinearLayout>
<!-- Rechte Seite mit den Buttons -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/edit_concert_button"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/edit_24dp_e8eaed_fill0_wght400_grad0_opsz24"
app:tint="@color/teal_700"
android:contentDescription="Edit Concert"
android:background="?android:selectableItemBackgroundBorderless" />
<ImageButton
android:id="@+id/delete_concert_button"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/delete"
app:tint="@color/red"
android:contentDescription="Delete Concert"
android:background="?android:selectableItemBackgroundBorderless" />
</LinearLayout>
</LinearLayout> </LinearLayout>