Skip to content

Commit

Permalink
Merge branch '#8-implement-malaria-profile-page' into #19-implement-t…
Browse files Browse the repository at this point in the history
…op-right-menu-malaria-profile

# Conflicts:
#	opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/domain/MemberObject.java
  • Loading branch information
whoisladleo committed Jul 1, 2019
2 parents 6013548 + 38afcea commit b5149ef
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 94 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,34 +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.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 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;

public class BaseMalariaProfileActivity extends BaseProfileActivity implements MalariaProfileContract.View, MalariaProfileContract.Presenter {
private Context context;
public class BaseMalariaProfileActivity extends BaseProfileActivity implements MalariaProfileContract.View {
protected MemberObject MEMBER_OBJECT;
private WeakReference<MalariaProfileContract.View> view;
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 @@ -42,8 +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 @@ -57,55 +51,39 @@ 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();
}

@Override
protected void setupViews() {
int age = new Period(new DateTime(MEMBER_OBJECT.getAge()), new DateTime()).getYears();

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));
textViewName = findViewById(R.id.textview_name);
textViewGender = findViewById(R.id.textview_gender);
textViewLocation = findViewById(R.id.textview_address);
textViewUniqueID = findViewById(R.id.textview_id);

TextView textViewGender = findViewById(R.id.textview_gender);
textViewGender.setText(MEMBER_OBJECT.getGender());
MEMBER_OBJECT = (MemberObject) getIntent().getSerializableExtra(Constants.MALARIA_MEMBER_OBJECT.MEMBER_OBJECT);

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

TextView textViewUniqueID = findViewById(R.id.textview_id);
textViewUniqueID.setText(MEMBER_OBJECT.getUniqueId());
}
profilePresenter.attachView(this);

@Override
public Context getContext() {
return context;
}
profilePresenter.fillProfileData(MEMBER_OBJECT);

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

@Override
public MalariaProfileContract.Presenter presenter() {
return (MalariaProfileContract.Presenter) presenter;
public void setProfileViewWithData() {
int age = new Period(new DateTime(MEMBER_OBJECT.getAge()), new DateTime()).getYears();
textViewName.setText(String.format("%s %s %s, %d", MEMBER_OBJECT.getFirstName(), MEMBER_OBJECT.getMiddleName(), MEMBER_OBJECT.getLastName(), age));
textViewGender.setText(MEMBER_OBJECT.getGender());
textViewLocation.setText(MEMBER_OBJECT.getAddress());
textViewUniqueID.setText(MEMBER_OBJECT.getUniqueId());
}


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

@Override
Expand All @@ -120,13 +98,15 @@ protected void fetchProfileData() {

@Override
public void onClick(View view) {
if(view.getId() == R.id.title_layout) {
if (view.getId() == R.id.title_layout) {
onBackPressed();
}
}

@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
Expand Up @@ -69,7 +69,7 @@
android:layout_marginTop="5dp"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:text="@string/patient_name_age"
android:text="Patient Name, Age"
android:textColor="@android:color/black"
android:textSize="@dimen/register_member_name_size"/>

Expand All @@ -88,7 +88,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/gender"
android:text="Gender"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@android:color/black"
android:textSize="@dimen/register_member_village_size"/>
Expand All @@ -110,7 +110,7 @@
android:gravity="center_horizontal"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:text="@string/address"
android:text="Address #24"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@android:color/black"
android:textSize="@dimen/register_member_village_size"/>
Expand All @@ -133,7 +133,7 @@
android:layout_gravity="center"
android:gravity="center"
android:paddingStart="0dp"
android:text="@string/id"
android:text="ID:123456"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@android:color/black"
android:textSize="@dimen/register_member_village_size"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
android:layout_marginTop="5dp"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:text="@string/patient_name_age"
android:text="Patient Name, Age"
android:textColor="@android:color/black"
android:textSize="@dimen/register_member_name_size"/>

Expand All @@ -88,7 +88,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/gender"
android:text="Gender"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@android:color/black"
android:textSize="@dimen/register_member_village_size"/>
Expand All @@ -110,7 +110,7 @@
android:gravity="center_horizontal"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:text="@string/address"
android:text="Address #24"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@android:color/black"
android:textSize="@dimen/register_member_village_size"/>
Expand All @@ -134,7 +134,7 @@
android:gravity="center"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:text="@string/id"
android:text="ID:123456"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@android:color/black"
android:textSize="@dimen/register_member_village_size"/>
Expand Down
4 changes: 0 additions & 4 deletions opensrp-chw-malaria/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
<string name="saving_dialog_title">Saving</string>
<string name="interpunct" translatable="false">\u00b7</string>
<string name="malaria_followup_visit">FOLLOWUP\nVisit</string>
<string name="patient_name_age">Patient Name, Age</string>
<string name="record_malaria">Record malaria follow-up</string>
<string name="gender">Male</string>
<string name="address">Address #24</string>
<string name="id">ID:123456</string>
<string name="collon">\u00b7</string>
<string name="return_to_previous_page">Return</string>

Expand Down
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 b5149ef

Please sign in to comment.