SquadHouseDev / SquadHouse

https://squadhousedev.github.io/
0 stars 1 forks source link

To do: Profile Page Core Features #8

Closed henrylao closed 3 years ago

henrylao commented 3 years ago

Overview

There are alot of pages that a User's profile can navigate to. Focus on the core features first, followed by the stretch.

profile-editting

Core

Resources:

henrylao commented 3 years ago

Some reference for the photo upload, note that since we're not using a camera its just a matter of extracting the absolute filepath to generate the URI for uploading to the Parse Server

    public File getPhotoFileUri(String photoFileName) {
        File mediaStorageDirectory = new File(getContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES), TAG);

        // Create the storage directtory if it does not exist
        if (!mediaStorageDirectory.exists() && !mediaStorageDirectory.mkdirs()) {
            Log.d(TAG, "failed to create media directory");
        }

        // Return the file target for the photo based on filename
        return new File(mediaStorageDirectory.getPath() + File.separator + photoFileName);
    }

    @SuppressLint("QueryPermissionsNeeded")
    private void launchCamera() {
        Log.d(TAG, "launchCamera: user clicked camera launcher");
        // Create an implicit intent to take a picture and return control to the calling application
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // Create a File reference for future access
        photoFile = getPhotoFileUri(photoFileName);

        // wrap File object into a content provider
        // required for API >= 24
        // See https://guides.codepath.com/android/Sharing-Content-with-Intents#sharing-files-with-api-24-or-higher
        Uri fileProvider = FileProvider.getUriForFile(getContext(), "com.codepath.fileprovider", photoFile);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileProvider);

        // If you call startActivityForResult() using an intent that no app can handle, your app will crash.
        // So as long as the result is not null, it's safe to use the intent.
        ComponentName activityName = intent.resolveActivity(getContext().getPackageManager());
        if (intent.resolveActivity(getContext().getPackageManager()) != null) {
            // Start the image capture intent to take photo
            startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); //
        }
    }