void CreateAddingDialog() { ContextThemeWrapper ctw = new ContextThemeWrapper(this, Android.Resource.Style.ThemeHoloLightDarkActionBar); AlertDialog.Builder builder = new AlertDialog.Builder(ctw); LayoutInflater inflater = Application.Context.GetSystemService(LayoutInflaterService) as LayoutInflater; View view = inflater.Inflate(Resource.Layout.AddingProfile, null); builder.SetView(view); EditText profileName = view.FindViewById <EditText>(Resource.Id.SyncProfileName); ImageButton selectFolder_btn = view.FindViewById <ImageButton>(Resource.Id.SelectFolder_btn); selectFolder_btn.Click += (sender, e) => { var intent = new Intent(this, typeof(FolderPickerActivity)); StartActivity(intent); }; builder.SetTitle("ДОБАВИТЬ НОВЫЙ ПРОФИЛЬ") .SetPositiveButton("ОК", (senderAlert, args) => { if (SyncProfilesHandler.AddNewProfile(profileName.Text, AppData.SelectedFolderPath, this)) { MessageDisplayer.ShowSuccessMessage(this, "Системные оповещения", "Новый профиль успешно добавлен."); Synchroniser service = new Synchroniser(new FolderHandler(AppData.SelectedFolderPath)); service.CreateSyncDataStore(); } profilesListView.Adapter = new ProfilesListAdapter(this, SyncProfilesHandler.AvailableProfilesList); }) .SetNegativeButton("Отмена", (senderAlert, args) => { Toast.MakeText(this, "Добавление профиля отменено!", ToastLength.Short).Show(); }); Dialog dialog = builder.Create(); dialog.Show(); }
/// <summary> /// Validates input name and folder to avoid the similar profiles. /// </summary> static bool CheckInputData(SyncProfile newProfile, Activity currentActivity) { if (newProfile.ProfileName == "" || newProfile.ProfileSyncFolderPath == "") { MessageDisplayer.ShowAlertMessage(currentActivity, "Ошибка добавления профиля", "Попытка создать профиль с пустым именем и/или пустым каталогом."); return(false); } else { if (AvailableProfilesList.Count != 0) { if (AvailableProfilesList.Any(profile => profile.ProfileName == newProfile.ProfileName)) { MessageDisplayer.ShowAlertMessage(currentActivity, "Ошибка добавления профиля", "Профиль с введеным именем уже существует.Пожалуйста, введите другое имя."); return(false); } else if (AvailableProfilesList.Any(profile => profile.ProfileSyncFolderPath == newProfile.ProfileSyncFolderPath)) { MessageDisplayer.ShowAlertMessage(currentActivity, "Ошибка добавления профиля", "Профиль с выбранным каталогом уже существует.Пожалуйста, выберите другой каталог."); return(false); } else { SaveProfile(newProfile); return(true); } } else { SaveProfile(newProfile); return(true); } } }