예제 #1
0
        public async void Delete()
        {
            if (await FileUtils.DirectoryExists(BaseFolder, this.LocalFolderName))
            {
                try
                {
                    await FileUtils.DeleteFolder(BaseFolder, this.LocalFolderName);
                }
                catch (Exception ex)
                {
                    QuranApp.NativeProvider.Log("error deleting file " + this.LocalFolderName);
                    telemetry.TrackException(ex, new Dictionary <string, string> {
                        { "Scenario", "DeletingReciterFile" }
                    });
                }
            }
            else
            {
                // Sometimes downloaded translation is kind of corrupted, need a way to delete this
                // corrupted item.
            }

            if (DeleteComplete != null)
            {
                DeleteComplete(this, null);
            }

            if (SettingsUtils.Get <string>(Constants.PREF_ACTIVE_QARI) == this.Name)
            {
                SettingsUtils.Set <string>(Constants.PREF_ACTIVE_QARI, string.Empty);
            }
        }
예제 #2
0
        private void RestoreSettings()
        {
            var preventSleep = SettingsUtils.Get <bool>(Constants.PREF_PREVENT_SLEEP);

            if (preventSleep)
            {
                QuranApp.NativeProvider.ToggleDeviceSleep(false);
            }

            // Set the current thread culture
            var cultureOverride = SettingsUtils.Get <string>(Constants.PREF_CULTURE_OVERRIDE);

            if (cultureOverride != "")
            {
                try
                {
                    CultureInfo.CurrentCulture   = new CultureInfo(cultureOverride);
                    CultureInfo.CurrentUICulture = new CultureInfo(cultureOverride);
                }
                catch
                {
                    //Ignore
                }
            }
        }
예제 #3
0
        private async Task ShowWelcomeMessage()
        {
            var versionFromConfig   = new Version(SettingsUtils.Get <string>(Constants.PREF_CURRENT_VERSION));
            var nameHelper          = SystemInfo.ApplicationName;
            var versionFromAssembly = new Version(SystemInfo.ApplicationVersion);

            if (versionFromAssembly > versionFromConfig)
            {
                var message =
                    @"Assalamu Aleikum,

Thank you for downloading Quran Windows. Please note that this is a BETA release and is still work in progress (especially audio support). 
New in Version 1.3.0:
* Added persistence of state to the main view
* Improved Arabic text above translation
* Updated Arabic localization by Saeed Hubaishan
* Added 'bismillah' to translations
* Misc. fixes and improvements

If you find any issues with the app or would like to provide suggestions, please use Contact Us option available via the menu. 

Jazzakum Allahu Kheiran,
Quran Windows Team";
                await QuranApp.NativeProvider.ShowInfoMessageBox(message, "Welcome");

                SettingsUtils.Set(Constants.PREF_CURRENT_VERSION, versionFromAssembly.ToString());
            }
        }
        public async void Delete()
        {
            if (await FileUtils.FileExists(LocalPath))
            {
                try
                {
                    await FileUtils.SafeFileDelete(LocalPath);
                }
                catch (Exception ex)
                {
                    QuranApp.NativeProvider.Log("error deleting file " + LocalPath);
                    telemetry.TrackException(ex, new Dictionary <string, string> {
                        { "Scenario", "DeletingTranslationFile" }
                    });
                }
            }
            else
            {
                // Sometimes downloaded translation is kind of corrupted, need a way to delete this
                // corrupted item.
            }

            if (DeleteComplete != null)
            {
                DeleteComplete(this, null);
            }

            if (SettingsUtils.Get <string>(Constants.PREF_ACTIVE_TRANSLATION).StartsWith(Path.GetFileName(LocalPath),
                                                                                         StringComparison.Ordinal))
            {
                SettingsUtils.Set <string>(Constants.PREF_ACTIVE_TRANSLATION, string.Empty);
            }
        }
예제 #5
0
파일: App.xaml.cs 프로젝트: sontx/dropzone
        protected override void OnStartup(StartupEventArgs e)
        {
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
            System.Windows.Forms.Application.EnableVisualStyles();
            Debugger.Init();
            Debugger.IsEnabledLog = SettingsUtils.Get <AppSettings>().IsEnabledDebugger;

            base.OnStartup(e);
        }
