package cz.vutbr.fit.iha.household;

import android.content.Context;
import cz.vutbr.fit.iha.Constants;
import cz.vutbr.fit.iha.adapter.Adapter;
import cz.vutbr.fit.iha.network.Network;
import cz.vutbr.fit.iha.network.xml.XmlParsers;

/**
 * Represents demo household with adapters and facilities loaded from local assets files.
 * 
 * @author Robyer
 */
public final class DemoHousehold extends Household {

	public static final String DEMO_EMAIL = "demo";
	
	public DemoHousehold(Context context, Network network) {
		super(context, network);

		prepareAdapters();
	}

	/**
	 * Prepare demo adapters.
	 */
	private void prepareAdapters() {
		try {
			XmlParsers parser = new XmlParsers();

			String assetName = Constants.ASSET_ADAPTERS_FILENAME;
			adaptersModel.setAdapters(parser.getDemoAdaptersFromAsset(mContext, assetName));

			for (Adapter adapter : adaptersModel.getAdapters()) {
				assetName = String.format(Constants.ASSET_LOCATIONS_FILENAME, adapter.getId());
				locationsModel.setLocationsByAdapter(adapter.getId(), parser.getDemoLocationsFromAsset(mContext, assetName));

				assetName = String.format(Constants.ASSET_ADAPTER_DATA_FILENAME, adapter.getId());
				facilitiesModel.setFacilitiesByAdapter(adapter.getId(), parser.getDemoFacilitiesFromAsset(mContext, assetName));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

@@ -30,16 +30,132 @@
 ehold;%0A%0A
+import java.util.List;%0Aimport java.util.Random;%0A%0Aimport org.joda.time.DateTime;%0Aimport org.joda.time.DateTimeZone;%0A%0A
 import a
@@ -254,16 +254,65 @@
 dapter;%0A
+import cz.vutbr.fit.iha.adapter.device.Facility;%0A
 import c
@@ -1343,118 +1343,388 @@
 %09%09%09%09
-facilitiesModel.setFacilitiesByAdapter(a
+List%3CFacility%3E facilities = parser.getDemoFacilitiesFromAsset(mContext, assetName);%0A%09%09%09%09%0A%09%09%09%09// Set last up
 da
-p
 te
-r.getId(), parser.getDemoFacilitiesFromAsset(mContext, assetName)
+ time to time between (-26 hours, now%3E%0A%09%09%09%09for (Facility facility : facilities) %7B%0A%09%09%09%09%09facility.setLastUpdate(DateTime.now(DateTimeZone.UTC).minusSeconds(new Random().nextInt(60*60*26)));%0A%09%09%09%09%7D%0A%09%09%09%09%0A%09%09%09%09facilitiesModel.setFacilitiesByAdapter(adapter.getId(), facilities
 );%0A%09

Set last update time of demo facilities to time between (-26 hours, now>