package todomore.android.metawidget;

import java.util.Map;

import org.metawidget.android.widget.AndroidMetawidget;
import org.metawidget.widgetbuilder.iface.WidgetBuilder;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class TodoMoreAndroidWidgetBuilder implements WidgetBuilder<View, AndroidMetawidget> {

	private static final String TAG = "TAWB";

	public TodoMoreAndroidWidgetBuilder() {
		Log.d(TAG, "TodoAndroidWidgetBuilder()");
		// empty
	}
	
	@Override
	public View buildWidget(String elementName, 
			Map<String, String> attributes, 
			AndroidMetawidget metaWidget) {
		// Log.d(TAG, String.format("buildWidget(%s, %s, %s)", elementName, attributes, metaWidget));
		Context context = metaWidget.getContext();
		String type = attributes.get("type");
		String readOnlyStr = attributes.get("read-only");
		boolean readOnly = Boolean.parseBoolean(readOnlyStr);
		if (elementName.equals("entity") && type.equals("com.darwinsys.todo.model.Date")) {
			return readOnly ? new TextView(context) : new EditText(context);
		}
		return null;
	}

}

@@ -316,16 +316,55 @@
 tView;%0A%0A
+import com.darwinsys.todo.model.Date;%0A%0A
 public c
@@ -1022,83 +1022,40 @@
 if (
-elementName.equals(%22entity%22) && type.equals(%22com.darwinsys.todo.model.Date%22
+type.equals(Date.class.getName()
 )) %7B

Remove duplicate labels from Date fields.