-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timob 12176: Implementation of ListView #3935
Changes from 24 commits
f03926e
0939dfc
631eb29
fadb1fe
ad38236
1cc98d6
c600dee
9891f0b
a804e6e
08bb922
a45e863
6bf0077
2e9eec5
1e68f9e
f691eff
d5ff50f
073fb22
a93b3e0
ded8c0e
02cbc1d
9e1b358
cbaecc3
5276d4d
450daab
b58a856
59059c3
3f970d4
29e9a88
18a25ab
df01733
6551f78
9805f08
ac51568
6a099fe
7e30f25
92174c0
9836e27
c1e7588
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
android:paddingLeft="5sp" | ||
android:background="#A9A9A9" | ||
android:clickable="false" > | ||
|
||
<TextView | ||
android:id="@+id/title" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textColor="#FFFFFF" | ||
android:clickable="false" | ||
android:focusable="false" | ||
android:focusableInTouchMode="false" | ||
android:typeface="sans" | ||
android:textSize="14sp"/> | ||
|
||
</LinearLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width= "fill_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" > | ||
|
||
<ti.modules.titanium.ui.widget.listview.ListItemLayout | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1"> | ||
|
||
<ti.modules.titanium.ui.widget.listview.TiBaseListViewItem | ||
android:id="@+id/listItem" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
|
||
</ti.modules.titanium.ui.widget.listview.ListItemLayout> | ||
|
||
<ImageView | ||
android:id="@+id/accessoryType" | ||
android:contentDescription="@string/accessoryType" | ||
android:layout_width="wrap_content" | ||
android:layout_height= "fill_parent" | ||
android:adjustViewBounds="true" | ||
android:scaleType="centerInside" | ||
android:maxWidth="35dp" | ||
android:focusable="false" | ||
android:focusableInTouchMode="false" /> | ||
|
||
|
||
|
||
</LinearLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name">Titanium UI Module</string> | ||
<string name="accessoryType">One of the following images: isCheck, hasChild, or custom image.</string> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use camel case here because some OS are case insensitive and some are case sensitive and this may introduce name conflict. BTW, in order to avoid the name conflict, it is better to add the package name to the string name, eg. titanium_ui_widget_listview_accessory_type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, for all the resources used by titanium, like layout and drawable, we should add the package name to the res name/id to avoid name conflict. |
||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package ti.modules.titanium.ui.widget.listview; | ||
|
||
import java.util.HashMap; | ||
|
||
import org.appcelerator.kroll.KrollDict; | ||
import org.appcelerator.titanium.TiC; | ||
import org.appcelerator.titanium.util.TiConvert; | ||
|
||
import ti.modules.titanium.ui.ImageViewProxy; | ||
import ti.modules.titanium.ui.LabelProxy; | ||
import ti.modules.titanium.ui.widget.listview.TiTemplate.DataItem; | ||
import android.app.Activity; | ||
|
||
public class DefaultTemplate extends TiTemplate { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think TiTemplate should be named TiListViewTemplate and DefaultTemplate should be TiDefaultListViewTemplate. Just having template as the name is too generic and it's not clear that it's associated with listview. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
public static final String DEFAULT_LABEL_BINDING = "title"; | ||
public static final String DEFAULT_IMAGE_BINDING = "image"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two constants have been in TiC. Don't need to define here again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
public DefaultTemplate(String id, KrollDict properties, Activity activity) { | ||
super(id, properties); | ||
generateDefaultProps(activity); | ||
} | ||
|
||
public void generateDefaultProps(Activity activity) { | ||
|
||
//Generate root item data proxy | ||
ListItemProxy proxy = new ListItemProxy(); | ||
proxy.setActivity(activity); | ||
rootItem = new DataItem(proxy, TiC.PROPERTY_PROPERTIES, null); | ||
dataItems.put(itemID, rootItem); | ||
|
||
//Init default properties for our proxies | ||
KrollDict defaultLabelProperties = new KrollDict(); | ||
KrollDict defaultImageProperties = new KrollDict(); | ||
|
||
//Generate label proxy | ||
LabelProxy labelProxy = new LabelProxy(); | ||
labelProxy.setActivity(activity); | ||
//Generate properties | ||
defaultLabelProperties.put("left", "10%"); | ||
defaultLabelProperties.put("text", "label"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use TiC.PROPERTY_LEFT and TiC.PROPERTY_TEXT instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
//bind the proxy and default properties | ||
DataItem labelItem = new DataItem(labelProxy, DEFAULT_LABEL_BINDING, rootItem); | ||
dataItems.put(DEFAULT_LABEL_BINDING, labelItem); | ||
//set default properties | ||
labelItem.setDefaultProperties(defaultLabelProperties); | ||
//add child | ||
rootItem.addChild(labelItem); | ||
|
||
//Generate image proxy | ||
ImageViewProxy imageProxy = new ImageViewProxy(); | ||
imageProxy.setActivity(activity); | ||
//Generate properties | ||
defaultImageProperties.put("right", "0"); | ||
defaultImageProperties.put("height", "100"); | ||
defaultImageProperties.put("width", "100"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use TiC constants instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
//bind the proxy and default properties | ||
DataItem imageItem = new DataItem (imageProxy, DEFAULT_IMAGE_BINDING, rootItem); | ||
dataItems.put(DEFAULT_IMAGE_BINDING, imageItem); | ||
//set default properties | ||
imageItem.setDefaultProperties(defaultImageProperties); | ||
//add child | ||
rootItem.addChild(imageItem); | ||
|
||
|
||
} | ||
private void parseDefaultData(KrollDict data) { | ||
if (!data.containsKey(TiC.PROPERTY_PROPERTIES)) { | ||
return; | ||
} | ||
|
||
KrollDict properties = data.getKrollDict(TiC.PROPERTY_PROPERTIES); | ||
KrollDict clone_properties = new KrollDict((HashMap)properties.clone()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about cloning the hashmap. Why do we clone this if we're just going to create a new krolldict with it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if (clone_properties.containsKey(TiC.PROPERTY_TITLE)) { | ||
KrollDict text = new KrollDict(); | ||
text.put(TiC.PROPERTY_TEXT, TiConvert.toString(clone_properties, TiC.PROPERTY_TITLE)); | ||
data.put(TiC.PROPERTY_TITLE, text); | ||
if (clone_properties.containsKey(TiC.PROPERTY_FONT)) { | ||
text.put(TiC.PROPERTY_FONT, clone_properties.getKrollDict(TiC.PROPERTY_FONT).clone()); | ||
clone_properties.remove(TiC.PROPERTY_FONT); | ||
} | ||
if (clone_properties.containsKey(TiC.PROPERTY_COLOR)) { | ||
text.put(TiC.PROPERTY_COLOR, clone_properties.get(TiC.PROPERTY_COLOR)); | ||
clone_properties.remove(TiC.PROPERTY_COLOR); | ||
} | ||
clone_properties.remove(TiC.PROPERTY_TITLE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we only support the "text", "font" and "color" properties for the default template? Because we support more properties in our Ti.UI.Label. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes if they're using built-in template, only "text", "color" and "font" are supported for the label, and only "image" is supported for image. |
||
} | ||
|
||
if (clone_properties.containsKey(TiC.PROPERTY_IMAGE)) { | ||
KrollDict image = new KrollDict(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm probably missing something. Why are we storing the image as a kroll dict instead of a string into 'data'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because I'm converting something like var item = {properties: {image: "img.png", backgroundColor: "blue"} } into var item = {properties: {backgroundColor: "blue"} , image: {image: "img.png"} }. Basically Im converting the special case into the regular expected case of "binding": "properties". Easier to process data if all data are in the same format. |
||
image.put(TiC.PROPERTY_IMAGE, TiConvert.toString(clone_properties, TiC.PROPERTY_IMAGE)); | ||
data.put(TiC.PROPERTY_IMAGE, image); | ||
clone_properties.remove(TiC.PROPERTY_IMAGE); | ||
} | ||
|
||
data.put(TiC.PROPERTY_PROPERTIES, clone_properties); | ||
} | ||
|
||
public void updateDefaultProperties(KrollDict data) { | ||
|
||
parseDefaultData(data); | ||
super.updateDefaultProperties(data); | ||
} | ||
|
||
public void mergeWithDefaultProperties(KrollDict data) { | ||
parseDefaultData(data); | ||
super.mergeWithDefaultProperties(data); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ti.modules.titanium.ui.widget.listview; | ||
|
||
import org.appcelerator.titanium.view.TiCompositeLayout; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.ViewGroup; | ||
|
||
public class ListItemLayout extends TiCompositeLayout{ | ||
|
||
public ListItemLayout(Context context, AttributeSet set) { | ||
super(context, set); | ||
} | ||
|
||
@Override | ||
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) { | ||
LayoutParams params = generateDefaultLayoutParams(); | ||
params.autoFillsWidth = true; | ||
return params; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this class is needed. It's just a TiCompositeLayout with width to be fill by default. You can probably just apply it to the layout params of your view during creation. Similar to how we do it in ViewProxy. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ti.modules.titanium.ui.widget.listview; | ||
|
||
import org.appcelerator.kroll.annotations.Kroll; | ||
import org.appcelerator.titanium.TiC; | ||
import org.appcelerator.titanium.proxy.TiViewProxy; | ||
import org.appcelerator.titanium.view.TiUIView; | ||
|
||
import ti.modules.titanium.ui.UIModule; | ||
import android.app.Activity; | ||
|
||
@Kroll.proxy(creatableInModule = UIModule.class) | ||
public class ListItemProxy extends TiViewProxy { | ||
|
||
|
||
public TiUIView createView(Activity activity) { | ||
return new TiListItem(this); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why we are inflating from xml? I'm just asking for consistency sake since we don't really do that anywhere else in titanium. We just instantiate it programmatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's cleaner and faster. Definitely a lot cleaner though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt it's faster, it still has to instantiate it the same way. If anything it would be slightly slower since it has to parse the xml (probably negligible though). Personally I'd rather keep it consistent so we don't have these xml files floating around (my personal preference).