diff --git a/app/src/main/java/core/notevault/MainActivity.java b/app/src/main/java/core/notevault/MainActivity.java index 47f7173..b235cf6 100644 --- a/app/src/main/java/core/notevault/MainActivity.java +++ b/app/src/main/java/core/notevault/MainActivity.java @@ -12,6 +12,7 @@ import androidx.navigation.ui.AppBarConfiguration; import androidx.navigation.ui.NavigationUI; import androidx.drawerlayout.widget.DrawerLayout; import androidx.appcompat.app.AppCompatActivity; +import core.notevault.data.MusicDatabase; import core.notevault.data.MusicNote; import core.notevault.databinding.ActivityMainBinding; import core.notevault.ui.metadatadialog.MetaDataDialog; @@ -21,6 +22,8 @@ public class MainActivity extends AppCompatActivity implements MetaDataDialog.On private AppBarConfiguration mAppBarConfiguration; private ActivityMainBinding binding; + private MusicDatabase musicDB; + @Override protected void onCreate(Bundle 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); NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration); NavigationUI.setupWithNavController(navigationView, navController); + + musicDB = MusicDatabase.getDatabase(this); } @Override @@ -60,5 +65,8 @@ public class MainActivity extends AppCompatActivity implements MetaDataDialog.On public void onMetadataEntered(String title, String composer, int year, String genre) { MusicNote musicNote = new MusicNote(title, null, composer, year, genre); + new Thread(() -> { + musicDB.musicNoteDao().insert(musicNote); + }).start(); } } \ No newline at end of file diff --git a/app/src/main/java/core/notevault/ui/metadatadialog/MetaDataDialog.java b/app/src/main/java/core/notevault/ui/metadatadialog/MetaDataDialog.java index b5f1043..ff5777b 100644 --- a/app/src/main/java/core/notevault/ui/metadatadialog/MetaDataDialog.java +++ b/app/src/main/java/core/notevault/ui/metadatadialog/MetaDataDialog.java @@ -41,7 +41,13 @@ public class MetaDataDialog extends DialogFragment { .setPositiveButton("Speichern", (dialog, which) -> { String title = title_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(); listener.onMetadataEntered(title, composer, year, genre);