diff --git a/app/src/main/java/core/notevault/MainActivity.java b/app/src/main/java/core/notevault/MainActivity.java index 26d8fac..47f7173 100644 --- a/app/src/main/java/core/notevault/MainActivity.java +++ b/app/src/main/java/core/notevault/MainActivity.java @@ -1,6 +1,7 @@ package core.notevault; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.view.Menu; import com.google.android.material.snackbar.Snackbar; @@ -11,9 +12,11 @@ import androidx.navigation.ui.AppBarConfiguration; import androidx.navigation.ui.NavigationUI; import androidx.drawerlayout.widget.DrawerLayout; import androidx.appcompat.app.AppCompatActivity; +import core.notevault.data.MusicNote; import core.notevault.databinding.ActivityMainBinding; +import core.notevault.ui.metadatadialog.MetaDataDialog; -public class MainActivity extends AppCompatActivity { +public class MainActivity extends AppCompatActivity implements MetaDataDialog.OnMetadataListener { private AppBarConfiguration mAppBarConfiguration; private ActivityMainBinding binding; @@ -52,4 +55,10 @@ public class MainActivity extends AppCompatActivity { return NavigationUI.navigateUp(navController, mAppBarConfiguration) || super.onSupportNavigateUp(); } + + @Override + public void onMetadataEntered(String title, String composer, int year, String genre) { + MusicNote musicNote = new MusicNote(title, null, composer, year, genre); + + } } \ No newline at end of file diff --git a/app/src/main/java/core/notevault/data/MusicNote.java b/app/src/main/java/core/notevault/data/MusicNote.java index 8bac568..d9196c9 100644 --- a/app/src/main/java/core/notevault/data/MusicNote.java +++ b/app/src/main/java/core/notevault/data/MusicNote.java @@ -11,8 +11,20 @@ public class MusicNote { private String title; private String filePath; private String composer; + private int year; private String genre; + public MusicNote(String title, String filePath, String composer, int year, String genre) { + this.title = title; + this.filePath = filePath; + this.composer = composer; + this.year = year; + this.genre = genre; + } + + public MusicNote() { + } + public int getId() { return id; } @@ -52,4 +64,12 @@ public class MusicNote { public void setGenre(String genre) { this.genre = genre; } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } } diff --git a/app/src/main/java/core/notevault/ui/home/HomeFragment.java b/app/src/main/java/core/notevault/ui/home/HomeFragment.java index 96714dc..b91234e 100644 --- a/app/src/main/java/core/notevault/ui/home/HomeFragment.java +++ b/app/src/main/java/core/notevault/ui/home/HomeFragment.java @@ -53,7 +53,9 @@ public class HomeFragment extends Fragment { private void handleFile(Uri uri) { // Hier kannst du die Logik zum Speichern oder Anzeigen der Datei implementieren MetaDataDialog metaDataDialog = new MetaDataDialog(); + metaDataDialog.setFileUri(uri); metaDataDialog.show(getParentFragmentManager(), MetaDataDialog.TAG); + homeViewModel.addNote(uri); // Speichere die URI im ViewModel Toast.makeText(getActivity(), "Datei ausgewählt: " + uri.getPath(), Toast.LENGTH_SHORT).show(); } @@ -74,4 +76,6 @@ public class HomeFragment extends Fragment { super.onDestroyView(); binding = null; } + + } \ 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 2cd88a0..b5f1043 100644 --- a/app/src/main/java/core/notevault/ui/metadatadialog/MetaDataDialog.java +++ b/app/src/main/java/core/notevault/ui/metadatadialog/MetaDataDialog.java @@ -2,22 +2,101 @@ package core.notevault.ui.metadatadialog; import android.app.AlertDialog; import android.app.Dialog; +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; import android.os.Bundle; +import android.provider.OpenableColumns; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; import core.notevault.R; public class MetaDataDialog extends DialogFragment { + private Uri fileUri; + + public interface OnMetadataListener { + void onMetadataEntered(String title, String composer, int year, String genre); + } + + private OnMetadataListener listener; @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + LayoutInflater inflater = requireActivity().getLayoutInflater(); + View dialogView = inflater.inflate(R.layout.fragment_metadata_dialog, null); // Ersetze 'your_dialog_layout' durch deinen Dateinamen + + EditText title_input = dialogView.findViewById(R.id.title_input); + title_input.setText(this.extraxtTitleFromFilePath()); + EditText composer_input = dialogView.findViewById(R.id.composer_input); + EditText year_input = dialogView.findViewById(R.id.year_input); + EditText genre_input = dialogView.findViewById(R.id.genre_input); + return new AlertDialog.Builder(requireContext()) - .setMessage("Import-Einstellungen") - .setPositiveButton("Speichern", (dialog, which) -> {} ) + .setView(dialogView) + .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 genre = genre_input.getText().toString(); + + listener.onMetadataEntered(title, composer, year, genre); + } ) + .setNegativeButton("Abbrechen", (dialog, which) -> {} ) .create(); } + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + if (context instanceof OnMetadataListener) { + listener = (OnMetadataListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnMetadataListener"); + } + } + + public Uri getFileUri() { + return fileUri; + } + + public void setFileUri(Uri fileUri) { + this.fileUri = fileUri; + } + + private String extraxtTitleFromFilePath() { + String fileName = ""; + + // Überprüfen, ob die Uri ein Content-Uri ist + if (this.fileUri.getScheme().equals("content")) { + // ContentResolver verwenden, um die Datei zu finden + Cursor cursor = requireContext().getContentResolver().query(this.fileUri, null, null, null, null); + if (cursor != null) { + int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); + if (cursor.moveToFirst()) { + // Den Dateinamen aus dem Cursor abfragen + fileName = cursor.getString(nameIndex); + } + cursor.close(); + } + } else if (this.fileUri.getScheme().equals("file")) { + // Bei einer Datei-Uri einfach den letzten Pfadsegment verwenden + fileName = this.fileUri.getLastPathSegment(); + } + + if(fileName.contains(".")) { + fileName = fileName.substring(0, fileName.lastIndexOf(".")); + fileName = fileName.replace("_", " "); + fileName = fileName.replace("-", ""); + } + + return fileName; + } + public static String TAG = "MetaDataDialog"; } diff --git a/app/src/main/res/layout/fragment_metadata_dialog.xml b/app/src/main/res/layout/fragment_metadata_dialog.xml index 264cffe..e006006 100644 --- a/app/src/main/res/layout/fragment_metadata_dialog.xml +++ b/app/src/main/res/layout/fragment_metadata_dialog.xml @@ -1,7 +1,126 @@ - + - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file