コード例 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_book_data_edit);

            _database = Database.Instance;

            AuthorTextView = FindViewById <TextView>(Resource.Id.text_view_book_author);
            var authorEditImageButton = FindViewById <ImageButton>(Resource.Id.image_button_edit_author);

            TitleTextView = FindViewById <TextView>(Resource.Id.text_view_book_title);
            var titleEditImageButton = FindViewById <ImageButton>(Resource.Id.image_button_edit_title);

            IsbnTextView = FindViewById <TextView>(Resource.Id.text_view_book_isbn);
            var isbnEditImageButton  = FindViewById <ImageButton>(Resource.Id.image_button_edit_isbn);
            var GenreSpinner         = FindViewById <Spinner>(Resource.Id.spinner_book_genre);
            var bookmarkRecyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView_bookmarkList);

            var saveButton        = FindViewById <Button>(Resource.Id.button_book_save);
            var cancelButton      = FindViewById <Button>(Resource.Id.button_book_cancel);
            var addBookmarkButton = FindViewById <Button>(Resource.Id.button_addBookmark);

            saveButton.Click        += OnSaveButtonClick;
            cancelButton.Click      += OnCancelButtonClick;
            addBookmarkButton.Click += AddBookMarkButtonClick;

            authorEditImageButton.Click += OnAuthorEditImageButtonClick;
            titleEditImageButton.Click  += OnTitleEditImageButtonClick;
            isbnEditImageButton.Click   += OnIsbnEditImageButtonClick;

            var dialog = UserDialogs.Instance.Loading("Loading");

            var extra = Intent.GetStringExtra("book");

            if (!string.IsNullOrEmpty(extra))
            {
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(ClientBookDto));
                StringReader  sr            = new StringReader(extra);
                Dto = (ClientBookDto)xmlSerializer.Deserialize(sr);
                var bookmarkList = _database.SelectTable <ClientBookmarkDto>().Where(bm => bm.BookId == Dto.BookId).ToList();
                BookmarkAdapter.AddBookmark(bookmarkList);
            }
            else
            {
                Dto = new ClientBookDto();
            }

            GenreList = _database.GetGenres();

            var adapter = new ArrayAdapter <string>(this, Resource.Layout.support_simple_spinner_dropdown_item, GenreList.Select(g => g.GenreName).ToList());

            GenreSpinner.Adapter       = adapter;
            GenreSpinner.ItemSelected += OnGenreSpinnerItemSelected;

            if (string.IsNullOrEmpty(Dto.GenreId))
            {
                Dto.Genre   = GenreList.FirstOrDefault();
                Dto.GenreId = Dto.Genre.GenreId;
            }
            GenreSpinner.SetSelection(GenreList.IndexOf(Dto.Genre));

            BookmarkAdapter.RecyclerView = bookmarkRecyclerView;
            bookmarkRecyclerView.SetAdapter(BookmarkAdapter);
            bookmarkRecyclerView.SetLayoutManager(new LinearLayoutManager(this));
            BookmarkAdapter.Context = this;

            AuthorTextView.Text = Dto.Author;
            TitleTextView.Text  = Dto.Title;
            IsbnTextView.Text   = Dto.Isbn;

            dialog.Dispose();
        }
コード例 #2
0
        private async void AddBookMarkButtonClick(object sender, EventArgs e)
        {
            var config = new PromptConfig
            {
                Title      = "Könyvjelző hozzáadása",
                Message    = "Adja meg a könyvjelző oldalszámát!",
                OkText     = "Mentés",
                CancelText = "Mégse"
            };
            var result = await UserDialogs.Instance.PromptAsync(config);

            if (result.Ok)
            {
                try
                {
                    var pageNumber = int.Parse(result.Text);

                    var dialog = UserDialogs.Instance.Loading("Loading");

                    using (var client = new HttpClient())
                    {
                        var bookmark = new ClientBookmarkDto
                        {
                            BookId      = Dto.BookId,
                            PageNumber  = pageNumber,
                            BookmarkId  = new Guid().ToString(),
                            LastUpdated = DateTime.Now,
                            #region tmp ki lesz veve
                            UserIdentifier = HbrApplication.UserIdentifier
                                             #endregion
                        };

                        var request = new AddBookmarkRequest
                        {
                            BookmarkId = bookmark.BookmarkId,
                            BookId     = bookmark.BookId,
                            PageNumber = bookmark.PageNumber,
                            #region tmp ki lesz veve
                            UserIdentifier = HbrApplication.UserIdentifier
                                             #endregion
                        };

                        if (CheckInternetConnection())
                        {
                            await client.PostAsJsonAsync("https://hbr.azurewebsites.net/api/Bookmark/AddBookmark", request);
                        }

                        BookmarkAdapter.AddBookmark(new List <ClientBookmarkDto> {
                            bookmark
                        });
                        _database.AddElement(bookmark);
                    }
                    dialog.Dispose();
                }
                catch (Exception)
                {
                    await UserDialogs.Instance.AlertAsync(new AlertConfig
                    {
                        Title   = "Hibás oldalszám!",
                        Message = "Az oldalszám csak szám lehet, ezért a könyvjelző nem lett hozzáadva!"
                    });
                }
            }
        }