Explorar o código

fix progressbar issues

Luke Owncloud %!s(int64=10) %!d(string=hai) anos
pai
achega
7741bd2866

+ 21 - 9
src/com/owncloud/android/files/services/FileUploadService.java

@@ -575,7 +575,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
             case NOW:
             case NOW:
                 Log_OC.d(TAG, "Calling uploadFile for " + uploadDbObject.getRemotePath());
                 Log_OC.d(TAG, "Calling uploadFile for " + uploadDbObject.getRemotePath());
                 RemoteOperationResult uploadResult = uploadFile(uploadDbObject);
                 RemoteOperationResult uploadResult = uploadFile(uploadDbObject);
-                
+                //TODO store renamed upload path?
                 updateDatabaseUploadResult(uploadResult, mCurrentUpload);
                 updateDatabaseUploadResult(uploadResult, mCurrentUpload);
                 notifyUploadResult(uploadResult, mCurrentUpload);
                 notifyUploadResult(uploadResult, mCurrentUpload);
                 sendFinalBroadcast(uploadResult, mCurrentUpload);                
                 sendFinalBroadcast(uploadResult, mCurrentUpload);                
@@ -679,7 +679,14 @@ public class FileUploadService extends Service implements OnDatatransferProgress
          * a {@link FileUploaderBinder} instance
          * a {@link FileUploaderBinder} instance
          */
          */
         private Map<String, OnDatatransferProgressListener> mBoundListeners = new HashMap<String, OnDatatransferProgressListener>();
         private Map<String, OnDatatransferProgressListener> mBoundListeners = new HashMap<String, OnDatatransferProgressListener>();
