X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/db01425a0740a443e4e005f9fb91af7f2faafe40..bf23f0b5e906f5adb96cb59bc4c10232ff28e4ed:/src/com/owncloud/android/ui/activity/FileDisplayActivity.java diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 8f4c27af..2b07fa4a 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -54,10 +54,7 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.view.Window; -import android.widget.ArrayAdapter; -import android.widget.TextView; import android.widget.Toast; import com.owncloud.android.MainApp; @@ -111,11 +108,9 @@ import java.io.File; * Displays, what files the user has available in his ownCloud. */ -public class FileDisplayActivity extends HookActivity implements - FileFragment.ContainerActivity, ActionBar.OnNavigationListener, +public class FileDisplayActivity extends HookActivity + implements FileFragment.ContainerActivity, OnSslUntrustedCertListener, OnEnforceableRefreshListener { - - private ArrayAdapter mDirectories; private SyncBroadcastReceiver mSyncBroadcastReceiver; private UploadFinishReceiver mUploadFinishReceiver; @@ -197,18 +192,16 @@ public class FileDisplayActivity extends HookActivity implements } // Action bar setup - mDirectories = new CustomArrayAdapter(this, - R.layout.support_simple_spinner_dropdown_item); getSupportActionBar().setHomeButtonEnabled(true); // mandatory since Android ICS, // according to the official // documentation + if (getFile() != null) { + updateActionBarTitle(); + } setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/); // always AFTER setContentView(...) ; to work around bug in its implementation - - // TODO Remove??, it is done in onPostCreate -// mDrawerToggle.syncState(); setBackgroundText(); @@ -260,7 +253,6 @@ public class FileDisplayActivity extends HookActivity implements file = getStorageManager().getFileByPath(OCFile.ROOT_PATH); // never returns null } setFile(file); - setNavigationListWithFolder(file); if (!stateWasRecovered) { Log_OC.d(TAG, "Initializing Fragments in onAccountChanged.."); @@ -277,23 +269,6 @@ public class FileDisplayActivity extends HookActivity implements } - private void setNavigationListWithFolder(OCFile file) { - mDirectories.clear(); - OCFile fileIt = file; - String parentPath; - while(fileIt != null && fileIt.getFileName() != OCFile.ROOT_PATH) { - if (fileIt.isFolder()) { - mDirectories.add(fileIt.getFileName()); - } - // get parent from path - parentPath = fileIt.getRemotePath().substring(0, - fileIt.getRemotePath().lastIndexOf(fileIt.getFileName())); - fileIt = getStorageManager().getFileByPath(parentPath); - } - mDirectories.add(OCFile.PATH_SEPARATOR); - } - - private void createMinFragments() { OCFileListFragment listOfFiles = new OCFileListFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); @@ -522,8 +497,14 @@ public class FileDisplayActivity extends HookActivity implements break; } case android.R.id.home: { + FileFragment second = getSecondFragment(); + OCFile currentDir = getCurrentDir(); if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawer(GravityCompat.START); + } else if((currentDir != null && currentDir.getParentId() != 0) || + (second != null && second.getFile() != null)) { + onBackPressed(); + } else { mDrawerLayout.openDrawer(GravityCompat.START); } @@ -595,30 +576,6 @@ public class FileDisplayActivity extends HookActivity implements } } - - @Override - public boolean onNavigationItemSelected(int itemPosition, long itemId) { - if (itemPosition != 0) { - String targetPath = ""; - for (int i=itemPosition; i < mDirectories.getCount() - 1; i++) { - targetPath = mDirectories.getItem(i) + OCFile.PATH_SEPARATOR + targetPath; - } - targetPath = OCFile.PATH_SEPARATOR + targetPath; - OCFile targetFolder = getStorageManager().getFileByPath(targetPath); - if (targetFolder != null) { - browseTo(targetFolder); - } - - // the next operation triggers a new call to this method, but it's necessary to - // ensure that the name exposed in the action bar is the current directory when the - // user selected it in the navigation list - if (getSupportActionBar().getNavigationMode() == ActionBar.NAVIGATION_MODE_LIST && - itemPosition != 0) - getSupportActionBar().setSelectedNavigationItem(0); - } - return true; - } - /** * Called, when the user selected something for uploading * @@ -669,9 +626,6 @@ public class FileDisplayActivity extends HookActivity implements String[] remotePaths = new String[filePaths.length]; String remotePathBase = ""; - for (int j = mDirectories.getCount() - 2; j >= 0; --j) { - remotePathBase += OCFile.PATH_SEPARATOR + mDirectories.getItem(j); - } if (!remotePathBase.endsWith(OCFile.PATH_SEPARATOR)) remotePathBase += OCFile.PATH_SEPARATOR; for (int j = 0; j< remotePaths.length; j++) { @@ -782,20 +736,18 @@ public class FileDisplayActivity extends HookActivity implements public void onBackPressed() { OCFileListFragment listOfFiles = getListOfFilesFragment(); if (mDualPane || getSecondFragment() == null) { + if (getFile() != null && getFile().getParentId() == 0) { + finish(); + return; + } if (listOfFiles != null) { // should never be null, indeed - if (mDirectories.getCount() <= 1) { - finish(); - return; - } - int levelsUp = listOfFiles.onBrowseUp(); - for (int i=0; i < levelsUp && mDirectories.getCount() > 1 ; i++) { - popDirname(); - } + listOfFiles.onBrowseUp(); } } if (listOfFiles != null) { // should never be null, indeed setFile(listOfFiles.getCurrentFile()); } + updateActionBarTitle(); cleanSecondFragment(); } @@ -825,6 +777,7 @@ public class FileDisplayActivity extends HookActivity implements // refresh Navigation Drawer account list mNavigationDrawerAdapter.updateAccountList(); + // refresh list of files refreshListOfFilesFragment(); @@ -845,7 +798,8 @@ public class FileDisplayActivity extends HookActivity implements registerReceiver(mUploadFinishReceiver, uploadIntentFilter); // Listen for download messages - IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.getDownloadAddedMessage()); + IntentFilter downloadIntentFilter = new IntentFilter( + FileDownloader.getDownloadAddedMessage()); downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage()); mDownloadFinishReceiver = new DownloadFinishReceiver(); registerReceiver(mDownloadFinishReceiver, downloadIntentFilter); @@ -875,63 +829,6 @@ public class FileDisplayActivity extends HookActivity implements Log_OC.v(TAG, "onPause() end"); } - /** - * Pushes a directory to the drop down list - * @param directory to push - * @throws IllegalArgumentException If the {@link OCFile#isFolder()} returns false. - */ - public void pushDirname(OCFile directory) { - if(!directory.isFolder()){ - throw new IllegalArgumentException("Only directories may be pushed!"); - } - mDirectories.insert(directory.getFileName(), 0); - setFile(directory); - } - - /** - * Pops a directory name from the drop down list - * @return True, unless the stack is empty - */ - public boolean popDirname() { - mDirectories.remove(mDirectories.getItem(0)); - return !mDirectories.isEmpty(); - } - - // Custom array adapter to override text colors - private class CustomArrayAdapter extends ArrayAdapter { - - public CustomArrayAdapter(FileDisplayActivity ctx, int view) { - super(ctx, view); - } - - public View getView(int position, View convertView, ViewGroup parent) { - View v = super.getView(position, convertView, parent); - - ((TextView) v).setTextColor(getResources().getColorStateList( - android.R.color.white)); - - fixRoot((TextView) v ); - return v; - } - - public View getDropDownView(int position, View convertView, - ViewGroup parent) { - View v = super.getDropDownView(position, convertView, parent); - - ((TextView) v).setTextColor(getResources().getColorStateList( - android.R.color.white)); - - fixRoot((TextView) v ); - return v; - } - - private void fixRoot(TextView v) { - if (v.getText().equals(OCFile.PATH_SEPARATOR)) { - v.setText(R.string.default_display_name_for_root_folder); - } - } - - } private class SyncBroadcastReceiver extends BroadcastReceiver { @@ -967,8 +864,9 @@ public class FileDisplayActivity extends HookActivity implements // current folder was removed from the server Toast.makeText( FileDisplayActivity.this, String.format( - getString(R.string.sync_current_folder_was_removed), - mDirectories.getItem(0)), + getString(R.string. + sync_current_folder_was_removed), + synchFolderRemotePath), Toast.LENGTH_LONG) .show(); browseToRoot(); @@ -1222,36 +1120,16 @@ public class FileDisplayActivity extends HookActivity implements public void browseToRoot() { OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { // should never be null, indeed - while (mDirectories.getCount() > 1) { - popDirname(); - } OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH); listOfFiles.listDirectory(root); // TODO Enable when "On Device" is recovered ? // listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice()); setFile(listOfFiles.getCurrentFile()); startSyncFolderOperation(root, false); + updateActionBarTitle(); } cleanSecondFragment(); - } - - - public void browseTo(OCFile folder) { - if (folder == null || !folder.isFolder()) { - throw new IllegalArgumentException("Trying to browse to invalid folder " + folder); - } - OCFileListFragment listOfFiles = getListOfFilesFragment(); - if (listOfFiles != null) { - setNavigationListWithFolder(folder); - listOfFiles.listDirectory(folder); - // TODO Enable when "On Device" is recovered ? - // listOfFiles.listDirectory(folder, MainApp.getOnlyOnDevice()); - setFile(listOfFiles.getCurrentFile()); - startSyncFolderOperation(folder, false); - } else { - Log_OC.e(TAG, "Unexpected null when accessing list fragment"); - } - cleanSecondFragment(); + } @@ -1262,9 +1140,9 @@ public class FileDisplayActivity extends HookActivity implements */ @Override public void onBrowsedDownTo(OCFile directory) { - pushDirname(directory); cleanSecondFragment(); - + setFile(directory); + updateActionBarTitle(); // Sync Folder startSyncFolderOperation(directory, false); @@ -1300,7 +1178,7 @@ public class FileDisplayActivity extends HookActivity implements OCFile currentDir = getCurrentDir(); boolean noRoot = (currentDir != null && currentDir.getParentId() != 0); // actionBar.setDisplayHomeAsUpEnabled(noRoot); -// actionBar.setDisplayShowTitleEnabled(!noRoot); +// actionBar.setDisplayShowTitleEnabled(!noRoot); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(true); if (!noRoot) { @@ -1311,10 +1189,7 @@ public class FileDisplayActivity extends HookActivity implements getString(R.string.default_display_name_for_root_folder)); } } - actionBar.setNavigationMode(!noRoot ? ActionBar.NAVIGATION_MODE_STANDARD : - ActionBar.NAVIGATION_MODE_LIST); - actionBar.setListNavigationCallbacks(mDirectories, this); - // assuming mDirectories is updated + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } else { actionBar.setDisplayHomeAsUpEnabled(true); @@ -1858,54 +1733,8 @@ public class FileDisplayActivity extends HookActivity implements private void sortByName(boolean ascending){ getListOfFilesFragment().sortByName(ascending); } - -// public void restart(){ -// Intent i = new Intent(this, FileDisplayActivity.class); -// i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); -// startActivity(i); -// } - -// public void closeDrawer() { -// mDrawerLayout.closeDrawers(); -// } - -// private class DrawerItemClickListener implements ListView.OnItemClickListener { -// @Override -// public void onItemClick(AdapterView parent, View view, int position, long id) { -// if (mShowAccounts && position > 0){ -// position = position - 1; -// } -// switch (position){ -// case 0: // Accounts -// mShowAccounts = !mShowAccounts; -// mNavigationDrawerAdapter.setShowAccounts(mShowAccounts); -// mNavigationDrawerAdapter.notifyDataSetChanged(); -// break; -// -// case 1: // All Files -// // TODO Enable when "On Device" is recovered ? -// //MainApp.showOnlyFilesOnDevice(false); -// mDrawerLayout.closeDrawers(); -// break; -// -// // TODO Enable when "On Device" is recovered ? -//// case 2: -//// MainApp.showOnlyFilesOnDevice(true); -//// mDrawerLayout.closeDrawers(); -//// break; -// -// case 2: // Settings -// Intent settingsIntent = new Intent(getApplicationContext(), -// Preferences.class); -// startActivity(settingsIntent); -// break; -// -// case 3: // Logs -// Intent loggerIntent = new Intent(getApplicationContext(), -// LogHistoryActivity.class); -// startActivity(loggerIntent); -// break; -// } -// } -// } + + public void allFilesOption() { + browseToRoot(); + } }