Merge pull request #1088 from owncloud/updated_docs_about_target_of_PRs
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / UploadFilesActivity.java
index 83e7bc0..7a7f8e5 100644 (file)
@@ -1,5 +1,8 @@
-/* ownCloud Android client application
- *   Copyright (C) 2012-2013 ownCloud Inc.
+/**
+ *   ownCloud Android client application
+ *
+ *   @author David A. Velasco
+ *   Copyright (C) 2015 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License version 2,
  *
  *   This program is free software: you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License version 2,
@@ -25,6 +28,8 @@ import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Environment;
 import android.support.v4.app.DialogFragment;
 import android.os.Bundle;
 import android.os.Environment;
 import android.support.v4.app.DialogFragment;
+import android.support.v7.app.ActionBar;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
@@ -32,12 +37,6 @@ import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.TextView;
 
 import android.widget.Button;
 import android.widget.TextView;
 
-import com.actionbarsherlock.app.ActionBar;
-import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
-import com.actionbarsherlock.internal.view.menu.ActionMenuItemView;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
 import com.owncloud.android.R;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
 import com.owncloud.android.R;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
@@ -51,13 +50,11 @@ import com.owncloud.android.utils.FileStorageUtils;
 /**
  * Displays local files and let the user choose what of them wants to upload
  * to the current ownCloud account
 /**
  * Displays local files and let the user choose what of them wants to upload
  * to the current ownCloud account
- * 
- * @author David A. Velasco
- * 
  */
 
 public class UploadFilesActivity extends FileActivity implements
  */
 
 public class UploadFilesActivity extends FileActivity implements
