Skip to content

Commit 65e7606

Browse files
v5.1 (#48)
2 parents 772c381 + 5e73ace commit 65e7606

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

app/src/main/java/com/wirelessalien/zipxtract/fragment/MainFragment.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import android.os.Environment
3535
import android.os.FileObserver
3636
import android.os.FileObserver.CREATE
3737
import android.os.FileObserver.DELETE
38+
import android.os.FileObserver.DELETE_SELF
39+
import android.os.FileObserver.MODIFY
3840
import android.os.FileObserver.MOVED_FROM
3941
import android.os.FileObserver.MOVED_TO
4042
import android.os.FileObserver.MOVE_SELF
@@ -957,7 +959,7 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On
957959
val directoryToObserve = File(currentPath ?: Environment.getExternalStorageDirectory().absolutePath)
958960

959961
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
960-
fileObserver = object : FileObserver(directoryToObserve, CREATE or DELETE or MOVE_SELF or MOVED_TO or MOVED_FROM or MODIFY or CLOSE_WRITE or ATTRIB) {
962+
fileObserver = object : FileObserver(directoryToObserve, CREATE or DELETE or MOVE_SELF or MOVED_TO or MOVED_FROM or MODIFY or CLOSE_WRITE or ATTRIB or DELETE_SELF) {
961963
override fun onEvent(event: Int, path: String?) {
962964
if (path == null) return
963965

@@ -966,7 +968,7 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On
966968
}
967969
}
968970
} else {
969-
fileObserver = object : FileObserver(directoryToObserve.absolutePath, CREATE or DELETE or MOVE_SELF or MOVED_TO or MOVED_FROM or MODIFY or CLOSE_WRITE or ATTRIB) {
971+
fileObserver = object : FileObserver(directoryToObserve.absolutePath, CREATE or DELETE or MOVE_SELF or MOVED_TO or MOVED_FROM or MODIFY or CLOSE_WRITE or ATTRIB or DELETE_SELF) {
970972
override fun onEvent(event: Int, path: String?) {
971973
if (path == null) return
972974

@@ -998,22 +1000,22 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On
9981000
adapter.notifyItemInserted(position)
9991001
}
10001002
}
1001-
(event and DELETE) != 0 -> {
1003+
(event and DELETE) != 0 || (event and DELETE_SELF) != 0 -> {
10021004
// Remove deleted file
10031005
val position = adapter.files.indexOfFirst { it.absolutePath == file.absolutePath }
10041006
if (position != -1) {
10051007
adapter.files.removeAt(position)
10061008
adapter.notifyItemRemoved(position)
10071009
}
10081010
}
1009-
// (event and MODIFY) != 0 -> {
1010-
// // Update modified file
1011-
// val position = adapter.files.indexOfFirst { it.absolutePath == file.absolutePath }
1012-
// if (position != -1) {
1013-
// adapter.files[position] = file
1014-
// adapter.notifyItemChanged(position)
1015-
// }
1016-
// }
1011+
(event and MODIFY) != 0 -> {
1012+
// Update modified file
1013+
val position = adapter.files.indexOfFirst { it.absolutePath == file.absolutePath }
1014+
if (position != -1) {
1015+
adapter.files[position] = file
1016+
adapter.notifyItemChanged(position)
1017+
}
1018+
}
10171019
}
10181020
}
10191021
}
@@ -1054,7 +1056,7 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On
10541056
override fun onResume() {
10551057
super.onResume()
10561058
if (checkStoragePermissions()) {
1057-
updateAdapterWithFullList()
1059+
// updateAdapterWithFullList()
10581060
startFileObserver()
10591061
}
10601062
}

0 commit comments

Comments
 (0)