From a503d6dfcefb1fdcf9e819a2b8b3398aefcffffc Mon Sep 17 00:00:00 2001 From: maxiaoping <634115572@qq.com> Date: Tue, 29 Mar 2022 22:45:18 +0800 Subject: [PATCH] Edit file synchronization, for example onlyOffice (#928) --- app/build.gradle | 6 ++--- .../seadroid2/monitor/SeafileObserver.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 58fcb9d32..49fea6707 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" @@ -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' diff --git a/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java b/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java index da5eea8fd..fcd22e5a6 100644 --- a/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java +++ b/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java @@ -34,6 +34,7 @@ public SeafileObserver(Account account, CachedFileChangedListener listener) { this.listener = listener; alterationObserver = new FileAlterationObserver(getAccountDir()); alterationObserver.addListener(this); + startWatching(); watchAllCachedFiles(); } @@ -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) { } @@ -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!");