Skip to content

Commit

Permalink
feat: added option to click profile image (openMF#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReCodee authored Nov 28, 2020
1 parent 2ed3e44 commit 6a8a9ed
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ interface EditProfilePresenter extends BasePresenter {

void handleProfileImageRemoved();

void handleClickProfileImageRequest();

void handleExitOnUnsavedChanges();

void onDialogNegative();
Expand All @@ -48,6 +50,8 @@ interface EditProfileView extends BaseView<EditProfilePresenter> {

void changeProfileImage();

void clickProfileImage();

void onUpdateEmailError(String message);

void onUpdateMobileError(String message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public void handleProfileImageRemoved() {
mEditProfileView.showDefaultImageByUsername(mPreferencesHelper.getFullName());
}

@Override
public void handleClickProfileImageRequest() {
mEditProfileView.clickProfileImage();
}

@Override
public void handleNecessaryDataSave() {
mEditProfileView.showFab();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.FloatingActionButton;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class EditProfileActivity extends BaseActivity implements

private static final int REQUEST_READ_IMAGE = 1;
private static final int REQUEST_READ_EXTERNAL_STORAGE = 7;
private static final int REQUEST_CAMERA = 0;

@Inject
EditProfilePresenter mPresenter;
Expand Down Expand Up @@ -268,6 +270,23 @@ public void hideKeyboard() {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_CAMERA: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the
// camera-related task you need to do.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);

} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toaster.showToast(this,
getString(R.string.need_camera_permission_to_click_profile_picture));
}
return;
}
case REQUEST_READ_EXTERNAL_STORAGE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
Expand All @@ -285,7 +304,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
showToast(Constants.NEED_EXTERNAL_STORAGE_PERMISSION_TO_BROWSE_IMAGES);
}
}

// other 'case' lines to check for other
// permissions this app might request.
}
Expand All @@ -303,6 +321,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
} else if (requestCode == UCrop.REQUEST_CROP) {
handleCropResult(data);
} else if (requestCode == REQUEST_CAMERA) {
Bundle extras = data.getExtras();
Bitmap profileBitmapImage = (Bitmap) extras.get("data");
ivUserImage.setImageBitmap(profileBitmapImage);
}
}
}
Expand Down Expand Up @@ -348,6 +370,11 @@ public void changeProfileImage() {
pickImageFromGallery();
}

@Override
public void clickProfileImage() {
clickProfilePicFromCamera();
}

