Пример #1
0
        private void SplitTextWithChordsToTextAndChords()
        {
            if (TextWithChords.Count == 0)
            {
                return;
            }
            StringBuilder chords = new StringBuilder();
            StringBuilder text   = new StringBuilder();

            foreach (TextLineWithChords textLineWithChords in TextWithChords)
            {
                chords.AppendLine(textLineWithChords.Chords);
                text.AppendLine(textLineWithChords.TextLine);
            }

            if (!String.IsNullOrWhiteSpace(Text) && !Text.Equals(text.ToString()))
            {
                Text      = TekstowoHelper.DeleteStartAndEndEmptyLines(text.ToString());
                Song.Text = Text;
            }


            if (!String.IsNullOrWhiteSpace(Chords) && !Chords.Equals(chords.ToString()))
            {
                Chords      = chords.ToString();
                Song.Chords = Chords;
            }
        }
Пример #2
0
        async Task SearchText()
        {
            try
            {
                int searchType;
                FindedSongObject songToFind = new FindedSongObject()
                {
                    Title = Title, Artist = Artist
                };



                if ((Title != null && !Title.Equals("")) && (Artist != null && !Artist.Equals("")))
                {
                    songToFind.WorkingTitle  = TekstowoHelper.NormalizeTextWithoutPolishSpecialChar(Title.ToLower().Replace(" ", "_"));
                    songToFind.WorkingArtist = TekstowoHelper.NormalizeTextWithoutPolishSpecialChar(Artist.ToLower().Replace(" ", "_"));
                    searchType = 1;
                }
                else if ((Artist != null && !Artist.Equals("")) && (Title == null || Title.Equals("")))
                {
                    songToFind.WorkingArtist = TekstowoHelper.NormalizeTextWithoutPolishSpecialChar(Artist.ToLower().Replace(" ", "_"));
                    searchType = 2;
                }
                else if ((Artist == null || Artist.Equals("")) && (Title != null && !Title.Equals("")))
                {
                    songToFind.WorkingTitle = TekstowoHelper.NormalizeTextWithoutPolishSpecialChar(Title.ToLower().Replace(" ", "_"));
                    searchType = 3;
                }
                else
                {
                    await _pageService.DisplayAlert(AppResources.AlertDialog_Error, AppResources.AlertDialog_CompleteAtLeastOneField, AppResources.AlertDialog_OK);

                    return;
                }

                switch (searchType)
                {
                case 1:
                    Text = await TekstowoHelper.FindTextFromArtistAndTitle(songToFind);

                    if (Text == null)
                    {
                        goto case 2;
                    }
                    else
                    {
                        break;
                    }

                case 2:
                    List <FindedSongObject> artistSongs = await TekstowoHelper.SearchArtistSongs(songToFind);

                    if (artistSongs.Count == 0)
                    {
                        songToFind = await TekstowoHelper.SearchArtist(songToFind);

                        if (songToFind == null)
                        {
                            break;
                        }
                        List <FindedSongObject> findedSongs = await TekstowoHelper.SearchArtistSongs(songToFind, true);

                        if (findedSongs.Count != 0)
                        {
                            List <string> listOfSongsFullName = new List <string>();
                            foreach (var item in findedSongs)
                            {
                                listOfSongsFullName.Add(item.FullSongName);
                            }
                            string choosenSong = await _pageService.DisplayPositionToChoose(AppResources.DisplayPositionToChoose_ChooseSong, AppResources.AlertDialog_Cancel, null, listOfSongsFullName.ToArray());

                            if (choosenSong.Equals(AppResources.AlertDialog_Cancel))
                            {
                                break;
                            }
                            songToFind = findedSongs[listOfSongsFullName.IndexOf(choosenSong)];
                            Text       = await TekstowoHelper.FindTextFromArtistAndTitle(songToFind, true);

                            if (!String.IsNullOrEmpty(Text))
                            {
                                Title  = songToFind.Title;
                                Artist = songToFind.Artist;
                            }
                        }
                    }
                    else
                    {
                        List <string> listOfSongsFullName = new List <string>();
                        foreach (var item in artistSongs)
                        {
                            listOfSongsFullName.Add(item.FullSongName);
                        }
                        string choosenSong = await _pageService.DisplayPositionToChoose(AppResources.DisplayPositionToChoose_ChooseSong, AppResources.AlertDialog_Cancel, null, listOfSongsFullName.ToArray());

                        if (choosenSong.Equals(AppResources.AlertDialog_Cancel))
                        {
                            break;
                        }
                        songToFind = artistSongs[listOfSongsFullName.IndexOf(choosenSong)];
                        Text       = await TekstowoHelper.FindTextFromArtistAndTitle(songToFind, true);

                        if (!String.IsNullOrEmpty(Text))
                        {
                            Title = songToFind.Title;
                        }
                    }
                    break;

                case 3:
                    songToFind = await TekstowoHelper.SearchSong(songToFind);

                    if (songToFind == null)
                    {
                        break;
                    }
                    Text = await TekstowoHelper.FindTextFromArtistAndTitle(songToFind, true);

                    if (!String.IsNullOrEmpty(Text))
                    {
                        Title  = songToFind.Title;
                        Artist = songToFind.Artist;
                    }

                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                Log.Debug(TAG, e.Message);
                await _pageService.DisplayAlert(AppResources.AlertDIalog_UnexpectedError, AppResources.AlertDIalog_UnexpectedErrorMessage, AppResources.AlertDialog_OK);
            }
        }