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

Commit

Permalink
navigating from contacts list to the clicked contact
Browse files Browse the repository at this point in the history
  • Loading branch information
smukov committed Jul 9, 2016
1 parent fdc1be9 commit 5244bee
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.view.Menu;
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;
Expand Down Expand Up @@ -59,8 +58,6 @@ public void onClick(View view) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame ,(Fragment) currentFragment)
.commit();

setTitle(R.string.titleMyProfile);
}

@Override
Expand Down Expand Up @@ -101,8 +98,6 @@ public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();

setTitle(item.getTitle());

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

Expand All @@ -116,12 +111,16 @@ public boolean onNavigationItemSelected(MenuItem item) {
currentFragment = new ProfileFragment();
}

fragmentManager.beginTransaction()
.replace(R.id.content_frame, (Fragment) currentFragment)
.commit();
openNewFragment(currentFragment);

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

public void openNewFragment(INavigationFragment newFragment){
fragmentManager.beginTransaction()
.replace(R.id.content_frame, (Fragment) newFragment)
.commit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ public abstract class BaseNavigationFragment extends Fragment
protected FloatingActionButton fab;

protected abstract void prepareFloatingActionButton();

protected final void setTitle(String title){
getActivity().setTitle(title);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ public abstract class BaseNavigationListFragment extends ListFragment
protected FloatingActionButton fab;

protected abstract void prepareFloatingActionButton();

protected final void setTitle(String title){
getActivity().setTitle(title);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@
import android.widget.TextView;

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

import org.w3c.dom.Text;

/**
* Created by smukov on 18-Jun-16.
*/
public class ContactFragment extends BaseNavigationFragment {

Contact contact;

TextView profileName;
TextView employment;
TextView education;
TextView interests;
TextView knowledgeable;
TextView currentGoals;

@Nullable
@Override
Expand All @@ -33,10 +43,17 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

setTitle(contact.getFullName());
prepareFloatingActionButton();

profileName = (TextView) view.findViewById(R.id.profile_name);
profileName.setText("Dr. Gregory House");
employment = (TextView) view.findViewById(R.id.txtEmployment);
education = (TextView) view.findViewById(R.id.txtEducation);
interests = (TextView) view.findViewById(R.id.txtInterests);
knowledgeable = (TextView) view.findViewById(R.id.txtKnowledgeable);
currentGoals = (TextView) view.findViewById(R.id.txtCurrentGoals);

prepareUI(contact);
}

@Override
Expand All @@ -55,4 +72,17 @@ public void onClick(View view) {
}
});
}

public void setContact(Contact contact){
this.contact = contact;
}

private void prepareUI(Contact contact){
profileName.setText(contact.getFullName());
employment.setText(contact.getEmployment());
education.setText(contact.getEducation());
interests.setText(contact.getInterests());
knowledgeable.setText(contact.getKnowledgeableIn());
currentGoals.setText(contact.getCurrentGoals());
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.thesis.smukov.anative.NavigationFragment;

import android.content.Intent;
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 android.widget.AdapterView;
import android.widget.ListView;

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

import java.util.ArrayList;
Expand All @@ -20,6 +24,7 @@ public class ContactsFragment extends BaseNavigationListFragment {

private ContactsAdapter adapter;
private ArrayList<Contact> lstContacts;
private ListView listView;

@Nullable
@Override
Expand All @@ -32,9 +37,21 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

setTitle(getResources().getString(R.string.titleMyContacts));
prepareFloatingActionButton();

loadContacts();

listView = getListView();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ContactFragment contactFragment = new ContactFragment();
contactFragment.setContact(adapter.getItem(position));

((NavigationActivity)getActivity()).openNewFragment(contactFragment);
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

setTitle(getResources().getString(R.string.titleMyProfile));
prepareFloatingActionButton();

profileName = (TextView) view.findViewById(R.id.profile_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

setTitle(getResources().getString(R.string.titleSettings));
prepareFloatingActionButton();
}

Expand Down

0 comments on commit 5244bee

Please sign in to comment.