Handle MusicNote Objects in NoteSongAdapter
This commit is contained in:
parent
d3b94fdcb3
commit
73fe1bf812
@ -57,24 +57,18 @@ public class HomeFragment extends Fragment {
|
||||
return root;
|
||||
}
|
||||
|
||||
private class LoadSongTitlesTask extends AsyncTask<Void, Void, List<String>> {
|
||||
private class LoadSongTitlesTask extends AsyncTask<Void, Void, List<MusicNote>> {
|
||||
|
||||
@Override
|
||||
protected List<String> doInBackground(Void... voids) {
|
||||
protected List<MusicNote> doInBackground(Void... voids) {
|
||||
MusicDatabase db = MusicDatabase.getDatabase(getContext());
|
||||
MusicNoteDAO musicNoteDAO = db.musicNoteDao();
|
||||
List<MusicNote> songs = musicNoteDAO.getAllNotes();
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
for (MusicNote song : songs) {
|
||||
result.add(song.getTitle());
|
||||
}
|
||||
return result;
|
||||
return musicNoteDAO.getAllNotes();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<String> songTitles) {
|
||||
noteSongAdapter.updateSongTitles(songTitles); // Aktualisiere den Adapter mit den Titeln
|
||||
protected void onPostExecute(List<MusicNote> songs) {
|
||||
noteSongAdapter.updateSongTitles(songs); // Aktualisiere den Adapter mit den Titeln
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,15 +7,16 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import core.notevault.R;
|
||||
import core.notevault.data.MusicNote;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class NoteSongAdapter extends RecyclerView.Adapter<NoteSongAdapter.NoteViewHolder> {
|
||||
|
||||
private final List<String> noteTitles;
|
||||
private final List<MusicNote> noteTitles;
|
||||
|
||||
public NoteSongAdapter(List<String> noteTitles) {
|
||||
public NoteSongAdapter(List<MusicNote> noteTitles) {
|
||||
this.noteTitles = noteTitles;
|
||||
}
|
||||
|
||||
@ -33,7 +34,7 @@ public class NoteSongAdapter extends RecyclerView.Adapter<NoteSongAdapter.NoteVi
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull NoteViewHolder holder, int position) {
|
||||
holder.titleTextView.setText(noteTitles.get(position));
|
||||
holder.titleTextView.setText(noteTitles.get(position).getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,9 +42,9 @@ public class NoteSongAdapter extends RecyclerView.Adapter<NoteSongAdapter.NoteVi
|
||||
return noteTitles.size();
|
||||
}
|
||||
|
||||
public void updateSongTitles(List<String> songTitles) {
|
||||
public void updateSongTitles(List<MusicNote> songs) {
|
||||
this.noteTitles.clear();
|
||||
this.noteTitles.addAll(songTitles);
|
||||
this.noteTitles.addAll(songs);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user