Update Added Notes
This commit is contained in:
		
							parent
							
								
									4de3a459e6
								
							
						
					
					
						commit
						7bd430e0f9
					
				@ -24,6 +24,7 @@ import core.notevault.data.NoteSheet;
 | 
			
		||||
import core.notevault.databinding.ActivityMainBinding;
 | 
			
		||||
import core.notevault.ui.gallery.GalleryFragment;
 | 
			
		||||
import core.notevault.ui.gallery.editor.ConcertEditorDialog;
 | 
			
		||||
import core.notevault.ui.home.HomeFragment;
 | 
			
		||||
import core.notevault.ui.metadatadialog.MetaDataDialog;
 | 
			
		||||
import core.notevault.util.NoteSheetsUtil;
 | 
			
		||||
 | 
			
		||||
@ -86,6 +87,16 @@ public class MainActivity extends AppCompatActivity implements MetaDataDialog.On
 | 
			
		||||
                NoteSheet noteSheet = new NoteSheet(musicNoteID, filePath);
 | 
			
		||||
                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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -32,6 +32,5 @@ public class GalleryViewModel extends ViewModel {
 | 
			
		||||
            currentConcerts.add(concert);
 | 
			
		||||
            concerts.setValue(currentConcerts);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -53,6 +53,10 @@ public class HomeFragment extends Fragment {
 | 
			
		||||
        recyclerView.setAdapter(noteSongAdapter);
 | 
			
		||||
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
 | 
			
		||||
 | 
			
		||||
        homeViewModel.getNoteTitles().observe(getViewLifecycleOwner(), songs -> {
 | 
			
		||||
            noteSongAdapter.updateSongTitles(songs);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        new LoadSongTitlesTask().execute();
 | 
			
		||||
 | 
			
		||||
        return root;
 | 
			
		||||
@ -69,7 +73,7 @@ public class HomeFragment extends Fragment {
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void addSong(MusicNote musicNote) {
 | 
			
		||||
        this.homeViewModel.addSong(musicNote);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import core.notevault.MainActivity;
 | 
			
		||||
import core.notevault.data.MusicDatabase;
 | 
			
		||||
import core.notevault.data.MusicNote;
 | 
			
		||||
import core.notevault.ui.metadatadialog.MetaDataDialog;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
@ -13,21 +14,25 @@ import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class HomeViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private final MutableLiveData<List<String>> noteTitles;
 | 
			
		||||
    private final MutableLiveData<List<MusicNote>> noteTitles;
 | 
			
		||||
 | 
			
		||||
    public HomeViewModel() {
 | 
			
		||||
        noteTitles = new MutableLiveData<>(new ArrayList<>());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<String>> getNoteTitles() {
 | 
			
		||||
    public LiveData<List<MusicNote>> getNoteTitles() {
 | 
			
		||||
        return noteTitles;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNoteTitles(ArrayList<String> noteTitles) {
 | 
			
		||||
    public void setNoteTitles(List<MusicNote> 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);
 | 
			
		||||
        }
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
@ -111,7 +111,7 @@ public class NoteSongAdapter extends RecyclerView.Adapter<NoteSongAdapter.NoteVi
 | 
			
		||||
        @Override
 | 
			
		||||
        protected List<NoteSheet> doInBackground(Void... voids) {
 | 
			
		||||
            List<NoteSheet> sheets =  musicNoteDAO.getNoteSheetsForMusicSong(this.musicNoteId);
 | 
			
		||||
            Log.d("LoadNoteSheetsTask", "Loaded NoteSheets: " + sheets.get(0));
 | 
			
		||||
            Log.d("LoadNoteSheetsTask", "Loaded NoteSheets: " + sheets.size());
 | 
			
		||||
            return sheets;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user