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
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
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
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
}\r
\r
private class SyncBroadcastReceiver extends BroadcastReceiver {\r
+\r
/**\r
* {@link BroadcastReceiver} to enable syncing feedback in UI\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