X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/8e36e7cc3e6218ccb80ee2af3eb0a19df24e339f..8de92ba3b0cedc91f68e480e3e83b2c4009cee2d:/src/com/owncloud/android/ui/activity/UploadFilesActivity.java diff --git a/src/com/owncloud/android/ui/activity/UploadFilesActivity.java b/src/com/owncloud/android/ui/activity/UploadFilesActivity.java index 84fdc638..83e7bc07 100644 --- a/src/com/owncloud/android/ui/activity/UploadFilesActivity.java +++ b/src/com/owncloud/android/ui/activity/UploadFilesActivity.java @@ -2,9 +2,8 @@ * Copyright (C) 2012-2013 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -26,7 +25,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; import android.support.v4.app.DialogFragment; -import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; @@ -36,16 +34,19 @@ import android.widget.TextView; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar.OnNavigationListener; -import com.actionbarsherlock.app.SherlockFragmentActivity; +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.ui.dialog.IndeterminateProgressDialog; -import com.owncloud.android.ui.fragment.ConfirmationDialogFragment; +import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener; import com.owncloud.android.ui.fragment.LocalFileListFragment; -import com.owncloud.android.ui.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener; +import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; -import com.owncloud.android.Log_OC; -import com.owncloud.android.R; /** * Displays local files and let the user choose what of them wants to upload @@ -55,7 +56,7 @@ import com.owncloud.android.R; * */ -public class UploadFilesActivity extends SherlockFragmentActivity implements +public class UploadFilesActivity extends FileActivity implements LocalFileListFragment.ContainerActivity, OnNavigationListener, OnClickListener, ConfirmationDialogFragmentListener { private ArrayAdapter mDirectories; @@ -63,10 +64,9 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements private LocalFileListFragment mFileListFragment; private Button mCancelBtn; private Button mUploadBtn; - private Account mAccount; + private Account mAccountOnCreation; private DialogFragment mCurrentDialog; - public static final String EXTRA_ACCOUNT = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_ACCOUNT"; public static final String EXTRA_CHOSEN_FILES = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CHOSEN_FILES"; public static final int RESULT_OK_AND_MOVE = RESULT_FIRST_USER; @@ -76,6 +76,8 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements 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) { @@ -88,7 +90,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements mCurrentDir = Environment.getExternalStorageDirectory(); } - mAccount = getIntent().getParcelableExtra(EXTRA_ACCOUNT); + mAccountOnCreation = getAccount(); /// USER INTERFACE @@ -111,15 +113,18 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements mCancelBtn.setOnClickListener(this); mUploadBtn = (Button) findViewById(R.id.upload_files_btn_upload); mUploadBtn.setOnClickListener(this); + // Action bar setup ActionBar actionBar = getSupportActionBar(); + actionBar.setIcon(DisplayUtils.getSeasonalIconId()); 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); + // wait dialog if (mCurrentDialog != null) { mCurrentDialog.dismiss(); @@ -128,8 +133,15 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements 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; @@ -140,12 +152,33 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements } break; } + case R.id.actionbar_select_all:{ + if(selectAllToggled){ + toggleOffSelectAll(); + }else{ + toggleOnSelectAll(item); + } + break; + } 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) { @@ -176,6 +209,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(false); } + toggleOffSelectAll(); } @@ -243,10 +277,11 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements * {@inheritDoc} */ @Override - public void onDirectoryClick(File directory) { + public void onDirectoryClick(File directory) { pushDirname(directory); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); + toggleOffSelectAll(); } @@ -320,7 +355,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements File localFile = new File(localPath); total += localFile.length(); } - return (FileStorageUtils.getUsableSpace(mAccount.name) >= total); + return (FileStorageUtils.getUsableSpace(mAccountOnCreation.name) >= total); } /** @@ -348,8 +383,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements 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); dialog.setOnConfirmationListener(UploadFilesActivity.this); - mCurrentDialog = dialog; - mCurrentDialog.show(getSupportFragmentManager(), QUERY_TO_MOVE_DIALOG_TAG); + dialog.show(getSupportFragmentManager(), QUERY_TO_MOVE_DIALOG_TAG); } } } @@ -364,16 +398,12 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements setResult(RESULT_OK_AND_MOVE, data); finish(); } - mCurrentDialog.dismiss(); - mCurrentDialog = null; } @Override public void onNeutral(String callerTag) { Log_OC.d(TAG, "Phantom neutral button in dialog was clicked; dialog tag is " + callerTag); - mCurrentDialog.dismiss(); - mCurrentDialog = null; } @@ -381,8 +411,22 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements public void onCancel(String callerTag) { /// nothing to do; don't finish, let the user change the selection Log_OC.d(TAG, "Negative button in dialog was clicked; dialog tag is " + callerTag); - mCurrentDialog.dismiss(); - mCurrentDialog = null; + } + + + @Override + protected void onAccountSet(boolean stateWasRecovered) { + super.onAccountSet(stateWasRecovered); + if (getAccount() != null) { + if (!mAccountOnCreation.equals(getAccount())) { + setResult(RESULT_CANCELED); + finish(); + } + + } else { + setResult(RESULT_CANCELED); + finish(); + } }