Skip to content

Commit

Permalink
Edit file synchronization, for example onlyOffice (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxiaoping authored Mar 29, 2022
1 parent b85eb85 commit a503d6d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'com.seafile.seadroid2'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 117
versionName "2.2.42"
versionCode 119
versionName "2.2.44"
multiDexEnabled true
resValue "string", "authorities", applicationId + '.cameraupload.provider'
resValue "string", "account_type", "com.seafile.seadroid2.account.api2"
Expand Down Expand Up @@ -100,7 +100,7 @@ android {
implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
implementation 'com.github.kevinsawicki:http-request:6.0'
implementation 'commons-io:commons-io:2.4'
implementation 'commons-io:commons-io:2.11.0'
implementation 'com.google.guava:guava:18.0'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
implementation 'com.cocosw:bottomsheet:1.3.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public SeafileObserver(Account account, CachedFileChangedListener listener) {
this.listener = listener;
alterationObserver = new FileAlterationObserver(getAccountDir());
alterationObserver.addListener(this);
startWatching();
watchAllCachedFiles();
}

Expand Down Expand Up @@ -82,6 +83,9 @@ public Account getAccount() {
public void startWatching() {
try {
alterationObserver.initialize();
FileAlterationObserverRunner fileAlterationObserverRunner = new FileAlterationObserverRunner(alterationObserver);
Thread observer = new Thread(fileAlterationObserverRunner);
observer.start();
} catch (Exception e) {

}
Expand All @@ -96,6 +100,26 @@ public void stopWatching() {
}
}

public class FileAlterationObserverRunner implements Runnable {
private final FileAlterationObserver fileAlterationObserver;

public FileAlterationObserverRunner(FileAlterationObserver fileAlterationObserver) {
this.fileAlterationObserver = fileAlterationObserver;
}

@Override
public void run() {
while (true) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
fileAlterationObserver.checkAndNotify();
}
}
}

@Override
public void onDirectoryChange(File directory) {
Log.v(DEBUG_TAG, directory.getPath() + " was modified!");
Expand Down

0 comments on commit a503d6d

Please sign in to comment.