Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/#8-implement-malaria-profile-pag…
Browse files Browse the repository at this point in the history
…e' into #20-implement-malaria-follo-up-visit

# Conflicts:
#	opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java
#	opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/domain/MemberObject.java
  • Loading branch information
whoisladleo committed Jul 1, 2019
2 parents 9b2a144 + 38afcea commit a7dc147
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 93 deletions.
1 change: 1 addition & 0 deletions opensrp-chw-malaria/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ dependencies {
implementation 'id.zelory:compressor:1.0.4'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.+'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,30 @@
package org.smartregister.chw.malaria.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.design.widget.AppBarLayout;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewOutlineProvider;
import android.widget.TextView;
import android.widget.Toast;

import org.joda.time.DateTime;
import org.joda.time.Period;
import org.smartregister.chw.malaria.contract.MalariaProfileContract;
import org.smartregister.chw.malaria.domain.MemberObject;
import org.smartregister.chw.malaria.presenter.BaseMalariaProfilePresenter;
import org.smartregister.chw.malaria.util.Constants;
import org.smartregister.helper.ImageRenderHelper;
import org.smartregister.malaria.R;
import org.smartregister.view.activity.BaseProfileActivity;

import java.lang.ref.WeakReference;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class BaseMalariaProfileActivity extends BaseProfileActivity implements MalariaProfileContract.View, MalariaProfileContract.Presenter {
private Context context;
private MemberObject MEMBER_OBJECT;
private View recordMalariaView;
private TextView textViewRecordMalaria;
private WeakReference<MalariaProfileContract.View> view;
public class BaseMalariaProfileActivity extends BaseProfileActivity implements MalariaProfileContract.View {
protected MemberObject MEMBER_OBJECT;
private BaseMalariaProfilePresenter profilePresenter;
private TextView textViewName, textViewGender, textViewLocation, textViewUniqueID;

public static void startProfileActivity(Activity activity, MemberObject memberObject) {
Intent intent = new Intent(activity, BaseMalariaProfileActivity.class);
Expand All @@ -50,9 +38,6 @@ protected void onCreation() {
Toolbar toolbar = findViewById(R.id.collapsing_toolbar);
setSupportActionBar(toolbar);

MEMBER_OBJECT = (MemberObject) getIntent().getSerializableExtra(Constants.MALARIA_MEMBER_OBJECT.MEMBER_OBJECT);


ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
Expand All @@ -66,31 +51,32 @@ public void onClick(View v) {
BaseMalariaProfileActivity.this.finish();
}
});
appBarLayout = (AppBarLayout)this.findViewById(R.id.collapsing_toolbar_appbarlayout);
appBarLayout = this.findViewById(R.id.collapsing_toolbar_appbarlayout);
if (Build.VERSION.SDK_INT >= 21) {
appBarLayout.setOutlineProvider((ViewOutlineProvider)null);
appBarLayout.setOutlineProvider(null);
}

imageRenderHelper = new ImageRenderHelper(this);
setupViews();
textViewName = findViewById(R.id.textview_name);
textViewGender = findViewById(R.id.textview_gender);
textViewLocation = findViewById(R.id.textview_address);
textViewUniqueID = findViewById(R.id.textview_id);

MEMBER_OBJECT = (MemberObject) getIntent().getSerializableExtra(Constants.MALARIA_MEMBER_OBJECT.MEMBER_OBJECT);

initializePresenter();

profilePresenter.attachView(this);

profilePresenter.fillProfileData(MEMBER_OBJECT);

}

@Override
protected void setupViews() {
public void setProfileViewWithData() {
int age = new Period(new DateTime(MEMBER_OBJECT.getAge()), new DateTime()).getYears();
recordMalariaView = findViewById(R.id.record_visit_malaria);
textViewRecordMalaria = findViewById(R.id.textview_record_malaria);

TextView textViewName = findViewById(R.id.textview_name);
textViewName.setText(String.format("%s %s %s, %d", MEMBER_OBJECT.getFirstName(), MEMBER_OBJECT.getMiddleName(), MEMBER_OBJECT.getLastName(), age));

TextView textViewGender = findViewById(R.id.textview_gender);
textViewGender.setText(MEMBER_OBJECT.getGender());

TextView textViewLocation = findViewById(R.id.textview_address);
textViewLocation.setText(MEMBER_OBJECT.getAddress());

TextView textViewUniqueID = findViewById(R.id.textview_id);
textViewUniqueID.setText(MEMBER_OBJECT.getUniqueId());

recordMalariaButton(MEMBER_OBJECT.getMalariaTestDate());
Expand All @@ -116,29 +102,10 @@ private void recordMalariaButton(String malaria_test_date) {
}
}

@Override
public Context getContext() {
return context;
}

@Override
public MalariaProfileContract.View getView() {
if(view != null) {
return view.get();
} else {
return null;
}
}

@Override
public MalariaProfileContract.Presenter presenter() {
return (MalariaProfileContract.Presenter) presenter;
}


@Override
protected void initializePresenter() {
presenter = new BaseMalariaProfilePresenter(this, MEMBER_OBJECT);
profilePresenter = new BaseMalariaProfilePresenter(this, MEMBER_OBJECT);
}

@Override
Expand Down Expand Up @@ -168,7 +135,9 @@ public void onClick(View view) {
}

@Override
public void onDestroy(boolean b) {
//
protected void onDestroy() {
profilePresenter.detachView();
super.onDestroy();

}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
package org.smartregister.chw.malaria.contract;

import android.content.Context;
import org.smartregister.view.contract.BaseProfileContract;

public interface MalariaProfileContract {
interface View {
Context getContext();

MalariaProfileContract.View getView();

MalariaProfileContract.Presenter presenter();

}

interface Presenter extends BaseProfileContract.Presenter {
void setProfileViewWithData();
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
package org.smartregister.chw.malaria.presenter;

import android.content.Context;

import org.smartregister.chw.malaria.contract.MalariaProfileContract;
import org.smartregister.chw.malaria.domain.MemberObject;

import java.lang.ref.WeakReference;

public class BaseMalariaProfilePresenter implements MalariaProfileContract.Presenter, MalariaProfileContract.View {
protected WeakReference<MalariaProfileContract.View> view;
protected MemberObject memberObject;
public class BaseMalariaProfilePresenter {
protected MalariaProfileContract.View view;
private MemberObject memberObject;
protected Context context;


public BaseMalariaProfilePresenter(MalariaProfileContract.View contractView, MemberObject memberObject) {
this.view = new WeakReference<>(contractView);
public BaseMalariaProfilePresenter(MalariaProfileContract.View view, MemberObject memberObject) {
this.view = view;
this.memberObject = memberObject;

}

@Override
public Context getContext() {
return null;
public void attachView(MalariaProfileContract.View view) {
this.view = view;
}

@Override
public MalariaProfileContract.View getView() {
if(view != null) {
return view.get();
}
return null;
public void detachView() {
this.view = null;
}

@Override
public MalariaProfileContract.Presenter presenter() {
return null;
}


@Override
public void onDestroy(boolean b) {
//destroy
public void fillProfileData(MemberObject memberObject) {
if (memberObject != null) {
view.setProfileViewWithData();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.smartregister.presenter;

import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.smartregister.chw.malaria.contract.MalariaProfileContract;
import org.smartregister.chw.malaria.domain.MemberObject;
import org.smartregister.chw.malaria.presenter.BaseMalariaProfilePresenter;

import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

public class BaseMalariaProfilePresenterTest {
@Mock
private MalariaProfileContract.View view = Mockito.mock(MalariaProfileContract.View.class);
@Mock
BaseMalariaProfilePresenter profilePresenter = Mockito.mock(BaseMalariaProfilePresenter.class);

@Mock
MemberObject memberObject = Mockito.mock(MemberObject.class);

@Test
public void fillProfileData_doesntCallsSetProfileViewWithDataIfMemberObjectEmpty() {
profilePresenter.fillProfileData(memberObject);
verify(view, never()).setProfileViewWithData();
}
}

0 comments on commit a7dc147

Please sign in to comment.