-    LocalFileListFragment.ContainerActivity, OnNavigationListener, OnClickListener, ConfirmationDialogFragmentListener {
+    LocalFileListFragment.ContainerActivity, ActionBar.OnNavigationListener,
+        OnClickListener, ConfirmationDialogFragmentListener {
     
     private ArrayAdapter<String> mDirectories;
     private File mCurrentDir = null;
     
     private ArrayAdapter<String> mDirectories;
     private File mCurrentDir = null;
@@ -67,17 +64,17 @@ public class UploadFilesActivity extends FileActivity implements
     private Account mAccountOnCreation;
     private DialogFragment mCurrentDialog;
     
     private Account mAccountOnCreation;
     private DialogFragment mCurrentDialog;
     
-    public static final String EXTRA_CHOSEN_FILES = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CHOSEN_FILES";
+    public static final String EXTRA_CHOSEN_FILES =
+            UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CHOSEN_FILES";
 
     public static final int RESULT_OK_AND_MOVE = RESULT_FIRST_USER; 
     
 
     public static final int RESULT_OK_AND_MOVE = RESULT_FIRST_USER; 
     
-    private static final String KEY_DIRECTORY_PATH = UploadFilesActivity.class.getCanonicalName() + ".KEY_DIRECTORY_PATH";
+    private static final String KEY_DIRECTORY_PATH =
+            UploadFilesActivity.class.getCanonicalName() + ".KEY_DIRECTORY_PATH";
     private static final String TAG = "UploadFilesActivity";
     private static final String WAIT_DIALOG_TAG = "WAIT";
     private static final String QUERY_TO_MOVE_DIALOG_TAG = "QUERY_TO_MOVE";
     
     private static final String TAG = "UploadFilesActivity";
     private static final String WAIT_DIALOG_TAG = "WAIT";
     private static final String QUERY_TO_MOVE_DIALOG_TAG = "QUERY_TO_MOVE";
     
-    private boolean selectAllToggled = false;
-    private Menu menu;
     
     @Override
     public void onCreate(Bundle savedInstanceState) {
     
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -85,7 +82,8 @@ public class UploadFilesActivity extends FileActivity implements
         super.onCreate(savedInstanceState);
 
         if(savedInstanceState != null) {
         super.onCreate(savedInstanceState);
 
         if(savedInstanceState != null) {
-            mCurrentDir = new File(savedInstanceState.getString(UploadFilesActivity.KEY_DIRECTORY_PATH));
+            mCurrentDir = new File(savedInstanceState.getString(
+                    UploadFilesActivity.KEY_DIRECTORY_PATH));
         } else {
             mCurrentDir = Environment.getExternalStorageDirectory();
         }
         } else {
             mCurrentDir = Environment.getExternalStorageDirectory();
         }
@@ -95,7 +93,8 @@ public class UploadFilesActivity extends FileActivity implements
         /// USER INTERFACE
             
         // Drop-down navigation 
         /// USER INTERFACE
             
         // Drop-down navigation 
-        mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
+        mDirectories = new CustomArrayAdapter<String>(this,
+                R.layout.support_simple_spinner_dropdown_item);
         File currDir = mCurrentDir;
         while(currDir != null && currDir.getParentFile() != null) {
             mDirectories.add(currDir.getName());
         File currDir = mCurrentDir;
         while(currDir != null && currDir.getParentFile() != null) {
             mDirectories.add(currDir.getName());
@@ -105,7 +104,8 @@ public class UploadFilesActivity extends FileActivity implements
 
         // Inflate and set the layout view
         setContentView(R.layout.upload_files_layout);
 
         // Inflate and set the layout view
         setContentView(R.layout.upload_files_layout);
-        mFileListFragment = (LocalFileListFragment) getSupportFragmentManager().findFragmentById(R.id.local_files_list);
+        mFileListFragment = (LocalFileListFragment)
+                getSupportFragmentManager().findFragmentById(R.id.local_files_list);
         
         
         // Set input controllers
         
         
         // Set input controllers
@@ -118,13 +118,13 @@ public class UploadFilesActivity extends FileActivity implements
         // Action bar setup
         ActionBar actionBar = getSupportActionBar();
         actionBar.setIcon(DisplayUtils.getSeasonalIconId());
         // Action bar setup
         ActionBar actionBar = getSupportActionBar();
         actionBar.setIcon(DisplayUtils.getSeasonalIconId());
-        actionBar.setHomeButtonEnabled(true);   // mandatory since Android ICS, according to the official documentation
+        actionBar.setHomeButtonEnabled(true);   // mandatory since Android ICS, according to the
+                                                // official documentation
         actionBar.setDisplayHomeAsUpEnabled(mCurrentDir != null && mCurrentDir.getName() != null);
         actionBar.setDisplayShowTitleEnabled(false);
         actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
         actionBar.setListNavigationCallbacks(mDirectories, this);
         
         actionBar.setDisplayHomeAsUpEnabled(mCurrentDir != null && mCurrentDir.getName() != null);
         actionBar.setDisplayShowTitleEnabled(false);
         actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
         actionBar.setListNavigationCallbacks(mDirectories, this);
         
-        
         // wait dialog
         if (mCurrentDialog != null) {
             mCurrentDialog.dismiss();
         // wait dialog
         if (mCurrentDialog != null) {
             mCurrentDialog.dismiss();
@@ -133,15 +133,8 @@ public class UploadFilesActivity extends FileActivity implements
             
         Log_OC.d(TAG, "onCreate() end");
     }
             
         Log_OC.d(TAG, "onCreate() end");
     }
-    @Override
-    public boolean onCreateOptionsMenu(Menu menu) {
-        // Inflate the menu items for use in the action bar
-        MenuInflater inflater = getSherlock().getMenuInflater();
-        inflater.inflate(R.menu.file_select_all, menu);     
-        this.menu = menu;
-        return true;
-    }
+
+
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         boolean retval = true;
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         boolean retval = true;
@@ -152,33 +145,12 @@ public class UploadFilesActivity extends FileActivity implements
                 }
                 break;
             }
                 }
                 break;
             }
-            case R.id.actionbar_select_all:{
-                if(selectAllToggled){
-                    toggleOffSelectAll();
-                }else{
-                    toggleOnSelectAll(item);
-                }
-                break;
-            }
             default:
                 retval = super.onOptionsItemSelected(item);
         }
         return retval;
     }
             default:
                 retval = super.onOptionsItemSelected(item);
         }
         return retval;
     }
-    public void toggleOffSelectAll(MenuItem item){
-        selectAllToggled = false;
-        item.setIcon(android.R.drawable.checkbox_off_background);
-        mFileListFragment.deselectAll();
-    }
-    public void toggleOffSelectAll(){
-        MenuItem item = menu.findItem(R.id.actionbar_select_all);
-        toggleOffSelectAll(item);
-    }
-    public void toggleOnSelectAll(MenuItem item){
-        selectAllToggled = true;
-        item.setIcon(android.R.drawable.checkbox_on_background);        
-        mFileListFragment.selectAll();
-    }
+
     
     @Override
     public boolean onNavigationItemSelected(int itemPosition, long itemId) {
     
     @Override
     public boolean onNavigationItemSelected(int itemPosition, long itemId) {
@@ -209,13 +181,13 @@ public class UploadFilesActivity extends FileActivity implements
             ActionBar actionBar = getSupportActionBar(); 
             actionBar.setDisplayHomeAsUpEnabled(false);
         } 
             ActionBar actionBar = getSupportActionBar(); 
             actionBar.setDisplayHomeAsUpEnabled(false);
         } 
