Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Image[] _images;
- private Image[] _previewImages;
- private ImageSource[] _imageSources;
- public ShowRoomPage()
- {
- InitializeComponent();
- Loading(true);
- /Other stuff leightweight
- //var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
- Task.Factory.StartNew(() =>
- {
- Thread.Sleep(5000);
- int count = InitializeImages();
- return count;
- }).ContinueWith(r =>
- {
- Device.BeginInvokeOnMainThread(async () =>
- {
- if (r.Result == GlobalSettings.ImageCount)
- ButtonsGrid.ColumnDefinitions[1].Width = 0;
- else
- ButtonsGrid.ColumnDefinitions[1].Width = GridLength.Star;
- for (int i = 0; i < r.Result; i++)
- {
- ImagesGrid.Children.Add(_previewImages[i]);
- ImagesStackLayout.Children.Add(_images[i]);
- }
- await ShowWallpaperInPreview();
- await Loading(false);
- });
- });
- }
- private int InitializeImages()
- {
- int lastImageIndex = GlobalSettings.ImageCount - GlobalSettings.PremiumCount + GlobalSettings.Unlocked;
- _images = new Image[lastImageIndex];
- _previewImages = new Image[lastImageIndex];
- _imageSources = new ImageSource[lastImageIndex];
- //Foreach not premium wallpaper image
- for (int i = 0; i < lastImageIndex; i++)
- {
- //Create the path
- var path = "Wallpaper.Images.Wallpapers.W" + i + ".jpg";
- //Create images
- _imageSources[i] = ImageSource.FromResource(path);
- _images[i] = new Image()
- {
- Source = _imageSources[i],
- Scale = 0.95,
- Opacity = 0.75
- };
- _previewImages[i] = new Image()
- {
- Source = _imageSources[i],
- Opacity = 0
- };
- //Event when user taps on the image
- int index = i;
- var tgr = new TapGestureRecognizer();
- tgr.Tapped += async (sender, args) =>
- {
- if (!_canInteract)
- return;
- _canInteract = false;
- //Show the image in the preview
- _selectedImage = index;
- await ShowWallpaperInPreview();
- _canInteract = true;
- };
- _images[i].GestureRecognizers.Add(tgr);
- }
- return lastImageIndex;
- }
- private async Task Loading(bool value)
- {
- if (value)
- {
- //Hide the view
- _canInteract = false;
- MainGrid.IsVisible = false;
- MainActivityIndicator.IsRunning = true;
- }
- else
- {
- //Fade in the view
- MainActivityIndicator.IsRunning = false;
- MainGrid.Opacity = 0;
- MainGrid.IsVisible = true;
- await MainGrid.FadeTo(1, 800);
- _canInteract = true;
- }
- }
- <?xml version="1.0" encoding="utf-8" ?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- x:Class="Wallpaper.ShowRoomPage"
- xmlns:ads="clr-namespace:Wallpaper.Controls;assembly=Wallpaper"
- Title="Wallpapers">
- <ContentPage.Content>
- <Grid BackgroundColor="{StaticResource BackgroundColor}">
- <!--Activity Indicator-->
- <ActivityIndicator x:Name="MainActivityIndicator" HorizontalOptions="Center" VerticalOptions="Center" WidthRequest="45" HeightRequest="45" Color="{StaticResource SecondAccentColor}"/>
- <Grid x:Name="MainGrid">
- <Grid.RowDefinitions>
- <RowDefinition Height="35"/>
- <RowDefinition Height="21"/>
- <RowDefinition Height="4*"/>
- <RowDefinition Height="21"/>
- <RowDefinition Height="*"/>
- <RowDefinition Height="10"/>
- <RowDefinition Height="40"/>
- <RowDefinition Height="Auto"/>
- </Grid.RowDefinitions>
- <!--Preview image-->
- <Grid x:Name="ImagesGrid" Grid.Row="2">
- <Image x:Name="PreviewImage"/>
- </Grid>
- <!--All images-->
- <ScrollView Grid.Row="4" Orientation="Horizontal" HorizontalScrollBarVisibility="Never">
- <StackLayout x:Name="ImagesStackLayout" Spacing="10" Orientation="Horizontal"/>
- </ScrollView>
- </Grid>
- </Grid>
- </ContentPage.Content>
- </ContentPage>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement