Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/complete overhaul of edit event functionality #100

Merged
merged 10 commits into from
Mar 24, 2024

This file was deleted.

78 changes: 0 additions & 78 deletions app/src/main/java/com/example/scanpal/AddEditEventFragment.java

This file was deleted.

45 changes: 13 additions & 32 deletions app/src/main/java/com/example/scanpal/AddEventFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,19 @@ public class AddEventFragment extends Fragment {

public AddEventFragment() {
// Required empty public constructor

}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.add_edit_event, null, false);
((MainActivity) requireActivity()).setNavbarVisibility(false);

//Fragment UI
TextView pageHeader = view.findViewById(R.id.add_edit_event_Header);
pageHeader.setText("Create Event");

//TODO: Remove the delete button from page when creating event
this.deleteButton = view.findViewById(R.id.add_edit_deleteButton);
this.deleteButton.setVisibility(View.GONE); // no need for delete button when creating an event
this.deleteButton.setVisibility(View.GONE);


this.saveButton = view.findViewById(R.id.add_edit_save_button);
Expand All @@ -87,9 +85,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
this.profileImageView = view.findViewById(R.id.add_edit_event_ImageView);

imageController = new ImageController();


//getting an instance of the currentUser
userController = new UserController(FirebaseFirestore.getInstance(), view.getContext());
eventController = new EventController();

Expand All @@ -101,20 +96,11 @@ public void onSuccess(User user) {

@Override
public void onError(Exception e) {
Toast.makeText(view.getContext(), "Failed to fetch User Data", Toast.LENGTH_LONG).show();

//TODO: probably should navigate back to the events page on failure?

}
});

this.newEvent = new Event(this.Organizer, "", "");//blank event for now until user clicks 'save'


//log test getting name
Log.d("STORAGE", userController.fetchStoredUsername());
this.newEvent = new Event(this.Organizer, "", "");

//Implementing the Save button
saveButton.setOnClickListener(v -> {

//checking for valid input
Expand All @@ -136,28 +122,21 @@ public void onError(Exception e) {
newEvent.setPosterURI(imageUri);
newEvent.setAnnouncementCount(0L);

//now add the new event to the database
eventController.addEvent(newEvent);

NavController navController = NavHostFragment.findNavController(AddEventFragment.this);
navController.navigate(R.id.addEditEventComplete);
((MainActivity) requireActivity()).setNavbarVisibility(true);
}

});


//Implementing the Back button to return to Events Page
backButton.setOnClickListener(v -> {

//just go back to the previous screen without doing anything
NavController navController = NavHostFragment.findNavController(AddEventFragment.this);
navController.navigate(R.id.addEditEventComplete);
((MainActivity) requireActivity()).setNavbarVisibility(true);
});

editImageButton.setOnClickListener(v -> {
// what to do when trying to edit image
openGallery();
});
editImageButton.setOnClickListener(v -> openGallery());

return view;
}
Expand All @@ -172,14 +151,16 @@ private void openGallery() {
}

/**
* Uploads the selected image to Firebase Storage and updates the user's profile image URL.
* Uploads the selected image to Firebase Storage, specifying a folder and filename.
*
* @param imageUri The URI of the image selected by the user.
*/
private void uploadImageToFirebase(Uri imageUri) {
imageController.uploadImage(imageUri,
taskSnapshot -> Toast.makeText(getContext(), "Image Uploaded Successfully", Toast.LENGTH_SHORT).show(),
e -> Toast.makeText(getContext(), "Upload failed: " + e.getMessage(), Toast.LENGTH_SHORT).show());
}
String folderPath = "events";
String fileName = "event_" + newEvent.getId() + ".jpg";

imageController.uploadImage(imageUri, folderPath, fileName,
uri -> System.out.println("Success"),
e -> Log.e("AddEventFragment", "Upload failed: " + e.getMessage()));
}
}
Loading
Loading