package com.averi.worldscribe.activities;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.averi.worldscribe.ArticleTextField;
import com.averi.worldscribe.Category;
import com.averi.worldscribe.R;
import com.averi.worldscribe.adapters.MembersAdapter;
import com.averi.worldscribe.utilities.ExternalReader;
import com.averi.worldscribe.views.BottomBar;

import java.util.ArrayList;

public class GroupActivity extends ArticleActivity {

    private RecyclerView membersList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        membersList = (RecyclerView) findViewById(R.id.recyclerMembers);

        populateMembers();
    }

    @Override
    protected int getLayoutResourceID() {
        return R.layout.activity_group;
    }

    @Override
    protected ImageView getImageView() { return (ImageView) findViewById(R.id.imageGroup); }

    @Override
    protected BottomBar getBottomBar() {
        return (BottomBar) findViewById(R.id.bottomBar);
    }

    @Override
    protected RecyclerView getConnectionsRecycler() {
        return (RecyclerView) findViewById(R.id.recyclerConnections);
    }

    @Override
    protected Button getAddConnectionButton() {
        return (Button) findViewById(R.id.buttonAddConnection);
    }

    @Override
    protected RecyclerView getSnippetsRecycler() {
        return (RecyclerView) findViewById(R.id.recyclerSnippets);
    }

    @Override
    protected ArrayList<ArticleTextField> getTextFields() {
        Resources resources = getResources();
        ArrayList<ArticleTextField> textFields = new ArrayList<>();

        textFields.add(new ArticleTextField(resources.getString(R.string.mandateText),
                (EditText) findViewById(R.id.editMandate),
                this, getWorldName(), Category.Group, getArticleName()));
        textFields.add(new ArticleTextField(resources.getString(R.string.historyHint),
                (EditText) findViewById(R.id.editHistory),
                this, getWorldName(), Category.Group, getArticleName()));

        return textFields;
    }

    private void populateMembers() {
        membersList.setLayoutManager(new LinearLayoutManager(this));
        membersList.setAdapter(new MembersAdapter(this, getWorldName(), getArticleName()));
    }

}

@@ -36,16 +36,47 @@
 ities;%0A%0A
+import android.content.Intent;%0A
 import a
@@ -232,16 +232,42 @@
 erView;%0A
+import android.view.View;%0A
 import a
@@ -440,16 +440,57 @@
 tegory;%0A
+import com.averi.worldscribe.Membership;%0A
 import c
@@ -610,22 +610,20 @@
 ies.
-ExternalReader
+IntentFields
 ;%0Aim
@@ -750,16 +750,70 @@
 vity %7B%0A%0A
+    public static final int RESULT_NEW_MEMBER = 300;%0A%0A
     priv
@@ -841,16 +841,52 @@
 ersList;
+%0A    private Button addMemberButton;
 %0A%0A    @O
@@ -1072,33 +1072,268 @@
 s);%0A
-%0A        populateMembers(
+        addMemberButton = (Button) findViewById(R.id.buttonAddMember);%0A%0A        populateMembers();%0A%0A        addMemberButton.setOnClickListener(new View.OnClickListener() %7B%0A            @Override%0A            public void onClick(View v) %7B addMember(); %7D%0A        %7D
 );%0A 
@@ -2757,199 +2757,1873 @@
     
-private void populateMembers() %7B%0A        membersList.setLayoutManager(new LinearLayoutManager(this));%0A        membersList.setAdapter(new MembersAdapter(this, getWorldName(), getArticleName())
+@Override%0A    protected void onActivityResult(int requestCode, int resultCode, Intent data) %7B%0A        super.onActivityResult(requestCode, resultCode, data);%0A%0A        switch (requestCode) %7B%0A            case RESULT_NEW_MEMBER:%0A                if (resultCode == RESULT_OK) %7B%0A                    Membership newMembership = new Membership();%0A                    newMembership.worldName = getWorldName();%0A                    newMembership.groupName = getArticleName();%0A                    newMembership.memberName = data.getStringExtra(IntentFields.ARTICLE_NAME);%0A%0A                    Intent editMembershipIntent = new Intent(this, EditMembershipActivity.class);%0A                    editMembershipIntent.putExtra(IntentFields.MEMBERSHIP, newMembership);%0A                    startActivity(editMembershipIntent);%0A                %7D%0A        %7D%0A    %7D%0A%0A    private void populateMembers() %7B%0A        membersList.setLayoutManager(new LinearLayoutManager(this));%0A        membersList.setAdapter(new MembersAdapter(this, getWorldName(), getArticleName()));%0A    %7D%0A%0A    /**%0A     * Opens SelectArticleActivity so the user can select a new Member to add to this Group.%0A     */%0A    private void addMember() %7B%0A        Intent selectGroupIntent = new Intent(this, SelectArticleActivity.class);%0A        MembersAdapter membersAdapter = (MembersAdapter) membersList.getAdapter();%0A%0A        selectGroupIntent.putExtra(IntentFields.WORLD_NAME, getWorldName());%0A        selectGroupIntent.putExtra(IntentFields.CATEGORY, Category.Person);%0A        selectGroupIntent.putExtra(IntentFields.MAIN_ARTICLE_CATEGORY, Category.Group);%0A        selectGroupIntent.putExtra(IntentFields.MAIN_ARTICLE_NAME, getArticleName());%0A        selectGroupIntent.putExtra(IntentFields.EXISTING_LINKS,%0A                membersAdapter.getLinkedArticleList());%0A        startActivityForResult(selectGroupIntent, RESULT_NEW_MEMBER
 );%0A 

Add Membership creation in GroupActivity