Commit 01af5c48 authored by narinder Rana's avatar 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
......@@ -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){
......
......@@ -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()) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment