Esempio n. 1
0
        private void OnItemClick(object sender, ApiKeysManagementAdapter.ItemEventArgs e)
        {
            if (e?.Item == null || e.Item.IsReadOnly)
            {
                return;
            }

            var providerId = e.Item.Id;

            try
            {
                switch (e.Action)
                {
                case ApiKeysManagementViewHolder.EditActions.Edit:
                    var dialogs = new Dialogs();
                    dialogs.ApiKeyDialog(activity: this, providerType: e.Item.ProviderType,
                                         providerId: providerId, alwaysShowDialog: true, okAction: () =>
                    {
                        NotifyItemChanged(e.Position);
                    }, cancelAction: null, toastLength: AppSettings.ToastLength, log: Log);
                    break;

                case ApiKeysManagementViewHolder.EditActions.Delete:
                    var keys = AppSettings.Default.GetApiKeys();
                    if (keys.ContainsKey(providerId))
                    {
                        var dlg = new WidgetUtil();
                        dlg.ShowDialog(context: this, titleId: Resource.String.ApiKeysManagementTitle,
                                       message: GetString(Resource.String.IcDeleteApiKeyConfirmation),
                                       okAction: () =>
                        {
                            try
                            {
                                keys.Remove(providerId);
                                AppSettings.Default.SaveApiKeys(keys);

                                //HARDCODE:
                                if (providerId == AppSettings.GoogleMapsGeocodingApiProviderId &&
                                    AppSettings.Default.UseGoogleMapsGeocodingApi)
                                {
                                    AppSettings.Default.UseGoogleMapsGeocodingApi = false;
                                    SetChangeActivityResult();
                                }

                                NotifyItemChanged(e.Position);
                            }
                            catch (Exception ex)
                            {
                                Log.Error(ex);
                                Toast.MakeText(this, GetString(Resource.String.InternalError),
                                               AppSettings.ToastLength).Show();
                            }
                        });
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                Toast.MakeText(this, Resource.String.InternalError, AppSettings.ToastLength).Show();
            }
        }