Skip to content

Commit

Permalink
Merge pull request #64 from flipkart-incubator/issue-63
Browse files Browse the repository at this point in the history
Resolves issue #63
  • Loading branch information
thekirankumar authored Dec 28, 2016
2 parents 5e6702f + 6ff4b2d commit cb4dc31
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 187 deletions.
5 changes: 5 additions & 0 deletions data/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
"padding": "16dp",
"paddingBottom": "0dp"
},
{
"type": "DataDrivenExample",
"padding": "16dp",
"paddingBottom": "0dp"
},
{
"type": "CircleView",
"layout_width": "150dp",
Expand Down
35 changes: 35 additions & 0 deletions data/layouts.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,40 @@
]
}
]
},
"DataDrivenExample": {
"type": "FrameLayout",
"layout_width": "match_parent",
"layout_height": "wrap_content",
"children": [
{
"type": "LinearLayout",
"orientation": "horizontal",
"layout_width": "match_parent",
"background": "#ffffff",
"padding": "16dp",
"children": {
"data": "$user.tags",
"layout":{
"type": "TextView",
"dataContext": {
"tag": "user.tags[$index]"
},
"layout_marginRight": "8dp",
"layout_height": "32dp",
"textSize": "12sp",
"textColor": "#2cdb81",
"text": "$tag",
"padding": "8dp",
"gravity": "center",
"border": {
"width": "2dp",
"color": "#cccccc",
"bgColor": "#efefef"
}
}
}
}
]
}
}
7 changes: 6 additions & 1 deletion data/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"experience": {
"current": 4561,
"max": 9999
}
},
"tags": [
"alpha",
"beta",
"gamma"
]
}
}
6 changes: 3 additions & 3 deletions demo/src/main/res/drawable/border.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
-->

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#cccccc" />
android:color="#cccccc"/>

<solid android:color="#efefef" />
<solid android:color="#efefef"/>
</shape>
12 changes: 6 additions & 6 deletions demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:id="@+id/inflate_native"
Expand All @@ -27,7 +27,7 @@
android:text="Native"
android:padding="8dp"
android:layout_margin="8dp"
tools:ignore="HardcodedText" />
tools:ignore="HardcodedText"/>

<Button
android:id="@+id/inflate_proteus"
Expand All @@ -36,7 +36,7 @@
android:text="Proteus"
android:padding="8dp"
android:layout_margin="8dp"
tools:ignore="HardcodedText" />
tools:ignore="HardcodedText"/>

<LinearLayout
android:layout_width="match_parent"
Expand Down
24 changes: 12 additions & 12 deletions demo/src/main/res/layout/activity_native.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
-->

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -48,22 +48,22 @@
android:text="TextView"
android:textColor="#000000"
android:textSize="12sp"
tools:ignore="HardcodedText" />
tools:ignore="HardcodedText"/>

<TextView
android:id="@+id/html_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="14sp"
tools:ignore="RtlHardcoded" />
tools:ignore="RtlHardcoded"/>

<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="8dp"
android:src="@drawable/github_icon"
tools:ignore="RtlHardcoded" />
tools:ignore="RtlHardcoded"/>

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -81,7 +81,7 @@
android:text="1"
android:textColor="#2cdb81"
android:textSize="12sp"
tools:ignore="HardcodedText,RtlHardcoded" />
tools:ignore="HardcodedText,RtlHardcoded"/>

<TextView
android:layout_width="0dp"
Expand All @@ -93,7 +93,7 @@
android:text="2"
android:textColor="#2cdb81"
android:textSize="12sp"
tools:ignore="HardcodedText,RtlHardcoded" />
tools:ignore="HardcodedText,RtlHardcoded"/>

<TextView
android:layout_width="0dp"
Expand All @@ -105,17 +105,17 @@
android:text="3"
android:textColor="#2cdb81"
android:textSize="12sp"
tools:ignore="HardcodedText,RtlHardcoded" />
tools:ignore="HardcodedText,RtlHardcoded"/>

</LinearLayout>

</LinearLayout>

</FrameLayout>

<include layout="@layout/relative_layout_example" />
<include layout="@layout/relative_layout_example"/>