예제 #6
0
        private async void AyahContextMenuClick(object sender, RoutedEventArgs e)
        {
            var menuFlyoutItem = sender as MenuFlyoutItem;

            if (menuFlyoutItem == null)
            {
                return;
            }

            QuranAyah selectedAyah = menuFlyoutItem.DataContext as QuranAyah;

            if (selectedAyah == null)
            {
                return;
            }

            var menuItem = menuFlyoutItem.Text;

            if (menuItem == Core.Properties.Resources.bookmark_ayah)
            {
                ViewModel.AddAyahBookmark(selectedAyah);
            }
            else if (menuItem == Core.Properties.Resources.copy)
            {
                ViewModel.CopyAyahToClipboard(selectedAyah);
            }
            else if (menuItem == Core.Properties.Resources.share_ayah)
            {
                _ayahToShare      = selectedAyah;
                _ayahToShare.Text = await ViewModel.GetAyahString(_ayahToShare);

                DataTransferManager.ShowShareUI();
            }
            else if (menuItem == Core.Properties.Resources.recite_ayah)
            {
                int currentQari = AudioUtils.GetReciterIdByName(SettingsUtils.Get <string>(Constants.PREF_ACTIVE_QARI));
                if (currentQari == -1)
                {
                    Frame.Navigate(typeof(RecitersListView), null, new DrillInNavigationTransitionInfo());
                }
                else
                {
                    try
                    {
                        await ViewModel.PlayFromAyah(selectedAyah);

                        UpdateAudioControls(AudioState.Playing);
                    }
                    catch (Exception ex)
                    {
                        telemetry.TrackException(ex);
                    }
                }
            }

            ViewModel.SelectedAyah = null;
        }
예제 #7
0
        private void btnSettings_OnClick(object sender, RoutedEventArgs e)
        {
            var settingsWindow = new SettingsWindow {
                Owner = this
            };

            settingsWindow.ShowDialog();
            Debugger.IsEnabledLog = SettingsUtils.Get <AppSettings>().IsEnabledDebugger;
        }
예제 #8
0
        public SettingsWindow()
        {
            InitializeComponent();

            var settings = SettingsUtils.Get <AppSettings>();

            propertyGrid.SelectedObject = settings;
            propertyGrid.HelpVisible    = false;
            propertyGrid.ToolbarVisible = false;
        }
