Insert MusicNote into database
This commit is contained in:
parent
cf19780f97
commit
2dec0c28ee
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user