private async void Menu_MenuItemClick(object sender, PopupMenu.MenuItemClickEventArgs e, int position) { if (e.Item.ItemId == Resource.Id.action_delete) { PasswordDialogFragment dialog = new PasswordDialogFragment((Activity)context); dialog.Func = () => { AccountController storageController = new AccountController(); bool result = storageController.Delete(this[position].Id); if (result) { AccountChange(this, new EventArgs()); Toast.MakeText(context, "Аккаунт " + this[position].Name + " удален", ToastLength.Long).Show(); return(new Task <bool>(() => true)); } else { Toast.MakeText(context, "Неудача", ToastLength.Long).Show(); return(new Task <bool>(() => false)); } }; dialog.Show(); } else if (e.Item.ItemId == Resource.Id.action_change) { ChangeAccountDialogFragment dialog = new ChangeAccountDialogFragment((Activity)context, this[position]); dialog.Func = () => { AccountChange(this, new EventArgs()); Toast.MakeText(context, "Аккаунт успешно изменен", ToastLength.Long).Show(); return(true); }; dialog.Show(); } else if (e.Item.ItemId == Resource.Id.action_get_password) { ClipboardManager clipboard = (ClipboardManager)context.GetSystemService(Context.ClipboardService); AccountController ac = new AccountController(); string result = await ac.GetPassword(this[position].Id); if (!string.IsNullOrWhiteSpace(result)) { ClipData clip = ClipData.NewPlainText("password", result); clipboard.PrimaryClip = clip; Toast.MakeText(context, "Пароль скопирован", ToastLength.Long).Show(); } } }
private void Menu_MenuItemClick(object sender, PopupMenu.MenuItemClickEventArgs e, int position) { if (e.Item.ItemId == Resource.Id.action_delete) { PasswordDialogFragment dialog = new PasswordDialogFragment((Activity)context); dialog.Func = () => { StorageController storageController = new StorageController(); bool result = storageController.Delete(storages[position].Name); if (result) { StorageChange(this, new EventArgs()); Toast.MakeText(context, "Хранилище " + storages[position].Name + " удалено", ToastLength.Long).Show(); return(new Task <bool>(() => true)); } else { Toast.MakeText(context, "Неудача", ToastLength.Long).Show(); return(new Task <bool>(() => false)); } }; dialog.Show(); } else if (e.Item.ItemId == Resource.Id.action_change) { ChangeKeyDialogFragment dialog = new ChangeKeyDialogFragment((Activity)context, storages[position].Name); dialog.Func = () => { Toast.MakeText(context, "Ключ успешно изменен", ToastLength.Long).Show(); return(true); }; dialog.Show(); } else if (e.Item.ItemId == Resource.Id.action_connect) { KeyDialogFragment dialog = new KeyDialogFragment((Activity)context, storages[position].Name); dialog.Func = () => { EnterKey(this, new EventArgs()); Toast.MakeText(context, "Вы вошли в хранилище", ToastLength.Long).Show(); return(true); }; dialog.Show(); } }
private void DeleteAllStorages_Click(object sender, EventArgs e, ViewGroup view) { PasswordDialogFragment dialog = new PasswordDialogFragment(Activity); dialog.Func = () => { StorageController storageController = new StorageController(); bool result = storageController.DeleteAll(); if (result) { UpdateStorages(view); Toast.MakeText(Context, "Все хранилища удалены", ToastLength.Long).Show(); return(new Task <bool>(() => true)); } else { Toast.MakeText(Context, "Неудача", ToastLength.Long).Show(); return(new Task <bool>(() => false)); } }; dialog.Show(); }
private void DeleteAllAccounts_Click(object sender, EventArgs e) { PasswordDialogFragment dialog = new PasswordDialogFragment(Activity); dialog.Func = () => { AccountController storageController = new AccountController(); bool result = storageController.DeleteAll(); if (result) { UpdateAccounts(); Toast.MakeText(Context, "Все аккаунты удалены", ToastLength.Long).Show(); return(new Task <bool>(() => true)); } else { Toast.MakeText(Context, "Неудача", ToastLength.Long).Show(); return(new Task <bool>(() => false)); } }; dialog.Show(); }
private void Menu_MenuItemClick(object sender, PopupMenu.MenuItemClickEventArgs e, int position) { if (e.Item.ItemId == Resource.Id.action_delete) { PasswordDialogFragment dialog = new PasswordDialogFragment((Activity)context); dialog.Func = () => { FileController fc = new FileController(); bool result = fc.Delete(this[position].Name); if (result) { FileChange(this, new EventArgs()); Toast.MakeText(context, "Файл " + this[position].Name + " удален", ToastLength.Long).Show(); return(new Task <bool>(() => true)); } else { Toast.MakeText(context, fc.Exceptions.FirstOrDefault().Message, ToastLength.Long).Show(); return(new Task <bool>(() => false)); } }; dialog.Show(); } else if (e.Item.ItemId == Resource.Id.action_get_decrypt) { PasswordDialogFragment dialog = new PasswordDialogFragment((Activity)context); dialog.Func = async() => { FileController fc = new FileController(); byte[] result = await fc.GetDecryptFile(this[position].Name, this[position].Type); if (result != null) { bool isWriteable = Android.OS.Environment.MediaMounted.Equals(Android.OS.Environment.ExternalStorageState); if (!isWriteable) { return(false); } string path = Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath, this[position].Name + "." + this[position].Type); using (FileStream stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { await stream.WriteAsync(result, 0, result.Length); } Toast.MakeText(context, "Файл " + this[position].Name + " загружен", ToastLength.Long).Show(); return(true); } else { Toast.MakeText(context, fc.Exceptions.FirstOrDefault().Message, ToastLength.Long).Show(); return(false); } }; dialog.Show(); } else if (e.Item.ItemId == Resource.Id.action_get_encrypt) { PasswordDialogFragment dialog = new PasswordDialogFragment((Activity)context); dialog.Func = async() => { FileController fc = new FileController(); byte[] result = await fc.GetEncryptFile(this[position].Name, this[position].Type); if (result != null) { bool isWriteable = Android.OS.Environment.MediaMounted.Equals(Android.OS.Environment.ExternalStorageState); if (!isWriteable) { return(false); } string path = Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath, this[position].Name + "." + this[position].Type); using (FileStream stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { stream.WriteAsync(result, 0, result.Length); } Toast.MakeText(context, "Файл " + this[position].Name + " загружен", ToastLength.Long).Show(); return(true); } else { Toast.MakeText(context, fc.Exceptions.FirstOrDefault().Message, ToastLength.Long).Show(); return(false); } }; dialog.Show(); } }