예제 #9
0
        private async Task LoadBookmarkList()
        {
            Bookmarks.Clear();
            var lastPage = SettingsUtils.Get <int>(Constants.PREF_LAST_PAGE);

            if (lastPage > 0)
            {
                var lastPageItem = new ItemViewModel();
                lastPageItem.Title   = QuranUtils.GetSurahNameFromPage(lastPage, true);
                lastPageItem.Details = string.Format("{0} {1}, {2} {3}", Resources.quran_page, lastPage,
                                                     QuranUtils.GetJuzTitle(),
                                                     QuranUtils.GetJuzFromPage(lastPage));
                lastPageItem.PageNumber = lastPage;
                lastPageItem.Image      = new BitmapImage(new Uri("ms-appx:///Assets/Images/favorite.png"));
                lastPageItem.ItemType   = ItemViewModelType.Bookmark;
                lastPageItem.Group      = Resources.bookmarks_current_page;
                lastPageItem.Id         = lastPageItem.Group;
                Bookmarks.Add(lastPageItem);
            }

            using (var bookmarksAdapter = new BookmarksDatabaseHandler())
            {
                try
                {
                    var bookmarks = bookmarksAdapter.GetBookmarks(true, BoomarkSortOrder.Location);
                    if (bookmarks.Count > 0)
                    {
                        //Load untagged first
                        foreach (var bookmark in bookmarks)
                        {
                            if (bookmark.Tags == null)
                            {
                                Bookmarks.Add(await CreateBookmarkModel(bookmark));
                            }
                        }

                        //Load tagged
                        foreach (var bookmark in bookmarks)
                        {
                            if (bookmark.Tags != null)
                            {
                                Bookmarks.Add(await CreateBookmarkModel(bookmark));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    telemetry.TrackException(ex, new Dictionary <string, string> {
                        { "Scenario", "LoadingBookmarks" }
                    });
                    QuranApp.NativeProvider.Log("failed to load bookmarks: " + ex.Message);
                }
            }
        }
예제 #10
0
        public ITransferRequest DownloadAsync(string from, string to)
        {
            var serverUri = new Uri(from, UriKind.Absolute);
            var phoneUri  = new Uri(to, UriKind.Relative);

            if (SettingsUtils.Get <bool>(Constants.PREF_ALT_DOWNLOAD))
            {
                return(DownloadAsyncViaWebClient(serverUri, phoneUri));
            }
            else
            {
                return(DownloadAsyncViaBackgroundTranfer(serverUri, phoneUri));
            }
        }
예제 #11
0
        public async Task PlayFromAyah(QuranAyah ayah)
        {
            int currentQari = AudioUtils.GetReciterIdByName(SettingsUtils.Get <string>(Constants.PREF_ACTIVE_QARI));

            if (currentQari == -1)
            {
                return;
            }

            var request = new QuranAudioTrack(currentQari, ayah,
                                              FileUtils.ScreenInfo);

            // if necessary download aya position file
            await DownloadAyahPositionFile();

            QuranApp.NativeProvider.AudioProvider.SetTrack(request);
        }
예제 #12
0
        public override async Task Refresh()
        {
            SupportedLanguages = new ObservableCollection <KeyValuePair <string, string> >();
            foreach (var lang in GetSupportedLanguages())
            {
                SupportedLanguages.Add(lang);
            }
            SupportedAudioBlocks = new ObservableCollection <KeyValuePair <string, string> >();
            foreach (var enumValue in Enum.GetNames(typeof(AudioDownloadAmount)))
            {
                SupportedAudioBlocks.Add(new KeyValuePair <string, string>(enumValue, enumValue));
            }

            var translation = SettingsUtils.Get <string>(Constants.PREF_ACTIVE_TRANSLATION);

            if (!string.IsNullOrEmpty(translation) && translation.Contains("|"))
            {
                ActiveTranslation = translation.Split('|')[1];
            }
            else
            {
                ActiveTranslation = "None";
            }

            var reciter = SettingsUtils.Get <string>(Constants.PREF_ACTIVE_QARI);

            if (!string.IsNullOrEmpty(reciter))
            {
                ActiveReciter = reciter;
            }
            else
            {
                ActiveReciter = "None";
            }

            SelectedLanguage         = SettingsUtils.Get <string>(Constants.PREF_CULTURE_OVERRIDE);
            TextSize                 = SettingsUtils.Get <double>(Constants.PREF_TRANSLATION_TEXT_SIZE);
            ArabicTextSize           = SettingsUtils.Get <double>(Constants.PREF_ARABIC_TEXT_SIZE);
            ShowArabicInTranslation  = SettingsUtils.Get <bool>(Constants.PREF_SHOW_ARABIC_IN_TRANSLATION);
            AltDownloadMethod        = SettingsUtils.Get <bool>(Constants.PREF_ALT_DOWNLOAD);
            PreventPhoneFromSleeping = SettingsUtils.Get <bool>(Constants.PREF_PREVENT_SLEEP);
            KeepInfoOverlay          = SettingsUtils.Get <bool>(Constants.PREF_KEEP_INFO_OVERLAY);
            NightMode                = SettingsUtils.Get <bool>(Constants.PREF_NIGHT_MODE);
        }
예제 #13
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (targetType != typeof(double))
            {
                throw new InvalidOperationException("The target must be double");
            }

            if (value != null && value.ToString() == "TranslationViewHeader")
            {
                return(50);
            }
            else if (value != null && value.ToString() == "ArabicText")
            {
                return(SettingsUtils.Get <double>(Constants.PREF_TRANSLATION_TEXT_SIZE) *
                       Constants.ARABIC_FONT_SCALE_RELATIVE_TO_TRANSLATION);
            }
            else
            {
                return(SettingsUtils.Get <double>(Constants.PREF_TRANSLATION_TEXT_SIZE));
            }
        }
예제 #14
0
        private void LogSettingsUsed()
        {
            Dictionary <string, string> settings = new Dictionary <string, string>();

            settings["TranslationView"] = ShowTranslation.ToString();
            try {
                var translation = SettingsUtils.Get <string>(Constants.PREF_ACTIVE_TRANSLATION);
                if (!string.IsNullOrEmpty(translation) && translation.Contains("|"))
                {
                    settings["ActiveTranslation"] = translation.Split('|')[1];
                }
                else
                {
                    settings["ActiveTranslation"] = "None";
                }

                var reciter = SettingsUtils.Get <string>(Constants.PREF_ACTIVE_QARI);
                if (!string.IsNullOrEmpty(reciter))
                {
                    settings["ActiveReciter"] = reciter;
                }
                else
                {
                    settings["ActiveReciter"] = "None";
                }

                settings["SelectedLanguage"]         = SettingsUtils.Get <string>(Constants.PREF_CULTURE_OVERRIDE);
                settings["TextSize"]                 = SettingsUtils.Get <double>(Constants.PREF_TRANSLATION_TEXT_SIZE).ToString();
                settings["ShowArabicInTranslation"]  = SettingsUtils.Get <bool>(Constants.PREF_SHOW_ARABIC_IN_TRANSLATION).ToString();
                settings["PreventPhoneFromSleeping"] = SettingsUtils.Get <bool>(Constants.PREF_PREVENT_SLEEP).ToString();
                settings["KeepInfoOverlay"]          = SettingsUtils.Get <bool>(Constants.PREF_KEEP_INFO_OVERLAY).ToString();
                settings["NightMode"]                = SettingsUtils.Get <bool>(Constants.PREF_NIGHT_MODE).ToString();
            }
            catch
            {
                // Ignore
            }

            telemetry.TrackEvent("FlipPage", settings);
        }
예제 #15
0
        public override async Task Initialize()
        {
            IsLoading = true;
            ClearPages();
            Orientation = DisplayInformation.GetForCurrentView().CurrentOrientation;
            if (SettingsUtils.Get <bool>(Constants.PREF_NIGHT_MODE))
            {
                Theme = ElementTheme.Dark;
            }
            else
            {
                Theme = ElementTheme.Light;
            }
            KeepInfoOverlay = SettingsUtils.Get <bool>(Constants.PREF_KEEP_INFO_OVERLAY);
            //Update translations
            var translation = SettingsUtils.Get <string>(Constants.PREF_ACTIVE_TRANSLATION);

            if (!string.IsNullOrEmpty(translation))
            {
                TranslationFile = translation.Split('|')[0];
                if (await HasTranslationFile())
                {
                    ShowTranslation         = SettingsUtils.Get <bool>(Constants.PREF_SHOW_TRANSLATION);
                    ShowArabicInTranslation = SettingsUtils.Get <bool>(Constants.PREF_SHOW_ARABIC_IN_TRANSLATION);
                }
                if (await HasTranslationFile())
                {
                    using (var db = new QuranDatabaseHandler <QuranAyah>(this.TranslationFile))
                    {
                        _bismillahTranslation = (await new TaskFactory().StartNew(() => db.GetVerse(1, 1))).Text;
                    }
                }
            }
            await CreatePages();
            await LoadCurrentPage();

            await base.Initialize();

            IsLoading = false;
        }
예제 #16
0
        private async Task LoadImageFromLocalPath(StorageFile imageFile)
        {
            using (var imageFileStream = await imageFile.OpenReadAsync())
            {
                var bitmap = new WriteableBitmap(1, 1); // avoid creating intermediate BitmapImage
                await bitmap.SetSourceAsync(imageFileStream);

                if (SettingsUtils.Get <bool>(Constants.PREF_NIGHT_MODE))
                {
                    try
                    {
                        await InvertColors(bitmap);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                imageSourceBitmap   = bitmap;
                progress.Visibility = Visibility.Collapsed;
            }
        }
예제 #17
0
        private async void AudioPlay(object sender, RoutedEventArgs e)
        {
            int currentQari = AudioUtils.GetReciterIdByName(SettingsUtils.Get <string>(Constants.PREF_ACTIVE_QARI));

            if (currentQari == -1)
            {
                Frame.Navigate(typeof(RecitersListView), null, new DrillInNavigationTransitionInfo());
            }
            else
            {
                try
                {
                    await ViewModel.Play();

                    UpdateAudioControls(AudioState.Playing);
                }
                catch (Exception ex)
                {
                    telemetry.TrackException(ex);
                }
            }
        }
예제 #18
0
        private void OnReceivedSuccessfully(List <string> savedFiles)
        {
            var receivingFiles = _session.WillReceiveFiles;

            Debugger.Log($"Sent {receivingFiles.Count} file(s) successfully");

            var settings        = SettingsUtils.Get <AppSettings>();
            var currentReceiver = _currentReceiver;

            if (!settings.IsShowNotification || currentReceiver == null)
            {
                return;
            }

            var neighbor = _station.GetNeighbor(currentReceiver.RemoteAddress);

            var notificationViewModel = new NotificationViewModel(neighbor.ToString(), savedFiles, currentReceiver.SaveDir);
            var notificationWindow    = new NotificationWindow {
                DataContext = notificationViewModel
            };

            notificationWindow.Show();
        }
예제 #19
0
        private async Task LoadPage(PageViewModel pageModel)
        {
            if (pageModel == null)
            {
                return;
            }

            // Set image
            if (pageModel.ImageSource == null)
            {
                pageModel.ImageSource = FileUtils.GetImageOnlineUri(FileUtils.GetPageFileName(pageModel.PageNumber));
            }

            // Set translation
            if (pageModel.Translations.Count == 0)
            {
                try
                {
                    if (!await HasTranslationFile())
                    {
                        return;
                    }

                    List <QuranAyah> versesTranslation = null;
                    using (var db = new QuranDatabaseHandler <QuranAyah>(this.TranslationFile))
                    {
                        versesTranslation = await new TaskFactory().StartNew(() => db.GetVerses(pageModel.PageNumber));
                    }

                    FlowDirection flowDirection          = FlowDirection.LeftToRight;
                    Regex         translationFilePattern = new Regex(@"quran\.([\w-]+)\..*");
                    var           fileMatch = translationFilePattern.Match(this.TranslationFile);
                    if (fileMatch.Success)
                    {
                        try
                        {
                            var cultureName = fileMatch.Groups[1].Value;
                            if (cultureName.Length > 2)
                            {
                                cultureName = cultureName.Substring(0, 2);
                            }
                            var cultureInfo = new CultureInfo(cultureName);
                            if (cultureInfo.TextInfo.IsRightToLeft)
                            {
                                flowDirection = FlowDirection.RightToLeft;
                            }
                        }
                        catch (Exception e)
                        {
                            telemetry.TrackException(e, new Dictionary <string, string> {
                                { "Scenario", "ParseTranslationFileForFlowDirection" }
                            });
                        }
                    }

                    List <ArabicAyah> versesArabic = null;
                    if (SettingsUtils.Get <bool>(Constants.PREF_SHOW_ARABIC_IN_TRANSLATION))
                    {
                        try
                        {
                            using (var dbArabic = new QuranDatabaseHandler <ArabicAyah>(FileUtils.ArabicDatabase))
                            {
                                versesArabic = await new TaskFactory().StartNew(() => dbArabic.GetVerses(pageModel.PageNumber));
                            }
                        }
                        catch (Exception e)
                        {
                            telemetry.TrackException(e, new Dictionary <string, string> {
                                { "Scenario", "OpenArabicDatabase" }
                            });
                        }
                    }

                    int tempSurah = -1;
                    for (int i = 0; i < versesTranslation.Count; i++)
                    {
                        var verse = versesTranslation[i];
                        if (verse.Surah != tempSurah)
                        {
                            pageModel.Translations.Add(new VerseViewModel(this)
                            {
                                IsHeader = true,
                                Text     = QuranUtils.GetSurahName(verse.Surah, true)
                            });

                            tempSurah = verse.Surah;
                        }


                        string translation = verse.Text;
                        if (QuranUtils.HasBismillah(verse.Surah) && verse.Surah != 1 && verse.Ayah == 1)
                        {
                            translation = _bismillahTranslation + " " + translation;
                        }
                        var verseViewModel = new VerseViewModel(this)
                        {
                            Surah         = verse.Surah,
                            Ayah          = verse.Ayah,
                            Text          = translation,
                            FlowDirection = flowDirection
                        };
                        if (versesArabic != null)
                        {
                            verseViewModel.ArabicText = versesArabic[i].Text;
                        }

                        pageModel.Translations.Add(verseViewModel);
                    }
                }
                catch (Exception e)
                {
                    // Try delete bad translation file if error is "no such table: verses"
                    try
                    {
                        if (e.Message.StartsWith("no such table:", StringComparison.OrdinalIgnoreCase))
                        {
                            await FileUtils.SafeFileDelete(Path.Combine(FileUtils.GetQuranDatabaseDirectory(),
                                                                        this.TranslationFile));
                        }
                    }
                    catch
                    {
                        // Do nothing
                    }
                    pageModel.Translations.Add(new VerseViewModel(this)
                    {
                        Text = "Error loading translation..."
                    });
                    telemetry.TrackException(e, new Dictionary <string, string> {
                        { "Scenario", "LoadingTranslation" }
                    });
                }
            }
            return;
        }
예제 #20
0
        public async void Load(string query)
        {
            if (this.IsLoading)
            {
                return;
            }

            this.IsLoading = true;
            var translation = SettingsUtils.Get <string>(Constants.PREF_ACTIVE_TRANSLATION);

            if (!string.IsNullOrEmpty(translation))
            {
                var translationFile = translation.Split('|')[0];

                try
                {
                    var translationVerses = new List <QuranAyah>();
                    var arabicVerses      = new List <ArabicAyah>();
                    var taskFactory       = new TaskFactory();

                    if (await FileUtils.FileExists(FileUtils.DatabaseFolder, translationFile))
                    {
                        using (var db = new QuranDatabaseHandler <QuranAyah>(Path.Combine(FileUtils.GetQuranDatabaseDirectory(), translationFile)))
                        {
                            translationVerses = await taskFactory.StartNew(() => db.Search(query));
                        }
                    }
                    using (var dbArabic = new QuranDatabaseHandler <ArabicAyah>(FileUtils.ArabicDatabase))
                    {
                        arabicVerses = await taskFactory.StartNew(() => dbArabic.Search(query));
                    }
                    this.SearchResults.Clear();

                    // Merging 2 results
                    int a           = 0;
                    int t           = 0;
                    var arabicVerse = new QuranAyah {
                        Surah = int.MaxValue, Ayah = int.MaxValue
                    };
                    var translationVerse = new QuranAyah {
                        Surah = int.MaxValue, Ayah = int.MaxValue
                    };
                    var verseToDisplay = new QuranAyah();
                    var comparer       = new AyahComparer();

                    while (a < arabicVerses.Count || t < translationVerses.Count)
                    {
                        if (a < arabicVerses.Count)
                        {
                            arabicVerse = arabicVerses[a];
                        }
                        else
                        {
                            arabicVerse = new QuranAyah {
                                Surah = int.MaxValue, Ayah = int.MaxValue
                            }
                        };

                        if (t < translationVerses.Count)
                        {
                            translationVerse = translationVerses[t];
                        }
                        else
                        {
                            translationVerse = new QuranAyah {
                                Surah = int.MaxValue, Ayah = int.MaxValue
                            }
                        };

                        if (comparer.Compare(arabicVerse, translationVerse) > 0)
                        {
                            verseToDisplay = translationVerse;
                            t++;
                        }
                        else if (comparer.Compare(arabicVerse, translationVerse) < 0)
                        {
                            verseToDisplay = arabicVerse;
                            a++;
                        }
                        else if (comparer.Compare(arabicVerse, translationVerse) == 0)
                        {
                            verseToDisplay = arabicVerse;
                            a++;
                            t++;
                        }

                        var verse = verseToDisplay;
                        var text  = TrimText(verse.Text, MaxPreviewCharacter);
                        this.SearchResults.Add(new ItemViewModel
                        {
                            Id =
                                string.Format("{0} ({1}:{2})", QuranUtils.GetSurahName(verse.Surah, false), verse.Surah,
                                              verse.Ayah),
                            Details      = text,
                            PageNumber   = QuranUtils.GetPageFromAyah(verse.Surah, verse.Ayah),
                            SelectedAyah = new QuranAyah(verse.Surah, verse.Ayah)
                        });
                    }
                    return;
                }
                catch (Exception ex)
                {
                    telemetry.TrackException(ex, new Dictionary <string, string> {
                        { "Scenario", "LoadingTranslations" }
                    });
                    this.SearchResults.Add(new ItemViewModel
                    {
                        Id           = "Error",
                        Details      = "Error performing translation",
                        PageNumber   = 1,
                        SelectedAyah = new QuranAyah()
                    });
                }
                finally
                {
                    IsLoading = false;
                }
            }
            await QuranApp.NativeProvider.ShowInfoMessageBox(Resources.no_translation_to_search);
        }
예제 #21
0
        // When page is navigated to set data context to selected item in list
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            await ViewModel.Initialize();

            await BuildLocalizedMenu();

            BuildContextMenu();
            UpdateAudioControls(ViewModel.AudioPlayerState);

            // Hide status bar
            if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1, 0))
            {
                var statusBar = StatusBar.GetForCurrentView();
                await statusBar.HideAsync();
            }

            NavigationData parameters = e.Parameter as NavigationData;

            if (parameters == null)
            {
                parameters = new NavigationData();
            }

            ViewModel.CurrentPageNumber = SettingsUtils.Get <int>(Constants.PREF_LAST_PAGE);

            //Monitor property changes
            ViewModel.PropertyChanged += async(sender, args) =>
            {
                if (args.PropertyName == "CurrentPageIndex")
                {
                    if (ViewModel.CurrentPageIndex != -1)
                    {
                        radSlideView.SelectedItem = ViewModel.Pages[ViewModel.CurrentPageIndex];
                    }
                }
                if (args.PropertyName == "AudioPlayerState")
                {
                    UpdateAudioControls(ViewModel.AudioPlayerState);
                }
                if (args.PropertyName == "CurrentPageBookmarked")
                {
                    SetBookmarkNavigationLink();
                }
                if (args.PropertyName == "TwoPageView")
                {
                    await SetPageFormatNavigationLink();
                }
            };

            //Try extract translation from query
            var translation = SettingsUtils.Get <string>(Constants.PREF_ACTIVE_TRANSLATION);

            if (!string.IsNullOrEmpty(translation))
            {
                if (ViewModel.TranslationFile != translation.Split('|')[0] ||
                    ViewModel.ShowTranslation != SettingsUtils.Get <bool>(Constants.PREF_SHOW_TRANSLATION) ||
                    ViewModel.ShowArabicInTranslation != SettingsUtils.Get <bool>(Constants.PREF_SHOW_ARABIC_IN_TRANSLATION))
                {
                    ViewModel.Pages.Clear();
                }
                ViewModel.TranslationFile = translation.Split('|')[0];
                if (await ViewModel.HasTranslationFile())
                {
                    ViewModel.ShowTranslation = SettingsUtils.Get <bool>(Constants.PREF_SHOW_TRANSLATION);
                }
                else
                {
                    ViewModel.ShowTranslation = false;
                }
                ViewModel.ShowArabicInTranslation = SettingsUtils.Get <bool>(Constants.PREF_SHOW_ARABIC_IN_TRANSLATION);
            }
            else
            {
                ViewModel.TranslationFile         = null;
                ViewModel.ShowTranslation         = false;
                ViewModel.ShowArabicInTranslation = false;
            }

            // set KeepInfoOverlay according to setting
            ViewModel.KeepInfoOverlay = SettingsUtils.Get <bool>(Constants.PREF_KEEP_INFO_OVERLAY);

            //Select ayah
            if (parameters.Surah != null && parameters.Ayah != null)
            {
                ViewModel.SelectedAyah = new QuranAyah(parameters.Surah.Value, parameters.Ayah.Value);
            }
            else
            {
                ViewModel.SelectedAyah = null;
            }

            // Listen to share requests
            _dataTransferManager = DataTransferManager.GetForCurrentView();
            _dataTransferManager.DataRequested += DataShareRequested;
        }
예제 #22
0
 public VerseViewModel(DetailsViewModel parent)
 {
     Parent         = parent;
     FontSize       = SettingsUtils.Get <double>(Constants.PREF_TRANSLATION_TEXT_SIZE);
     ArabicFontSize = FontSize * Constants.ARABIC_FONT_SCALE_RELATIVE_TO_TRANSLATION;
 }
예제 #23
0
 public VerseViewModel(DetailsViewModel parent)
 {
     Parent         = parent;
     FontSize       = SettingsUtils.Get <double>(Constants.PREF_TRANSLATION_TEXT_SIZE);
     ArabicFontSize = SettingsUtils.Get <double>(Constants.PREF_ARABIC_TEXT_SIZE);
 }