aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/utils
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2017-07-06 21:16:01 +0200
committerPacien TRAN-GIRARD2017-07-06 21:16:01 +0200
commit819b3a44920e303a670928ee56e32b5ae02efca1 (patch)
tree5fa0c255a04220f676615ea4f287d31bbd4c83e8 /app/src/main/java/org/pacien/tincapp/utils
parentc045543ee4c4fabf5ee38bfb4695d98d9190d862 (diff)
downloadtincapp-819b3a44920e303a670928ee56e32b5ae02efca1.tar.gz
Refresh network and node lists
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/utils')
-rw-r--r--app/src/main/java/org/pacien/tincapp/utils/AndroidExtensions.kt23
-rw-r--r--app/src/main/java/org/pacien/tincapp/utils/FileObserver.kt16
2 files changed, 39 insertions, 0 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/utils/AndroidExtensions.kt b/app/src/main/java/org/pacien/tincapp/utils/AndroidExtensions.kt
new file mode 100644
index 0000000..732b5b2
--- /dev/null
+++ b/app/src/main/java/org/pacien/tincapp/utils/AndroidExtensions.kt
@@ -0,0 +1,23 @@
1package org.pacien.tincapp.utils
2
3import android.widget.ArrayAdapter
4import android.widget.TextView
5import org.pacien.tincapp.R
6import org.pacien.tincapp.context.App
7
8/**
9 * @author pacien
10 */
11
12fun <T> ArrayAdapter<T>.setElements(list: Collection<T>) {
13 setNotifyOnChange(false)
14 clear()
15 addAll(list)
16 notifyDataSetChanged()
17 setNotifyOnChange(true)
18}
19
20fun TextView.setText(list: List<String>) {
21 if (list.isNotEmpty()) text = list.joinToString("\n")
22 else text = App.getContext().getString(R.string.value_none)
23}
diff --git a/app/src/main/java/org/pacien/tincapp/utils/FileObserver.kt b/app/src/main/java/org/pacien/tincapp/utils/FileObserver.kt
new file mode 100644
index 0000000..0370c47
--- /dev/null
+++ b/app/src/main/java/org/pacien/tincapp/utils/FileObserver.kt
@@ -0,0 +1,16 @@
1package org.pacien.tincapp.utils
2
3/**
4 * @author pacien
5 */
6class FileObserver(path: String,
7 mask: Int = android.os.FileObserver.ALL_EVENTS,
8 private val listener: (event: Int, path: String?) -> Unit) : android.os.FileObserver(path, mask) {
9
10 override fun onEvent(event: Int, path: String?) = listener(event, path)
11
12 companion object {
13 val CHANGE = CREATE or DELETE or MODIFY or MOVED_TO or MOVED_FROM
14 }
15
16}