<include layout="@layout/simple_data_binding_example" />
<include layout="@layout/simple_data_binding_example"/>

</LinearLayout>
</ScrollView>
26 changes: 13 additions & 13 deletions demo/src/main/res/layout/relative_layout_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
-->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp">


<RelativeLayout
Expand All @@ -39,23 +39,23 @@
android:text="Center"
android:textColor="#323232"
android:textSize="14sp"
tools:ignore="HardcodedText" />
tools:ignore="HardcodedText"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/center"
android:layout_centerHorizontal="true"
android:layout_marginBottom="8dp"
android:src="@drawable/star_filled" />
android:src="@drawable/star_filled"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/center"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:src="@drawable/star_filled" />
android:src="@drawable/star_filled"/>

<ImageView
android:layout_width="wrap_content"
Expand All @@ -64,7 +64,7 @@
android:layout_marginLeft="8dp"
android:layout_toRightOf="@id/center"
android:src="@drawable/star_filled"
tools:ignore="RtlHardcoded" />
tools:ignore="RtlHardcoded"/>

<ImageView
android:layout_width="wrap_content"
Expand All @@ -73,7 +73,7 @@
android:layout_marginRight="8dp"
android:layout_toLeftOf="@id/center"
android:src="@drawable/star_filled"
tools:ignore="RtlHardcoded" />
tools:ignore="RtlHardcoded"/>

<ImageView
android:layout_width="100dp"
Expand All @@ -84,7 +84,7 @@
android:background="#027cd5"
android:padding="8dp"
android:scaleType="fitCenter"
tools:ignore="RtlHardcoded" />
tools:ignore="RtlHardcoded"/>

</RelativeLayout>

Expand Down
6 changes: 3 additions & 3 deletions demo/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
-->

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<item
android:id="@+id/settings"
android:orderInCategory="100"
android:title="Settings"
app:showAsAction="always"
tools:ignore="HardcodedText" />
tools:ignore="HardcodedText"/>

</menu>
10 changes: 9 additions & 1 deletion demo/src/main/res/raw/data_init.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
},
"data": {
"totalAchievements": 114,
"tags": ["Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Mike"]
"tags": [
"Alpha",
"Bravo",
"Charlie",
"Delta",
"Echo",
"Foxtrot",
"Mike"
]
}
}
6 changes: 5 additions & 1 deletion demo/src/main/res/raw/data_update.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
},
"data": {
"totalAchievements": 114,
"tags": ["Alpha", "Bravo", "Charlie"]
"tags": [
"Alpha",
"Bravo",
"Charlie"
]
}
}
1 change: 1 addition & 0 deletions demo/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
-->

<resources>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
Expand Down
3 changes: 3 additions & 0 deletions demo/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

</resources>
Expand Down
7 changes: 4 additions & 3 deletions demo/src/performance/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
android:theme="@style/AppTheme.NoActionBar">
<activity android:name=".performance.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".performance.ProteusActivity"/>
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
minSdkVersion 14
targetSdkVersion 24
versionCode 410000
versionName "4.1.0"
versionName "4.1.1"
}

lintOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ public DataContext(DataContext dataContext) {
this.isClone = true;
}

public static DataContext updateDataContext(DataContext dataContext, JsonObject data, JsonObject scope) {
public static DataContext updateDataContext(DataContext dataContext, JsonObject data, JsonObject scope, int dataIndex) {
JsonObject reverseScope = new JsonObject();
JsonObject newData = new JsonObject();

dataContext.setIndex(dataIndex);

if (data == null) {
data = new JsonObject();
}
Expand Down Expand Up @@ -157,11 +159,11 @@ public void setIndex(int index) {
this.index = index;
}

public DataContext createChildDataContext(JsonObject scope, int childIndex) {
return updateDataContext(new DataContext(), data, scope);
public DataContext createChildDataContext(JsonObject scope, int dataIndex) {
return updateDataContext(new DataContext(), data, scope, dataIndex);
}

public void updateDataContext(JsonObject data) {
updateDataContext(this, data, scope);
updateDataContext(this, data, scope, index);
}
}
Loading

0 comments on commit cb4dc31

Please sign in to comment.