Merge branch 'develop' into send_file_pr311_with_develop
authormasensio <masensio@solidgear.es>
Thu, 27 Feb 2014 07:40:17 +0000 (08:40 +0100)
committermasensio <masensio@solidgear.es>
Thu, 27 Feb 2014 07:40:17 +0000 (08:40 +0100)
1  2 
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@@ -34,7 -34,6 +34,7 @@@ import android.content.IntentFilter
  import android.content.ServiceConnection;
  import android.content.SharedPreferences;
  import android.content.SyncRequest;
 +import android.content.res.Configuration;
  import android.content.res.Resources.NotFoundException;
  import android.database.Cursor;
  import android.net.Uri;
@@@ -121,7 -120,6 +121,7 @@@ OCFileListFragment.ContainerActivity, F
      private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
      private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
      //private static final String KEY_REFRESH_SHARES_IN_PROGRESS = "SHARES_IN_PROGRESS";
 +    private static final String KEY_WAITING_TO_SEND = "WAITING_TO_SEND";
  
      public static final int DIALOG_SHORT_WAIT = 0;
      private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 1;
      private boolean mSyncInProgress = false;
      //private boolean mRefreshSharesInProgress = false;
  
 +    private OCFile mWaitingToSend;
 +
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          Log_OC.d(TAG, "onCreate() start");
              mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW);
              mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS);
              //mRefreshSharesInProgress = savedInstanceState.getBoolean(KEY_REFRESH_SHARES_IN_PROGRESS);
 +            mWaitingToSend = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND);
             
          } else {
              mWaitingToPreview = null;
              mSyncInProgress = false;
              //mRefreshSharesInProgress = false;
 +            mWaitingToSend = null;
          }        
  
          /// USER INTERFACE
              unbindService(mUploadConnection);
      }
  
 +    @Override
 +    public void onConfigurationChanged(Configuration newConfig) {
 +        super.onConfigurationChanged(newConfig);
 +    }
  
      /**
       *  Called when the ownCloud {@link Account} associated to the Activity was just updated.
          outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
          outState.putBoolean(FileDisplayActivity.KEY_SYNC_IN_PROGRESS, mSyncInProgress);
          //outState.putBoolean(FileDisplayActivity.KEY_REFRESH_SHARES_IN_PROGRESS, mRefreshSharesInProgress);
 +        outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND, mWaitingToSend);
  
          Log_OC.d(TAG, "onSaveInstanceState() end");
      }
          // Listen for sync messages
          IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START);
          syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END);
-         syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_SIZE_SYNCED);
+         //syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_SIZE_SYNCED);
          syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED);
          syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
          syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
                  refreshSecondFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
              }
  
 +            if (mWaitingToSend != null) {
 +                mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath()); // Update the file to send
 +                if (mWaitingToSend.isDown() && mWaitingToSend.getStoragePath()!=null) {
 +                    sendDownloadedFile();
 +                }
 +            }
 +            
              removeStickyBroadcast(intent);
          }
  
      }
      */
  
 +    /**
 +     * Requests the download of the received {@link OCFile} , updates the UI
 +     * to monitor the download progress and prepares the activity to send the file
 +     * when the download finishes.
 +     * 
 +     * @param file          {@link OCFile} to download and preview.
 +     */
 +    @Override
 +    public void startDownloadForSending(OCFile file) {
 +        mWaitingToSend = file;
 +        requestForDownload(mWaitingToSend);
 +        boolean hasSecondFragment = (getSecondFragment()!= null);
 +        updateFragmentsVisibility(hasSecondFragment);
 +    }
 +    
 +    private void requestForDownload(OCFile file) {
 +        Account account = getAccount();
 +        if (!mDownloaderBinder.isDownloading(account, file)) {
 +            Intent i = new Intent(this, FileDownloader.class);
 +            i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
 +            i.putExtra(FileDownloader.EXTRA_FILE, file);
 +            startService(i);
 +        }
 +    }
 +    
 +    private void sendDownloadedFile(){
 +        getFileOperationsHelper().sendDownloadedFile(mWaitingToSend, this);
 +        mWaitingToSend = null;
 +    }
 +    
  }