Ejemplo n.º 1
0
 public async void ReadJokeAsync(string joke)
 {
     if (joke != null)
     {
         await TextToSpeech.SpeakAsync(joke);
     }
     else
     {
         _toastMessage.ShowToast(selectErrorMessage);
     }
 }
        public async void RequestQuote()
        {
            try
            {
                if (!string.IsNullOrEmpty(quoteUrl))
                {
                    Scroll = ScrollEnum.Scroll;
                    var quotes = await _tronaldDumpService.GetQuoteAsync(quoteUrl);

                    if (quotes != null)
                    {
                        var id = 1;

                        if (Quotes.Count > 0)
                        {
                            id = Quotes.Last().Id + 1;
                        }

                        var quote = new QuoteItem
                        {
                            Id    = id,
                            Quote = quotes.value,
                            Tags  = quotes.tags,
                            Icon  = iconUrl
                        };

                        Quotes.Add(quote);

                        if (Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.UWP)
                        {
                            await _databaseService.AddQuote(new QuoteDbItem { Icon  = quote.Icon,
                                                                              Id    = quote.Id,
                                                                              Quote = quote.Quote,
                                                                              Tags  = String.Join(";", quote.Tags.ToArray()) });
                        }
                    }
                    else
                    {
                        _toastMessage.ShowToast(commonErrorMessage);
                    }
                }
                else
                {
                    _toastMessage.ShowToast(apiErrorMessage);
                }
            }
            catch { _toastMessage.ShowToast(commonErrorMessage); }
        }
Ejemplo n.º 3
0
        public ChuckJokesPageViewModel(IJokeService jokeService,
                                       IDatabaseService databaseService,
                                       ISettingsService settingsService,
                                       IToastMessage toastMessage)
        {
            _jokeService     = jokeService;
            _databaseService = databaseService;
            _settingsService = settingsService;
            _toastMessage    = toastMessage;

            OnAddJokeCommand    = new DelegateCommand(AddJokeAsync, CanAddJokeAsync);
            OnCellTappedCommand = new DelegateCommand <string>(ReadJokeAsync, CanReadJokeAsync);
            OnDeleteJokeCommand = new DelegateCommand <JokeItem>(DeleteJoke);

            LoadUrl();

            var dbJokes = _databaseService.GetJokes();

            if (dbJokes != null)
            {
                foreach (var item in dbJokes)
                {
                    JokeList.Add(item);
                }
            }

            UpdateBindedCollection();

            if (!ExtensionMethods.IsConnected())
            {
                _toastMessage.ShowToast(notConnectedMessage);
            }
        }
Ejemplo n.º 4
0
        public async void AddMemeAsync()
        {
            try
            {
                if (!string.IsNullOrEmpty(url))
                {
                    var value = await _tronaldDumpService.GetMemeAsync(url);

                    if (value != null)
                    {
                        var id = 1;

                        if (ImageCollection.Count > 0)
                        {
                            id = ImageCollection.Last().Id + 1;
                        }

                        var meme = new MemeDbItem
                        {
                            Id    = id,
                            Image = value
                        };

                        ImageCollection.Add(meme);
                        if (Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.UWP)
                        {
                            await _databaseService.AddMeme(meme);
                        }
                    }
                    else
                    {
                        _toastMessage.ShowToast(commonErrorMessage);
                    }
                }
                else
                {
                    _toastMessage.ShowToast(apiErrorMessage);
                }
            }
            catch { _toastMessage.ShowToast(commonErrorMessage); }
        }
Ejemplo n.º 5
0
        public HomePageViewModel(ISettingsService settingsService,
                                 IDatabaseService databaseService,
                                 IToastMessage toastMessage)
        {
            _settingsService = settingsService;
            _databaseService = databaseService;
            _toastMessage    = toastMessage;

            //_databaseService.DeleteDatabase();

            var dbJoke = _databaseService.GetRandomJoke();

            if (dbJoke != null)
            {
                Joke = dbJoke;
            }

            var dbQuote = _databaseService.GetRandomQuote();

            if (dbQuote != null)
            {
                Quote = new QuoteItem
                {
                    Tags  = dbQuote.Tags.Split(';').ToList(),
                    Icon  = dbQuote.Icon,
                    Id    = dbQuote.Id,
                    Quote = dbQuote.Quote
                }
            }
            ;

            var dbMeme = _databaseService.GetRandomMeme();

            if (dbMeme != null)
            {
                Meme = new MemeDbItem
                {
                    Image = dbMeme.Image,
                    Id    = dbMeme.Id
                }
            }
            ;

            InitSettings();

            if (!ExtensionMethods.IsConnected())
            {
                _toastMessage.ShowToast(notConnectedMessage);
            }
        }
        public TronaldDumpQuotesPageViewModel(ITronaldDumpService tronaldDumpService,
                                              IDatabaseService databaseService,
                                              ISettingsService settingsService,
                                              IToastMessage toastMessage)
        {
            _tronaldDumpService = tronaldDumpService;
            _databaseService    = databaseService;
            _settingsService    = settingsService;
            _toastMessage       = toastMessage;

            OnRequestNewQuoteCommand = new DelegateCommand(RequestQuote, CanRequestQuote);
            OnCellTappedCommand      = new DelegateCommand <string>(ReadQuoteAsync, CanReadQuoteAsync);
            OnDeleteQuoteCommand     = new DelegateCommand <QuoteItem>(DeleteQuote);

            GetQuoteUrl();

            var dbQuotes = _databaseService.GetQuotes();

            if (dbQuotes != null)
            {
                foreach (var item in dbQuotes)
                {
                    Quotes.Add(new QuoteItem {
                        Tags  = item.Tags.Split(';').ToList(),
                        Icon  = item.Icon,
                        Id    = item.Id,
                        Quote = item.Quote
                    });
                }
            }

            if (!ExtensionMethods.IsConnected())
            {
                _toastMessage.ShowToast(notConnectedMessage);
            }
        }