Example #1
0
        private async Task LoadImage(Data.MagazineViewModel mag)
        {
            try
            {
                var file = await StorageFile.GetFileFromPathAsync(mag.PngPath);

                var image = new BitmapImage();
                await image.SetSourceAsync(await file.OpenReadAsync());

                mag.Image        = image;
                thumbnail.Source = mag.Image;
            }
            catch { }
        }
        public async Task Init(Data.MagazineViewModel mag)
        {
            _item = mag;
            product_id = mag.FileName.Replace(".pdf", "");
            relativePath = mag.RelativePath;
            licenseInformation = CurrentAppSimulator.LicenseInformation;

            var appListing = await CurrentAppSimulator.LoadListingInformationAsync();
            var productListings = appListing.ProductListings;
            ProductListing product = null;
            try {
                product = productListings["yearlysubscritpion"];

            } catch { }

            statusContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
            buttonContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            subscribeBtn.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            subscribeBtn1.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            buyMag.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            this.Visibility = Windows.UI.Xaml.Visibility.Visible;

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try {
                        receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();
                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);

                    } catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync("yearlysubscritpion", receipt);
                        var url = DownloadManager.GetUrl("yearlysubscritpion", receipt, relativePath);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            subscribeBtn.Content = "Subscribe to Wind for 1 year: " + product.FormattedPrice;
                            subscribeBtn.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else 
                    {
                        var url = await DownloadManager.GetUrl("yearlysubscritpion", relativePath);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            subscribeBtn.Content = "Subscribe to Wind for 1 year: " + product.FormattedPrice;
                            subscribeBtn.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    //var productLicense1 = licenseInformation.ProductLicenses["Subscription1"];
                    //var longdateTemplate = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longdate");
                    //var text = "Subscription1 expires on: " + longdateTemplate.Format(productLicense1.ExpirationDate);
                    //var remainingDays = (productLicense1.ExpirationDate - DateTime.Now).Days;
                    if (Bought != null)
                    {
                        var url = await DownloadManager.GetUrl("yearlysubscritpion", relativePath);
                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try {
                                receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();

                            }  catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync("yearlysubscritpion", receipt);
                                url = DownloadManager.GetUrl("yearlysubscritpion", receipt, relativePath);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog("Purchase successfull");
                        var task = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            try {
                product = productListings["monthlysubscription"];

            } catch { }

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try
                    {
                        receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();
                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);

                    }
                    catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync("monthlysubscription", receipt);
                        var url = DownloadManager.GetUrl("monthlysubscription", receipt, relativePath);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            subscribeBtn1.Content = "Subscribe to Wind for 6 months: " + product.FormattedPrice;
                            subscribeBtn1.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else
                    {
                        var url = await DownloadManager.GetUrl("monthlysubscription", relativePath);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            subscribeBtn1.Content = "Subscribe to Wind for 6 months: " + product.FormattedPrice;
                            subscribeBtn1.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    if (Bought != null)
                    {
                        var url = await DownloadManager.GetUrl("monthlysubscription", relativePath);
                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try
                            {
                                receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();

                            }
                            catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync("monthlysubscription", receipt);
                                url = DownloadManager.GetUrl("monthlysubscription", receipt, relativePath);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog("Purchase successfull");
                        var task = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            try {
                product = productListings[product_id];

            } catch { }

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try
                    {
                        receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();
                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);

                    }
                    catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync(product_id, receipt);
                        var url = DownloadManager.GetUrl(product_id, receipt, relativePath);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            buyMag.Content = "Buy " + mag.Title + " for: " + product.FormattedPrice;
                            buyMag.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else
                    {
                        var url = await DownloadManager.GetUrl(product_id, relativePath);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            buyMag.Content = "Buy " + mag.Title + " for: " + product.FormattedPrice;
                            buyMag.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    if (Bought != null)
                    {
                        var url = await DownloadManager.GetUrl(product_id, relativePath);
                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try
                            {
                                receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();

                            }
                            catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync(product_id, receipt);
                                url = DownloadManager.GetUrl(product_id, receipt, relativePath);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog("Purchase successfull");
                        var task = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            if (product != null)
            {
                var url = await DownloadManager.GetUrl(product_id, relativePath);
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try
                    {
                        receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();
                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);

                    }
                    catch { }
                    if (receipt != "")
                    {
                        Bought(this, url);
                    }
                    else
                    {
                        buyMag.Content = "Buy " + mag.Title + " for: " + product.FormattedPrice;
                        buyMag.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    }
                }
                else
                {
                    if (Bought != null)
                    {
                        this.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try
                            {
                                receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();

                            }
                            catch { }
                            if (receipt != null)
                            {
                                Bought(this, url);
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog("Purchase successfull");
                        var task = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            statusContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            buttonContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }
        public async Task Init(Data.MagazineViewModel mag, bool local = false)
        {
            thumbnail.Source = mag.Image;
            title.Text = mag.Title;
            subtitle.Text = mag.Subtitle;

            if (local)
            {
                _item = mag;

                noOptions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                subscribeBtnContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                buyMagContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                getSampleContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

                openContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                delete.Text = "Delete";
                deleteContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;

                if (_item.IsSampleDownloaded)
                    subtitle.Text += " SAMPLE";

                this.Visibility = Windows.UI.Xaml.Visibility.Visible;

                return;
            }

            if (mag.IsSampleDownloaded)
            {
                getSample.Text = "Open sample";
                getSampleButton.Content = "\xe16f";
            }
            else
            {
                getSample.Text = "Download sample";
                getSampleButton.Content = "\xe118";
            }

            _item = mag;
            product_id = mag.FileName.Replace("_.pdf", "");
            relativePath = mag.RelativePath;
            licenseInformation = CurrentAppSimulator.LicenseInformation;

            var appListing = await CurrentAppSimulator.LoadListingInformationAsync();
            var productListings = appListing.ProductListings;
            ProductListing product = null;
            
            //statusContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
            //buttonContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            subscribeBtnContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            buyMagContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            getSampleContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
            openContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            deleteContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            this.Visibility = Windows.UI.Xaml.Visibility.Visible;

            try
            {
                product = productListings[product_id];

            }
            catch { }

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try
                    {
                        receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();
                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);

                    }
                    catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync(product_id, receipt);
                        var app = Application.Current as App;
                        var url = DownloadManager.GetUrl(product_id, receipt, relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                            buyMag.Text = "Buy this number for: " + product.FormattedPrice;
                            buyMagContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl(product_id, relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                            buyMag.Text = "Buy this number for: " + product.FormattedPrice;
                            buyMagContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    if (Bought != null)
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl(product_id, relativePath, app.ClientName, app.MagazineName);
                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try
                            {
                                receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();

                            }
                            catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync(product_id, receipt);
                                url = DownloadManager.GetUrl(product_id, receipt, relativePath, app.ClientName, app.MagazineName);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog("Purchase successfull");
                        var task = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            product = null;

            try {

                product = productListings["yearlysubscription"];

            } catch { }

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try {
                        receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();
                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);

                    } catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync("yearlysubscription", receipt);
                        var app = Application.Current as App;
                        var url = DownloadManager.GetUrl("yearlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn.Text = "Subscribe for 1 year: " + product.FormattedPrice;
                            subscribeBtnContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else 
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("yearlysubscription", relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn.Text = "Subscribe for 1 year: " + product.FormattedPrice;
                            subscribeBtnContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    //var productLicense1 = licenseInformation.ProductLicenses["Subscription1"];
                    //var longdateTemplate = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longdate");
                    //var text = "Subscription1 expires on: " + longdateTemplate.Format(productLicense1.ExpirationDate);
                    //var remainingDays = (productLicense1.ExpirationDate - DateTime.Now).Days;
                    if (Bought != null)
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("yearlysubscription", relativePath, app.ClientName, app.MagazineName);
                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try {
                                receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();

                            }  catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync("yearlysubscription", receipt);
                                url = DownloadManager.GetUrl("yearlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog("Purchase successfull");
                        var task = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            product = null;

            try {
                product = productListings["monthlysubscription"];

            } catch { }

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try
                    {
                        receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();
                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);

                    }
                    catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync("monthlysubscription", receipt);
                        var app = Application.Current as App;
                        var url = DownloadManager.GetUrl("monthlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn1.Text = "Subscribe for 1 month: " + product.FormattedPrice;
                            subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("monthlysubscription", relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn1.Text = "Subscribe for 1 month: " + product.FormattedPrice;
                            subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    if (Bought != null)
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("monthlysubscription", relativePath, app.ClientName, app.MagazineName);
                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try
                            {
                                receipt = await CurrentAppSimulator.GetAppReceiptAsync().AsTask();

                            }
                            catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync("monthlysubscription", receipt);
                                url = DownloadManager.GetUrl("monthlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog("Purchase successfull");
                        var task = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            if (buyMagContainer.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
            {
                if (subscribeBtnContainer.Visibility == Windows.UI.Xaml.Visibility.Visible)
                {
                    //subscribeBtnContainer.Margin = new Thickness(0, 22, 0, 10);
                }
                else if (subscribeBtn1Container.Visibility == Windows.UI.Xaml.Visibility.Visible)
                {
                    //subscribeBtn1.Margin = new Thickness(0, 22, 0, 10);
                }
                else
                {
                    noOptions.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
            }

            //statusContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            //buttonContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }
Example #4
0
        public async Task Init(Data.MagazineViewModel mag, bool local = false, bool intern = false)
        {
            bool needToUpdateImage = false;

            if (mag.Image != null)
            {
                thumbnail.Source = mag.Image;
            }
            else
            {
                needToUpdateImage = true;
            }

            title.Text    = mag.Title;
            subtitle.Text = mag.Subtitle;
            var loader = new ResourceLoader();

            if (local)
            {
                _item = mag;

                noOptions.Visibility              = Windows.UI.Xaml.Visibility.Collapsed;
                noOptions.Text                    = loader.GetString("no_options");
                subscribeBtnContainer.Visibility  = Windows.UI.Xaml.Visibility.Collapsed;
                subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                buyMagContainer.Visibility        = Windows.UI.Xaml.Visibility.Collapsed;
                getSampleContainer.Visibility     = Windows.UI.Xaml.Visibility.Collapsed;

                open.Text = loader.GetString("read");
                openContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                delete.Text = loader.GetString("delete");
                deleteContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;

                if (_item.IsSampleDownloaded)
                {
                    subtitle.Text += " SAMPLE";
                }

                this.Visibility = Windows.UI.Xaml.Visibility.Visible;

                return;
            }

            if (mag.IsSampleDownloaded)
            {
                getSample.Text          = loader.GetString("open_sample");
                getSampleButton.Content = "\xe16f";
            }
            else
            {
                getSample.Text          = loader.GetString("download_sample");
                getSampleButton.Content = "\xe118";
            }

            _item              = mag;
            product_id         = mag.FileName.Replace("_.pdf", "");
            relativePath       = mag.RelativePath;
            licenseInformation = CurrentApp.LicenseInformation;
            IReadOnlyDictionary <string, ProductListing> productListings = null;

            try
            {
                var appListing = await CurrentApp.LoadListingInformationAsync();

                productListings = appListing.ProductListings;
            }
            catch
            {
                subscribeBtnContainer.Visibility  = Windows.UI.Xaml.Visibility.Collapsed;
                subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                buyMagContainer.Visibility        = Windows.UI.Xaml.Visibility.Collapsed;
                if (!intern)
                {
                    getSampleContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
                else
                {
                    getSampleContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                }
                openContainer.Visibility   = Windows.UI.Xaml.Visibility.Collapsed;
                deleteContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                noOptions.Visibility       = Windows.UI.Xaml.Visibility.Visible;
                noOptions.Text             = loader.GetString("no_options");
                this.Visibility            = Windows.UI.Xaml.Visibility.Visible;

                if (needToUpdateImage)
                {
                    var task = LoadImage(mag);
                }

                return;
            }

            ProductListing product = null;

            //statusContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
            //buttonContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            subscribeBtnContainer.Visibility  = Windows.UI.Xaml.Visibility.Collapsed;
            subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            buyMagContainer.Visibility        = Windows.UI.Xaml.Visibility.Collapsed;
            if (!intern)
            {
                getSampleContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }
            else
            {
                getSampleContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
            openContainer.Visibility   = Windows.UI.Xaml.Visibility.Collapsed;
            deleteContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            this.Visibility = Windows.UI.Xaml.Visibility.Visible;

            try
            {
                product = productListings[product_id];
            }
            catch { }

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try
                    {
                        receipt = await CurrentApp.GetAppReceiptAsync().AsTask();

                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);
                    }
                    catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync(product_id, receipt);

                        var app = Application.Current as App;
                        var url = DownloadManager.GetUrl(product_id, receipt, relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility       = Windows.UI.Xaml.Visibility.Collapsed;
                            buyMag.Text                = loader.GetString("buy_number") + " " + product.FormattedPrice;
                            buyMagContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl(product_id, relativePath, app.ClientName, app.MagazineName);

                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility       = Windows.UI.Xaml.Visibility.Collapsed;
                            buyMag.Text                = loader.GetString("buy_number") + " " + product.FormattedPrice;
                            buyMagContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    if (Bought != null)
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl(product_id, relativePath, app.ClientName, app.MagazineName);

                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try
                            {
                                receipt = await CurrentApp.GetAppReceiptAsync().AsTask();
                            }
                            catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync(product_id, receipt);

                                url = DownloadManager.GetUrl(product_id, receipt, relativePath, app.ClientName, app.MagazineName);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task          = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task          = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog(loader.GetString("purchase_successfull"));
                        var task          = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            product = null;

            try {
                product = productListings["yearlysubscription"];
            } catch { }

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try {
                        receipt = await CurrentApp.GetAppReceiptAsync().AsTask();

                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);
                    } catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync("yearlysubscription", receipt);

                        var app = Application.Current as App;
                        var url = DownloadManager.GetUrl("yearlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility             = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn.Text                = loader.GetString("subscribe_one_year") + " " + product.FormattedPrice;
                            subscribeBtnContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("yearlysubscription", relativePath, app.ClientName, app.MagazineName);

                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility             = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn.Text                = loader.GetString("subscribe_one_year") + " " + product.FormattedPrice;
                            subscribeBtnContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    //var productLicense1 = licenseInformation.ProductLicenses["Subscription1"];
                    //var longdateTemplate = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longdate");
                    //var text = "Subscription1 expires on: " + longdateTemplate.Format(productLicense1.ExpirationDate);
                    //var remainingDays = (productLicense1.ExpirationDate - DateTime.Now).Days;
                    if (Bought != null)
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("yearlysubscription", relativePath, app.ClientName, app.MagazineName);

                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try {
                                receipt = await CurrentApp.GetAppReceiptAsync().AsTask();
                            }  catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync("yearlysubscription", receipt);

                                url = DownloadManager.GetUrl("yearlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task          = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task          = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog(loader.GetString("purchase_successfull"));
                        var task          = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            product = null;

            try {
                product = productListings["monthlysubscription"];
            } catch { }

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try
                    {
                        receipt = await CurrentApp.GetAppReceiptAsync().AsTask();

                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);
                    }
                    catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync("monthlysubscription", receipt);

                        var app = Application.Current as App;
                        var url = DownloadManager.GetUrl("monthlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn1.Text   = loader.GetString("subscribe_one_month") + " " + product.FormattedPrice;
                            subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("monthlysubscription", relativePath, app.ClientName, app.MagazineName);

                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn1.Text   = loader.GetString("subscribe_one_month") + " " + product.FormattedPrice;
                            subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    if (Bought != null)
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("monthlysubscription", relativePath, app.ClientName, app.MagazineName);

                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try
                            {
                                receipt = await CurrentApp.GetAppReceiptAsync().AsTask();
                            }
                            catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync("monthlysubscription", receipt);

                                url = DownloadManager.GetUrl("monthlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task          = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task          = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog(loader.GetString("purchase_successfull"));
                        var task          = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            if (buyMagContainer.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
            {
                if (subscribeBtnContainer.Visibility == Windows.UI.Xaml.Visibility.Visible)
                {
                    //subscribeBtnContainer.Margin = new Thickness(0, 22, 0, 10);
                }
                else if (subscribeBtn1Container.Visibility == Windows.UI.Xaml.Visibility.Visible)
                {
                    //subscribeBtn1.Margin = new Thickness(0, 22, 0, 10);
                }
                else
                {
                    noOptions.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    noOptions.Text       = loader.GetString("no_options");
                }
            }

            if (needToUpdateImage)
            {
                await LoadImage(mag);
            }

            //statusContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            //buttonContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }
Example #5
0
        public static IReadOnlyList<MagazineViewModel> LoadMagazines(IList<LibrelioLocalUrl> magazines, IList<LibrelioLocalUrl> magazinesDownloaded, int width) {

           var list = new List<MagazineViewModel>();

            bool newGroup = false;
            MagazineDataGroup group = null;
            var loader = new ResourceLoader();
            if (GetGroup(loader.GetString("my_magazines")) == null) {

                group = new MagazineDataGroup(loader.GetString("my_magazines"), loader.GetString("my_magazines"), "");
                newGroup = true;

            } else {

                group = GetGroup(loader.GetString("my_magazines"));
            }

            if (newGroup) {

                _sampleDataSource.AllGroups.Add(group);
                newGroup = false;
            }

            for (int i = 0; i < magazinesDownloaded.Count; i++) {

                if (magazinesDownloaded[i].IsDownloaded) {

                    var m = new MagazineModel(magazinesDownloaded[i], i);
                    var item = GetItem(m.fileName);
                    if (item != null)
                    {
                        var b = item.Update(1, 1, width, m);
                        if (b) list.Add(item);
                        continue;
                    }

                    group.Items.Add(new MagazineViewModel(m.fileName, 1, 1, width, m.Title, m.Subtitle, group, m));
                }
            }

            newGroup = false;

            if (GetGroup(loader.GetString("all_magazines")) == null) {

                group = new MagazineDataGroup(loader.GetString("all_magazines"), loader.GetString("all_magazines"), "");
                newGroup = true;

            } else {

                group = GetGroup(loader.GetString("all_magazines"));
            }

            if (newGroup) {

                _sampleDataSource.AllGroups.Add(group);
                newGroup = false;
            }

            for (int i = 0; i < magazines.Count; i++) {

                var m = new MagazineModel(magazines[i], magazines[i].Index);
                var item = GetItem(m.fileName + "1");
                if (item != null)
                {
                    if (m.Index == 0)
                    {
                        var b = item.Update(2, 2, width, m);
                        if (b) list.Add(item);
                    }
                    else
                    {
                        var b = item.Update(1, 1, width, m);
                        if (b) list.Add(item);
                    }

                    continue;
                }

                if (m.Index == 0) {

                    var it = new MagazineViewModel(m.fileName + "1", 2, 2, width, m.Title, m.Subtitle, group, m);
                    if (it.IsDownloaded)
                        it.SecondButtonVisible = false;
                    if (it.Index < group.Items.Count)
                        group.Items.Insert(it.Index, it);
                    else
                        group.Items.Add(it);

                    list.Add(it);

                } else {

                    var it = new MagazineViewModel(m.fileName + "1", 1, 1, width, m.Title, m.Subtitle, group, m);
                    if (it.IsDownloaded)
                        it.SecondButtonVisible = false;
                    if (it.Index < group.Items.Count)
                        group.Items.Insert(it.Index, it);
                    else
                        group.Items.Add(it);

                    list.Add(it);
                }
            }

            var removeCollection = new ObservableCollection<MagazineViewModel>();
            for (int p = 0; p < group.Items.Count; p++)
            {
                var it = group.Items[p];
                var result = magazines.Any(magazine => magazine.FullName.Equals(it.FileName));
                if (!result)
                    removeCollection.Add(it);
            }
            foreach (var it in removeCollection)
            {
                group.Items.Remove(it);
            }

            return list;
        }
Example #6
0
        public static IReadOnlyList <MagazineViewModel> LoadMagazines(IList <LibrelioLocalUrl> magazines, IList <LibrelioLocalUrl> magazinesDownloaded, int width)
        {
            var list = new List <MagazineViewModel>();

            bool newGroup           = false;
            MagazineDataGroup group = null;
            var loader = new ResourceLoader();

            if (GetGroup(loader.GetString("my_magazines")) == null)
            {
                group    = new MagazineDataGroup(loader.GetString("my_magazines"), loader.GetString("my_magazines"), "");
                newGroup = true;
            }
            else
            {
                group = GetGroup(loader.GetString("my_magazines"));
            }

            if (newGroup)
            {
                _sampleDataSource.AllGroups.Add(group);
                newGroup = false;
            }

            for (int i = 0; i < magazinesDownloaded.Count; i++)
            {
                if (magazinesDownloaded[i].IsDownloaded)
                {
                    var m    = new MagazineModel(magazinesDownloaded[i], i);
                    var item = GetItem(m.fileName);
                    if (item != null)
                    {
                        var b = item.Update(1, 1, width, m);
                        if (b)
                        {
                            list.Add(item);
                        }
                        continue;
                    }

                    group.Items.Add(new MagazineViewModel(m.fileName, 1, 1, width, m.Title, m.Subtitle, group, m));
                }
            }

            newGroup = false;

            if (GetGroup(loader.GetString("all_magazines")) == null)
            {
                group    = new MagazineDataGroup(loader.GetString("all_magazines"), loader.GetString("all_magazines"), "");
                newGroup = true;
            }
            else
            {
                group = GetGroup(loader.GetString("all_magazines"));
            }

            if (newGroup)
            {
                _sampleDataSource.AllGroups.Add(group);
                newGroup = false;
            }

            for (int i = 0; i < magazines.Count; i++)
            {
                var m    = new MagazineModel(magazines[i], magazines[i].Index);
                var item = GetItem(m.fileName + "1");
                if (item != null)
                {
                    if (m.Index == 0)
                    {
                        var b = item.Update(2, 2, width, m);
                        if (b)
                        {
                            list.Add(item);
                        }
                    }
                    else
                    {
                        var b = item.Update(1, 1, width, m);
                        if (b)
                        {
                            list.Add(item);
                        }
                    }

                    continue;
                }

                if (m.Index == 0)
                {
                    var it = new MagazineViewModel(m.fileName + "1", 2, 2, width, m.Title, m.Subtitle, group, m);
                    if (it.IsDownloaded)
                    {
                        it.SecondButtonVisible = false;
                    }
                    if (it.Index < group.Items.Count)
                    {
                        group.Items.Insert(it.Index, it);
                    }
                    else
                    {
                        group.Items.Add(it);
                    }

                    list.Add(it);
                }
                else
                {
                    var it = new MagazineViewModel(m.fileName + "1", 1, 1, width, m.Title, m.Subtitle, group, m);
                    if (it.IsDownloaded)
                    {
                        it.SecondButtonVisible = false;
                    }
                    if (it.Index < group.Items.Count)
                    {
                        group.Items.Insert(it.Index, it);
                    }
                    else
                    {
                        group.Items.Add(it);
                    }

                    list.Add(it);
                }
            }

            var removeCollection = new ObservableCollection <MagazineViewModel>();

            for (int p = 0; p < group.Items.Count; p++)
            {
                var it     = group.Items[p];
                var result = magazines.Any(magazine => magazine.FullName.Equals(it.FileName));
                if (!result)
                {
                    removeCollection.Add(it);
                }
            }
            foreach (var it in removeCollection)
            {
                group.Items.Remove(it);
            }

            return(list);
        }
Example #7
0
        public static async Task<MagazineManager> LoadLocalMagazinesAsync()
        {
            if (_sampleDataSource.AllGroups.Count > 0) return null;

            var manager = new MagazineManager("http://librelio-europe.s3.amazonaws.com/niveales/wind/", "Magazines");

            await manager.LoadLocalMagazineList();

            bool newGroup = false;
            MagazineDataGroup group = null;
            if (GetGroup("My Magazines") == null) {

                group = new MagazineDataGroup("My Magazines", "My Magazines", "");
                newGroup = true;

            } else {

                group = GetGroup("My Magazines");
            }

            if (newGroup) {

                _sampleDataSource.AllGroups.Add(group);
                newGroup = false;
            }

            for (int i = 0; i < manager.MagazineLocalUrl.Count; i++) {

                if (manager.MagazineLocalUrl[i].IsDownloaded) {

                    var m = new MagazineModel(manager.MagazineLocalUrl[i], i);
                    if (GetItem(m.Title + m.Subtitle) != null) continue;
                    BitmapImage image = null;
                    try
                    {

                        var file = await StorageFile.GetFileFromPathAsync(m.pngPath);
                        image = new BitmapImage();
                        await image.SetSourceAsync(await file.OpenReadAsync());

                    }
                    catch { }
                    int index = 0;
                    for (int p = 0; p < group.Items.Count; p++)
                    {
                        index = p + 1;
                        if (group.Items[p].Index > m.Index)
                            break;
                    }
                    if (group.Items.Count == 0)
                        group.Items.Insert(index, new MagazineViewModel(m.Title + m.Subtitle, 2, 2, m.Title, m.Subtitle, image, group, m));
                    else
                        group.Items.Insert(index, new MagazineViewModel(m.Title + m.Subtitle, 1, 1, m.Title, m.Subtitle, image, group, m));
                }
            }

            newGroup = false;

            if (GetGroup("All Magazines") == null) {

                group = new MagazineDataGroup("All Magazines", "All Magazines", "");
                newGroup = true;

            } else {

                group = GetGroup("All Magazines");
            }

            if (newGroup)
            {
                _sampleDataSource.AllGroups.Add(group);
                newGroup = false;
            }

            for (int i = 0; i < manager.MagazineLocalUrl.Count; i++) {

                    var m = new MagazineModel(manager.MagazineLocalUrl[i], i);
                    if (GetItem(m.Title + m.Subtitle + "1") != null) continue;
                    BitmapImage image = null;
                    try
                    {
                        //if (m.isDowloaded) {

                        //    var file = await StorageFile.GetFileFromPathAsync(m.pngPath);
                        //    image = new BitmapImage();
                        //    await image.SetSourceAsync(await file.OpenReadAsync());

                        //} else {

                            image = new BitmapImage(new Uri(m.pngUrl));
                        //}

                    }
                    catch { }
                    int index = 0;
                    for (int p = 0; p < group.Items.Count; p++)
                    {
                        index = p + 1;
                        if (group.Items[p].Index > m.Index)
                            break;
                    }
                    MagazineViewModel item = null;
                    if (group.Items.Count == 0)
                        item = new MagazineViewModel(m.Title + m.Subtitle + "1", 2, 2, m.Title, m.Subtitle, image, group, m);
                    else
                        item = new MagazineViewModel(m.Title + m.Subtitle + "1", 1, 1, m.Title, m.Subtitle, image, group, m);

                    if (m.isDowloaded)
                        item.SecondButtonVisible = false;
                    group.Items.Insert(index, item);
            }

            return manager;
        }
Example #8
0
        public static async Task<MagazineManager> LoadMagazinesAsync()
        {
            if (_sampleDataSource.AllGroups.Count > 0) return null;

            var manager = new MagazineManager("http://librelio-europe.s3.amazonaws.com/niveales/wind/", "Magazines");

            await manager.LoadLocalMagazineList();

            //if (manager.MagazineLocalUrl.Count == 0)
            //{
                //await manager.LoadPLISTAsync();
            //}

            bool newGroup = false;
            MagazineDataGroup group = null;
            if (GetGroup("My Magazines") == null) {

                group = new MagazineDataGroup("My Magazines", "My Magazines", "");
                newGroup = true;

            } else {

                group = GetGroup("My Magazines");
            }

            if (newGroup) {

                _sampleDataSource.AllGroups.Add(group);
                newGroup = false;
            }

            for (int i = 0; i < manager.MagazineLocalUrl.Count; i++)
            {

                if (manager.MagazineLocalUrl[i].IsDownloaded)
                {

                    var m = new MagazineModel(manager.MagazineLocalUrl[i], i);
                    if (GetItem(m.Title + m.Subtitle) != null) continue;
                    BitmapImage image = null;
                    try
                    {

                        var file = await StorageFile.GetFileFromPathAsync(m.pngPath);
                        image = new BitmapImage();
                        await image.SetSourceAsync(await file.OpenReadAsync());

                    }
                    catch { }
                    if (group.Items.Count == 0)
                        group.Items.Add(new MagazineViewModel(m.Title + m.Subtitle, 2, 2, m.Title, m.Subtitle, image, group, m));
                    else
                        group.Items.Add(new MagazineViewModel(m.Title + m.Subtitle, 1, 1, m.Title, m.Subtitle, image, group, m));
                }
            }

            newGroup = false;

            if (GetGroup("All Magazines") == null) {

                group = new MagazineDataGroup("All Magazines", "All Magazines", "");
                newGroup = true;

            } else {

                group = GetGroup("All Magazines");
            }

            if (newGroup)
            {
                _sampleDataSource.AllGroups.Add(group);
                newGroup = false;
            }

            await manager.LoadPLISTAsync();

            var count = manager.MagazineLocalUrl.Count;
            if (count == 0)
                count = manager.MagazineUrl.Count;
            for (int i = 0; i < count; i++)
            {
                LibrelioLocalUrl localUrl = null;
                MagazineModel m = null;
                //if (manager.MagazineLocalUrl.Count == 0)
                //{
                    localUrl = manager.FindInMetadata(manager.MagazineUrl[i]);
                    if (localUrl != null && localUrl.IsDownloaded)
                        m = new MagazineModel(localUrl, manager.MagazineUrl[i].Index);
                    else
                        m = new MagazineModel(manager.MagazineUrl[i]);
                //}
                //else
                //{
                    //localUrl = manager.MagazineLocalUrl[i];
                    //m = new MagazineModel(localUrl, i);
                //}

                if (GetItem(m.Title + m.Subtitle + "1") != null) continue;
                BitmapImage image = null;
                try
                {

                    if (localUrl != null && localUrl.IsDownloaded)
                    {

                        var file = await StorageFile.GetFileFromPathAsync(m.pngPath);
                        image = new BitmapImage();
                        await image.SetSourceAsync(await file.OpenReadAsync());

                    }
                    else
                    {

                        image = new BitmapImage(new Uri(m.pngUrl));
                    }

                }
                catch { }
                MagazineViewModel item = null;
                if (group.Items.Count == 0)
                    item = new MagazineViewModel(m.Title + m.Subtitle + "1", 2, 2, m.Title, m.Subtitle, image, group, m);
                else
                    item = new MagazineViewModel(m.Title + m.Subtitle + "1", 1, 1, m.Title, m.Subtitle, image, group, m);

                if (localUrl != null && localUrl.IsDownloaded)
                    item.SecondButtonVisible = false;
                group.Items.Add(item);
            }

            group.Items = new ObservableCollection<MagazineViewModel>(group.Items.OrderBy(item => item.Index));
            
            //if (GetGroup("All Magazines") != null) return null;

            //PList list = new PList("Assets/data/magazines.plist");
            ////TODODEBUG try

            //    List<dynamic> arr = list[""];
            //    group = new MagazineDataGroup("All Magazines", "All Magazines", "");
            //    for (int i = 0; i < arr.Count; i++)
            //    {
            //        var m = new MagazineModel((Dictionary<string, dynamic>)arr[i]);
            //        group.Items.Add(new MagazineViewModel("", "", "", null, group, m));
            //    }
            //    _sampleDataSource.AllGroups.Add(group);

            return manager;
        }
Example #9
0
        public static IReadOnlyList<MagazineViewModel> LoadMagazines(IList<LibrelioLocalUrl> magazines)
        {
            var list = new List<MagazineViewModel>();

            bool newGroup = false;
            MagazineDataGroup group = null;
            if (GetGroup("My Magazines") == null) {

                group = new MagazineDataGroup("My Magazines", "My Magazines", "");
                newGroup = true;

            } else {

                group = GetGroup("My Magazines");
            }

            if (newGroup) {

                _sampleDataSource.AllGroups.Add(group);
                newGroup = false;
            }

            for (int i = 0; i < magazines.Count; i++) {

                if (magazines[i].IsDownloaded) {

                    var m = new MagazineModel(magazines[i], i);
                    var item = GetItem(m.Title + m.Subtitle);
                    if (item != null)
                    {
                        var b = item.Update(1, 1, m);
                        if (b) list.Add(item);
                        continue;
                    }

                    group.Items.Add(new MagazineViewModel(m.Title + m.Subtitle, 1, 1, m.Title, m.Subtitle, group, m));
                }
            }

            newGroup = false;

            if (GetGroup("All Magazines") == null) {

                group = new MagazineDataGroup("All Magazines", "All Magazines", "");
                newGroup = true;

            } else {

                group = GetGroup("All Magazines");
            }

            if (newGroup) {

                _sampleDataSource.AllGroups.Add(group);
                newGroup = false;
            }

            for (int i = 0; i < magazines.Count; i++) {

                var m = new MagazineModel(magazines[i], i);
                var item = GetItem(m.Title + m.Subtitle + "1");
                if (item != null)
                {
                    if (item.Index == 0)
                    {
                        var b = item.Update(2, 2, m);
                        if (b) list.Add(item);
                    }
                    else
                    {
                        var b = item.Update(1, 1, m);
                        if (b) list.Add(item);
                    }

                    continue;
                }

                if (group.Items.Count == 0) {

                    var it = new MagazineViewModel(m.Title + m.Subtitle + "1", 2, 2, m.Title, m.Subtitle, group, m);
                    if (it.IsDownloaded)
                        it.SecondButtonVisible = false;
                    group.Items.Add(it);

                } else {

                    var it = new MagazineViewModel(m.Title + m.Subtitle + "1", 1, 1, m.Title, m.Subtitle, group, m);
                    if (it.IsDownloaded)
                        it.SecondButtonVisible = false;
                    group.Items.Add(it);
                }
            }

            return list;
        }