private void ShowFtpDialog(Activity activity, Util.FileSelectedHandler onStartBrowse, Action onCancel) { #if !NoNet AlertDialog.Builder builder = new AlertDialog.Builder(activity); View dlgContents = activity.LayoutInflater.Inflate(Resource.Layout.ftpcredentials, null); builder.SetView(dlgContents); builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { string host = dlgContents.FindViewById <EditText>(Resource.Id.ftp_host).Text; string portText = dlgContents.FindViewById <EditText>(Resource.Id.ftp_port).Text; FtpEncryptionMode encryption = (FtpEncryptionMode)dlgContents.FindViewById <Spinner>(Resource.Id.ftp_encryption).SelectedItemPosition; int port = NetFtpFileStorage.GetDefaultPort(encryption); if (!string.IsNullOrEmpty(portText)) { int.TryParse(portText, out port); } string user = dlgContents.FindViewById <EditText>(Resource.Id.ftp_user).Text; string password = dlgContents.FindViewById <EditText>(Resource.Id.ftp_password).Text; string initialPath = dlgContents.FindViewById <EditText>(Resource.Id.ftp_initial_dir).Text; string ftpPath = new NetFtpFileStorage(_activity, App.Kp2a).BuildFullPath(host, port, initialPath, user, password, encryption); onStartBrowse(ftpPath); }); EventHandler <DialogClickEventArgs> evtH = new EventHandler <DialogClickEventArgs>((sender, e) => onCancel()); builder.SetNegativeButton(Android.Resource.String.Cancel, evtH); builder.SetTitle(activity.GetString(Resource.String.enter_ftp_login_title)); Dialog dialog = builder.Create(); dialog.Show(); #endif }
private void ShowFtpDialog(Activity activity, Util.FileSelectedHandler onStartBrowse, Action onCancel, string defaultPath) { #if !NoNet AlertDialog.Builder builder = new AlertDialog.Builder(activity); View dlgContents = activity.LayoutInflater.Inflate(Resource.Layout.ftpcredentials, null); if (!defaultPath.EndsWith(_schemeSeparator)) { var connection = NetFtpFileStorage.ConnectionSettings.FromIoc(IOConnectionInfo.FromPath(defaultPath)); dlgContents.FindViewById <EditText>(Resource.Id.ftp_user).Text = connection.Username; dlgContents.FindViewById <EditText>(Resource.Id.ftp_password).Text = connection.Password; dlgContents.FindViewById <Spinner>(Resource.Id.ftp_encryption).SetSelection((int)connection.EncryptionMode); var uri = NetFtpFileStorage.IocToUri(IOConnectionInfo.FromPath(defaultPath)); string pathAndQuery = uri.PathAndQuery; var host = uri.Host; var localPath = pathAndQuery; if (!uri.IsDefaultPort) { dlgContents.FindViewById <EditText>(Resource.Id.ftp_port).Text = uri.Port.ToString(); } dlgContents.FindViewById <EditText>(Resource.Id.ftp_host).Text = host; dlgContents.FindViewById <EditText>(Resource.Id.ftp_initial_dir).Text = localPath; } builder.SetView(dlgContents); builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { string host = dlgContents.FindViewById <EditText>(Resource.Id.ftp_host).Text; string portText = dlgContents.FindViewById <EditText>(Resource.Id.ftp_port).Text; FtpEncryptionMode encryption = (FtpEncryptionMode)dlgContents.FindViewById <Spinner>(Resource.Id.ftp_encryption).SelectedItemPosition; int port = NetFtpFileStorage.GetDefaultPort(encryption); if (!string.IsNullOrEmpty(portText)) { int.TryParse(portText, out port); } string user = dlgContents.FindViewById <EditText>(Resource.Id.ftp_user).Text; string password = dlgContents.FindViewById <EditText>(Resource.Id.ftp_password).Text; string initialPath = dlgContents.FindViewById <EditText>(Resource.Id.ftp_initial_dir).Text; string ftpPath = new NetFtpFileStorage(_activity, App.Kp2a).BuildFullPath(host, port, initialPath, user, password, encryption); onStartBrowse(ftpPath); }); EventHandler <DialogClickEventArgs> evtH = new EventHandler <DialogClickEventArgs>((sender, e) => onCancel()); builder.SetNegativeButton(Android.Resource.String.Cancel, evtH); builder.SetTitle(activity.GetString(Resource.String.enter_ftp_login_title)); Dialog dialog = builder.Create(); dialog.Show(); #endif }