-        toggleOffSelectAll();
     }
 
     
     @Override
     protected void onSaveInstanceState(Bundle outState) {
     }
 
     
     @Override
     protected void onSaveInstanceState(Bundle outState) {
-        // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
+        // responsibility of restore is preferred in onCreate() before than in
+        // onRestoreInstanceState when there are Fragments involved
         Log_OC.d(TAG, "onSaveInstanceState() start");
         super.onSaveInstanceState(outState);
         outState.putString(UploadFilesActivity.KEY_DIRECTORY_PATH, mCurrentDir.getAbsolutePath());
         Log_OC.d(TAG, "onSaveInstanceState() start");
         super.onSaveInstanceState(outState);
         outState.putString(UploadFilesActivity.KEY_DIRECTORY_PATH, mCurrentDir.getAbsolutePath());
@@ -277,11 +249,10 @@ public class UploadFilesActivity extends FileActivity implements
      * {@inheritDoc}
      */
     @Override
      * {@inheritDoc}
      */
     @Override
-    public void onDirectoryClick(File directory) { 
+    public void onDirectoryClick(File directory) {
         pushDirname(directory);
         ActionBar actionBar = getSupportActionBar();
         actionBar.setDisplayHomeAsUpEnabled(true);
         pushDirname(directory);
         ActionBar actionBar = getSupportActionBar();
         actionBar.setDisplayHomeAsUpEnabled(true);
-        toggleOffSelectAll();
     }
     
     
     }
     
     
@@ -325,8 +296,6 @@ public class UploadFilesActivity extends FileActivity implements
      * to upload into the ownCloud local folder.
      * 
      * Maybe an AsyncTask is not strictly necessary, but who really knows.
      * to upload into the ownCloud local folder.
      * 
      * Maybe an AsyncTask is not strictly necessary, but who really knows.
-     * 
-     * @author David A. Velasco
      */
     private class CheckAvailableSpaceTask extends AsyncTask<Void, Void, Boolean> {
 
      */
     private class CheckAvailableSpaceTask extends AsyncTask<Void, Void, Boolean> {
 
@@ -355,7 +324,7 @@ public class UploadFilesActivity extends FileActivity implements
                 File localFile = new File(localPath);
                 total += localFile.length();
             }
                 File localFile = new File(localPath);
                 total += localFile.length();
             }
-            return (FileStorageUtils.getUsableSpace(mAccountOnCreation.name) >= total);
+            return (new Boolean(FileStorageUtils.getUsableSpace(mAccountOnCreation.name) >= total));
         }
 
         /**
         }
 
         /**
@@ -379,9 +348,12 @@ public class UploadFilesActivity extends FileActivity implements
                 finish();
                 
             } else {
                 finish();
                 
             } else {
-                // show a dialog to query the user if wants to move the selected files to the ownCloud folder instead of copying
+                // show a dialog to query the user if wants to move the selected files
+                // to the ownCloud folder instead of copying
                 String[] args = {getString(R.string.app_name)};
                 String[] args = {getString(R.string.app_name)};
-                ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance(R.string.upload_query_move_foreign_files, args, R.string.common_yes, -1, R.string.common_no);
+                ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance(
+                    R.string.upload_query_move_foreign_files, args, R.string.common_yes, -1, R.string.common_no
+                );
                 dialog.setOnConfirmationListener(UploadFilesActivity.this);
                 dialog.show(getSupportFragmentManager(), QUERY_TO_MOVE_DIALOG_TAG);
             }
                 dialog.setOnConfirmationListener(UploadFilesActivity.this);
                 dialog.show(getSupportFragmentManager(), QUERY_TO_MOVE_DIALOG_TAG);
             }
@@ -392,7 +364,8 @@ public class UploadFilesActivity extends FileActivity implements
     public void onConfirmation(String callerTag) {
         Log_OC.d(TAG, "Positive button in dialog was clicked; dialog tag is " + callerTag);
         if (callerTag.equals(QUERY_TO_MOVE_DIALOG_TAG)) {
     public void onConfirmation(String callerTag) {
         Log_OC.d(TAG, "Positive button in dialog was clicked; dialog tag is " + callerTag);
         if (callerTag.equals(QUERY_TO_MOVE_DIALOG_TAG)) {
-            // return the list of selected files to the caller activity (success), signaling that they should be moved to the ownCloud folder, instead of copied
+            // return the list of selected files to the caller activity (success),
+            // signaling that they should be moved to the ownCloud folder, instead of copied
             Intent data = new Intent();
             data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
             setResult(RESULT_OK_AND_MOVE, data);
             Intent data = new Intent();
             data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
             setResult(RESULT_OK_AND_MOVE, data);