فهرست منبع

Update stuff for review

Mario Danic 8 سال پیش
والد
کامیت
16da98099b

+ 12 - 10
src/com/owncloud/android/MainApp.java

@@ -114,31 +114,33 @@ public class MainApp extends Application {
             Log_OC.d("Debug", "start logging");
         }
 
-        // clean broken synced folder entries
+        // previous versions of application created broken entries in the syncedfolderprovider
+        // database, and this cleans all that and leaves 1 (newest) entry per synced folder
+
         if (!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("legacyClean", false)) {
-            SyncedFolderProvider mProvider = new SyncedFolderProvider(MainApp.getAppContext().getContentResolver());
+            SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(MainApp.getAppContext().getContentResolver());
 
-            List<SyncedFolder> syncedFolderList = mProvider.getSyncedFolders();
-            Map<Pair<String, String>, Pair<Long, Boolean>> syncedFolders = new HashMap<>();
+            List<SyncedFolder> syncedFolderList = syncedFolderProvider.getSyncedFolders();
+            Map<Pair<String, String>, Long> syncedFolders = new HashMap<>();
             ArrayList<Long> ids = new ArrayList<>();
             for (SyncedFolder syncedFolder : syncedFolderList) {
                 Pair<String, String> checkPair = new Pair(syncedFolder.getAccount(), syncedFolder.getLocalPath());
                 if (syncedFolders.containsKey(checkPair)) {
-                    if (syncedFolder.getId() > syncedFolders.get(checkPair).first) {
-                        syncedFolders.put(checkPair, new Pair(syncedFolder.getId(), true));
+                    if (syncedFolder.getId() > syncedFolders.get(checkPair)) {
+                        syncedFolders.put(checkPair, syncedFolder.getId());
                     }
                 } else {
-                    syncedFolders.put(checkPair, new Pair(syncedFolder.getId(), false));
+                    syncedFolders.put(checkPair, syncedFolder.getId());
                 }
             }
 
-            for (Pair<Long, Boolean> pair : syncedFolders.values()) {
-                ids.add(pair.first);
+            for (Long idValue : syncedFolders.values()) {
+                ids.add(idValue);
             }
 
 
             if (ids.size() > 0) {
-                mProvider.deleteOtherSyncedFolders(mContext, ids);
+                syncedFolderProvider.deleteOtherSyncedFolders(mContext, ids);
             } else {
                 PreferenceManager.getDefaultSharedPreferences(mContext).edit().putBoolean("legacyClean", true).apply();
             }

+ 3 - 3
src/com/owncloud/android/files/services/FileDownloader.java

@@ -97,7 +97,7 @@ public class FileDownloader extends Service
     private NotificationCompat.Builder mNotificationBuilder;
     private int mLastPercent;
 
-    private Notification notification;
+    private Notification mNotification;
 
     public static String getDownloadAddedMessage() {
         return FileDownloader.class.getName() + DOWNLOAD_ADDED_MESSAGE;
@@ -122,7 +122,7 @@ public class FileDownloader extends Service
         mServiceHandler = new ServiceHandler(mServiceLooper, this);
         mBinder = new FileDownloaderBinder();
 
-        notification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext().
+        mNotification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext().
                 getResources().getString(R.string.app_name))
                 .build();
 
@@ -162,7 +162,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, notification);
+        startForeground(412, mNotification);
 
         if (!intent.hasExtra(EXTRA_ACCOUNT) ||
                 !intent.hasExtra(EXTRA_FILE)

+ 3 - 3
src/com/owncloud/android/files/services/FileUploader.java

@@ -109,7 +109,7 @@ public class FileUploader extends Service
     public static final String KEY_REMOTE_FILE = "REMOTE_FILE";
     public static final String KEY_MIME_TYPE = "MIME_TYPE";
 
-    private Notification notification;
+    private Notification mNotification;
 
     /**
      * Call this Service with only this Intent key if all pending uploads are to be retried.
@@ -351,7 +351,7 @@ public class FileUploader extends Service
 
         mUploadsStorageManager = new UploadsStorageManager(getContentResolver(), getApplicationContext());
 
-        notification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext().
+        mNotification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext().
                 getResources().getString(R.string.app_name))
                 .build();
 
@@ -408,7 +408,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, notification);
+        startForeground(411, mNotification);
 
         boolean retry = intent.getBooleanExtra(KEY_RETRY, false);
         AbstractList<String> requestedUploads = new Vector<String>();

+ 12 - 11
src/com/owncloud/android/services/FileAlterationMagicListener.java

@@ -93,19 +93,19 @@ public class FileAlterationMagicListener implements FileAlterationListener {
         if (file != null) {
 
             String mimetypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath());
-            Long dateFolder = file.lastModified();
-            final Locale current = context.getResources().getConfiguration().locale;
+            Long lastModificationTime = file.lastModified();
+            final Locale currentLocale = context.getResources().getConfiguration().locale;
 
             if ("image/jpeg".equalsIgnoreCase(mimetypeString) || "image/tiff".equalsIgnoreCase(mimetypeString)) {
                 try {
                     ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
-                    if (!TextUtils.isEmpty(exifInterface.getAttribute(ExifInterface.TAG_DATETIME))) {
-                        String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
+                    String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
+                    if (!TextUtils.isEmpty(exifDate)) {
                         ParsePosition pos = new ParsePosition(0);
-                        SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", current);
+                        SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", currentLocale);
                         sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
-                        Date datetime = sFormatter.parse(exifDate, pos);
-                        dateFolder = datetime.getTime();
+                        Date dateTime = sFormatter.parse(exifDate, pos);
+                        lastModificationTime = dateTime.getTime();
                     }
 
                 } catch (IOException e) {
@@ -114,7 +114,7 @@ public class FileAlterationMagicListener implements FileAlterationListener {
             }
 
 
-            final Long finalDateFolder = dateFolder;
+            final Long finalLastModificationTime = lastModificationTime;
 
                 final Runnable runnable = new Runnable() {
                 @Override
@@ -122,9 +122,9 @@ public class FileAlterationMagicListener implements FileAlterationListener {
                     PersistableBundle bundle = new PersistableBundle();
                     bundle.putString(SyncedFolderJobService.LOCAL_PATH, file.getAbsolutePath());
                     bundle.putString(SyncedFolderJobService.REMOTE_PATH, FileStorageUtils.getInstantUploadFilePath(
-                            current,
+                            currentLocale,
                             syncedFolder.getRemotePath(), file.getName(),
-                            finalDateFolder,
+                            finalLastModificationTime,
                             syncedFolder.getSubfolderByDate()));
                     bundle.putString(SyncedFolderJobService.ACCOUNT, syncedFolder.getAccount());
                     bundle.putInt(SyncedFolderJobService.UPLOAD_BEHAVIOUR, syncedFolder.getUploadAction());
@@ -137,7 +137,8 @@ public class FileAlterationMagicListener implements FileAlterationListener {
                             new ComponentName(context, SyncedFolderJobService.class))
                             .setRequiresCharging(syncedFolder.getChargingOnly())
                             .setMinimumLatency(10000)
-                            .setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY)
+                            .setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobInfo.NETWORK_TYPE_UNMETERED :
+                                    JobInfo.NETWORK_TYPE_ANY)
                             .setExtras(bundle)
                             .setPersisted(true)
                             .build();

+ 6 - 2
src/com/owncloud/android/services/observer/FileAlterationMagicObserver.java

@@ -14,8 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
- * Modified a bit by Mario Danic
+ * Original source code:
+ * https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java
+ *
+ * Modified by Mario Danic
  * Changes are Copyright (C) 2017 Mario Danic
+ * Copyright (C) 2017 Nextcloud GmbH
  *
  * Those changes are under the following licence:
  *
@@ -170,7 +174,7 @@ public class FileAlterationMagicObserver extends FileAlterationObserver implemen
     }
 
     /**
-     * Check whether the file and its chlidren have been created, modified or deleted.
+     * Check whether the file and its children have been created, modified or deleted.
      */
     public void checkAndNotify() {
 

+ 3 - 3
src/com/owncloud/android/services/observer/SyncedFolderObserverService.java

@@ -42,14 +42,14 @@ import java.io.FileFilter;
 
 public class SyncedFolderObserverService extends Service {
     private static final String TAG = "SyncedFolderObserverService";
-    private SyncedFolderProvider mProvider;
+    private SyncedFolderProvider syncedFolderProvider;
     private final IBinder mBinder = new SyncedFolderObserverBinder();
     private FileAlterationMonitor monitor;
     private FileFilter fileFilter;
 
     @Override
     public void onCreate() {
-        mProvider = new SyncedFolderProvider(MainApp.getAppContext().getContentResolver());
+        syncedFolderProvider = new SyncedFolderProvider(MainApp.getAppContext().getContentResolver());
         monitor = new FileAlterationMonitor();
 
         fileFilter = new FileFilter() {
@@ -60,7 +60,7 @@ public class SyncedFolderObserverService extends Service {
         };
 
 
-            for (SyncedFolder syncedFolder : mProvider.getSyncedFolders()) {
+            for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
                 if (syncedFolder.isEnabled()) {
                     FileAlterationMagicObserver observer = new FileAlterationMagicObserver(syncedFolder, fileFilter);
 

+ 1 - 1
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -256,7 +256,7 @@ public class FileDisplayActivity extends HookActivity
      * Opens a pop up info for the new instant upload and disabled the old instant upload.
      */
     private void upgradeNotificationForInstantUpload() {
-        // check for Android 5+ if legacy instant upload is activated --> disable + show info
+        // check for Android 6+ if legacy instant upload is activated --> disable + show info
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
                 (PreferenceManager.instantPictureUploadEnabled(this) ||
                         PreferenceManager.instantPictureUploadEnabled(this))) {