Update stuff according to review

This commit is contained in:
Mario Danic 2017-02-27 22:21:05 +01:00 committed by AndyScherzinger
parent b2e8cff801
commit 62126daff2
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
5 changed files with 21 additions and 22 deletions

View file

@ -66,6 +66,8 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import static com.owncloud.android.services.AdvancedFileAlterationListener.DELAY_INVOCATION_MS;
public class FileDownloader extends Service
implements OnDatatransferProgressListener, OnAccountsUpdateListener {
@ -80,6 +82,8 @@ public class FileDownloader extends Service
public static final String EXTRA_LINKED_TO_PATH = "LINKED_TO";
public static final String ACCOUNT_NAME = "ACCOUNT_NAME";
private static final int FOREGROUND_SERVICE_ID = 412;
private static final String TAG = FileDownloader.class.getSimpleName();
private Looper mServiceLooper;
@ -162,7 +166,7 @@ public class FileDownloader extends Service
public int onStartCommand(Intent intent, int flags, int startId) {
Log_OC.d(TAG, "Starting command with id " + startId);
startForeground(412, mNotification);
startForeground(FOREGROUND_SERVICE_ID, mNotification);
if (!intent.hasExtra(EXTRA_ACCOUNT) ||
!intent.hasExtra(EXTRA_FILE)

View file

@ -104,6 +104,8 @@ public class FileUploader extends Service
public static final String EXTRA_LINKED_TO_PATH = "LINKED_TO";
public static final String ACCOUNT_NAME = "ACCOUNT_NAME";
private static final int FOREGROUND_SERVICE_ID = 411;
public static final String KEY_FILE = "FILE";
public static final String KEY_LOCAL_FILE = "LOCAL_FILE";
public static final String KEY_REMOTE_FILE = "REMOTE_FILE";
@ -408,7 +410,7 @@ public class FileUploader extends Service
public int onStartCommand(Intent intent, int flags, int startId) {
Log_OC.d(TAG, "Starting command with id " + startId);
startForeground(411, mNotification);
startForeground(FOREGROUND_SERVICE_ID, mNotification);
boolean retry = intent.getBooleanExtra(KEY_RETRY, false);
AbstractList<String> requestedUploads = new Vector<String>();

View file

@ -51,7 +51,7 @@ import java.util.TimeZone;
public class AdvancedFileAlterationListener implements FileAlterationListener {
public static final String TAG = "AdvancedFileAlterationListener";
public static final int DELAY_INVOCATION_MS = 2500;
private Context context;
private SyncedFolder syncedFolder;
@ -88,7 +88,7 @@ public class AdvancedFileAlterationListener implements FileAlterationListener {
@Override
public void onFileCreate(final File file) {
onFileCreate(file, 2500);
onFileCreate(file, DELAY_INVOCATION_MS);
}
public void onFileCreate(final File file, int delay) {

View file

@ -21,20 +21,8 @@
* Changes are Copyright (C) 2017 Mario Danic
* Copyright (C) 2017 Nextcloud GmbH
*
* Those changes are under the following licence:
* All changes are under the same licence as the original.
*
* * 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;
@ -61,6 +49,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class AdvancedFileAlterationObserver extends FileAlterationObserver implements Serializable {
private static final long serialVersionUID = 1185122225658782848L;
private static final int DELAY_INVOCATION_MS = 2500;
private final List<AdvancedFileAlterationListener> listeners = new CopyOnWriteArrayList<>();
private FileEntry rootEntry;
private FileFilter fileFilter;
@ -226,19 +215,20 @@ public class AdvancedFileAlterationObserver extends FileAlterationObserver imple
/* fire directory/file events */
final File rootFile = rootEntry.getFile();
if (rootFile.exists()) {
checkAndNotify(rootEntry, rootEntry.getChildren(), listFiles(rootFile), 2500);
checkAndNotify(rootEntry, rootEntry.getChildren(), listFiles(rootFile), DELAY_INVOCATION_MS);
} else if (rootEntry.isExists()) {
try {
// try to init once more
init();
if (rootEntry.getFile().exists()) {
checkAndNotify(rootEntry, rootEntry.getChildren(), listFiles(rootEntry.getFile()), 2500);
checkAndNotify(rootEntry, rootEntry.getChildren(), listFiles(rootEntry.getFile()),
DELAY_INVOCATION_MS);
} else {
checkAndNotify(rootEntry, rootEntry.getChildren(), FileUtils.EMPTY_FILE_ARRAY, 2500);
checkAndNotify(rootEntry, rootEntry.getChildren(), FileUtils.EMPTY_FILE_ARRAY, DELAY_INVOCATION_MS);
}
} catch (Exception e) {
Log_OC.d("AdvancedFileAlterationObserver", "Failed getting an observer to intialize " + e);
checkAndNotify(rootEntry, rootEntry.getChildren(), FileUtils.EMPTY_FILE_ARRAY, 2500);
checkAndNotify(rootEntry, rootEntry.getChildren(), FileUtils.EMPTY_FILE_ARRAY, DELAY_INVOCATION_MS);
}
} // else didn't exist and still doesn't

View file

@ -41,6 +41,9 @@ import java.io.FileFilter;
public class SyncedFolderObserverService extends Service {
private static final String TAG = "SyncedFolderObserverService";
private static final int MONITOR_SCAN_INTERVAL = 1000;
private final IBinder mBinder = new SyncedFolderObserverBinder();
private FileAlterationMonitor monitor;
private FileFilter fileFilter;
@ -49,7 +52,7 @@ public class SyncedFolderObserverService extends Service {
public void onCreate() {
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(MainApp.getAppContext().
getContentResolver());
monitor = new FileAlterationMonitor(1000);
monitor = new FileAlterationMonitor(MONITOR_SCAN_INTERVAL);
fileFilter = new FileFilter() {
@Override