package cz.vutbr.fit.intelligenthomeanywhere.household;

import java.util.ArrayList;

import android.content.Context;
import cz.vutbr.fit.intelligenthomeanywhere.Constants;
import cz.vutbr.fit.intelligenthomeanywhere.User;
import cz.vutbr.fit.intelligenthomeanywhere.User.Gender;
import cz.vutbr.fit.intelligenthomeanywhere.User.Role;
import cz.vutbr.fit.intelligenthomeanywhere.adapter.Adapter;
import cz.vutbr.fit.intelligenthomeanywhere.adapter.device.BaseDevice;
import cz.vutbr.fit.intelligenthomeanywhere.adapter.parser.XmlDeviceParser;
import cz.vutbr.fit.intelligenthomeanywhere.listing.FavoritesListing;


public final class DemoHousehold extends Household {
	
	private final Context mContext;
	
	public DemoHousehold(Context context) {
		mContext = context;
		
		prepareUser();
		prepareAdapters();
		prepareListings();
	}
	
	private void prepareUser() {
		// Prepare demo user
		this.user = new User("John Doe", "john@doe.com", Role.Superuser, Gender.Male);
	}
	
	private void prepareAdapters() {
		// Prepare demo adapters
		this.adapters = new ArrayList<Adapter>();
		
		String filename = mContext.getExternalFilesDir(null).getPath() + Constants.DEMO_FILENAME;
		Adapter adapter = XmlDeviceParser.fromFile(filename);

		this.adapters.add(adapter);
	}
	
	private void prepareListings() {
		// Prepare demo listings
		this.favoritesListings = new ArrayList<FavoritesListing>();
		
		FavoritesListing list = new FavoritesListing("demoFavorites");
		list.setName("My favorites");
		list.setIcon("favorites");
		
		// Add some devices to this listing
		BaseDevice[] devices = (BaseDevice[])this.adapters.get(0).getDevices().values().toArray();
		
		list.addDevice(devices[3]);
		list.addDevice(devices[4]);
		list.addDevice(devices[7]);
		
		this.favoritesListings.add(list);
	}
	
}

@@ -1517,86 +1517,24 @@
 ;%0A%09%09
-%0A%09%09// Add some devices to this listing%0A%09%09Ba
+list.
 se
+t
 Device
-%5B%5D devices = (BaseDevice%5B%5D)
+s(
 this
@@ -1566,124 +1566,11 @@
 es()
-.values().toArray();%0A%09%09%0A%09%09list.addDevice(devices%5B3%5D);%0A%09%09list.addDevice(devices%5B4%5D);%0A%09%09list.addDevice(devices%5B7%5D);%0A%09%09
+);%0A
 %0A%09%09t

Fix crash in DemoHousehold