import android.accounts.Account;\r
import android.accounts.AccountManager;\r
import android.app.AlertDialog;\r
+import android.app.ProgressDialog;\r
import android.app.AlertDialog.Builder;\r
import android.app.Dialog;\r
import android.content.BroadcastReceiver;\r
import android.content.SharedPreferences;\r
import android.content.pm.PackageInfo;\r
import android.content.pm.PackageManager.NameNotFoundException;\r
+import android.content.res.Resources.NotFoundException;\r
import android.database.Cursor;\r
import android.net.Uri;\r
import android.os.Bundle;\r
+import android.os.Handler;\r
import android.preference.PreferenceManager;\r
import android.provider.MediaStore;\r
import android.support.v4.app.FragmentTransaction;\r
*/\r
\r
public class FileDisplayActivity extends SherlockFragmentActivity implements\r
- FileListFragment.ContainerActivity, OnNavigationListener, OnClickListener, android.view.View.OnClickListener {\r
+ FileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnClickListener, android.view.View.OnClickListener {\r
\r
private ArrayAdapter<String> mDirectories;\r
private OCFile mCurrentDir;\r
private DataStorageManager mStorageManager;\r
private SyncBroadcastReceiver mSyncBroadcastReceiver;\r
private UploadFinishReceiver mUploadFinishReceiver;\r
+ private DownloadFinishReceiver mDownloadFinishReceiver;\r
\r
private View mLayoutView = null;\r
private FileListFragment mFileList;\r
private static final int DIALOG_SETUP_ACCOUNT = 0;\r
private static final int DIALOG_CREATE_DIR = 1;\r
private static final int DIALOG_ABOUT_APP = 2;\r
+ public static final int DIALOG_SHORT_WAIT = 3;\r
\r
private static final int ACTION_SELECT_FILE = 1;\r
\r
+ private static final String TAG = "FileDisplayActivity";\r
+ \r
+ \r
@Override\r
public void onCreate(Bundle savedInstanceState) {\r
Log.i(getClass().toString(), "onCreate() start");\r
action = action.setType("*/*")\r
.addCategory(Intent.CATEGORY_OPENABLE);\r
startActivityForResult(\r
- Intent.createChooser(action, "Upload file from..."),\r
+ Intent.createChooser(action, getString(R.string.upload_chooser_title)),\r
ACTION_SELECT_FILE);\r
break;\r
}\r
IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE);\r
mUploadFinishReceiver = new UploadFinishReceiver();\r
registerReceiver(mUploadFinishReceiver, uploadIntentFilter);\r
+ \r
+ // Listen for download messages\r
+ IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE);\r
+ mDownloadFinishReceiver = new DownloadFinishReceiver();\r
+ registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);\r
\r
// Storage manager initialization\r
mStorageManager = new FileDataStorageManager(\r
unregisterReceiver(mUploadFinishReceiver);\r
mUploadFinishReceiver = null;\r
}\r
+ if (mDownloadFinishReceiver != null) {\r
+ unregisterReceiver(mDownloadFinishReceiver);\r
+ mDownloadFinishReceiver = null;\r
+ }\r
+ \r
getIntent().putExtra(FileDetailFragment.EXTRA_FILE, mCurrentDir);\r
Log.i(getClass().toString(), "onPause() end");\r
}\r
break;\r
case DIALOG_ABOUT_APP: {\r
builder = new AlertDialog.Builder(this);\r
- builder.setTitle("About");\r
+ builder.setTitle(getString(R.string.about_title));\r
PackageInfo pkg;\r
try {\r
pkg = getPackageManager().getPackageInfo(getPackageName(), 0);\r
} catch (NameNotFoundException e) {\r
builder = null;\r
dialog = null;\r
- e.printStackTrace();\r
+ Log.e(TAG, "Error while showing about dialog", e);\r
}\r
break;\r
}\r
\r
// Create directory\r
path += directoryName + OCFile.PATH_SEPARATOR;\r
- Thread thread = new Thread(new DirectoryCreator(path, a));\r
+ Thread thread = new Thread(new DirectoryCreator(path, a, new Handler()));\r
thread.start();\r
- \r
- // Save new directory in local database\r
- OCFile newDir = new OCFile(path);\r
- newDir.setMimetype("DIR");\r
- newDir.setParentId(mCurrentDir.getFileId());\r
- mStorageManager.saveFile(newDir);\r
- \r
- // Display the new folder right away\r
+ \r
dialog.dismiss();\r
- mFileList.listDirectory(mCurrentDir);\r
+ \r
+ showDialog(DIALOG_SHORT_WAIT);\r
}\r
});\r
builder.setNegativeButton(R.string.common_cancel,\r
dialog = builder.create();\r
break;\r
}\r
+ case DIALOG_SHORT_WAIT: {\r
+ ProgressDialog working_dialog = new ProgressDialog(this);\r
+ working_dialog.setMessage(getResources().getString(\r
+ R.string.wait_a_moment));\r
+ working_dialog.setIndeterminate(true);\r
+ working_dialog.setCancelable(false);\r
+ dialog = working_dialog;\r
+ break;\r
+ }\r
default:\r
dialog = null;\r
}\r
private String mTargetPath;\r
private Account mAccount;\r
private AccountManager mAm;\r
+ private Handler mHandler; \r
\r
- public DirectoryCreator(String targetPath, Account account) {\r
+ public DirectoryCreator(String targetPath, Account account, Handler handler) {\r
mTargetPath = targetPath;\r
mAccount = account;\r
mAm = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
+ mHandler = handler;\r
}\r
\r
@Override\r
\r
wdc.setCredentials(username, password);\r
wdc.allowSelfsignedCertificates();\r
- wdc.createDirectory(mTargetPath);\r
+ boolean created = wdc.createDirectory(mTargetPath);\r
+ if (created) {\r
+ mHandler.post(new Runnable() {\r
+ @Override\r
+ public void run() { \r
+ dismissDialog(DIALOG_SHORT_WAIT);\r
+ \r
+ // Save new directory in local database\r
+ OCFile newDir = new OCFile(mTargetPath);\r
+ newDir.setMimetype("DIR");\r
+ newDir.setParentId(mCurrentDir.getFileId());\r
+ mStorageManager.saveFile(newDir);\r
+ \r
+ // Display the new folder right away\r
+ mFileList.listDirectory(mCurrentDir);\r
+ }\r
+ });\r
+ \r
+ } else {\r
+ mHandler.post(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ dismissDialog(DIALOG_SHORT_WAIT);\r
+ try {\r
+ Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ \r
+ } catch (NotFoundException e) {\r
+ Log.e(TAG, "Error while trying to show fail message " , e);\r
+ }\r
+ }\r
+ });\r
+ }\r
}\r
\r
}\r
public void onReceive(Context context, Intent intent) {\r
boolean inProgress = intent.getBooleanExtra(\r
FileSyncService.IN_PROGRESS, false);\r
- String account_name = intent\r
+ String accountName = intent\r
.getStringExtra(FileSyncService.ACCOUNT_NAME);\r
\r
- Log.d("FileDisplay", "sync of account " + account_name\r
+ Log.d("FileDisplay", "sync of account " + accountName\r
+ " is in_progress: " + inProgress);\r
\r
- if (account_name.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) { \r
+ if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) { \r
\r
String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH); \r
\r
fillBlankRoot = (mCurrentDir != null);\r
}\r
\r
- if (synchFolderRemotePath != null && mCurrentDir != null && (mCurrentDir.getRemotePath().equals(synchFolderRemotePath) || fillBlankRoot) ) {\r
+ if ((synchFolderRemotePath != null && mCurrentDir != null && (mCurrentDir.getRemotePath().equals(synchFolderRemotePath)))\r
+ || fillBlankRoot ) {\r
+ if (!fillBlankRoot) \r
+ mCurrentDir = getStorageManager().getFileByPath(synchFolderRemotePath);\r
FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager()\r
.findFragmentById(R.id.fileList);\r
- mCurrentDir = getStorageManager().getFileByPath(synchFolderRemotePath);\r
if (fileListFragment != null) {\r
fileListFragment.listDirectory(mCurrentDir); \r
}\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
+ String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);\r
+\r
+ if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) &&\r
+ parentDir != null && \r
+ ( (mCurrentDir == null && parentDir.getFileName().equals("/")) ||\r
+ parentDir.equals(mCurrentDir)\r
+ )\r
) {\r
FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
if (fileListFragment != null) { \r
}\r
\r
}\r
+ \r
+ \r
+ /**\r
+ * Once the file download has finished -> update view\r
+ */\r
+ private class DownloadFinishReceiver extends BroadcastReceiver {\r
+ @Override\r
+ public void onReceive(Context context, Intent intent) {\r
+ String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);\r
+ String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);\r
+\r
+ if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) &&\r
+ mCurrentDir != null && mCurrentDir.getFileId() == mStorageManager.getFileByPath(downloadedRemotePath).getParentId()) {\r
+ FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ if (fileListFragment != null) { \r
+ fileListFragment.listDirectory();\r
+ }\r
+ }\r
+ }\r
+ }\r
\r
\r
@Override\r
}\r
}\r
\r
+ \r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void onFileStateChanged() {\r
+ FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ if (fileListFragment != null) { \r
+ fileListFragment.listDirectory();\r
+ }\r
+ }\r
+ \r
+ \r
/**\r
* Operations in this method should be preferably performed in onCreate to have a lighter onResume method. \r
* \r