Update Added Notes

This commit is contained in:
sebastian 2024-11-01 14:44:35 +01:00
parent 4de3a459e6
commit 7bd430e0f9
5 changed files with 31 additions and 10 deletions

View File

@ -24,6 +24,7 @@ import core.notevault.data.NoteSheet;
import core.notevault.databinding.ActivityMainBinding; import core.notevault.databinding.ActivityMainBinding;
import core.notevault.ui.gallery.GalleryFragment; import core.notevault.ui.gallery.GalleryFragment;
import core.notevault.ui.gallery.editor.ConcertEditorDialog; import core.notevault.ui.gallery.editor.ConcertEditorDialog;
import core.notevault.ui.home.HomeFragment;
import core.notevault.ui.metadatadialog.MetaDataDialog; import core.notevault.ui.metadatadialog.MetaDataDialog;
import core.notevault.util.NoteSheetsUtil; import core.notevault.util.NoteSheetsUtil;
@ -86,6 +87,16 @@ public class MainActivity extends AppCompatActivity implements MetaDataDialog.On
NoteSheet noteSheet = new NoteSheet(musicNoteID, filePath); NoteSheet noteSheet = new NoteSheet(musicNoteID, filePath);
musicDB.musicNoteDao().insertNoteSheet(noteSheet); musicDB.musicNoteDao().insertNoteSheet(noteSheet);
} }
runOnUiThread(() -> {
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment_content_main);
Fragment currentFragment = navHostFragment != null ? navHostFragment.getChildFragmentManager().getFragments().get(0) : null;
if(currentFragment instanceof HomeFragment) {
HomeFragment homeFragment = (HomeFragment) currentFragment;
homeFragment.addSong(musicNote);
}
});
}).start(); }).start();
} }

View File

@ -32,6 +32,5 @@ public class GalleryViewModel extends ViewModel {
currentConcerts.add(concert); currentConcerts.add(concert);
concerts.setValue(currentConcerts); concerts.setValue(currentConcerts);
} }
} }
} }

View File

@ -53,6 +53,10 @@ public class HomeFragment extends Fragment {
recyclerView.setAdapter(noteSongAdapter); recyclerView.setAdapter(noteSongAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
homeViewModel.getNoteTitles().observe(getViewLifecycleOwner(), songs -> {
noteSongAdapter.updateSongTitles(songs);
});
new LoadSongTitlesTask().execute(); new LoadSongTitlesTask().execute();
return root; return root;
@ -69,7 +73,7 @@ public class HomeFragment extends Fragment {
@Override @Override
protected void onPostExecute(List<MusicNote> songs) { protected void onPostExecute(List<MusicNote> songs) {
noteSongAdapter.updateSongTitles(songs); // Aktualisiere den Adapter mit den Titeln homeViewModel.setNoteTitles(songs);
} }
} }
@ -120,5 +124,7 @@ public class HomeFragment extends Fragment {
binding = null; binding = null;
} }
public void addSong(MusicNote musicNote) {
this.homeViewModel.addSong(musicNote);
}
} }

View File

@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import core.notevault.MainActivity; import core.notevault.MainActivity;
import core.notevault.data.MusicDatabase; import core.notevault.data.MusicDatabase;
import core.notevault.data.MusicNote;
import core.notevault.ui.metadatadialog.MetaDataDialog; import core.notevault.ui.metadatadialog.MetaDataDialog;
import java.util.ArrayList; import java.util.ArrayList;
@ -13,21 +14,25 @@ import java.util.List;
public class HomeViewModel extends ViewModel { public class HomeViewModel extends ViewModel {
private final MutableLiveData<List<String>> noteTitles; private final MutableLiveData<List<MusicNote>> noteTitles;
public HomeViewModel() { public HomeViewModel() {
noteTitles = new MutableLiveData<>(new ArrayList<>()); noteTitles = new MutableLiveData<>(new ArrayList<>());
} }
public LiveData<List<String>> getNoteTitles() { public LiveData<List<MusicNote>> getNoteTitles() {
return noteTitles; return noteTitles;
} }
public void setNoteTitles(ArrayList<String> noteTitles) { public void setNoteTitles(List<MusicNote> noteTitles) {
this.noteTitles.setValue(noteTitles); this.noteTitles.setValue(noteTitles);
} }
public void addNote(Uri uri) { public void addSong(MusicNote song) {
List<MusicNote> songs = noteTitles.getValue();
if(songs != null) {
songs.add(song);
this.noteTitles.setValue(songs);
}
} }
} }

View File

@ -111,7 +111,7 @@ public class NoteSongAdapter extends RecyclerView.Adapter<NoteSongAdapter.NoteVi
@Override @Override
protected List<NoteSheet> doInBackground(Void... voids) { protected List<NoteSheet> doInBackground(Void... voids) {
List<NoteSheet> sheets = musicNoteDAO.getNoteSheetsForMusicSong(this.musicNoteId); List<NoteSheet> sheets = musicNoteDAO.getNoteSheetsForMusicSong(this.musicNoteId);
Log.d("LoadNoteSheetsTask", "Loaded NoteSheets: " + sheets.get(0)); Log.d("LoadNoteSheetsTask", "Loaded NoteSheets: " + sheets.size());
return sheets; return sheets;
} }