package com.averi.worldscribe.activities;

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

import com.averi.worldscribe.utilities.ExternalReader;
import com.averi.worldscribe.views.BottomBar;
import com.averi.worldscribe.R;

public class PersonActivity extends ArticleActivity {

    private EditText aliasesField;
    private EditText ageField;
    private EditText biographyField;
    private RadioGroup genderGroup;

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

        aliasesField = (EditText) findViewById(R.id.editAliases);
        ageField = (EditText) findViewById(R.id.editAge);
        biographyField = (EditText) findViewById(R.id.editBio);
        genderGroup = (RadioGroup) findViewById(R.id.radioGroupGender);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Resources resources = getResources();

        loadTextFieldsData(resources);
        loadGender(resources);
    }

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

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

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

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

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

    /**
     * Retrieve this Person's aliases, age, biography data and display them in the corresponding
     * text fields.
     * @param resources A Resources instance containing this app's resource files and values.
     */
    private void loadTextFieldsData(Resources resources) {
        aliasesField.setText(ExternalReader.getArticleTextFieldData(this, super.getWorldName(),
                super.getCategory(), super.getArticleName(),
                resources.getString(R.string.aliasesField)));
        ageField.setText(ExternalReader.getArticleTextFieldData(this, super.getWorldName(),
                super.getCategory(), super.getArticleName(),
                resources.getString(R.string.ageField)));
        biographyField.setText(ExternalReader.getArticleTextFieldData(this, super.getWorldName(),
                super.getCategory(), super.getArticleName(),
                resources.getString(R.string.biographyField)));
    }

    /**
     * Load this Person's gender and display it.
     * @param resources A Resources instance containing this app's resource files and values.
     */
    private void loadGender(Resources resources) {
        String genderString = ExternalReader.getArticleTextFieldData(this, super.getWorldName(),
                super.getCategory(), super.getArticleName(),
                resources.getString(R.string.genderText));

        if (genderString.equals(resources.getString(R.string.maleText))) {
            genderGroup.check(R.id.radioButtonMale);
        } else if (genderString.equals(resources.getString(R.string.femaleText))) {
            genderGroup.check(R.id.radioButtonFemale);
        } else {
            genderGroup.check(R.id.radioButtonOtherGender);
        }
    }

}

@@ -100,16 +100,70 @@
 Bundle;%0A
+import android.support.v7.widget.LinearLayoutManager;%0A
 import a
@@ -197,24 +197,24 @@
 cyclerView;%0A
-
 import andro
@@ -301,16 +301,128 @@
 Group;%0A%0A
+import com.averi.worldscribe.adapters.ResidencesAdapter;%0Aimport com.averi.worldscribe.adapters.SnippetsAdapter;%0A
 import c
@@ -740,16 +740,57 @@
 erGroup;
+%0A    private RecyclerView residencesList;
 %0A%0A    @O
@@ -1155,24 +1155,103 @@
 oupGender);%0A
+        residencesList = (RecyclerView) findViewById(R.id.recyclerResidences);%0A
     %7D%0A%0A    @
@@ -1399,24 +1399,24 @@
 resources);%0A
-
         load
@@ -1430,24 +1430,54 @@
 resources);%0A
+        populateResidences();%0A
     %7D%0A%0A    @
@@ -3822,10 +3822,328 @@
 %0A    %7D%0A%0A
+    /**%0A     * Populate the Residences RecyclerView with cards for this Person's Residences.%0A     */%0A    private void populateResidences() %7B%0A        residencesList.setLayoutManager(new LinearLayoutManager(this));%0A        residencesList.setAdapter(new ResidencesAdapter(this, getWorldName(), getArticleName()));%0A    %7D%0A%0A
 %7D%0A

Add Residence cards to PersonActivity