Skip to content

Commit

Permalink
Update: Add imageloader in the detail activities #373
Browse files Browse the repository at this point in the history
Signed-off-by: James Maina <[email protected]>
  • Loading branch information
James Maina committed Jan 26, 2017
1 parent f0c3023 commit 931239c
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
import android.widget.TextView;

import org.ei.opensrp.Context;
import org.ei.opensrp.commonregistry.AllCommonsRepository;
import org.ei.opensrp.commonregistry.CommonPersonObject;
import org.ei.opensrp.commonregistry.CommonPersonObjectClient;
import org.ei.opensrp.domain.ProfileImage;
import org.ei.opensrp.indonesia.R;
import org.ei.opensrp.indonesia.application.BidanApplication;
import org.ei.opensrp.indonesia.kartu_ibu.NativeKISmartRegisterActivity;
import org.ei.opensrp.indonesia.lib.FlurryFacade;
import org.ei.opensrp.repository.DetailsRepository;
import org.ei.opensrp.repository.ImageRepository;
import org.ei.opensrp.view.activity.NativeANCSmartRegisterActivity;
import org.ei.opensrp.util.OpenSRPImageLoader;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -237,11 +236,10 @@ public void onClick(View v) {
ancKe.setText(": "+(ancclient.getDetails().get("ancKe") != null ? ancclient.getDetails().get("ancKe") : "-"));

ancDate.setText(": "+ (ancclient.getDetails().get("ancDate") != null ? ancclient.getDetails().get("ancDate") : "-"));
if(ancclient.getDetails().get("profilepic")!= null){
setImagetoHolderFromUri(ANCDetailActivity.this, ancclient.getDetails().get("profilepic"), kiview, R.mipmap.woman_placeholder);
}
else {
kiview.setImageDrawable(getResources().getDrawable(R.mipmap.woman_placeholder));

if(ancclient.getCaseId()!=null){//image already in local storage most likey ):
//set profile image by passing the client id.If the image doesn't exist in the image repository then download and save locally
BidanApplication.getInstance().getCachedImageLoaderInstance().getImageByClientId(ancclient.getCaseId(), OpenSRPImageLoader.getStaticImageListener(kiview, R.mipmap.woman_placeholder, R.mipmap.woman_placeholder));
}

nama.setText(getResources().getString(R.string.name)+ (ancclient.getColumnmaps().get("namalengkap") != null ? ancclient.getColumnmaps().get("namalengkap") : "-"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.ei.opensrp.indonesia.application.BidanApplication;
import org.ei.opensrp.repository.DetailsRepository;
import org.ei.opensrp.service.AlertService;
import org.ei.opensrp.util.FileUtilities;
import org.ei.opensrp.util.OpenSRPImageLoader;
import org.ei.opensrp.view.contract.SmartRegisterClient;
import org.ei.opensrp.view.contract.SmartRegisterClients;
Expand Down Expand Up @@ -167,14 +166,10 @@ public void getView(SmartRegisterClient smartRegisterClient, View convertView) {
final ImageView kiview = (ImageView)convertView.findViewById(R.id.img_profile);
//start profile image
viewHolder.profilepic.setTag(R.id.entity_id, pc.getColumnmaps().get("_id"));//required when saving file to disk
if(pc.getDetails().containsKey("imageid") && pc.getDetails().get("imageid")!=null && !pc.getDetails().get("imageid").isEmpty()){//image already in local storage most likey ):
mImageLoader.getImageWithId(pc.getColumnmaps().get("_id"), OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.drawable.woman_placeholder, R.drawable.woman_placeholder));

}else{
//create the url for download the image
String url= FileUtilities.getImageUrl(pc.getColumnmaps().get("_id"));
mImageLoader.get(url, OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.drawable.woman_placeholder, R.drawable.woman_placeholder));

if(pc.getColumnmaps().get("_id")!=null){//image already in local storage most likey ):
//set profile image by passing the client id.If the image doesn't exist in the image repository then download and save locally
BidanApplication.getInstance().getCachedImageLoaderInstance().getImageByClientId(pc.getColumnmaps().get("_id"), OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.drawable.woman_placeholder, R.drawable.woman_placeholder));
}
//end profile image

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import org.ei.opensrp.commonregistry.CommonPersonObjectClient;
import org.ei.opensrp.domain.ProfileImage;
import org.ei.opensrp.indonesia.R;
import org.ei.opensrp.indonesia.application.BidanApplication;
import org.ei.opensrp.indonesia.kartu_ibu.NativeKISmartRegisterActivity;
import org.ei.opensrp.repository.DetailsRepository;
import org.ei.opensrp.repository.ImageRepository;
import org.ei.opensrp.util.OpenSRPImageLoader;

import java.io.File;
import java.io.IOException;
Expand All @@ -35,7 +37,6 @@
import util.ImageFetcher;

import static org.ei.opensrp.util.StringUtil.humanize;
import static org.ei.opensrp.util.StringUtil.humanizeAndDoUPPERCASE;
/**
* Created by Iq on 07/09/16.
*/
Expand All @@ -51,6 +52,7 @@ public class AnakDetailActivity extends Activity {
private static ImageFetcher mImageFetcher;

public static CommonPersonObjectClient childclient;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -105,19 +107,19 @@ public void onClick(View v) {
DetailsRepository detailsRepository = org.ei.opensrp.Context.getInstance().detailsRepository();
detailsRepository.updateDetails(childclient);

if(childclient.getDetails().get("profilepic")!= null){
setImagetoHolderFromUri(AnakDetailActivity.this, childclient.getDetails().get("profilepic"), childview, R.drawable.child_boy_infant);
}
else {
if(childclient.getDetails().get("gender") != null && childclient.getDetails().get("gender").equals("laki")) {
childview.setImageDrawable(getResources().getDrawable(R.drawable.child_boy_infant));
} else if(childclient.getDetails().get("gender") != null && childclient.getDetails().get("gender").equals("male")) {
childview.setImageDrawable(getResources().getDrawable(R.drawable.child_boy_infant));
}
else {
childview.setImageDrawable(getResources().getDrawable(R.drawable.child_girl_infant));
}
String gender=childclient.getDetails().containsKey("gender")?childclient.getDetails().get("gender"):"laki";


//start profile image

int placeholderDrawable= gender.equalsIgnoreCase("male")?R.drawable.child_boy_infant:R.drawable.child_girl_infant;
childview.setTag(R.id.entity_id, childclient.getCaseId());//required when saving file to disk
if(childclient.getCaseId()!=null){//image already in local storage most likey ):
//set profile image by passing the client id.If the image doesn't exist in the image repository then download and save locally
BidanApplication.getInstance().getCachedImageLoaderInstance().getImageByClientId(childclient.getCaseId(), OpenSRPImageLoader.getStaticImageListener(childview, placeholderDrawable, placeholderDrawable));

}
//end profile image

AllCommonsRepository childRepository = org.ei.opensrp.Context.getInstance().allCommonsRepositoryobjects("ec_anak");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.ei.opensrp.indonesia.application.BidanApplication;
import org.ei.opensrp.repository.DetailsRepository;
import org.ei.opensrp.service.AlertService;
import org.ei.opensrp.util.FileUtilities;
import org.ei.opensrp.util.OpenSRPImageLoader;
import org.ei.opensrp.view.contract.SmartRegisterClient;
import org.ei.opensrp.view.contract.SmartRegisterClients;
Expand Down Expand Up @@ -160,15 +159,11 @@ else if(pc.getDetails().get("gender") != null && pc.getDetails().get("gender").e
viewHolder.berat_lahir.setText(pc.getDetails().get("beratLahir")!=null?pc.getDetails().get("beratLahir"):"");

//start profile image
viewHolder.profilepic.setTag(R.id.entity_id, pc.getColumnmaps().get("_id"));//required when saving file to disk
if(pc.getDetails().containsKey("imageid") && pc.getDetails().get("imageid")!=null && !pc.getDetails().get("imageid").isEmpty()){//image already in local storage most likey ):
mImageLoader.getImageWithId(pc.getColumnmaps().get("_id"), OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.drawable.woman_placeholder, R.drawable.woman_placeholder));

}else{
//create the url for download the image
String url= FileUtilities.getImageUrl(pc.getColumnmaps().get("_id"));
mImageLoader.get(url, OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.drawable.woman_placeholder, R.drawable.woman_placeholder));
viewHolder.profilepic.setTag(R.id.entity_id, pc.getCaseId());//required when saving file to disk

if(pc.getCaseId()!=null){//image already in local storage most likey ):
//set profile image by passing the client id.If the image doesn't exist in the image repository then download and save locally
BidanApplication.getInstance().getCachedImageLoaderInstance().getImageByClientId(pc.getCaseId(), OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.mipmap.woman_placeholder, R.mipmap.woman_placeholder));
}
//end profile image

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.ei.opensrp.indonesia.application.BidanApplication;
import org.ei.opensrp.repository.DetailsRepository;
import org.ei.opensrp.service.AlertService;
import org.ei.opensrp.util.FileUtilities;
import org.ei.opensrp.util.OpenSRPImageLoader;
import org.ei.opensrp.view.contract.SmartRegisterClient;
import org.ei.opensrp.view.contract.SmartRegisterClients;
Expand Down Expand Up @@ -153,14 +152,9 @@ public void getView(SmartRegisterClient smartRegisterClient, View convertView) {
viewHolder.visit_status.setText("");
//start profile image
viewHolder.profilepic.setTag(R.id.entity_id, pc.getColumnmaps().get("_id"));//required when saving file to disk
if(pc.getDetails().containsKey("imageid") && pc.getDetails().get("imageid")!=null && !pc.getDetails().get("imageid").isEmpty()){//image already in local storage most likey ):
mImageLoader.getImageWithId(pc.getColumnmaps().get("_id"), OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.drawable.woman_placeholder, R.drawable.woman_placeholder));

}else{
//create the url for download the image
String url= FileUtilities.getImageUrl(pc.getColumnmaps().get("_id"));
mImageLoader.get(url, OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.drawable.woman_placeholder, R.drawable.woman_placeholder));

if(pc.getCaseId()!=null){//image already in local storage most likey ):
//set profile image by passing the client id.If the image doesn't exist in the image repository then download and save locally
BidanApplication.getInstance().getCachedImageLoaderInstance().getImageByClientId(pc.getCaseId(), OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.mipmap.woman_placeholder, R.mipmap.woman_placeholder));
}
//end profile image
AllCommonsRepository iburep = org.ei.opensrp.Context.getInstance().allCommonsRepositoryobjects("ec_ibu");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import android.widget.TextView;

import org.ei.opensrp.Context;
import org.ei.opensrp.commonregistry.AllCommonsRepository;
import org.ei.opensrp.commonregistry.CommonPersonObject;
import org.ei.opensrp.commonregistry.CommonPersonObjectClient;
import org.ei.opensrp.domain.ProfileImage;
import org.ei.opensrp.indonesia.R;
import org.ei.opensrp.indonesia.application.BidanApplication;
import org.ei.opensrp.indonesia.lib.FlurryFacade;
import org.ei.opensrp.repository.DetailsRepository;
import org.ei.opensrp.repository.ImageRepository;
import org.ei.opensrp.util.OpenSRPImageLoader;

import java.io.File;
import java.io.IOException;
Expand All @@ -31,10 +31,11 @@
import java.util.Map;
import java.util.UUID;

import static org.ei.opensrp.util.StringUtil.humanize;
import util.ImageCache;
import util.ImageFetcher;

import static org.ei.opensrp.util.StringUtil.humanize;

/**
* Created by Iq on 07/09/16.
*/
Expand Down Expand Up @@ -133,13 +134,10 @@ public void onClick(View v) {
DetailsRepository detailsRepository = org.ei.opensrp.Context.getInstance().detailsRepository();
detailsRepository.updateDetails(kiclient);

if(kiclient.getDetails().get("profilepic")!= null){
setImagetoHolderFromUri(KIDetailActivity.this, kiclient.getDetails().get("profilepic"), kiview, R.mipmap.woman_placeholder);
}
else {
kiview.setImageDrawable(getResources().getDrawable(R.mipmap.woman_placeholder));
}

//set profile image by passing the client id.If the image doesn't exist in the image repository then download and save locally
BidanApplication.getInstance().getCachedImageLoaderInstance().getImageByClientId(kiclient.getCaseId(), OpenSRPImageLoader.getStaticImageListener(kiview, R.mipmap.woman_placeholder, R.mipmap.woman_placeholder));


nama.setText(getResources().getString(R.string.name)+ (kiclient.getColumnmaps().get("namalengkap") != null ? kiclient.getColumnmaps().get("namalengkap") : "-"));
nik.setText(getResources().getString(R.string.nik)+ (kiclient.getDetails().get("nik") != null ? kiclient.getDetails().get("nik") : "-"));
husband_name.setText(getResources().getString(R.string.husband_name)+ (kiclient.getColumnmaps().get("namaSuami") != null ? kiclient.getColumnmaps().get("namaSuami") : "-"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.ei.opensrp.indonesia.application.BidanApplication;
import org.ei.opensrp.repository.DetailsRepository;
import org.ei.opensrp.service.AlertService;
import org.ei.opensrp.util.FileUtilities;
import org.ei.opensrp.util.OpenSRPImageLoader;
import org.ei.opensrp.view.contract.SmartRegisterClient;
import org.ei.opensrp.view.contract.SmartRegisterClients;
Expand Down Expand Up @@ -139,14 +138,9 @@ public void getView(SmartRegisterClient smartRegisterClient, View convertView) {
final ImageView kiview = (ImageView)convertView.findViewById(R.id.img_profile);
//start profile image
viewHolder.profilepic.setTag(R.id.entity_id, pc.getColumnmaps().get("_id"));//required when saving file to disk
if(pc.getDetails().containsKey("imageid") && pc.getDetails().get("imageid")!=null && !pc.getDetails().get("imageid").isEmpty()){//image already in local storage most likey ):
mImageLoader.getImageWithId(pc.getColumnmaps().get("_id"), OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.drawable.woman_placeholder, R.drawable.woman_placeholder));

}else{
//create the url for download the image
String url= FileUtilities.getImageUrl(pc.getColumnmaps().get("_id"));
mImageLoader.get(url, OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.drawable.woman_placeholder, R.drawable.woman_placeholder));

if(pc.getCaseId()!=null){//image already in local storage most likey ):
//set profile image by passing the client id.If the image doesn't exist in the image repository then download and save locally
BidanApplication.getInstance().getCachedImageLoaderInstance().getImageByClientId(pc.getCaseId(), OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.mipmap.woman_placeholder, R.mipmap.woman_placeholder));
}
//end profile image

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import org.ei.opensrp.commonregistry.CommonPersonObjectClient;
import org.ei.opensrp.domain.ProfileImage;
import org.ei.opensrp.indonesia.R;
import org.ei.opensrp.indonesia.application.BidanApplication;
import org.ei.opensrp.indonesia.kartu_ibu.NativeKISmartRegisterActivity;
import org.ei.opensrp.indonesia.lib.FlurryFacade;
import org.ei.opensrp.repository.DetailsRepository;
import org.ei.opensrp.repository.ImageRepository;
import org.ei.opensrp.util.OpenSRPImageLoader;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -147,13 +149,13 @@ public void onClick(View v) {
DetailsRepository detailsRepository = org.ei.opensrp.Context.getInstance().detailsRepository();
detailsRepository.updateDetails(kiclient);

if(kiclient.getDetails().get("profilepic")!= null){
setImagetoHolderFromUri(KBDetailActivity.this, kiclient.getDetails().get("profilepic"), kiview, R.mipmap.woman_placeholder);
if(kiclient.getCaseId()!=null){//image already in local storage most likey ):
//set profile image by passing the client id.If the image doesn't exist in the image repository then download and save locally
BidanApplication.getInstance().getCachedImageLoaderInstance().getImageByClientId(kiclient.getCaseId(), OpenSRPImageLoader.getStaticImageListener(kiview, R.mipmap.woman_placeholder, R.mipmap.woman_placeholder));
}




nama.setText(getResources().getString(R.string.name)+ (kiclient.getColumnmaps().get("namalengkap") != null ? kiclient.getColumnmaps().get("namalengkap") : "-"));
nik.setText(getResources().getString(R.string.nik)+ (kiclient.getDetails().get("nik") != null ? kiclient.getDetails().get("nik") : "-"));
husband_name.setText(getResources().getString(R.string.husband_name)+ (kiclient.getColumnmaps().get("namaSuami") != null ? kiclient.getColumnmaps().get("namaSuami") : "-"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.ei.opensrp.indonesia.application.BidanApplication;
import org.ei.opensrp.repository.DetailsRepository;
import org.ei.opensrp.service.AlertService;
import org.ei.opensrp.util.FileUtilities;
import org.ei.opensrp.util.OpenSRPImageLoader;
import org.ei.opensrp.view.contract.SmartRegisterClient;
import org.ei.opensrp.view.contract.SmartRegisterClients;
Expand Down Expand Up @@ -190,14 +189,9 @@ public void getView(SmartRegisterClient smartRegisterClient, View convertView) {

//start profile image
viewHolder.profilepic.setTag(R.id.entity_id, pc.getColumnmaps().get("_id"));//required when saving file to disk
if(pc.getDetails().containsKey("imageid") && pc.getDetails().get("imageid")!=null && !pc.getDetails().get("imageid").isEmpty()){//image already in local storage most likey ):
mImageLoader.getImageWithId(pc.getColumnmaps().get("_id"), OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.drawable.woman_placeholder, R.drawable.woman_placeholder));

}else{
//create the url for download the image
String url= FileUtilities.getImageUrl(pc.getColumnmaps().get("_id"));
mImageLoader.get(url, OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.drawable.woman_placeholder, R.drawable.woman_placeholder));

if(pc.getCaseId()!=null){//image already in local storage most likey ):
//set profile image by passing the client id.If the image doesn't exist in the image repository then download and save locally
BidanApplication.getInstance().getCachedImageLoaderInstance().getImageByClientId(pc.getCaseId(), OpenSRPImageLoader.getStaticImageListener(viewHolder.profilepic, R.mipmap.woman_placeholder, R.mipmap.woman_placeholder));
}
//end profile image

Expand Down

0 comments on commit 931239c

Please sign in to comment.