private void pickImageFromGallery() {
if (Build.VERSION.SDK_INT >= 23 &&
ContextCompat.checkSelfPermission(getApplicationContext(),
Expand Down Expand Up @@ -377,6 +404,21 @@ private void handleCropResult(@NonNull Intent result) {
}
}

public void clickProfilePicFromCamera() {

if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

// Permission is not granted
requestPermissions(new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA);
} else {

// Permission has already been granted
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
}
}

@Override
public void showDiscardChangesDialog() {
dialogBox.setOnPositiveListener(new DialogInterface.OnClickListener() {
Expand Down Expand Up @@ -459,5 +501,11 @@ public void onRemoveProfileImageClicked() {
mEditProfilePresenter.handleProfileImageRemoved();
bottomSheetDialog.dismiss();
}

@OnClick(R.id.ll_click_profile_image_dialog_row)
public void onClickProfileImageClicked() {
mEditProfilePresenter.handleClickProfileImageRequest();
bottomSheetDialog.dismiss();
}
}
}
4 changes: 2 additions & 2 deletions mifospay/src/main/res/drawable/ic_camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:fillColor="#FF000000"
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
<path
android:fillColor="#FFFFFFFF"
android:fillColor="#FF000000"
android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
</vector>
63 changes: 47 additions & 16 deletions mifospay/src/main/res/layout/dialog_change_profile_picture.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,47 @@
android:orientation="vertical"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/ll_click_profile_image_dialog_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/value_8dp"
android:layout_marginStart="@dimen/value_5dp"
android:layout_marginEnd="@dimen/value_8dp"
android:layout_marginBottom="@dimen/value_8dp"
android:layout_marginLeft="@dimen/value_5dp"
android:layout_marginTop="@dimen/value_16dp"
android:layout_marginRight="@dimen/value_8dp">

<ImageView
android:id="@+id/iv_click_image_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_camera"
android:layout_marginStart="@dimen/value_3dp"
android:layout_marginLeft="@dimen/value_3dp" />

<TextView
android:id="@+id/tv_click_image_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/value_8dp"
android:layout_marginRight="@dimen/value_8dp"
android:text="@string/click_profile_picture" />

</LinearLayout>

<LinearLayout
android:id="@+id/ll_change_profile_image_dialog_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:padding="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="16dp" >
android:padding="@dimen/value_8dp"
android:layout_marginEnd="@dimen/value_8dp"
android:layout_marginLeft="@dimen/value_8dp"
android:layout_marginBottom="@dimen/value_8dp"
android:layout_marginTop="@dimen/value_16dp"
android:layout_marginRight="@dimen/value_8dp">

<ImageView
android:id="@+id/iv_change_profile_image"
Expand All @@ -26,8 +57,8 @@
android:id="@+id/tv_change_profile_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="@dimen/value_8dp"
android:layout_marginRight="@dimen/value_8dp"
android:text="@string/change_profile_picture" />

</LinearLayout>
Expand All @@ -36,25 +67,25 @@
android:id="@+id/ll_remove_profile_image_dialog_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp" >
android:padding="@dimen/value_8dp"
android:layout_marginStart="@dimen/value_8dp"
android:layout_marginEnd="@dimen/value_8dp"
android:layout_marginBottom="@dimen/value_8dp"
android:layout_marginLeft="@dimen/value_8dp"
android:layout_marginTop="@dimen/value_16dp" >

<ImageView
android:id="@+id/iv_remove_profile_image"
android:layout_width="27dp"
android:layout_width="@dimen/value_27dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_remove" />

<TextView
android:id="@+id/tv_remove_profile_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="@dimen/value_8dp"
android:layout_marginRight="@dimen/value_8dp"
android:text="@string/remove_profile_picture" />

</LinearLayout>
Expand Down
3 changes: 3 additions & 0 deletions mifospay/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@

<dimen name="value_10dp">10dp</dimen>
<dimen name="value_10sp">10sp</dimen>
<dimen name="value_16dp">16dp</dimen>
<dimen name="value_20dp">20dp</dimen>
<dimen name="value_27dp">27dp</dimen>
<dimen name="value_20sp">20sp</dimen>
<dimen name="value_15sp">15sp</dimen>
<dimen name="value_18sp">18sp</dimen>
<dimen name="value_40dp">40dp</dimen>
<dimen name="value_5dp">5dp</dimen>
<dimen name="value_3dp">3dp</dimen>
<dimen name="value_7dp">7dp</dimen>
<dimen name="value_8dp">8dp</dimen>
<dimen name="value_12dp">12dp</dimen>
<dimen name="value_15dp">15dp</dimen>
<dimen name="value_30dp">30dp</dimen>
Expand Down
6 changes: 4 additions & 2 deletions mifospay/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@
<string name="pin_code">Pin Code</string>
<string name="state">State</string>
<string name="no_transactions_found">No transactions found</string>
<string name="change_profile_picture">Change Profile Picture</string>
<string name="remove_profile_picture">Remove Profile Picture</string>
<string name="click_profile_picture">Click profile picture</string>
<string name="change_profile_picture">Pick profile picture from device</string>
<string name="need_camera_permission_to_click_profile_picture">Need camera permission to click profile picture</string>
<string name="remove_profile_picture">Remove profile picture</string>
<string name="sign_up_as">Sign up as</string>
<string name="merchant">Merchant</string>
<string name="customer">Customer</string>
Expand Down

0 comments on commit 6a8a9ed

Please sign in to comment.