+\r
+ // Custom array adapter to override text colors\r
+ private class CustomArrayAdapter<T> extends ArrayAdapter<T> {\r
+ \r
+ public CustomArrayAdapter(FileDisplayActivity ctx, int view) {\r
+ super(ctx, view);\r
+ }\r
+ \r
+ public View getView(int position, View convertView, ViewGroup parent) {\r
+ View v = super.getView(position, convertView, parent);\r
+ \r
+ ((TextView) v).setTextColor(getResources().getColorStateList(\r
+ android.R.color.white));\r
+ return v;\r
+ }\r
+ \r
+ public View getDropDownView(int position, View convertView,\r
+ ViewGroup parent) {\r
+ View v = super.getDropDownView(position, convertView, parent);\r
+ \r
+ ((TextView) v).setTextColor(getResources().getColorStateList(\r
+ android.R.color.white));\r
+ \r
+ return v;\r
+ }\r
+ \r
+ }\r
+\r
+ private class SyncBroadcastReceiver extends BroadcastReceiver {\r
+ /**\r
+ * {@link BroadcastReceiver} to enable syncing feedback in UI\r
+ */\r
+ @Override\r
+ public void onReceive(Context context, Intent intent) {\r
+ boolean inProgress = intent.getBooleanExtra(\r
+ FileSyncService.IN_PROGRESS, false);\r
+ String account_name = intent\r
+ .getStringExtra(FileSyncService.ACCOUNT_NAME);\r
+\r
+ Log.d("FileDisplay", "sync of account " + account_name\r
+ + " is in_progress: " + inProgress);\r
+\r
+ //if (account_name.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) { // TODO - probably this check should be added, but won't push it until really tests are done; no time now\r
+ \r
+ /// try to refresh the view with every message received from the FileSyncAdapter; brute, but more user friendly when there are a lot of files in the server\r
+ OCFile currentDir;\r
+ if (mCurrentDir == null)\r
+ currentDir = mStorageManager.getFileByPath("/");\r
+ else\r
+ currentDir = mStorageManager.getFileByPath(mCurrentDir.getRemotePath());\r
+ \r
+ if (currentDir != null) {\r
+ mCurrentDir = currentDir;\r
+ FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager()\r
+ .findFragmentById(R.id.fileList);\r
+ if (fileListFragment != null) {\r
+ if (!mCurrentDir.equals(fileListFragment.getCurrentFile())) {\r
+ fileListFragment.listDirectory(mCurrentDir); // only set the directory in the fragment first time\r
+ } else\r
+ fileListFragment.listDirectory(); // enough to show new files in the current directory if they are added after \r
+ }\r
+ }\r
+ \r
+ setSupportProgressBarIndeterminateVisibility(inProgress);\r
+ //}\r
+ }\r
+ }\r
+ \r
+\r
+ private class UploadFinishReceiver extends BroadcastReceiver {\r
+ /**\r
+ * Once the file upload has finished -> update view\r
+ * @author David A. Velasco\r
+ * {@link BroadcastReceiver} to enable upload feedback in UI\r
+ */\r
+ @Override\r
+ public void onReceive(Context context, Intent intent) {\r
+ long parentDirId = intent.getLongExtra(FileUploader.EXTRA_PARENT_DIR_ID, -1);\r
+ OCFile parentDir = mStorageManager.getFileById(parentDirId);\r
+ \r
+ if (parentDir != null && (\r
+ (mCurrentDir == null && parentDir.getFileName().equals("/")) ||\r
+ parentDir.equals(mCurrentDir))\r
+ ) {\r
+ FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ if (fileListFragment != null) { \r
+ fileListFragment.listDirectory();\r
+ }\r
+ }\r
+ }\r
+ \r
+ }\r
+\r
+ \r
+ @Override\r
+ public void onClick(View v) {\r
+ if (v.getId() == R.id.setup_account) {\r
+ Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);\r
+ intent.putExtra(android.provider.Settings.EXTRA_AUTHORITIES, new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });\r
+ startActivity(intent); \r
+ mForcedLoginToCreateFirstAccount = true;\r
+ }\r
+ }\r
+\r
+ \r
+ \r
+ \r
+ \r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public DataStorageManager getStorageManager() {\r
+ return mStorageManager;\r
+ }\r
+ \r
+ \r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void onDirectoryClick(OCFile directory) {\r
+ pushDirname(directory);\r
+ ActionBar actionBar = getSupportActionBar();\r
+ actionBar.setDisplayHomeAsUpEnabled(true);\r
+ \r
+ if (mDualPane) {\r
+ // Resets the FileDetailsFragment on Tablets so that it always displays\r
+ FileDetailFragment fileDetails = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
+ if (fileDetails != null) {\r
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
+ transaction.remove(fileDetails);\r
+ transaction.add(R.id.file_details_container, new FileDetailFragment(null, null));\r
+ transaction.commit();\r
+ }\r
+ }\r
+ }\r
+ \r
+ \r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void onFileClick(OCFile file) {\r
+ \r
+ // If we are on a large device -> update fragment\r
+ if (mDualPane) {\r
+ FileDetailFragment fileDetails = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
+ if (fileDetails == null) {\r
+ // first selected file since the current directory was listed\r
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
+ transaction.replace(R.id.file_details_container, new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);\r
+ transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);\r
+ transaction.commit();\r
+ } else {\r
+ // another select file\r
+ fileDetails.updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this));\r
+ } \r
+ \r
+ } else { // small or medium screen device -> new Activity\r
+ Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);\r
+ showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);\r
+ showDetailsIntent.putExtra(FileDownloader.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));\r
+ startActivity(showDetailsIntent);\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Operations in this method should be preferably performed in onCreate to have a lighter onResume method. \r
+ * \r
+ * But we need to delay them to onResume for the first start of the application, when no account exists and the login activity must be shown; and \r
+ * put instead the ugly view that shows the 'Setup' button to restart the login activity. \r
+ * \r
+ * In other way, if the users cancels or presses BACK in the login page that first time (users can be cruel sometimes) would show a blank view (the \r
+ * FragmentList view empty).\r
+ * \r
+ * This is temporal, until we found out how to get a result in this activity after launching the ADD_ACCOUNT Intent with startActivityForResult (not trivial)\r
+ */\r
+ private void initDelayedTilAccountAvailabe() {\r
+ setContentView(mLayoutView); \r
+ mDualPane = (findViewById(R.id.file_details_container) != null);\r
+ if (mDualPane && getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG) == null) {\r
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
+ transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment\r
+ transaction.commit();\r
+ }\r
+\r
+ }\r
+\r
+ \r
+}\r