Commit e23d7aa6 authored by narinder Rana's avatar narinder Rana
Browse files

call handleLocalFiles and skip scanLocalFiles

parent ef439986
Pipeline #132327 failed with stage
in 49 seconds
package foundation.e.drive.models;
import java.io.File;
import java.io.Serializable;
import java.util.List;
public class FileObserver implements Serializable {
private List<File> files;
private List<SyncedFileState> syncedFileStatesList;
public FileObserver(List<File> files, List<SyncedFileState> syncedFileStatesList) {
this.files = files;
this.syncedFileStatesList = syncedFileStatesList;
}
public List<File> getFiles() {
return files;
}
public void setFiles(List<File> files) {
this.files = files;
}
public List<SyncedFileState> getSyncedFileStatesList() {
return syncedFileStatesList;
}
public void setSyncedFileStatesList(List<SyncedFileState> syncedFileStatesList) {
this.syncedFileStatesList = syncedFileStatesList;
}
}
......@@ -16,7 +16,12 @@ import android.support.annotation.Nullable;
import android.util.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.models.SyncedFileState;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.RecursiveFileObserver;
public class FileObserverService extends Service {
......@@ -24,7 +29,8 @@ public class FileObserverService extends Service {
RecursiveFileObserver mFileObserver = null;
private int observerFlag=-1;
List<SyncedFileState> syncedFileStatesList=new ArrayList<>();
List<File> files=new ArrayList<>();
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
......@@ -56,22 +62,29 @@ public class FileObserverService extends Service {
Log.d("OnEvent", "...Event ..." + event+"...file ..." + file);
SyncedFileState syncedFileStates = DbHelper.loadSyncedFile(getApplicationContext(), file.getAbsolutePath(), true);
syncedFileStatesList.add(syncedFileStates);
files.add(file);
//Check internet
// Add event in List<File>
//InitializerService.fileObserver.add(file);
//call to ObserverService >> getSyncedFileState >> HandleLocal File
// try
// {
// if(observerFlag == -1){
// new AsyncTaskRunner().execute("");
// }
// }
// catch (Exception e)
// {
// e.printStackTrace();
// }
try
{
if(observerFlag == -1){
new AsyncTaskRunner().execute("");
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
......@@ -123,7 +136,10 @@ public class FileObserverService extends Service {
public void run() {
// Log.e("onPostExecute", "...ObserverService Intent..." );
// Do something after 20s = 20000ms
Intent observersServiceIntent = new Intent(getApplicationContext(), foundation.e.drive.services.ObserverService.class);
observersServiceIntent.putExtra("isFileObserverService", true);
observersServiceIntent.putExtra("fileObserverObject", new foundation.e.drive.models.FileObserver(files, syncedFileStatesList));
startService(observersServiceIntent);
observerFlag=-1;
......@@ -132,6 +148,7 @@ public class FileObserverService extends Service {
}
}
......
......@@ -28,6 +28,7 @@ import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......@@ -61,6 +62,8 @@ public class InitializerService extends Service
private int restartFolderCreationCounter =0;
private ConnectivityReceiver connectivityReceiver;
// public static List<File> fileObserver=new ArrayList<>();
@Override
public void onCreate() {
Log.i(TAG, "onCreate()");
......
......@@ -69,6 +69,8 @@ public class ObserverService extends Service implements OnRemoteOperationListene
private int initialFolderCounter;
private Account mAccount;
private HashMap<Integer, Parcelable> operationsForIntent;
private Boolean isFileObserverService;
private foundation.e.drive.models.FileObserver fileObserverObject;
/* Lifecycle Methods */
@Override
......@@ -82,6 +84,14 @@ public class ObserverService extends Service implements OnRemoteOperationListene
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand("+startId+")");
try {
isFileObserverService = (Boolean)intent.getExtras().get("isFileObserverService");
fileObserverObject = (foundation.e.drive.models.FileObserver)intent.getExtras().get("fileObserverObject");
}catch (Exception ex){
ex.printStackTrace();
}
CommonUtils.setServiceUnCaughtExceptionHandler(this);
SharedPreferences prefs = this.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
......@@ -239,7 +249,14 @@ public class ObserverService extends Service implements OnRemoteOperationListene
return;
}
} else {
scanLocalFiles();
if(isFileObserverService){
handleLocalFiles(fileObserverObject.getFiles(), fileObserverObject.getSyncedFileStatesList());
}else {
scanLocalFiles();
}
}
}
......@@ -628,10 +645,6 @@ public class ObserverService extends Service implements OnRemoteOperationListene
}
}
//Create function about getSyncedFileState input List<File> from Database
//call handleLocalFiles
/**
* This function determine the action to do depending for each file or syncedFileState
* If file has already be synced and modified since last synced then update (= upload)
......
......@@ -30,7 +30,12 @@ import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.resources.files.FileUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import foundation.e.drive.receivers.ScreenOffReceiver;
......@@ -291,4 +296,26 @@ public abstract class CommonUtils {
+ "\n File can be read?: " + f.canRead()
+ "\n File can be written?: " + f.canWrite();
}
/*
this function convert object to bytes
*/
private byte[] convertToBytes(Object object) throws IOException {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos)) {
out.writeObject(object);
return bos.toByteArray();
}
}
/*
this function convert bytes to Object
*/
private Object convertFromBytes(byte[] bytes) throws IOException, ClassNotFoundException {
try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream in = new ObjectInputStream(bis)) {
return in.readObject();
}
}
}
\ No newline at end of file
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