X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/8ba2ca7b8556de4aea4a7a8407a204b4dcfca34c..6a9eaaf9aa6ce01ed788d057c56face20fa88dc3:/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index 6bc0b0fc..c440847c 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import android.accounts.Account; import android.accounts.AccountManager; import android.app.AlertDialog; +import android.app.ProgressDialog; import android.app.AlertDialog.Builder; import android.app.Dialog; import android.content.BroadcastReceiver; @@ -36,9 +37,11 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.Resources.NotFoundException; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.preference.PreferenceManager; import android.provider.MediaStore; import android.support.v4.app.FragmentTransaction; @@ -80,7 +83,7 @@ import eu.alefzero.webdav.WebdavClient; */ public class FileDisplayActivity extends SherlockFragmentActivity implements - FileListFragment.ContainerActivity, OnNavigationListener, OnClickListener, android.view.View.OnClickListener { + FileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnClickListener, android.view.View.OnClickListener { private ArrayAdapter mDirectories; private OCFile mCurrentDir; @@ -104,9 +107,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements private static final int DIALOG_SETUP_ACCOUNT = 0; private static final int DIALOG_CREATE_DIR = 1; private static final int DIALOG_ABOUT_APP = 2; + public static final int DIALOG_SHORT_WAIT = 3; private static final int ACTION_SELECT_FILE = 1; + private static final String TAG = "FileDisplayActivity"; + + @Override public void onCreate(Bundle savedInstanceState) { Log.i(getClass().toString(), "onCreate() start"); @@ -185,7 +192,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements action = action.setType("*/*") .addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult( - Intent.createChooser(action, "Upload file from..."), + Intent.createChooser(action, getString(R.string.upload_chooser_title)), ACTION_SELECT_FILE); break; } @@ -441,7 +448,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements break; case DIALOG_ABOUT_APP: { builder = new AlertDialog.Builder(this); - builder.setTitle("About"); + builder.setTitle(getString(R.string.about_title)); PackageInfo pkg; try { pkg = getPackageManager().getPackageInfo(getPackageName(), 0); @@ -451,7 +458,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } catch (NameNotFoundException e) { builder = null; dialog = null; - e.printStackTrace(); + Log.e(TAG, "Error while showing about dialog", e); } break; } @@ -486,18 +493,12 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements // Create directory path += directoryName + OCFile.PATH_SEPARATOR; - Thread thread = new Thread(new DirectoryCreator(path, a)); + Thread thread = new Thread(new DirectoryCreator(path, a, new Handler())); thread.start(); - - // Save new directory in local database - OCFile newDir = new OCFile(path); - newDir.setMimetype("DIR"); - newDir.setParentId(mCurrentDir.getFileId()); - mStorageManager.saveFile(newDir); - - // Display the new folder right away + dialog.dismiss(); - mFileList.listDirectory(mCurrentDir); + + showDialog(DIALOG_SHORT_WAIT); } }); builder.setNegativeButton(R.string.common_cancel, @@ -509,6 +510,15 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements dialog = builder.create(); break; } + case DIALOG_SHORT_WAIT: { + ProgressDialog working_dialog = new ProgressDialog(this); + working_dialog.setMessage(getResources().getString( + R.string.wait_a_moment)); + working_dialog.setIndeterminate(true); + working_dialog.setCancelable(false); + dialog = working_dialog; + break; + } default: dialog = null; } @@ -582,11 +592,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements private String mTargetPath; private Account mAccount; private AccountManager mAm; + private Handler mHandler; - public DirectoryCreator(String targetPath, Account account) { + public DirectoryCreator(String targetPath, Account account, Handler handler) { mTargetPath = targetPath; mAccount = account; mAm = (AccountManager) getSystemService(ACCOUNT_SERVICE); + mHandler = handler; } @Override @@ -599,7 +611,39 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements wdc.setCredentials(username, password); wdc.allowSelfsignedCertificates(); - wdc.createDirectory(mTargetPath); + boolean created = wdc.createDirectory(mTargetPath); + if (created) { + mHandler.post(new Runnable() { + @Override + public void run() { + dismissDialog(DIALOG_SHORT_WAIT); + + // Save new directory in local database + OCFile newDir = new OCFile(mTargetPath); + newDir.setMimetype("DIR"); + newDir.setParentId(mCurrentDir.getFileId()); + mStorageManager.saveFile(newDir); + + // Display the new folder right away + mFileList.listDirectory(mCurrentDir); + } + }); + + } else { + mHandler.post(new Runnable() { + @Override + public void run() { + dismissDialog(DIALOG_SHORT_WAIT); + try { + Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); + msg.show(); + + } catch (NotFoundException e) { + Log.e(TAG, "Error while trying to show fail message " , e); + } + } + }); + } } } @@ -707,12 +751,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements private class DownloadFinishReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false); String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) && - downloadWasFine && mCurrentDir != null && mCurrentDir.getFileId() == mStorageManager.getFileByPath(downloadedRemotePath).getParentId()) { + mCurrentDir != null && mCurrentDir.getFileId() == mStorageManager.getFileByPath(downloadedRemotePath).getParentId()) { FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); if (fileListFragment != null) { fileListFragment.listDirectory(); @@ -789,6 +832,19 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } } + + /** + * {@inheritDoc} + */ + @Override + public void onFileStateChanged() { + FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); + if (fileListFragment != null) { + fileListFragment.listDirectory(); + } + } + + /** * Operations in this method should be preferably performed in onCreate to have a lighter onResume method. *