Skip to content

Commit 202bb4e

Browse files
committed
Added code syntax highlighting to Readme
1 parent 480b316 commit 202bb4e

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

todoapp/README.md

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# TODO-DataBinding
22

33
It is based on the [todo-mvp](https://github.com/googlesamples/android-architecture/tree/todo-mvp/todoapp) sample and uses the Data Binding library (currently in beta) to display data
4-
and bind UI elements to actions.
4+
and bind UI elements to actions.
55

66
It's doesn't follow a strict Model-View-ViewModel or a Model-View-Presenter
77
pattern, as it uses both View Models and Presenters.
@@ -20,52 +20,51 @@ data model.
2020
In the todo-mvp sample, a Task description is set in the [TaskDetailFragment](https://github.com/googlesamples/android-architecture/blob/todo-mvp/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailFragment.java):
2121

2222

23-
```
24-
public void onCreateView(...) {
25-
...
26-
mDetailDescription = (TextView)
23+
```java
24+
public void onCreateView(...) {
25+
...
26+
mDetailDescription = (TextView)
2727
root.findViewById(R.id.task_detail_description);
28-
}
28+
}
2929

30-
@Override
31-
public void showDescription(String description) {
32-
mDetailDescription.setVisibility(View.VISIBLE);
33-
mDetailDescription.setText(description);
34-
}
30+
@Override
31+
public void showDescription(String description) {
32+
mDetailDescription.setVisibility(View.VISIBLE);
33+
mDetailDescription.setText(description);
34+
}
3535
```
3636
In this sample, the [TaskDetailFragment](https://github.com/googlesamples/android-architecture/blob/todo-databinding/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailFragment.java) simply passes the Task to the data binding:
3737

3838

39-
```
40-
@Override
41-
public void showTask(Task task) {
42-
mViewDataBinding.setTask(task);
43-
}
39+
```java
40+
@Override
41+
public void showTask(Task task) {
42+
mViewDataBinding.setTask(task);
43+
}
4444
```
4545
and the library will take care of displaying it, as defined by the layout (<code>[taskdetail\_frag.xml](https://github.com/googlesamples/android-architecture/blob/todo-databinding/todoapp/app/src/main/res/layout/taskdetail_frag.xml)</code>)
4646

4747

48-
```
49-
<TextView
50-
android:id="@+id/task_detail_description"
51-
...
52-
android:text="@{task.description}" />
53-
48+
```xml
49+
<TextView
50+
android:id="@+id/task_detail_description"
51+
...
52+
android:text="@{task.description}" />
5453
```
5554
### Event binding
5655

57-
Data binding eliminates the need to call <code>findViewById() </code>and event binding can also help minimizing <code>setOnClickListener()</code>.
56+
Data binding eliminates the need to call <code>findViewById() </code>and event binding can also help minimizing <code>setOnClickListener()</code>.
5857

5958
In this CheckBox from <code>[taskdetail\_frag.xml](https://github.com/googlesamples/android-architecture/blob/todo-databinding/todoapp/app/src/main/res/layout/taskdetail_frag.xml)</code>, the presenter is called directly when the user taps on it:
6059

6160

62-
```
63-
<CheckBox
61+
```xml
62+
<CheckBox
6463
android:id="@+id/task_detail_complete"
6564
...
6665
android:checked="@{task.completed}"
6766
android:onCheckedChanged="@{(cb, isChecked) ->
68-
presenter.completeChanged(task, isChecked)}" />
67+
presenter.completeChanged(task, isChecked)}" />
6968
```
7069
### Observing data
7170

@@ -75,15 +74,15 @@ relevant properties are notified and the UI elements bound to those properties
7574
are updated.
7675

7776

78-
```
79-
public void setTaskListSize(int taskListSize) {
80-
mTaskListSize = taskListSize;
81-
notifyPropertyChanged(BR.noTaskIconRes);
82-
notifyPropertyChanged(BR.noTasksLabel);
83-
notifyPropertyChanged(BR.currentFilteringLabel);
84-
notifyPropertyChanged(BR.notEmpty);
85-
notifyPropertyChanged(BR.tasksAddViewVisible);
86-
}
77+
```java
78+
public void setTaskListSize(int taskListSize) {
79+
mTaskListSize = taskListSize;
80+
notifyPropertyChanged(BR.noTaskIconRes);
81+
notifyPropertyChanged(BR.noTasksLabel);
82+
notifyPropertyChanged(BR.currentFilteringLabel);
83+
notifyPropertyChanged(BR.notEmpty);
84+
notifyPropertyChanged(BR.tasksAddViewVisible);
85+
}
8786
```
8887
## Feature components
8988

0 commit comments

Comments
 (0)