Show Concerts

This commit is contained in:
sebastian 2024-11-01 10:37:57 +01:00
parent 395a374ac9
commit b62ea3bc91
5 changed files with 114 additions and 12 deletions

View File

@ -23,4 +23,7 @@ public interface MusicNoteDAO {
@Insert
void insertConcert(Concert concert);
@Query("SELECT * FROM concerts")
List<Concert> getAllConcerts();
}

View File

@ -0,0 +1,63 @@
package core.notevault.ui.gallery;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import core.notevault.R;
import core.notevault.data.Concert;
import core.notevault.ui.home.NoteSongAdapter;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class ConcertAdapter extends RecyclerView.Adapter<ConcertAdapter.ConcertViewHolder> {
private final List<Concert> concertList;
public ConcertAdapter(List<Concert> concertList) {
this.concertList = concertList;
}
public ConcertAdapter() {
this.concertList = new ArrayList<>();
}
@Override
public void onBindViewHolder(@NonNull ConcertViewHolder holder, int position) {
holder.concertTitleView.setText(concertList.get(position).getTitle());
}
@Override
public int getItemCount() {
return concertList.size();
}
@NonNull
@Override
public ConcertViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.concert_item, parent, false);
return new ConcertViewHolder(view);
}
public void updateConcerts(List<Concert> concerts) {
this.concertList.clear();
this.concertList.addAll(concerts);
notifyDataSetChanged();
}
public class ConcertViewHolder extends RecyclerView.ViewHolder {
TextView concertTitleView;
public ConcertViewHolder(@NonNull @NotNull View itemView) {
super(itemView);
concertTitleView = itemView.findViewById(R.id.concert_title);
}
}
}

View File

@ -1,5 +1,6 @@
package core.notevault.ui.gallery;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -8,14 +9,23 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import core.notevault.R;
import core.notevault.data.Concert;
import core.notevault.data.MusicDatabase;
import core.notevault.data.MusicNote;
import core.notevault.data.MusicNoteDAO;
import core.notevault.databinding.FragmentGalleryBinding;
import core.notevault.ui.gallery.editor.ConcertEditorDialog;
import java.util.List;
public class GalleryFragment extends Fragment {
private FragmentGalleryBinding binding;
private ConcertAdapter concertAdapter;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
@ -25,12 +35,32 @@ public class GalleryFragment extends Fragment {
binding = FragmentGalleryBinding.inflate(inflater, container, false);
View root = binding.getRoot();
RecyclerView recyclerView = root.findViewById(R.id.concert_recycler_view);
concertAdapter = new ConcertAdapter();
recyclerView.setAdapter(concertAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
new LoadConcerts().execute();
FloatingActionButton addConcertBtn = root.findViewById(R.id.add_concert_btn);
addConcertBtn.setOnClickListener(v -> onCreateNewConcert());
return root;
}
private class LoadConcerts extends AsyncTask<Void, Void, List<Concert>> {
@Override
protected List<Concert> doInBackground(Void... voids) {
MusicDatabase db = MusicDatabase.getDatabase(getContext());
MusicNoteDAO musicNoteDAO = db.musicNoteDao();
return musicNoteDAO.getAllConcerts();
}
@Override
protected void onPostExecute(List<Concert> concerts) {
concertAdapter.updateConcerts(concerts); // Aktualisiere den Adapter mit den Titeln
}
}
public void onCreateNewConcert() {
ConcertEditorDialog concertEditorDialog = new ConcertEditorDialog();
concertEditorDialog.show(getParentFragmentManager(), ConcertEditorDialog.TAG);

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/concert_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
</LinearLayout>

View File

@ -7,19 +7,12 @@
android:layout_height="match_parent"
tools:context=".ui.gallery.GalleryFragment">
<TextView
android:id="@+id/text_gallery"
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/concert_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
android:layout_height="match_parent"
android:layout_above="@+id/add_concert_btn"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:src="@drawable/add_24dp_e8eaed_fill0_wght400_grad0_opsz24"
android:layout_width="wrap_content"