Bladeren bron

Fixed NULL pointers and wrong handling of dialogs

David A. Velasco 12 jaren geleden
bovenliggende
commit
80448dc192

+ 1 - 1
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java

@@ -66,7 +66,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         // remove successfull uploading, ignore rest for reupload on reconnect
         if (intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false)) {
             DbHandler db = new DbHandler(context);
-            String localPath = intent.getStringExtra(FileUploader.EXTRA_FILE_PATH);
+            String localPath = intent.getStringExtra(FileUploader.EXTRA_OLD_FILE_PATH);
             if (!db.removeIUPendingFile(localPath,
                                         intent.getStringExtra(FileUploader.ACCOUNT_NAME))) {
                 Log.w(TAG, "Tried to remove non existing instant upload file " + localPath);

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

@@ -74,7 +74,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
     public static final String EXTRA_UPLOAD_RESULT = "RESULT";
     public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
     public static final String EXTRA_OLD_REMOTE_PATH = "OLD_REMOTE_PATH";
-    public static final String EXTRA_FILE_PATH = "FILE_PATH";
+    public static final String EXTRA_OLD_FILE_PATH = "OLD_FILE_PATH";
     public static final String ACCOUNT_NAME = "ACCOUNT_NAME";    
     
     public static final String KEY_FILE = "FILE";
@@ -562,7 +562,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
         mDefaultNotificationContentView = mNotification.contentView;
         mNotification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.progressbar_layout);
         mNotification.contentView.setProgressBar(R.id.status_progress, 100, 0, false);
-        mNotification.contentView.setTextViewText(R.id.status_text, String.format(getString(R.string.uploader_upload_in_progress_content), 0, new File(upload.getStoragePath()).getName()));
+        mNotification.contentView.setTextViewText(R.id.status_text, String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName()));
         mNotification.contentView.setImageViewResource(R.id.status_icon, R.drawable.icon);
         
         /// includes a pending intent in the notification showing the details view of the file
@@ -627,7 +627,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
             
             mNotification.setLatestEventInfo(   getApplicationContext(), 
                                                 getString(R.string.uploader_upload_succeeded_ticker), 
-                                                String.format(getString(R.string.uploader_upload_succeeded_content_single), (new File(upload.getStoragePath())).getName()), 
+                                                String.format(getString(R.string.uploader_upload_succeeded_content_single), upload.getFileName()), 
                                                 mNotification.contentIntent);
             
             mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotification);    // NOT AN ERROR; uploader_upload_in_progress_ticker is the target, not a new notification
