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