-
+        
+        /**
+         * Returns ongoing upload operation. May be null.
+         */
+        public UploadFileOperation getCurrentUploadOperation() {
+            return mCurrentUpload;
+        }
+        
         /**
         /**
          * Cancels a pending or current upload of a remote file.
          * Cancels a pending or current upload of a remote file.
          * 
          * 
@@ -1140,14 +1147,19 @@ public class FileUploadService extends Service implements OnDatatransferProgress
                 .setContentText(
                 .setContentText(
                         String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName()));
                         String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName()));
 
 
-        // / includes a pending intent in the notification showing the details
-        // view of the file
-        Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
-        showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, (Parcelable)upload.getFile());
-        showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, upload.getAccount());
-        showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//        // / includes a pending intent in the notification showing the details
+//        // view of the file
+//        Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
+//        showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, (Parcelable)upload.getFile());
+//        showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, upload.getAccount());
+//        showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+        Intent showUploadListIntent = new Intent(this, UploadListActivity.class);
+        showUploadListIntent.putExtra(FileActivity.EXTRA_FILE, (Parcelable)upload.getFile());
+        showUploadListIntent.putExtra(FileActivity.EXTRA_ACCOUNT, upload.getAccount());
+        showUploadListIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        showUploadListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
         mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
-                showDetailsIntent, 0));
+                showUploadListIntent, 0));
 
 
         mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotificationBuilder.build());
         mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotificationBuilder.build());
         
         

+ 13 - 7
src/com/owncloud/android/ui/activity/UploadListActivity.java

@@ -154,20 +154,26 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
 
 
         @Override
         @Override
         public void onServiceConnected(ComponentName component, IBinder service) {
         public void onServiceConnected(ComponentName component, IBinder service) {
-                
-            if (component.equals(new ComponentName(UploadListActivity.this, FileUploadService.class))) {
-                Log_OC.d(TAG, "UploadListActivty connected to Upload service");
-                mUploaderBinder = (FileUploaderBinder) service;
+            if (service instanceof FileUploaderBinder) {
+                if(mUploaderBinder == null)
+                {
+                    mUploaderBinder = (FileUploaderBinder) service;
+                    Log_OC.e(TAG, "UploadListActivity connected to Upload service. component: " + component + " service: "
+                            + service);
+                } else {
+                    Log_OC.e(TAG, "mUploaderBinder already set. mUploaderBinder: " + mUploaderBinder + " service:" + service);
+                }
             } else {
             } else {
+                Log_OC.e(TAG, "UploadListActivity not connected to Upload service. component: " + component
+                        + " service: " + service);
                 return;
                 return;
-            }
-            
+            }            
         }
         }
 
 
         @Override
         @Override
         public void onServiceDisconnected(ComponentName component) {
         public void onServiceDisconnected(ComponentName component) {
             if (component.equals(new ComponentName(UploadListActivity.this, FileUploadService.class))) {
             if (component.equals(new ComponentName(UploadListActivity.this, FileUploadService.class))) {
-                Log_OC.d(TAG, "UploadListActivty suddenly disconnected from Upload service");
+                Log_OC.d(TAG, "UploadListActivity suddenly disconnected from Upload service");
                 mUploaderBinder = null;
                 mUploaderBinder = null;
             }
             }
         }
         }

+ 17 - 7
src/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java

@@ -23,6 +23,7 @@ import android.widget.ProgressBar;
 import android.widget.TextView;
 import android.widget.TextView;
 
 
 import com.owncloud.android.R;
 import com.owncloud.android.R;
+import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.db.UploadDbHandler;
 import com.owncloud.android.db.UploadDbHandler;
 import com.owncloud.android.db.UploadDbHandler.UploadStatus;
 import com.owncloud.android.db.UploadDbHandler.UploadStatus;
@@ -30,6 +31,7 @@ import com.owncloud.android.db.UploadDbObject;
 import com.owncloud.android.files.services.FileUploadService;
 import com.owncloud.android.files.services.FileUploadService;
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.operations.UploadFileOperation;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.UploadUtils;
 import com.owncloud.android.utils.UploadUtils;
@@ -45,6 +47,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
     private Activity mActivity;
     private Activity mActivity;
     
     
     public ProgressListener mProgressListener; 
     public ProgressListener mProgressListener; 
+    UploadFileOperation mCurrentUpload;
     
     
     interface Refresh {
     interface Refresh {
         public void refresh();
         public void refresh();
@@ -139,7 +142,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
     public boolean areAllItemsEnabled() {
     public boolean areAllItemsEnabled() {
         return true;
         return true;
     }
     }
-
+    
     private View getView(UploadDbObject[] uploadsItems, int position, View convertView, ViewGroup parent) {
     private View getView(UploadDbObject[] uploadsItems, int position, View convertView, ViewGroup parent) {
         View view = convertView;
         View view = convertView;
         if (view == null) {
         if (view == null) {
@@ -167,10 +170,17 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
             case UPLOAD_IN_PROGRESS:
             case UPLOAD_IN_PROGRESS:
                 status = mActivity.getResources().getString(R.string.uploader_upload_in_progress_ticker);
                 status = mActivity.getResources().getString(R.string.uploader_upload_in_progress_ticker);
                 ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.upload_progress_bar);
                 ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.upload_progress_bar);
+                progressBar.setProgress(0);
                 progressBar.setVisibility(View.VISIBLE);
                 progressBar.setVisibility(View.VISIBLE);
                 mProgressListener = new ProgressListener(progressBar);
                 mProgressListener = new ProgressListener(progressBar);
-                parentFileActivity.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener,
-                        uploadObject.getAccount(mActivity), uploadObject.getOCFile());
+                if (parentFileActivity.getFileUploaderBinder() != null) {
+                    mCurrentUpload = parentFileActivity.getFileUploaderBinder().getCurrentUploadOperation();
+                    mCurrentUpload.addDatatransferProgressListener(mProgressListener);
+                } else {
+                    Log_OC.e(
+                            TAG,
+                            "UploadBinder == null. It should have been created on creating parentFileActivity which inherits from FileActivity. Fix that!");
+                }
                 break;
                 break;
             case UPLOAD_FAILED_GIVE_UP:
             case UPLOAD_FAILED_GIVE_UP:
                 if (uploadObject.getLastResult() != null) {
                 if (uploadObject.getLastResult() != null) {
@@ -214,11 +224,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
             if(uploadObject.getUploadStatus() != UploadStatus.UPLOAD_IN_PROGRESS) {
             if(uploadObject.getUploadStatus() != UploadStatus.UPLOAD_IN_PROGRESS) {
                 ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.upload_progress_bar);
                 ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.upload_progress_bar);
                 progressBar.setVisibility(View.GONE);
                 progressBar.setVisibility(View.GONE);
-                if(parentFileActivity.getFileUploaderBinder() != null && mProgressListener != null) {
-                    parentFileActivity.getFileUploaderBinder().removeDatatransferProgressListener(mProgressListener,
-                            uploadObject.getAccount(mActivity), uploadObject.getOCFile());
+                if(mCurrentUpload != null){
+                    mCurrentUpload.removeDatatransferProgressListener(mProgressListener);
                     mProgressListener = null;
                     mProgressListener = null;
-                }                
+                    mCurrentUpload = null;
+                }
             }
             }
             statusView.setText(status);
             statusView.setText(status);