Insert MusicNote into database

This commit is contained in:
Sebastian 2024-10-15 21:00:30 +02:00
parent cf19780f97
commit 2dec0c28ee
2 changed files with 15 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI; import androidx.navigation.ui.NavigationUI;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import core.notevault.data.MusicDatabase;
import core.notevault.data.MusicNote; import core.notevault.data.MusicNote;
import core.notevault.databinding.ActivityMainBinding; import core.notevault.databinding.ActivityMainBinding;
import core.notevault.ui.metadatadialog.MetaDataDialog; import core.notevault.ui.metadatadialog.MetaDataDialog;
@ -21,6 +22,8 @@ public class MainActivity extends AppCompatActivity implements MetaDataDialog.On
private AppBarConfiguration mAppBarConfiguration; private AppBarConfiguration mAppBarConfiguration;
private ActivityMainBinding binding; private ActivityMainBinding binding;
private MusicDatabase musicDB;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -40,6 +43,8 @@ public class MainActivity extends AppCompatActivity implements MetaDataDialog.On
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main); NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration); NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController); NavigationUI.setupWithNavController(navigationView, navController);
musicDB = MusicDatabase.getDatabase(this);
} }
@Override @Override
@ -60,5 +65,8 @@ public class MainActivity extends AppCompatActivity implements MetaDataDialog.On
public void onMetadataEntered(String title, String composer, int year, String genre) { public void onMetadataEntered(String title, String composer, int year, String genre) {
MusicNote musicNote = new MusicNote(title, null, composer, year, genre); MusicNote musicNote = new MusicNote(title, null, composer, year, genre);
new Thread(() -> {
musicDB.musicNoteDao().insert(musicNote);
}).start();
} }
} }

View File

@ -41,7 +41,13 @@ public class MetaDataDialog extends DialogFragment {
.setPositiveButton("Speichern", (dialog, which) -> { .setPositiveButton("Speichern", (dialog, which) -> {
String title = title_input.getText().toString(); String title = title_input.getText().toString();
String composer = composer_input.getText().toString(); String composer = composer_input.getText().toString();
int year = Integer.parseInt(year_input.getText().toString());
String year_string = year_input.getText().toString();
int year = 0;
if(!year_string.isEmpty()) {
year = Integer.parseInt(year_input.getText().toString());
}
String genre = genre_input.getText().toString(); String genre = genre_input.getText().toString();
listener.onMetadataEntered(title, composer, year, genre); listener.onMetadataEntered(title, composer, year, genre);