mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
Add profile picture on client
Display and allow for selection of profile picture
This commit is contained in:
parent
f5d71a0fff
commit
b81f3b3fd6
@ -53,4 +53,6 @@ dependencies {
|
|||||||
implementation 'com.squareup.okhttp3:okhttp:4.8.1'
|
implementation 'com.squareup.okhttp3:okhttp:4.8.1'
|
||||||
implementation 'com.crystal:crystalrangeseekbar:1.1.3'
|
implementation 'com.crystal:crystalrangeseekbar:1.1.3'
|
||||||
implementation 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'
|
implementation 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'
|
||||||
|
implementation "androidx.cardview:cardview:1.0.0"
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -3,6 +3,9 @@
|
|||||||
package="com.example.listify">
|
package="com.example.listify">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".Listify"
|
android:name=".Listify"
|
||||||
@ -13,6 +16,18 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:usesCleartextTraffic="true">
|
android:usesCleartextTraffic="true">
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="com.example.listify.provider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/file_paths">
|
||||||
|
</meta-data>
|
||||||
|
</provider>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
|||||||
@ -1,15 +1,22 @@
|
|||||||
package com.example.listify;
|
package com.example.listify;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.core.content.FileProvider;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
import androidx.navigation.NavController;
|
import androidx.navigation.NavController;
|
||||||
import androidx.navigation.Navigation;
|
import androidx.navigation.Navigation;
|
||||||
@ -17,15 +24,15 @@ import androidx.navigation.ui.AppBarConfiguration;
|
|||||||
import androidx.navigation.ui.NavigationUI;
|
import androidx.navigation.ui.NavigationUI;
|
||||||
import com.amplifyframework.auth.AuthException;
|
import com.amplifyframework.auth.AuthException;
|
||||||
import com.example.listify.data.List;
|
import com.example.listify.data.List;
|
||||||
import com.example.listify.data.ListDuplicate;
|
|
||||||
import com.example.listify.data.ListReposition;
|
|
||||||
import com.example.listify.data.SearchHistory;
|
|
||||||
import com.example.listify.ui.LoginPage;
|
import com.example.listify.ui.LoginPage;
|
||||||
import com.google.android.material.navigation.NavigationView;
|
import com.google.android.material.navigation.NavigationView;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static com.example.listify.SplashActivity.showSplash;
|
import static com.example.listify.SplashActivity.showSplash;
|
||||||
@ -33,6 +40,9 @@ import static com.example.listify.SplashActivity.showSplash;
|
|||||||
public class MainActivity extends AppCompatActivity implements CreateListDialogFragment.OnNewListListener {
|
public class MainActivity extends AppCompatActivity implements CreateListDialogFragment.OnNewListListener {
|
||||||
private AppBarConfiguration mAppBarConfiguration;
|
private AppBarConfiguration mAppBarConfiguration;
|
||||||
public static AuthManager am = new AuthManager();
|
public static AuthManager am = new AuthManager();
|
||||||
|
private File newImageFileLocation = null;
|
||||||
|
private final int CAMERA_CAPTURE = 1;
|
||||||
|
private final int IMAGE_SELECT = 2;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
@ -151,12 +161,49 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
|||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------//
|
//------------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||||
|
|
||||||
|
TextView emailView = navigationView.getHeaderView(0).findViewById(R.id.textViewEmailSidebar);
|
||||||
|
emailView.setText(am.getEmail());
|
||||||
|
|
||||||
|
ImageView profilePicture = navigationView.getHeaderView(0).findViewById(R.id.imageViewProfilePicture);
|
||||||
|
profilePicture.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
||||||
|
// builder.setView(navigationView.getHeaderView(0));
|
||||||
|
builder.setTitle("Change picture");
|
||||||
|
builder.setMessage("Please select a method to add a new profile picture.");
|
||||||
|
builder.setCancelable(true);
|
||||||
|
builder.setPositiveButton("Take picture", (dialog, which) -> {
|
||||||
|
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
|
File imageFileLocation = getOutputImageFile();
|
||||||
|
Log.i("Profile Picture", "New image file at " + imageFileLocation.getAbsolutePath());
|
||||||
|
newImageFileLocation = imageFileLocation;
|
||||||
|
Uri imageUri = FileProvider.getUriForFile(
|
||||||
|
MainActivity.this,
|
||||||
|
BuildConfig.APPLICATION_ID + ".provider",
|
||||||
|
imageFileLocation);
|
||||||
|
takePicture.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
|
||||||
|
startActivityForResult(takePicture, CAMERA_CAPTURE);
|
||||||
|
});
|
||||||
|
builder.setNeutralButton("Select picture", (dialog, which) -> {
|
||||||
|
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
|
||||||
|
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||||
|
startActivityForResult(pickPhoto, IMAGE_SELECT);
|
||||||
|
});
|
||||||
|
builder.setNegativeButton("Cancel", (dialog, which) -> {
|
||||||
|
});
|
||||||
|
AlertDialog dialog = builder.create();
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
mAppBarConfiguration = new AppBarConfiguration.Builder(
|
mAppBarConfiguration = new AppBarConfiguration.Builder(
|
||||||
R.id.nav_home, R.id.nav_profile, R.id.nav_logout)
|
R.id.nav_home, R.id.nav_profile, R.id.nav_logout)
|
||||||
.setDrawerLayout(drawer)
|
.setDrawerLayout(drawer)
|
||||||
@ -176,6 +223,55 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onActivityResult (int requestCode,
|
||||||
|
int resultCode,
|
||||||
|
Intent data) {
|
||||||
|
Uri selectedImage = null;
|
||||||
|
switch (requestCode){
|
||||||
|
case CAMERA_CAPTURE:
|
||||||
|
Log.i("Profile Picture", "Pulling image file at " + this.newImageFileLocation.getAbsolutePath());
|
||||||
|
selectedImage = Uri.fromFile(this.newImageFileLocation);
|
||||||
|
break;
|
||||||
|
case IMAGE_SELECT:
|
||||||
|
if ((data == null) || (data.getData() == null)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selectedImage = data.getData();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
MainActivity.super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||||
|
ImageView profilePicture = navigationView.getHeaderView(0).findViewById(R.id.imageViewProfilePicture);
|
||||||
|
profilePicture.setImageURI(selectedImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
//getOutputImageFile from https://developer.android.com/guide/topics/media/camera
|
||||||
|
private static File getOutputImageFile(){
|
||||||
|
// To be safe, you should check that the SDCard is mounted
|
||||||
|
// using Environment.getExternalStorageState() before doing this.
|
||||||
|
|
||||||
|
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
|
Environment.DIRECTORY_PICTURES), "MyCameraApp");
|
||||||
|
// This location works best if you want the created images to be shared
|
||||||
|
// between applications and persist after your app has been uninstalled.
|
||||||
|
|
||||||
|
// Create the storage directory if it does not exist
|
||||||
|
if (! mediaStorageDir.exists()){
|
||||||
|
if (! mediaStorageDir.mkdirs()){
|
||||||
|
Log.d("File creation", "failed to create directory");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a media file name
|
||||||
|
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
||||||
|
File mediaFile = new File(mediaStorageDir.getPath() + File.separator +
|
||||||
|
"IMG_"+ timeStamp + ".jpg");
|
||||||
|
Log.i("File creation", mediaFile.toString());
|
||||||
|
return mediaFile;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSupportNavigateUp() {
|
public boolean onSupportNavigateUp() {
|
||||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||||
@ -214,5 +310,8 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
|||||||
Toast.makeText(this, "An error occurred", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, "An error occurred", Toast.LENGTH_LONG).show();
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,8 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/Profile_Section"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="10dp"
|
android:layout_height="@dimen/nav_header_height"
|
||||||
android:background="@drawable/side_nav_bar"
|
android:background="@drawable/side_nav_bar"
|
||||||
android:gravity="bottom"
|
android:gravity="bottom"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
@ -12,24 +13,29 @@
|
|||||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
android:theme="@style/ThemeOverlay.AppCompat.Dark">
|
android:theme="@style/ThemeOverlay.AppCompat.Dark">
|
||||||
|
|
||||||
<!-- <ImageView-->
|
|
||||||
<!-- android:id="@+id/imageView"-->
|
|
||||||
<!-- android:layout_width="wrap_content"-->
|
|
||||||
<!-- android:layout_height="wrap_content"-->
|
|
||||||
<!-- android:contentDescription="@string/nav_header_desc"-->
|
|
||||||
<!-- android:paddingTop="@dimen/nav_header_vertical_spacing"-->
|
|
||||||
<!-- app:srcCompat="@mipmap/ic_launcher_round" />-->
|
|
||||||
|
|
||||||
<!-- <TextView-->
|
<androidx.cardview.widget.CardView
|
||||||
<!-- android:layout_width="match_parent"-->
|
android:layout_width="96dp"
|
||||||
<!-- android:layout_height="wrap_content"-->
|
android:layout_height="96dp"
|
||||||
<!-- android:paddingTop="@dimen/nav_header_vertical_spacing"-->
|
android:elevation="12dp"
|
||||||
<!-- android:text="@string/nav_header_title"-->
|
android:id="@+id/view2"
|
||||||
<!-- android:textAppearance="@style/TextAppearance.AppCompat.Body1" />-->
|
app:cardCornerRadius="48dp"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:background="#80000000">
|
||||||
|
<ImageView
|
||||||
|
android:layout_height="96dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:id="@+id/imageViewProfilePicture"
|
||||||
|
android:src="@raw/ic_launcher_round"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:background="#80000000"/>
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
<!-- <TextView-->
|
|
||||||
<!-- android:id="@+id/textView"-->
|
<TextView
|
||||||
<!-- android:layout_width="wrap_content"-->
|
android:id="@+id/textViewEmailSidebar"
|
||||||
<!-- android:layout_height="wrap_content"-->
|
android:layout_width="wrap_content"
|
||||||
<!-- android:text="@string/nav_header_subtitle" />-->
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:text="@string/nav_header_subtitle" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
BIN
Listify/app/src/main/res/raw/ic_launcher_round.png
Normal file
BIN
Listify/app/src/main/res/raw/ic_launcher_round.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
4
Listify/app/src/main/res/xml/file_paths.xml
Normal file
4
Listify/app/src/main/res/xml/file_paths.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<external-path name="external_files" path="." />
|
||||||
|
</paths>
|
||||||
Loading…
Reference in New Issue
Block a user