mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 13:45:35 +03:00
First step towards list persistance
This commit is contained in:
parent
7806ff2041
commit
9e44de9896
2 changed files with 82 additions and 1 deletions
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017 Mario Danic
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.services.observer;
|
||||
|
||||
import org.apache.commons.io.IOCase;
|
||||
import org.apache.commons.io.monitor.FileAlterationObserver;
|
||||
import org.apache.commons.io.monitor.FileEntry;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
||||
/**
|
||||
* Magical file observer
|
||||
*/
|
||||
|
||||
public class FileAlterationMagicObserver extends FileAlterationObserver {
|
||||
|
||||
public FileAlterationMagicObserver(String directoryName) {
|
||||
super(directoryName);
|
||||
}
|
||||
|
||||
public FileAlterationMagicObserver(String directoryName, FileFilter fileFilter) {
|
||||
super(directoryName, fileFilter);
|
||||
}
|
||||
|
||||
public FileAlterationMagicObserver(String directoryName, FileFilter fileFilter, IOCase caseSensitivity) {
|
||||
super(directoryName, fileFilter, caseSensitivity);
|
||||
}
|
||||
|
||||
public FileAlterationMagicObserver(File directory) {
|
||||
super(directory);
|
||||
}
|
||||
|
||||
public FileAlterationMagicObserver(File directory, FileFilter fileFilter) {
|
||||
super(directory, fileFilter);
|
||||
}
|
||||
|
||||
public FileAlterationMagicObserver(File directory, FileFilter fileFilter, IOCase caseSensitivity) {
|
||||
super(directory, fileFilter, caseSensitivity);
|
||||
}
|
||||
|
||||
public FileAlterationMagicObserver(FileEntry rootEntry, FileFilter fileFilter, IOCase caseSensitivity) {
|
||||
super(rootEntry, fileFilter, caseSensitivity);
|
||||
}
|
||||
}
|
|
@ -35,9 +35,11 @@ import com.owncloud.android.services.FileAlterationMagicListener;
|
|||
|
||||
import org.apache.commons.io.monitor.FileAlterationMonitor;
|
||||
import org.apache.commons.io.monitor.FileAlterationObserver;
|
||||
import org.apache.commons.io.monitor.FileEntry;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SyncedFolderObserverService extends Service {
|
||||
|
@ -62,12 +64,29 @@ public class SyncedFolderObserverService extends Service {
|
|||
return !pathname.getName().startsWith(".") && !pathname.getAbsolutePath().endsWith(".tmp");
|
||||
}
|
||||
};
|
||||
|
||||
FileEntry rootEntry;
|
||||
|
||||
Log_OC.d(TAG, "start");
|
||||
for (SyncedFolder syncedFolder : mProvider.getSyncedFolders()) {
|
||||
if (syncedFolder.isEnabled() && !syncedFolderMap.containsKey(syncedFolder.getLocalPath())) {
|
||||
Log_OC.d(TAG, "start observer: " + syncedFolder.getLocalPath());
|
||||
|
||||
FileAlterationObserver observer = new FileAlterationObserver(syncedFolder.getLocalPath(), fileFilter);
|
||||
Field f = null;
|
||||
try {
|
||||
observer.initialize();
|
||||
f = observer.getClass().getDeclaredField("rootEntry");
|
||||
f.setAccessible(true);
|
||||
rootEntry = (FileEntry) f.get(observer);
|
||||
observer = new FileAlterationMagicObserver(rootEntry, fileFilter, null);
|
||||
} catch (NoSuchFieldException e) {
|
||||
Log_OC.d(TAG, "Failed getting private field rootEntry via NoSuchFieldException");
|
||||
} catch (IllegalAccessException e) {
|
||||
Log_OC.d(TAG, "Failed getting private field rootEntry via IllegalAccessException");
|
||||
} catch (Exception e) {
|
||||
Log_OC.d(TAG, "Failed getting an observer to intialize");
|
||||
}
|
||||
|
||||
observer.addListener(new FileAlterationMagicListener(syncedFolder));
|
||||
monitor.addObserver(observer);
|
||||
syncedFolderMap.put(syncedFolder.getLocalPath(), observer);
|
||||
|
|
Loading…
Reference in a new issue