Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
eDrive
Commits
01af5c48
Commit
01af5c48
authored
Jun 09, 2021
by
narinder Rana
Browse files
adding AllSyncedFolders path into stack for observer only this folder
parent
82498267
Pipeline
#118982
passed with stage
in 3 minutes and 34 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/foundation/e/drive/services/FileObserverService.java
View file @
01af5c48
...
...
@@ -44,13 +44,17 @@ public class FileObserverService extends Service {
String
path
=
Environment
.
getExternalStorageDirectory
().
getAbsolutePath
();
Log
.
d
(
"obService"
,
path
);
mFileObserver
=
new
RecursiveFileObserver
(
path
,
new
RecursiveFileObserver
.
EventListener
()
{
mFileObserver
=
new
RecursiveFileObserver
(
getApplicationContext
(),
path
,
new
RecursiveFileObserver
.
EventListener
()
{
@Override
public
void
onEvent
(
int
event
,
File
file
)
{
//Modify =2, create =256, delete =512, movedTo =128
if
(
event
==
FileObserver
.
CREATE
||
event
==
FileObserver
.
MODIFY
||
event
==
FileObserver
.
DELETE
||
event
==
FileObserver
.
MOVED_TO
){
Log
.
d
(
"OnEvent"
,
"...Event ..."
+
event
+
"...file ..."
+
file
);
try
{
if
(
observerFlag
==
-
1
){
...
...
app/src/main/java/foundation/e/drive/utils/RecursiveFileObserver.java
View file @
01af5c48
...
...
@@ -3,34 +3,41 @@ package foundation.e.drive.utils;
import
java.io.File
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Stack
;
import
android.content.Context
;
import
android.os.FileObserver
;
import
android.util.Log
;
import
foundation.e.drive.database.DbHelper
;
import
foundation.e.drive.models.SyncedFolder
;
public
class
RecursiveFileObserver
extends
FileObserver
{
private
final
Map
<
String
,
FileObserver
>
mObservers
=
new
HashMap
<>();
private
String
mPath
;
private
int
mMask
;
private
EventListener
mListener
;
private
final
Context
applicationContext
;
private
String
mPath
;
private
int
mMask
;
private
EventListener
mListener
;
public
interface
EventListener
{
void
onEvent
(
int
event
,
File
file
);
}
public
RecursiveFileObserver
(
String
path
,
EventListener
listener
)
{
this
(
path
,
ALL_EVENTS
,
listener
);
public
RecursiveFileObserver
(
Context
applicationContext
,
String
path
,
EventListener
listener
)
{
this
(
applicationContext
,
path
,
ALL_EVENTS
,
listener
);
}
public
RecursiveFileObserver
(
String
path
,
int
mask
,
EventListener
listener
)
{
public
RecursiveFileObserver
(
Context
applicationContext
,
String
path
,
int
mask
,
EventListener
listener
)
{
super
(
path
,
mask
);
mPath
=
path
;
mMask
=
mask
|
FileObserver
.
CREATE
|
FileObserver
.
DELETE_SELF
;
mListener
=
listener
;
this
.
applicationContext
=
applicationContext
;
}
private
void
startWatching
(
String
path
)
{
...
...
@@ -48,7 +55,14 @@ public class RecursiveFileObserver extends FileObserver {
@Override
public
void
startWatching
()
{
Stack
<
String
>
stack
=
new
Stack
<>();
stack
.
push
(
mPath
);
//stack.push(mPath);
List
<
SyncedFolder
>
mSyncedFolders
=
DbHelper
.
getAllSyncedFolders
(
applicationContext
);
if
(!
mSyncedFolders
.
isEmpty
()){
for
(
SyncedFolder
syncedFolder:
mSyncedFolders
){
stack
.
push
(
syncedFolder
.
getLocalFolder
());
stack
.
push
(
syncedFolder
.
getRemoteFolder
());
}
}
// Recursively watch all child directories
while
(!
stack
.
empty
())
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment