Select File for MusicNotes
This commit is contained in:
parent
fbdb013484
commit
2b7215b61c
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
@ -23,6 +23,7 @@
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,32 +1,71 @@
|
||||
package core.notevault.ui.home;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import core.notevault.R;
|
||||
import core.notevault.databinding.FragmentHomeBinding;
|
||||
|
||||
public class HomeFragment extends Fragment {
|
||||
|
||||
private static final int PICK_FILE_REQUEST_CODE = 1;
|
||||
private FragmentHomeBinding binding;
|
||||
private HomeViewModel homeViewModel;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
HomeViewModel homeViewModel =
|
||||
homeViewModel =
|
||||
new ViewModelProvider(this).get(HomeViewModel.class);
|
||||
|
||||
binding = FragmentHomeBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
final TextView textView = binding.textHome;
|
||||
homeViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
||||
FloatingActionButton importBtn = root.findViewById(R.id.importMusicNotesBtn);
|
||||
importBtn.setOnClickListener(v -> openFileChooser());
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == PICK_FILE_REQUEST_CODE && resultCode == getActivity().RESULT_OK && data != null) {
|
||||
Uri uri = data.getData();
|
||||
if (uri != null) {
|
||||
handleFile(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFile(Uri uri) {
|
||||
// Hier kannst du die Logik zum Speichern oder Anzeigen der Datei implementieren
|
||||
homeViewModel.addNote(uri); // Speichere die URI im ViewModel
|
||||
Toast.makeText(getActivity(), "Datei ausgewählt: " + uri.getPath(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void openFileChooser() {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("*/*"); // Alle Dateitypen
|
||||
|
||||
String[] mimeTypes = {"application/pdf", "image/png", "image/jpeg"};
|
||||
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
|
||||
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
startActivityForResult(intent, PICK_FILE_REQUEST_CODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package core.notevault.ui.home;
|
||||
|
||||
import android.net.Uri;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
@ -16,4 +17,8 @@ public class HomeViewModel extends ViewModel {
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
|
||||
public void addNote(Uri uri) {
|
||||
System.out.println("Added file: " + uri.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:pathData="M440,520L200,520v-80h240v-240h80v240h240v80L520,520v240h-80v-240Z"
|
||||
android:fillColor="#e8eaed"/>
|
||||
</vector>
|
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e8eaed"><path d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z"/></svg>
|
After Width: | Height: | Size: 182 B |
@ -20,4 +20,16 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:src="@drawable/add_24dp_e8eaed_fill0_wght400_grad0_opsz24"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:id="@+id/importMusicNotesBtn"
|
||||
android:layout_marginEnd="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:backgroundTint="@color/teal_200"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user