/*
 * Copyright (C) 2015 Pedro Vicente Gomez Sanchez.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.pedrovgs.nox.sample;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import com.github.pedrovgs.nox.NoxItem;
import com.github.pedrovgs.nox.NoxView;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Pedro Vicente Gomez Sanchez.
 */
public class ContactsActivity extends ActionBarActivity {

  private NoxView noxView;

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contacts);
    configureNoxView();
  }

  private void configureNoxView() {
    noxView = (NoxView) findViewById(R.id.nox_view);
    List<NoxItem> contacts = getContacts();
    noxView.showNoxItems(contacts);
  }

  private List<NoxItem> getContacts() {
    List<NoxItem> contacts = new ArrayList<NoxItem>();
    for (int i = 0; i < 50; i++) {
      String contactUrl = "http://api.randomuser.me/portraits/thumb/women/" + i + ".jpg";
      NoxItem noxItem = new NoxItem(contactUrl);
      contacts.add(noxItem);
    }
    return contacts;
  }
}

@@ -722,16 +722,72 @@
 tivity;%0A
+import android.view.View;%0Aimport android.widget.Button;%0A
 import c
@@ -1043,16 +1043,141 @@
 noxView;
+%0A  private Button addContact;%0A  private Button removeContact;%0A  private int lastContactId;%0A%0A  private List%3CNoxItem%3E contacts;
 %0A%0A  @Ove
@@ -1347,16 +1347,786 @@
 View();%0A
+    configureButtons();%0A  %7D%0A%0A  private void configureButtons() %7B%0A    addContact = (Button) findViewById(R.id.add_contact);%0A    addContact.setOnClickListener(new View.OnClickListener() %7B%0A      @Override public void onClick(View v) %7B%0A        lastContactId++;%0A        String newContactUrl = getUrlForContact(lastContactId);%0A        contacts.add(new NoxItem(newContactUrl));%0A        noxView.showNoxItems(contacts);%0A      %7D%0A    %7D);%0A%0A    removeContact = (Button) findViewById(R.id.remove_contact);%0A    removeContact.setOnClickListener(new View.OnClickListener() %7B%0A      @Override public void onClick(View v) %7B%0A        int lastContact = contacts.size() - 1;%0A        contacts.remove(lastContact);%0A        lastContactId--;%0A        noxView.showNoxItems(contacts);%0A      %7D%0A    %7D);%0A
   %7D%0A%0A  p
@@ -2335,38 +2335,24 @@
 acts() %7B%0A   
- List%3CNoxItem%3E
  contacts = 
@@ -2401,17 +2401,17 @@
  0; i %3C 
-5
+4
 0; i++) 
@@ -2442,70 +2442,27 @@
 l = 
-%22http://api.randomuser.me/portraits/thumb/women/%22 + i + %22.jpg%22
+getUrlForContact(i)
 ;%0A  
@@ -2545,29 +2545,177 @@
     
-%7D%0A    return contacts
+  lastContactId = i;%0A    %7D%0A    return contacts;%0A  %7D%0A%0A  private String getUrlForContact(int i) %7B%0A    return %22http://api.randomuser.me/portraits/thumb/women/%22 + i + %22.jpg%22
 ;%0A  

Update ContactsActivity to be able to add contacts and remove by demand