Browse Source

OC-1130: Change the old dialog by the new dialog.

masensio 11 years ago
parent
commit
b884276998

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

@@ -123,7 +123,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     private static final int DIALOG_SSL_VALIDATOR = 2;
     private static final int DIALOG_CERT_NOT_SAVED = 3;
     
-    public static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
+    private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
 
     public static final String ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS";
 
@@ -612,6 +612,8 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
         Log_OC.d(TAG, "onSaveInstanceState() end");
     }
+    
+
 
     @Override
     protected void onResume() {
@@ -753,7 +755,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     /**
      * Show loading dialog 
      */
-    public void showDialog() {
+    public void showLoadingDialog() {
         // Construct dialog
         LoadingDialog loading = new LoadingDialog(getResources().getString(R.string.wait_a_moment));
         FragmentManager fm = getSupportFragmentManager();
@@ -762,6 +764,17 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         
     }
     
+    /**
+     * Dismiss loading dialog
+     */
+    public void dismissLoadingDialog(){
+        Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG);
+      if (frag != null) {
+          LoadingDialog loading = (LoadingDialog) frag;
+            loading.dismiss();
+        }
+    }
+    
     
     /**
      * Translates a content URI of an image to a physical path
@@ -1173,7 +1186,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
      * @param result        Result of the removal.
      */
     private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        dismissDialog(DIALOG_SHORT_WAIT);
+        dismissLoadingDialog();
         if (result.isSuccess()) {
             Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG);
             msg.show();
@@ -1205,11 +1218,12 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
      */
     private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) {
         if (result.isSuccess()) {
-            dismissDialog(DIALOG_SHORT_WAIT);
+            dismissLoadingDialog();
             refeshListOfFilesFragment();
 
         } else {
-            dismissDialog(DIALOG_SHORT_WAIT);
+            //dismissDialog(DIALOG_SHORT_WAIT);
+            dismissLoadingDialog();
             try {
                 Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); 
                 msg.show();
@@ -1229,7 +1243,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
      * @param result        Result of the renaming.
      */
     private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
-        dismissDialog(DIALOG_SHORT_WAIT);
+        dismissLoadingDialog();
         OCFile renamedFile = operation.getFile();
         if (result.isSuccess()) {
             if (mDualPane) {
@@ -1260,7 +1274,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
 
 
     private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
-        dismissDialog(DIALOG_SHORT_WAIT);
+        dismissLoadingDialog();
         OCFile syncedFile = operation.getLocalFile();
         if (!result.isSuccess()) {
             if (result.getCode() == ResultCode.SYNC_CONFLICT) {
@@ -1321,7 +1335,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                         mHandler,
                         FileDisplayActivity.this);
 
-                showDialog(DIALOG_SHORT_WAIT);
+                showLoadingDialog();
             }
         }
     }

+ 17 - 0
src/com/owncloud/android/ui/dialog/LoadingDialog.java

@@ -15,6 +15,17 @@ public class LoadingDialog extends DialogFragment {
 
     private String mMessage;
     
+    public LoadingDialog() {
+        super();
+    }
+    
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setRetainInstance(true);
+        setCancelable(false);
+    }
+
     public LoadingDialog(String message) {
         this.mMessage = message;
     }
@@ -38,4 +49,10 @@ public class LoadingDialog extends DialogFragment {
         return dialog;
     }
 
+    @Override
+    public void onDestroyView() {
+        if (getDialog() != null && getRetainInstance())
+            getDialog().setDismissMessage(null);
+            super.onDestroyView();
+    }
 }

+ 11 - 14
src/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -30,7 +30,6 @@ import android.content.Intent;
 import android.content.IntentFilter;
 import android.os.Bundle;
 import android.os.Handler;
-import android.support.v4.app.FragmentTransaction;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
@@ -46,11 +45,12 @@ import com.actionbarsherlock.view.MenuInflater;
 import com.actionbarsherlock.view.MenuItem;
 import com.owncloud.android.DisplayUtils;
 import com.owncloud.android.Log_OC;
+import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileObserverService;
 import com.owncloud.android.files.services.FileUploader;
-import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.operations.OnRemoteOperationListener;
 import com.owncloud.android.operations.RemoteOperation;
@@ -65,8 +65,6 @@ import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.dialog.EditNameDialog;
 import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
 
-import com.owncloud.android.R;
-
 import eu.alefzero.webdav.OnDatatransferProgressListener;
 
 /**
@@ -452,8 +450,8 @@ public class FileDetailFragment extends FileFragment implements
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
             
             // update ui 
-            boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
-            getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
+            //boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
+            ((FileDisplayActivity) getActivity()).showLoadingDialog();
             
         }
     }
@@ -468,8 +466,8 @@ public class FileDetailFragment extends FileFragment implements
                                                                 mStorageManager);
                 mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
                 
-                boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
-                getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
+                //boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
+                ((FileDisplayActivity) getActivity()).showLoadingDialog();
             }
         }
     }
@@ -761,8 +759,8 @@ public class FileDetailFragment extends FileFragment implements
                                                             newFilename, 
                                                             new FileDataStorageManager(mAccount, getActivity().getContentResolver()));
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
-            boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
-            getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
+            //boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
+            ((FileDisplayActivity) getActivity()).showLoadingDialog();
         }
     }
     
@@ -787,8 +785,7 @@ public class FileDetailFragment extends FileFragment implements
     
     
     private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
-        
+        ((FileDisplayActivity) getActivity()).dismissLoadingDialog();
         if (result.isSuccess()) {
             Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
             msg.show();
@@ -804,7 +801,7 @@ public class FileDetailFragment extends FileFragment implements
     }
     
     private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
-        getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
+        ((FileDisplayActivity) getActivity()).dismissLoadingDialog();
         
         if (result.isSuccess()) {
             updateFileDetails(((RenameFileOperation)operation).getFile(), mAccount);
@@ -826,7 +823,7 @@ public class FileDetailFragment extends FileFragment implements
     }
     
     private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
-        getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
+        ((FileDisplayActivity) getActivity()).dismissLoadingDialog();
         OCFile file = getFile();
         if (!result.isSuccess()) {
             if (result.getCode() == ResultCode.SYNC_CONFLICT) {

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

@@ -289,7 +289,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
                 Account account = AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity());
                 RemoteOperation operation = new SynchronizeFileOperation(mTargetFile, null, mContainerActivity.getStorageManager(), account, true, false, getSherlockActivity());
                 operation.execute(account, getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
-                getSherlockActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
+                ((FileDisplayActivity) getSherlockActivity()).showLoadingDialog();
                 return true;
             }
             case R.id.action_cancel_download: {
@@ -433,7 +433,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
                                                                 newFilename, 
                                                                 mContainerActivity.getStorageManager());
             operation.execute(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
-            getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
+            ((FileDisplayActivity) getActivity()).showLoadingDialog();
         }
     }
 
@@ -447,7 +447,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
                                                                     mContainerActivity.getStorageManager());
                 operation.execute(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
                 
-                getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
+                ((FileDisplayActivity) getActivity()).showLoadingDialog();
             }
         }
     }

+ 46 - 17
src/com/owncloud/android/ui/preview/PreviewImageActivity.java

@@ -26,6 +26,9 @@ import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.os.Bundle;
 import android.os.IBinder;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentTransaction;
 import android.support.v4.view.ViewPager;
 import android.view.MotionEvent;
 import android.view.View;
@@ -44,6 +47,7 @@ import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
+import com.owncloud.android.ui.dialog.LoadingDialog;
 import com.owncloud.android.ui.fragment.FileFragment;
 
 import com.owncloud.android.Log_OC;
@@ -63,6 +67,8 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
     public static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
     private static final String KEY_WAITING_FOR_BINDER = "WAITING_FOR_BINDER";
     
+    private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
+    
     private DataStorageManager mStorageManager;
     
     private ViewPager mViewPager; 
@@ -236,25 +242,48 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
     }
     
     
-    @Override
-    protected Dialog onCreateDialog(int id) {
-        Dialog dialog = null;
-        switch (id) {
-        case DIALOG_SHORT_WAIT: {
-            ProgressDialog working_dialog = new ProgressDialog(this);
-            working_dialog.setMessage(getResources().getString(
-                    R.string.wait_a_moment));
-            working_dialog.setIndeterminate(true);
-            working_dialog.setCancelable(false);
-            dialog = working_dialog;
-            break;
-        }
-        default:
-            dialog = null;
-        }
-        return dialog;
+//    @Override
+//    protected Dialog onCreateDialog(int id) {
+//        Dialog dialog = null;
+//        switch (id) {
+//        case DIALOG_SHORT_WAIT: {
+//            ProgressDialog working_dialog = new ProgressDialog(this);
+//            working_dialog.setMessage(getResources().getString(
+//                    R.string.wait_a_moment));
+//            working_dialog.setIndeterminate(true);
+//            working_dialog.setCancelable(false);
+//            dialog = working_dialog;
+//            break;
+//        }
+//        default:
+//            dialog = null;
+//        }
+//        return dialog;
+//    }
+    
+    
+    /**
+     * Show loading dialog 
+     */
+    public void showLoadingDialog() {
+        // Construct dialog
+        LoadingDialog loading = new LoadingDialog(getResources().getString(R.string.wait_a_moment));
+        FragmentManager fm = getSupportFragmentManager();
+        FragmentTransaction ft = fm.beginTransaction();
+        loading.show(ft, DIALOG_WAIT_TAG);
+        
     }
     
+    /**
+     * Dismiss loading dialog
+     */
+    public void dismissLoadingDialog(){
+        Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG);
+      if (frag != null) {
+          LoadingDialog loading = (LoadingDialog) frag;
+            loading.dismiss();
+        }
+    }
     
     /**
      * {@inheritDoc}

+ 3 - 2
src/com/owncloud/android/ui/preview/PreviewImageFragment.java

@@ -56,6 +56,7 @@ import com.owncloud.android.operations.OnRemoteOperationListener;
 import com.owncloud.android.operations.RemoteOperation;
 import com.owncloud.android.operations.RemoteOperationResult;
 import com.owncloud.android.operations.RemoveFileOperation;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.fragment.ConfirmationDialogFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
 
@@ -379,7 +380,7 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
                                                             mStorageManager);
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
             
-            getActivity().showDialog(PreviewImageActivity.DIALOG_SHORT_WAIT);
+            ((PreviewImageActivity) getActivity()).showLoadingDialog();
         }
     }
     
@@ -603,7 +604,7 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     }
     
     private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        getActivity().dismissDialog(PreviewImageActivity.DIALOG_SHORT_WAIT);
+        ((PreviewImageActivity) getActivity()).dismissLoadingDialog();
         
         if (result.isSuccess()) {
             Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);

+ 2 - 3
src/com/owncloud/android/ui/preview/PreviewMediaFragment.java

@@ -662,7 +662,7 @@ public class PreviewMediaFragment extends FileFragment implements
                                                             mStorageManager);
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
             
-            getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
+            ((FileDisplayActivity) getActivity()).showLoadingDialog();
         }
     }
     
@@ -716,8 +716,7 @@ public class PreviewMediaFragment extends FileFragment implements
     }
     
     private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
-        
+        ((FileDisplayActivity) getActivity()).dismissLoadingDialog();
         if (result.isSuccess()) {
             Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
             msg.show();