From 05bd632db186ad93875544dd47f960474b684276 Mon Sep 17 00:00:00 2001 From: Miroslav Smukov Date: Tue, 5 Jul 2016 21:52:19 +0200 Subject: [PATCH] implemented basic Contacts page --- .../anative/Adapters/ContactsAdapter.java | 95 +++++++++++++++++++ .../thesis/smukov/anative/Models/Contact.java | 92 ++++++++++++++++++ .../smukov/anative/NavigationActivity.java | 3 +- .../BaseNavigationListFragment.java | 15 +++ .../NavigationFragment/ContactsFragment.java | 78 +++++++++++++++ .../src/main/res/layout/contacts_layout.xml | 13 +++ .../src/main/res/layout/list_item_contact.xml | 34 +++++++ 7 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 Android/app/src/main/java/com/thesis/smukov/anative/Adapters/ContactsAdapter.java create mode 100644 Android/app/src/main/java/com/thesis/smukov/anative/Models/Contact.java create mode 100644 Android/app/src/main/java/com/thesis/smukov/anative/NavigationFragment/BaseNavigationListFragment.java create mode 100644 Android/app/src/main/java/com/thesis/smukov/anative/NavigationFragment/ContactsFragment.java create mode 100644 Android/app/src/main/res/layout/contacts_layout.xml create mode 100644 Android/app/src/main/res/layout/list_item_contact.xml diff --git a/Android/app/src/main/java/com/thesis/smukov/anative/Adapters/ContactsAdapter.java b/Android/app/src/main/java/com/thesis/smukov/anative/Adapters/ContactsAdapter.java new file mode 100644 index 0000000..2b3ac03 --- /dev/null +++ b/Android/app/src/main/java/com/thesis/smukov/anative/Adapters/ContactsAdapter.java @@ -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 lstContacts; + private Activity context; + + public ContactsAdapter(Activity context, List 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 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; + } + +} diff --git a/Android/app/src/main/java/com/thesis/smukov/anative/Models/Contact.java b/Android/app/src/main/java/com/thesis/smukov/anative/Models/Contact.java new file mode 100644 index 0000000..7f5b3bd --- /dev/null +++ b/Android/app/src/main/java/com/thesis/smukov/anative/Models/Contact.java @@ -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; + } +} diff --git a/Android/app/src/main/java/com/thesis/smukov/anative/NavigationActivity.java b/Android/app/src/main/java/com/thesis/smukov/anative/NavigationActivity.java index 9610eb1..5db3c9b 100644 --- a/Android/app/src/main/java/com/thesis/smukov/anative/NavigationActivity.java +++ b/Android/app/src/main/java/com/thesis/smukov/anative/NavigationActivity.java @@ -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; @@ -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(); diff --git a/Android/app/src/main/java/com/thesis/smukov/anative/NavigationFragment/BaseNavigationListFragment.java b/Android/app/src/main/java/com/thesis/smukov/anative/NavigationFragment/BaseNavigationListFragment.java new file mode 100644 index 0000000..98ca5fd --- /dev/null +++ b/Android/app/src/main/java/com/thesis/smukov/anative/NavigationFragment/BaseNavigationListFragment.java @@ -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(); +} diff --git a/Android/app/src/main/java/com/thesis/smukov/anative/NavigationFragment/ContactsFragment.java b/Android/app/src/main/java/com/thesis/smukov/anative/NavigationFragment/ContactsFragment.java new file mode 100644 index 0000000..6bf8116 --- /dev/null +++ b/Android/app/src/main/java/com/thesis/smukov/anative/NavigationFragment/ContactsFragment.java @@ -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 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 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()); + setListAdapter(adapter); + + for(int i=0; i + + + + + \ No newline at end of file diff --git a/Android/app/src/main/res/layout/list_item_contact.xml b/Android/app/src/main/res/layout/list_item_contact.xml new file mode 100644 index 0000000..5734f4c --- /dev/null +++ b/Android/app/src/main/res/layout/list_item_contact.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + \ No newline at end of file