Browse code

Initial commit (losing old history)

Dario Rodriguez authored on 08/04/2026 17:25:38
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,79 @@
1
+/*
2
+ * Copyright (c) 2023 Samson Achiaga
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+package com.certified.audionote.adapter
18
+
19
+import android.graphics.Paint
20
+import android.view.View
21
+import android.widget.ImageView
22
+import android.widget.TextView
23
+import androidx.databinding.BindingAdapter
24
+import androidx.recyclerview.widget.RecyclerView
25
+import com.certified.audionote.model.Note
26
+
27
+@BindingAdapter("listItems")
28
+fun bindItemRecyclerView(recyclerView: RecyclerView, data: List<Note>?) {
29
+    val adapter = recyclerView.adapter as NoteRecyclerAdapter
30
+    adapter.submitList(data)
31
+}
32
+
33
+@BindingAdapter("visible")
34
+fun View.setVisible(visible: Boolean) {
35
+    visibility = if (visible) View.VISIBLE else View.GONE
36
+}
37
+
38
+@BindingAdapter("editNoteVisible")
39
+fun View.setEditNoteVisible(audioLength: Long) {
40
+    visibility = when (audioLength) {
41
+        0L -> View.GONE
42
+        else -> View.VISIBLE
43
+    }
44
+}
45
+
46
+@BindingAdapter("timerVisible")
47
+fun View.setTimerVisible(audioLength: Long) {
48
+    visibility = when (audioLength) {
49
+        0L -> View.GONE
50
+        else -> View.VISIBLE
51
+    }
52
+}
53
+
54
+@BindingAdapter("strikeThrough")
55
+fun strikeThrough(textView: TextView, strikeThrough: Boolean) {
56
+    if (strikeThrough) {
57
+        textView.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG
58
+    } else {
59
+        textView.paintFlags = 0
60
+    }
61
+}
62
+
63
+@BindingAdapter("timeText")
64
+fun TextView.timeText(value: Long) {
65
+    text = if (value >= 3600)
66
+        String.format("%02d:%02d:%02d", value / 3600, (value % 3600) / 60, value % 60)
67
+    else
68
+        String.format("%02d:%02d", (value % 3600) / 60, value % 60)
69
+}
70
+
71
+@BindingAdapter("image")
72
+fun ImageView.loadImage(image: Int) {
73
+    setImageResource(image)
74
+}
75
+
76
+@BindingAdapter("sizeText")
77
+fun TextView.sizeText(value: String) {
78
+    text = "${value}MB"
79
+}
0 80
\ No newline at end of file