Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import androidx.annotation.VisibleForTesting;
import com.google.android.material.navigation.NavigationView;
import androidx.test.espresso.IdlingResource;
Expand All @@ -17,7 +18,6 @@
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.widget.SwitchCompat;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -42,6 +42,7 @@
import com.mifos.utils.EspressoIdlingResource;
import com.mifos.utils.PrefManager;


import butterknife.BindView;
import butterknife.ButterKnife;

Expand All @@ -59,6 +60,7 @@ public class DashboardActivity extends MifosBaseActivity
@BindView(R.id.drawer)
DrawerLayout mDrawerLayout;


View mNavigationHeader;
SwitchCompat userStatusToggle;
private Menu menu;
Expand Down Expand Up @@ -181,6 +183,7 @@ public void onDrawerSlide(View drawerView, float slideOffset) {
loadClientDetails();
}


@Override
public boolean onNavigationItemSelected(MenuItem item) {

Expand Down Expand Up @@ -232,7 +235,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
break;
}

mDrawerLayout.closeDrawer(Gravity.START);
mDrawerLayout.closeDrawer(GravityCompat.START);
mNavigationView.setCheckedItem(R.id.item_dashboard);
return true;
}
Expand Down Expand Up @@ -297,7 +300,7 @@ private void loadClientDetails() {
public void onBackPressed() {
// check if the nav mDrawer is open
if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawer(Gravity.START);
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
if (doubleBackToExitPressedOnce) {
setMenuCreateClient(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@

package com.mifos.mifosxdroid.online.clientdetails;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;

import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentTransaction;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
Expand Down Expand Up @@ -64,6 +71,7 @@
import com.mifos.utils.Utils;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -74,6 +82,7 @@
import butterknife.OnClick;
import okhttp3.ResponseBody;

import static android.app.Activity.RESULT_OK;
import static android.view.View.GONE;
import static android.view.View.OnClickListener;
import static android.view.View.OnTouchListener;
Expand All @@ -83,8 +92,9 @@
public class ClientDetailsFragment extends MifosBaseFragment implements ClientDetailsMvpView {

// Intent response codes. Each response code must be a unique integer.
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 1;

private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 2;
private static final int UPLOAD_IMAGE_ACTIVITY_REQUEST_CODE = 1;
private static final int CHECK_PERMISSIONS = 1010;
public static final int MENU_ITEM_DATA_TABLES = 1000;
public static final int MENU_ITEM_PIN_POINT = 1001;
public static final int MENU_ITEM_CLIENT_CHARGES = 1003;
Expand All @@ -96,7 +106,7 @@ public class ClientDetailsFragment extends MifosBaseFragment implements ClientDe
public static final int MENU_ITEM_SURVEYS = 1008;
public static final int MENU_ITEM_NOTE = 1009;


String imgDecodableString;
private final String TAG = ClientDetailsFragment.class.getSimpleName();

public int clientId;
Expand Down Expand Up @@ -161,7 +171,8 @@ public class ClientDetailsFragment extends MifosBaseFragment implements ClientDe

private View rootView;
private OnFragmentInteractionListener mListener;
private File capturedClientImageFile;
private File clientImageFile = new File(Environment.getExternalStorageDirectory().toString() +
"/client_image.png");
private AccountAccordion accountAccordion;
private boolean isClientActive = false;

Expand All @@ -188,7 +199,7 @@ public void onCreate(Bundle savedInstanceState) {
clientId = getArguments().getInt(Constants.CLIENT_ID);
}
setHasOptionsMenu(true);
capturedClientImageFile = new File(getActivity().getExternalCacheDir(), "client_image.png");
checkPermissions();
}

@Override
Expand Down Expand Up @@ -226,8 +237,52 @@ public void onAttach(Activity activity) {

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == Activity.RESULT_OK)
uploadImage(capturedClientImageFile);
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == UPLOAD_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK
&& null != data) {
// Get the Image from data

Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };

// Get the cursor
Cursor cursor = getActivity().getApplicationContext().getContentResolver().query(
selectedImage,
filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgDecodableString = cursor.getString(columnIndex);
cursor.close();
Bitmap pickedImage = BitmapFactory.decodeFile(imgDecodableString);
saveBitmap(clientImageFile, pickedImage);
uploadImage(clientImageFile);
} else if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE
&& resultCode == RESULT_OK) {
uploadImage(clientImageFile);
} else {
Toaster.show(rootView, R.string.havent_picked_image,
Toast.LENGTH_LONG);
}
} catch (Exception e) {
Toaster.show(rootView, e.toString(), Toast.LENGTH_LONG);
}
}

public void saveBitmap(File file, Bitmap mBitmap) {
try {
file.createNewFile();
FileOutputStream fOut = null;
fOut = new FileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
} catch (Exception exception) {
//Empty catch block to prevent crashing
}
}

@Override
Expand Down Expand Up @@ -295,10 +350,30 @@ public boolean onOptionsItemSelected(MenuItem item) {

public void captureClientImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(capturedClientImageFile));
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(clientImageFile));
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}

private void checkPermissions() {
if (ContextCompat.checkSelfPermission(getActivity(),
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getActivity(),
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
CHECK_PERMISSIONS);
}
}

public void uploadClientImage() {
// Create intent to Open Image applications like Gallery, Google Photos
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
galleryIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(clientImageFile));
startActivityForResult(galleryIntent, UPLOAD_IMAGE_ACTIVITY_REQUEST_CODE);
}


/**
* A service to upload the image of the client.
*
Expand Down Expand Up @@ -486,6 +561,9 @@ public void onClick(View view) {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.client_image_upload:
uploadClientImage();
break;
case R.id.client_image_capture:
captureClientImage();
break;
Expand Down Expand Up @@ -528,6 +606,7 @@ public void showUploadImageProgressbar(boolean b) {
}
}


public void loadClientProfileImage() {
pb_imageProgressBar.setVisibility(VISIBLE);
ImageLoaderUtils.loadImage(getActivity(), clientId, iv_clientImage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void onCompleted() {

@Override
public void onError(Throwable e) {
getMvpView().showUploadImageFailed("Failed to update image");
getMvpView().showUploadImageFailed("Unable to update image");
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions mifosng-android/src/main/res/menu/client_image_popup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<item
android:id="@+id/client_image_capture"
android:title="@string/menu_take_photo" />
<item
android:id="@+id/client_image_upload"
android:title="@string/menu_upload_photo" />
<item
android:id="@+id/client_image_remove"
android:title="@string/menu_remove_photo" />
Expand Down
2 changes: 2 additions & 0 deletions mifosng-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@
<string name="tenant_identifier">Tenant Identifier</string>
<string name="dashboard">Dashboard</string>
<string name="menu_take_photo">Take new photo</string>
<string name="menu_upload_photo">Upload new photo</string>
<string name="menu_remove_photo">Remove photo</string>
<string name="toast_welcome">Welcome</string>
<string name="client_image_updated">Client image updated</string>
Expand Down Expand Up @@ -700,6 +701,7 @@
<string name="failed_to_fetch_loan_transaction_template">Failed to fetch loan transaction
template</string>
<string name="generic_failure_message">Request failed. Please try again.</string>
<string name="havent_picked_image">You haven\'t picked an image.</string>


<string-array name="office_ids">
Expand Down