Enter minimum meta data of music note
This commit is contained in:
parent
39463c8df3
commit
cf19780f97
@ -1,6 +1,7 @@
|
|||||||
package core.notevault;
|
package core.notevault;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
@ -11,9 +12,11 @@ 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.MusicNote;
|
||||||
import core.notevault.databinding.ActivityMainBinding;
|
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 AppBarConfiguration mAppBarConfiguration;
|
||||||
private ActivityMainBinding binding;
|
private ActivityMainBinding binding;
|
||||||
@ -52,4 +55,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|
||||||
|| super.onSupportNavigateUp();
|
|| super.onSupportNavigateUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMetadataEntered(String title, String composer, int year, String genre) {
|
||||||
|
MusicNote musicNote = new MusicNote(title, null, composer, year, genre);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -11,8 +11,20 @@ public class MusicNote {
|
|||||||
private String title;
|
private String title;
|
||||||
private String filePath;
|
private String filePath;
|
||||||
private String composer;
|
private String composer;
|
||||||
|
private int year;
|
||||||
private String genre;
|
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() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -52,4 +64,12 @@ public class MusicNote {
|
|||||||
public void setGenre(String genre) {
|
public void setGenre(String genre) {
|
||||||
this.genre = genre;
|
this.genre = genre;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getYear() {
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYear(int year) {
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,9 @@ public class HomeFragment extends Fragment {
|
|||||||
private void handleFile(Uri uri) {
|
private void handleFile(Uri uri) {
|
||||||
// Hier kannst du die Logik zum Speichern oder Anzeigen der Datei implementieren
|
// Hier kannst du die Logik zum Speichern oder Anzeigen der Datei implementieren
|
||||||
MetaDataDialog metaDataDialog = new MetaDataDialog();
|
MetaDataDialog metaDataDialog = new MetaDataDialog();
|
||||||
|
metaDataDialog.setFileUri(uri);
|
||||||
metaDataDialog.show(getParentFragmentManager(), MetaDataDialog.TAG);
|
metaDataDialog.show(getParentFragmentManager(), MetaDataDialog.TAG);
|
||||||
|
|
||||||
homeViewModel.addNote(uri); // Speichere die URI im ViewModel
|
homeViewModel.addNote(uri); // Speichere die URI im ViewModel
|
||||||
Toast.makeText(getActivity(), "Datei ausgewählt: " + uri.getPath(), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), "Datei ausgewählt: " + uri.getPath(), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
@ -74,4 +76,6 @@ public class HomeFragment extends Fragment {
|
|||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
binding = null;
|
binding = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -2,22 +2,101 @@ package core.notevault.ui.metadatadialog;
|
|||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
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.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import core.notevault.R;
|
import core.notevault.R;
|
||||||
|
|
||||||
public class MetaDataDialog extends DialogFragment {
|
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
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
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())
|
return new AlertDialog.Builder(requireContext())
|
||||||
.setMessage("Import-Einstellungen")
|
.setView(dialogView)
|
||||||
.setPositiveButton("Speichern", (dialog, which) -> {} )
|
.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();
|
.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";
|
public static String TAG = "MetaDataDialog";
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,126 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:id="@+id/metadata_dialog">
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:id="@+id/metadata_dialog">
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:text="Import-Einstellungen"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/dialog_title"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="18sp"/>
|
||||||
|
|
||||||
|
<TableLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:text="Titel: "
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/title_label"/>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:inputType="text"
|
||||||
|
android:ems="10"
|
||||||
|
android:id="@+id/title_input"
|
||||||
|
android:hint="Titel eingeben"
|
||||||
|
android:foregroundTint="#000000"
|
||||||
|
android:minHeight="48dp"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:minWidth="48dp"/>
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:text="Komponisten: "
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/composer_label"/>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="text"
|
||||||
|
android:ems="10"
|
||||||
|
android:id="@+id/composer_input"
|
||||||
|
android:hint="Komponisten eingeben"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:minWidth="48dp"
|
||||||
|
android:minHeight="48dp"
|
||||||
|
android:padding="16dp"/>
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:text="Jahr: "
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/year_label"/>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="numberSigned"
|
||||||
|
android:ems="10"
|
||||||
|
android:id="@+id/year_input"
|
||||||
|
android:hint="Erscheinungsjahr eingeben"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:minWidth="48dp"
|
||||||
|
android:minHeight="48dp"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:text="Genre: "
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/genre_label"/>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="text"
|
||||||
|
android:ems="10"
|
||||||
|
android:id="@+id/genre_input"
|
||||||
|
android:hint="Genre eingeben"
|
||||||
|
android:minWidth="48dp"
|
||||||
|
android:minHeight="48dp"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
</TableLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user