@@ -651,9 +651,9 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
             if (uploadResult.getCode() == ResultCode.LOCAL_STORAGE_FULL ||
                 uploadResult.getCode() == ResultCode.LOCAL_STORAGE_NOT_COPIED) {
                 // TODO we need a class to provide error messages for the users from a RemoteOperationResult and a RemoteOperation 
-                content = String.format(getString(R.string.error__upload__local_file_not_copied), (new File(upload.getStoragePath())).getName(), getString(R.string.app_name));
+                content = String.format(getString(R.string.error__upload__local_file_not_copied), upload.getFileName(), getString(R.string.app_name));
             } else {
-                content = String.format(getString(R.string.uploader_upload_failed_content_single), (new File(upload.getStoragePath())).getName());
+                content = String.format(getString(R.string.uploader_upload_failed_content_single), upload.getFileName());
             }
             finalNotification.setLatestEventInfo(   getApplicationContext(), 
                                                     getString(R.string.uploader_upload_failed_ticker), 
@@ -685,7 +685,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
         if (upload.wasRenamed()) {
             end.putExtra(EXTRA_OLD_REMOTE_PATH, upload.getOldFile().getRemotePath());
         }
-        end.putExtra(EXTRA_FILE_PATH, upload.getStoragePath());
+        end.putExtra(EXTRA_OLD_FILE_PATH, upload.getOriginalStoragePath());
         end.putExtra(ACCOUNT_NAME, upload.getAccount().name);
         end.putExtra(EXTRA_UPLOAD_RESULT, uploadResult.isSuccess());
         sendStickyBroadcast(end);

+ 19 - 9
src/com/owncloud/android/operations/UploadFileOperation.java

@@ -64,6 +64,8 @@ public class UploadFileOperation extends RemoteOperation {
     private boolean mForceOverwrite = false;
     private int mLocalBehaviour = FileUploader.LOCAL_BEHAVIOUR_COPY;
     private boolean mWasRenamed = false;
+    private String mOriginalFileName = null;
+    private String mOriginalStoragePath = null;
     PutMethod mPutMethod = null;
     private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
     private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
@@ -88,6 +90,8 @@ public class UploadFileOperation extends RemoteOperation {
         mIsInstant = isInstant;
         mForceOverwrite = forceOverwrite;
         mLocalBehaviour = localBehaviour;
+        mOriginalStoragePath = mFile.getStoragePath();
+        mOriginalFileName = mFile.getFileName();
     }
 
 
@@ -95,6 +99,10 @@ public class UploadFileOperation extends RemoteOperation {
         return mAccount;
     }
     
+    public String getFileName() {
+        return mOriginalFileName;
+    }
+    
     public OCFile getFile() {
         return mFile;
     }
@@ -103,6 +111,10 @@ public class UploadFileOperation extends RemoteOperation {
         return mOldFile; 
     }
     
+    public String getOriginalStoragePath() {
+        return mOriginalStoragePath;
+    }
+    
     public String getStoragePath() {
         return mFile.getStoragePath();
     }
@@ -147,8 +159,7 @@ public class UploadFileOperation extends RemoteOperation {
     protected RemoteOperationResult run(WebdavClient client) {
         RemoteOperationResult result = null;
         boolean localCopyPassed = false, nameCheckPassed = false;
-        String originalStoragePath = mFile.getStoragePath();
-        File temporalFile = null, originalFile = new File(originalStoragePath), expectedFile = null;
+        File temporalFile = null, originalFile = new File(mOriginalStoragePath), expectedFile = null;
         try {
             /// rename the file to upload, if necessary
             if (!mForceOverwrite) {
@@ -164,7 +175,7 @@ public class UploadFileOperation extends RemoteOperation {
             expectedFile = new File(expectedPath);
             
             /// check location of local file; if not the expected, copy to a temporal file before upload (if COPY is the expected behaviour)
-            if (!originalStoragePath.equals(expectedPath) && mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY) {
+            if (!mOriginalStoragePath.equals(expectedPath) && mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY) {
 
                 if (FileStorageUtils.getUsableSpace(mAccount.name) < originalFile.length()) {
                     result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_FULL);
@@ -174,7 +185,7 @@ public class UploadFileOperation extends RemoteOperation {
                     String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
                     mFile.setStoragePath(temporalPath);
                     temporalFile = new File(temporalPath);
-                    if (!originalStoragePath.equals(temporalPath)) {   // preventing weird but possible situation
+                    if (!mOriginalStoragePath.equals(temporalPath)) {   // preventing weird but possible situation
                         InputStream in = null;
                         OutputStream out = null;
                         try {
@@ -194,7 +205,7 @@ public class UploadFileOperation extends RemoteOperation {
                             try {
                                 if (in != null) in.close();
                             } catch (Exception e) {
-                                Log.d(TAG, "Weird exception while closing input stream for " + originalStoragePath + " (ignoring)", e);
+                                Log.d(TAG, "Weird exception while closing input stream for " + mOriginalStoragePath + " (ignoring)", e);
                             }
                             try {
                                 if (out != null) out.close();
@@ -231,7 +242,6 @@ public class UploadFileOperation extends RemoteOperation {
                     } else {                                // FileUploader.LOCAL_BEHAVIOUR_MOVE
                         fileToMove = originalFile;
                     }
-                    expectedFile = new File(mFile.getStoragePath());
                     if (!expectedFile.equals(fileToMove) && !fileToMove.renameTo(expectedFile)) {
                         mFile.setStoragePath(null); // forget the local file
                         // by now, treat this as a success; the file was uploaded; the user won't like that the local file is not linked, but this should be a veeery rare fail;
@@ -259,7 +269,7 @@ public class UploadFileOperation extends RemoteOperation {
                 temporalFile.delete();
             }
             if (result.isSuccess()) {
-                Log.i(TAG, "Upload of " + originalStoragePath + " to " + mRemotePath + ": " + result.getLogMessage());
+                Log.i(TAG, "Upload of " + mOriginalStoragePath + " to " + mRemotePath + ": " + result.getLogMessage());
                     
             } else {
                 if (result.getException() != null) {
@@ -269,9 +279,9 @@ public class UploadFileOperation extends RemoteOperation {
                     } else if (!localCopyPassed) {
                         complement = " (while copying local file to " + FileStorageUtils.getSavePath(mAccount.name) + ")";
                     }
-                    Log.e(TAG, "Upload of " + originalStoragePath + " to " + mRemotePath + ": " + result.getLogMessage() + complement, result.getException());
+                    Log.e(TAG, "Upload of " + mOriginalStoragePath + " to " + mRemotePath + ": " + result.getLogMessage() + complement, result.getException());
                 } else {
-                    Log.e(TAG, "Upload of " + originalStoragePath + " to " + mRemotePath + ": " + result.getLogMessage());
+                    Log.e(TAG, "Upload of " + mOriginalStoragePath + " to " + mRemotePath + ": " + result.getLogMessage());
                 }
             }
         }

+ 3 - 3
src/com/owncloud/android/ui/activity/UploadFilesActivity.java

@@ -363,7 +363,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements
             setResult(RESULT_OK_AND_MOVE, data);
             finish();
         }
-        //mCurrentDialog.dismiss();
+        mCurrentDialog.dismiss();
         mCurrentDialog = null;
     }
 
@@ -371,7 +371,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements
     @Override
     public void onNeutral(String callerTag) {
         Log.d(TAG, "Phantom neutral button in dialog was clicked; dialog tag is " + callerTag);
-        //mCurrentDialog.dismiss();
+        mCurrentDialog.dismiss();
         mCurrentDialog = null;
     }
 
@@ -380,7 +380,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements
     public void onCancel(String callerTag) {
         /// nothing to do; don't finish, let the user change the selection
         Log.d(TAG, "Negative button in dialog was clicked; dialog tag is " + callerTag);
-        //mCurrentDialog.dismiss();
+        mCurrentDialog.dismiss();
         mCurrentDialog = null;
     }    
 

+ 10 - 1
src/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -50,6 +50,7 @@ import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Handler;
+import android.support.v4.app.DialogFragment;
 import android.support.v4.app.FragmentTransaction;
 import android.util.Log;
 import android.view.Display;
@@ -121,6 +122,7 @@ public class FileDetailFragment extends SherlockFragment implements
     
     private Handler mHandler;
     private RemoteOperation mLastRemoteOperation;
+    private DialogFragment mCurrentDialog;
 
     private static final String TAG = FileDetailFragment.class.getSimpleName();
     public static final String FTAG = "FileDetails"; 
@@ -353,7 +355,8 @@ public class FileDetailFragment extends SherlockFragment implements
                         mFile.isDown() ? R.string.confirmation_remove_local : -1,
                         R.string.common_cancel);
                 confDialog.setOnConfirmationListener(this);
-                confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
+                mCurrentDialog = confDialog;
+                mCurrentDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
                 break;
             }
             case R.id.fdOpenBtn: {
@@ -427,6 +430,8 @@ public class FileDetailFragment extends SherlockFragment implements
                 getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
             }
         }
+        mCurrentDialog.dismiss();
+        mCurrentDialog = null;
     }
     
     @Override
@@ -438,11 +443,15 @@ public class FileDetailFragment extends SherlockFragment implements
             mStorageManager.saveFile(mFile);
             updateFileDetails(mFile, mAccount);
         }
+        mCurrentDialog.dismiss();
+        mCurrentDialog = null;
     }
     
     @Override
     public void onCancel(String callerTag) {
         Log.d(TAG, "REMOVAL CANCELED");
+        mCurrentDialog.dismiss();
+        mCurrentDialog = null;
     }
     
     

+ 11 - 2
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -51,6 +51,7 @@ import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
+import android.support.v4.app.DialogFragment;
 import android.util.Log;
 import android.view.ContextMenu;
 import android.view.MenuInflater;
@@ -78,7 +79,8 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
     
     private Handler mHandler;
     private OCFile mTargetFile;
-
+    
+    private DialogFragment mCurrentDialog;
     
     /**
      * {@inheritDoc}
@@ -261,7 +263,8 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
                         neuBtnStringId,
                         R.string.common_cancel);
                 confDialog.setOnConfirmationListener(this);
-                confDialog.show(getFragmentManager(), FileDetailFragment.FTAG_CONFIRMATION);
+                mCurrentDialog = confDialog;
+                mCurrentDialog.show(getFragmentManager(), FileDetailFragment.FTAG_CONFIRMATION);
                 return true;
             }
             case R.id.open_file_item: {
@@ -495,6 +498,8 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
                 
                 getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
             }
+            mCurrentDialog.dismiss();
+            mCurrentDialog = null;
         }
     }
     
@@ -510,6 +515,8 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
             mTargetFile.setStoragePath(null);
             mContainerActivity.getStorageManager().saveFile(mTargetFile);
         }
+        mCurrentDialog.dismiss();
+        mCurrentDialog = null;
         listDirectory();
         mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
     }
@@ -517,6 +524,8 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
     @Override
     public void onCancel(String callerTag) {
         Log.d(TAG, "REMOVAL CANCELED");
+        mCurrentDialog.dismiss();
+        mCurrentDialog = null;
     }