Skip to content

Commit fdb8e95

Browse files
committed
Changes style of completed tasks (strike-through)
1 parent 5fdd6cc commit fdb8e95

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksListBindings.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.example.android.architecture.blueprints.todoapp.tasks
1717

18+
import android.graphics.Paint
19+
import android.widget.TextView
1820
import androidx.databinding.BindingAdapter
1921
import androidx.recyclerview.widget.RecyclerView
2022
import com.example.android.architecture.blueprints.todoapp.data.Task
@@ -26,3 +28,12 @@ import com.example.android.architecture.blueprints.todoapp.data.Task
2628
fun setItems(listView: RecyclerView, items: List<Task>) {
2729
(listView.adapter as TasksAdapter).submitList(items)
2830
}
31+
32+
@BindingAdapter("app:completedTask")
33+
fun setStyle(textView: TextView, enabled: Boolean) {
34+
if (enabled) {
35+
textView.paintFlags = textView.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
36+
} else {
37+
textView.paintFlags = textView.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
38+
}
39+
}

app/src/main/res/layout/task_item.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
~ See the License for the specific language governing permissions and
1414
~ limitations under the License.
1515
-->
16-
<layout xmlns:android="http://schemas.android.com/apk/res/android">
16+
<layout xmlns:android="http://schemas.android.com/apk/res/android"
17+
xmlns:app="http://schemas.android.com/apk/res-auto">
1718

1819
<data>
1920

@@ -31,7 +32,6 @@
3132
<LinearLayout
3233
android:layout_width="match_parent"
3334
android:layout_height="?android:attr/listPreferredItemHeight"
34-
android:background="@{task.completed ? @drawable/list_completed_touch_feedback : @drawable/touch_feedback}"
3535
android:orientation="horizontal"
3636
android:paddingLeft="@dimen/activity_horizontal_margin"
3737
android:paddingRight="@dimen/activity_horizontal_margin"
@@ -53,7 +53,9 @@
5353
android:layout_height="wrap_content"
5454
android:layout_gravity="center_vertical"
5555
android:layout_marginLeft="@dimen/activity_horizontal_margin"
56+
android:layout_marginStart="@dimen/activity_horizontal_margin"
5657
android:textAppearance="@style/TextAppearance.AppCompat.Title"
57-
android:text="@{task.titleForList}" />
58+
android:text="@{task.titleForList}"
59+
app:completedTask="@{task.completed}" />
5860
</LinearLayout>
5961
</layout>

0 commit comments

Comments
 (0)