Эх сурвалжийг харах

Merge pull request #6439 from nextcloud/ezaquarii/migrate-data-transfer-listener-to-user-model

Migrate data transfer listener to User model
Tobias Kaminsky 4 жил өмнө
parent
commit
a7b90ed588

+ 4 - 10
src/main/java/com/owncloud/android/files/services/FileDownloader.java

@@ -347,13 +347,10 @@ public class FileDownloader extends Service
          * Adds a listener interested in the progress of the download for a concrete file.
          *
          * @param listener Object to notify about progress of transfer.
-         * @param account  ownCloud account holding the file of interest.
          * @param file     {@link OCFile} of interest for listener.
          */
-        public void addDatatransferProgressListener(
-                OnDatatransferProgressListener listener, Account account, OCFile file
-        ) {
-            if (account == null || file == null || listener == null) {
+        public void addDatatransferProgressListener(OnDatatransferProgressListener listener, OCFile file) {
+            if (file == null || listener == null) {
                 return;
             }
             mBoundListeners.put(file.getFileId(), listener);
@@ -364,13 +361,10 @@ public class FileDownloader extends Service
          * Removes a listener interested in the progress of the download for a concrete file.
          *
          * @param listener      Object to notify about progress of transfer.
-         * @param account       ownCloud account holding the file of interest.
          * @param file          {@link OCFile} of interest for listener.
          */
-        public void removeDatatransferProgressListener(
-                OnDatatransferProgressListener listener, Account account, OCFile file
-        ) {
-            if (account == null || file == null || listener == null) {
+        public void removeDatatransferProgressListener(OnDatatransferProgressListener listener, OCFile file) {
+            if (file == null || listener == null) {
                 return;
             }
             Long fileId = file.getFileId();

+ 10 - 9
src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -47,6 +47,7 @@ import android.os.Parcelable;
 import android.os.Process;
 import android.util.Pair;
 
+import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.device.BatteryStatus;
 import com.nextcloud.client.device.PowerManagementService;
@@ -1207,19 +1208,19 @@ public class FileUploader extends Service
          * Adds a listener interested in the progress of the upload for a concrete file.
          *
          * @param listener Object to notify about progress of transfer.
-         * @param account  ownCloud account holding the file of interest.
+         * @param user  user owning the file of interest.
          * @param file     {@link OCFile} of interest for listener.
          */
         public void addDatatransferProgressListener(
             OnDatatransferProgressListener listener,
-            Account account,
+            User user,
             OCFile file
         ) {
-            if (account == null || file == null || listener == null) {
+            if (user == null || file == null || listener == null) {
                 return;
             }
 
-            String targetKey = buildRemoteName(account.name, file.getRemotePath());
+            String targetKey = buildRemoteName(user.getAccountName(), file.getRemotePath());
             mBoundListeners.put(targetKey, listener);
         }
 
@@ -1245,19 +1246,19 @@ public class FileUploader extends Service
          * Removes a listener interested in the progress of the upload for a concrete file.
          *
          * @param listener Object to notify about progress of transfer.
-         * @param account  ownCloud account holding the file of interest.
-         * @param file     {@link OCFile} of interest for listener.
+         * @param user user owning the file of interest.
+         * @param file {@link OCFile} of interest for listener.
          */
         public void removeDatatransferProgressListener(
             OnDatatransferProgressListener listener,
-            Account account,
+            User user,
             OCFile file
         ) {
-            if (account == null || file == null || listener == null) {
+            if (user == null || file == null || listener == null) {
                 return;
             }
 
-            String targetKey = buildRemoteName(account.name, file.getRemotePath());
+            String targetKey = buildRemoteName(user.getAccountName(), file.getRemotePath());
             if (mBoundListeners.get(targetKey) == listener) {
                 mBoundListeners.remove(targetKey);
             }

+ 4 - 4
src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -715,11 +715,11 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
         if (progressListener != null) {
             if (containerActivity.getFileDownloaderBinder() != null) {
                 containerActivity.getFileDownloaderBinder().
-                        addDatatransferProgressListener(progressListener, user.toPlatformAccount(), getFile());
+                        addDatatransferProgressListener(progressListener, getFile());
             }
             if (containerActivity.getFileUploaderBinder() != null) {
                 containerActivity.getFileUploaderBinder().
-                        addDatatransferProgressListener(progressListener, user.toPlatformAccount(), getFile());
+                        addDatatransferProgressListener(progressListener, user, getFile());
             }
         } else {
             Log_OC.d(TAG, "progressListener == null");
@@ -730,11 +730,11 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
         if (progressListener != null) {
             if (containerActivity.getFileDownloaderBinder() != null) {
                 containerActivity.getFileDownloaderBinder().
-                        removeDatatransferProgressListener(progressListener, user.toPlatformAccount(), getFile());
+                        removeDatatransferProgressListener(progressListener, getFile());
             }
             if (containerActivity.getFileUploaderBinder() != null) {
                 containerActivity.getFileUploaderBinder().
-                        removeDatatransferProgressListener(progressListener, user.toPlatformAccount(), getFile());
+                        removeDatatransferProgressListener(progressListener, user, getFile());
             }
         }
     }

+ 3 - 6
src/main/java/com/owncloud/android/ui/preview/FileDownloadFragment.java

@@ -262,9 +262,7 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
 
     public void listenForTransferProgress() {
         if (mProgressListener != null && !mListening && containerActivity.getFileDownloaderBinder() != null) {
-            containerActivity.getFileDownloaderBinder().addDatatransferProgressListener(
-                    mProgressListener, user.toPlatformAccount(), getFile()
-            );
+            containerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, getFile());
             mListening = true;
             setButtonsForTransferring();
         }
@@ -273,9 +271,8 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
 
     public void leaveTransferProgress() {
         if (mProgressListener != null && containerActivity.getFileDownloaderBinder() != null) {
-            containerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(
-                    mProgressListener, user.toPlatformAccount(), getFile()
-            );
+            containerActivity.getFileDownloaderBinder()
+                .removeDatatransferProgressListener(mProgressListener, getFile());
             mListening = false;
         }
     }