import com.owncloud.android.datamodel.OCFile;\r
import com.owncloud.android.files.services.FileDownloader;\r
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
+import com.owncloud.android.files.services.FileObserverService;\r
import com.owncloud.android.files.services.FileUploader;\r
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
import com.owncloud.android.network.OwnCloudClientUtils;\r
+import com.owncloud.android.operations.RemoteOperationResult;\r
import com.owncloud.android.syncadapter.FileSyncService;\r
+import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
+import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
import com.owncloud.android.ui.fragment.FileDetailFragment;\r
import com.owncloud.android.ui.fragment.OCFileListFragment;\r
\r
*/\r
\r
public class FileDisplayActivity extends SherlockFragmentActivity implements\r
- OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener {\r
+ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener {\r
\r
private ArrayAdapter<String> mDirectories;\r
private OCFile mCurrentDir = null;\r
private FileDownloaderBinder mDownloaderBinder = null;\r
private FileUploaderBinder mUploaderBinder = null;\r
private ServiceConnection mDownloadConnection = null, mUploadConnection = null;\r
+ private RemoteOperationResult mLastSslUntrustedServerResult = null;\r
\r
private OCFileListFragment mFileList;\r
\r
private static final int DIALOG_ABOUT_APP = 2;\r
public static final int DIALOG_SHORT_WAIT = 3;\r
private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 4;\r
+ private static final int DIALOG_SSL_VALIDATOR = 5;\r
+ private static final int DIALOG_CERT_NOT_SAVED = 6;\r
+\r
\r
private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;\r
private static final int ACTION_SELECT_MULTIPLE_FILES = 2;\r
}\r
\r
// file observer\r
- /*Intent observer_intent = new Intent(this, FileObserverService.class);\r
+ Intent observer_intent = new Intent(this, FileObserverService.class);\r
observer_intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_INIT_OBSERVED_LIST);\r
startService(observer_intent);\r
- */\r
+ \r
\r
/// USER INTERFACE\r
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);\r
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);\r
actionBar.setListNavigationCallbacks(mDirectories, this);\r
setSupportProgressBarIndeterminateVisibility(false); // always AFTER setContentView(...) ; to workaround bug in its implementation\r
- \r
+ \r
Log.d(getClass().toString(), "onCreate() end");\r
}\r
\r
-\r
+ \r
/**\r
* Launches the account creation activity. To use when no ownCloud account is available\r
*/\r
break;\r
}\r
case R.id.startSync: {\r
- ContentResolver.cancelSync(null, AccountAuthenticator.AUTH_TOKEN_TYPE); // cancel the current synchronizations of any ownCloud account\r
- Bundle bundle = new Bundle();\r
- bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
- ContentResolver.requestSync(\r
- AccountUtils.getCurrentOwnCloudAccount(this),\r
- AccountAuthenticator.AUTH_TOKEN_TYPE, bundle);\r
+ startSynchronization();\r
break;\r
}\r
case R.id.action_upload: {\r
return retval;\r
}\r
\r
+ private void startSynchronization() {\r
+ ContentResolver.cancelSync(null, AccountAuthenticator.AUTH_TOKEN_TYPE); // cancel the current synchronizations of any ownCloud account\r
+ Bundle bundle = new Bundle();\r
+ bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
+ ContentResolver.requestSync(\r
+ AccountUtils.getCurrentOwnCloudAccount(this),\r
+ AccountAuthenticator.AUTH_TOKEN_TYPE, bundle);\r
+ }\r
+\r
+\r
@Override\r
public boolean onNavigationItemSelected(int itemPosition, long itemId) {\r
int i = itemPosition;\r
registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);\r
\r
// List current directory\r
- mFileList.listDirectory(mCurrentDir); // we should find the way to avoid the need of this\r
+ mFileList.listDirectory(mCurrentDir); // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)\r
\r
} else {\r
\r
Log.d(getClass().toString(), "onPause() end");\r
}\r
\r
+ \r
+ @Override\r
+ protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {\r
+ if (id == DIALOG_SSL_VALIDATOR && mLastSslUntrustedServerResult != null) {\r
+ ((SslValidatorDialog)dialog).updateResult(mLastSslUntrustedServerResult);\r
+ }\r
+ }\r
+\r
+ \r
@Override\r
protected Dialog onCreateDialog(int id) {\r
Dialog dialog = null;\r
PackageInfo pkg;\r
try {\r
pkg = getPackageManager().getPackageInfo(getPackageName(), 0);\r
- builder.setMessage("ownCloud android client\n\nversion: " + pkg.versionName );\r
+ builder.setMessage(String.format(getString(R.string.about_message), pkg.versionName));\r
builder.setIcon(android.R.drawable.ic_menu_info_details);\r
dialog = builder.create();\r
} catch (NameNotFoundException e) {\r
dialog = builder.create();\r
break;\r
}\r
+ case DIALOG_SSL_VALIDATOR: {\r
+ dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);\r
+ break;\r
+ }\r
+ case DIALOG_CERT_NOT_SAVED: {\r
+ builder = new AlertDialog.Builder(this);\r
+ builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));\r
+ builder.setCancelable(false);\r
+ builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {\r
+ @Override\r
+ public void onClick(DialogInterface dialog, int which) {\r
+ dialog.dismiss();\r
+ };\r
+ });\r
+ dialog = builder.create();\r
+ break;\r
+ }\r
default:\r
dialog = null;\r
}\r
mStorageManager.saveFile(newDir);\r
\r
// Display the new folder right away\r
- mFileList.listDirectory(mCurrentDir);\r
+ mFileList.listDirectory();\r
}\r
});\r
\r
}\r
\r
private class SyncBroadcastReceiver extends BroadcastReceiver {\r
+\r
/**\r
* {@link BroadcastReceiver} to enable syncing feedback in UI\r
*/\r
OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager()\r
.findFragmentById(R.id.fileList);\r
if (fileListFragment != null) {\r
- fileListFragment.listDirectory(mCurrentDir); \r
+ fileListFragment.listDirectory(mCurrentDir);\r
}\r
}\r
\r
setSupportProgressBarIndeterminateVisibility(inProgress);\r
\r
}\r
+ \r
+ RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncService.SYNC_RESULT);\r
+ if (synchResult != null) {\r
+ if (synchResult.getCode().equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {\r
+ mLastSslUntrustedServerResult = synchResult;\r
+ showDialog(DIALOG_SSL_VALIDATOR); \r
+ }\r
+ }\r
}\r
}\r
\r
}\r
\r
\r
+ @Override\r
+ public void onSavedCertificate() {\r
+ startSynchronization(); \r
+ }\r
+\r
+\r
+ @Override\r
+ public void onFailedSavingCertificate() {\r
+ showDialog(DIALOG_CERT_NOT_SAVED);\r
+ }\r
+\r
+\r
}\r