Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
implemented basic Contacts page
Browse files Browse the repository at this point in the history
  • Loading branch information
smukov committed Jul 5, 2016
1 parent 924adfc commit 05bd632
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.thesis.smukov.anative.Adapters;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.thesis.smukov.anative.Models.Contact;
import com.thesis.smukov.anative.R;

import java.util.List;

/**
* Created by smuko on 05-Jul-16.
*/
public class ContactsAdapter extends BaseAdapter {

private final List<Contact> lstContacts;
private Activity context;

public ContactsAdapter(Activity context, List<Contact> contacts) {
this.context = context;
this.lstContacts = contacts;
}

@Override
public int getCount() {
if (lstContacts != null) {
return lstContacts.size();
} else {
return 0;
}
}

@Override
public Contact getItem(int position) {
if (lstContacts != null) {
return lstContacts.get(position);
} else {
return null;
}
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
Contact contact = getItem(position);
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

if (convertView == null) {
convertView = vi.inflate(R.layout.list_item_contact, null);
holder = createViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

holder.txtFullName.setText(contact.getFullName());
holder.txtEmployment.setText(contact.getEmployment());
holder.txtEducation.setText(contact.getEducation());

return convertView;
}

public void add(Contact contact) {
lstContacts.add(contact);
}

public void add(List<Contact> contacts) {
lstContacts.addAll(contacts);
}

private ViewHolder createViewHolder(View v) {
ViewHolder holder = new ViewHolder();
holder.txtFullName = (TextView) v.findViewById(R.id.profile_name);
holder.txtEmployment = (TextView) v.findViewById(R.id.txtEmployment);
holder.txtEducation = (TextView) v.findViewById(R.id.txtEducation);
return holder;
}

private static class ViewHolder {
public TextView txtFullName;
public TextView txtEmployment;
public TextView txtEducation;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.thesis.smukov.anative.Models;

/**
* Created by smuko on 05-Jul-16.
*/
public class Contact {
private Long id;
private Long userId;
private String firstName;
private String lastName;
private String employment;
private String education;
private String knowledgeableIn;
private String interests;
private String currentGoals;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Long getUserId() {
return userId;
}

public void setUserId(Long userId) {
this.userId = userId;
}

public String getFullName() {
return firstName + " " + lastName;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getEmployment() {
return employment;
}

public void setEmployment(String employment) {
this.employment = employment;
}

public String getEducation() {
return education;
}

public void setEducation(String education) {
this.education = education;
}

public String getKnowledgeableIn() {
return knowledgeableIn;
}

public void setKnowledgeableIn(String knowledgeableIn) {
this.knowledgeableIn = knowledgeableIn;
}

public String getInterests() {
return interests;
}

public void setInterests(String interests) {
this.interests = interests;
}

public String getCurrentGoals() {
return currentGoals;
}

public void setCurrentGoals(String currentGoals) {
this.currentGoals = currentGoals;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.MenuItem;

import com.thesis.smukov.anative.NavigationFragment.ContactFragment;
import com.thesis.smukov.anative.NavigationFragment.ContactsFragment;
import com.thesis.smukov.anative.NavigationFragment.INavigationFragment;
import com.thesis.smukov.anative.NavigationFragment.ProfileFragment;
import com.thesis.smukov.anative.NavigationFragment.SettingsFragment;
Expand Down Expand Up @@ -99,7 +100,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == R.id.nav_contacts) {
currentFragment = new ContactFragment();
currentFragment = new ContactsFragment();

} else if (id == R.id.nav_settings) {
currentFragment = new SettingsFragment();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.thesis.smukov.anative.NavigationFragment;

import android.app.ListFragment;
import android.support.design.widget.FloatingActionButton;
import android.view.View;


public abstract class BaseNavigationListFragment extends ListFragment
implements INavigationFragment{

protected View myView;
protected FloatingActionButton fab;

protected abstract void prepareFloatingActionButton();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.thesis.smukov.anative.NavigationFragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.thesis.smukov.anative.Adapters.ContactsAdapter;
import com.thesis.smukov.anative.Models.Contact;
import com.thesis.smukov.anative.R;

import java.util.ArrayList;

/**
* Created by smuko on 05-Jul-16.
*/
public class ContactsFragment extends BaseNavigationListFragment {

private ContactsAdapter adapter;
private ArrayList<Contact> lstContacts;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myView = inflater.inflate(R.layout.contacts_layout, container, false);
return myView;
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

prepareFloatingActionButton();

loadContacts();
}

@Override
protected void prepareFloatingActionButton() {
if(fab == null){
fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
}
fab.hide();
}

public void displayContact(Contact contact) {
adapter.add(contact);
adapter.notifyDataSetChanged();
}

private void loadContacts(){

lstContacts = new ArrayList<Contact>();

Contact con = new Contact();
con.setFirstName("Gregory");
con.setLastName("House");
con.setEmployment("Head of Diagnostic @ PPT Hospital");
con.setEducation("Attended Hopkins University 1979-1984");
lstContacts.add(con);
Contact con2 = new Contact();
con2.setFirstName("Hugh");
con2.setLastName("Laurie");
con2.setEmployment("Actor, Writer, Director, Author, etc.");
con2.setEducation("Attended Selwyn College, Cambridge 1978 - 1984");
lstContacts.add(con2);

adapter = new ContactsAdapter(getActivity(), new ArrayList<Contact>());
setListAdapter(adapter);

for(int i=0; i<lstContacts.size(); i++) {
Contact contact = lstContacts.get(i);
displayContact(contact);
}
}
}
13 changes: 13 additions & 0 deletions Android/app/src/main/res/layout/contacts_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>

</LinearLayout>
34 changes: 34 additions & 0 deletions Android/app/src/main/res/layout/list_item_contact.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="7dp"
android:paddingBottom="7dp">

<include layout="@layout/profile_header"/>

<Space
android:layout_width="20dp"
android:layout_height="20dp" />

<TextView
android:id="@+id/txtEmployment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/hint_employment"
android:textSize="16sp"
android:ellipsize="middle"
/>


<TextView
android:id="@+id/txtEducation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_gravity="center_horizontal"
android:text="@string/hint_faculty" />

</LinearLayout>

0 comments on commit 05bd632

Please sign in to comment.