Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<AotAssemblies>false</AotAssemblies>
<EnableLLVM>false</EnableLLVM>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<BundleAssemblies>false</BundleAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -54,8 +58,11 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.3.0.819712-pre2" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.0" />
<PackageReference Include="Xamarin.Forms.Visual.Material">
<Version>4.2.0.815419</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
Expand Down Expand Up @@ -101,4 +108,4 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protected override void OnCreate(Bundle savedInstanceState)
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
global::Xamarin.Forms.FormsMaterial.Init(this, savedInstanceState);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
<PackageReference Include="Xamarin.Forms" Version="4.3.0.819712-pre2" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.9" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.0" />
<PackageReference Include="Xamarin.Forms.Visual.Material">
<Version>4.2.0.815419</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CarouselViewChallenge\CarouselViewChallenge.csproj">
Expand All @@ -159,4 +162,4 @@
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsAppli
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");

global::Xamarin.Forms.Forms.Init();
global::Xamarin.Forms.FormsMaterial.Init();
LoadApplication(new App());

return base.FinishedLaunching(app, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.3.0.819712-pre2" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.0" />
<PackageReference Include="Xamarin.Forms.Visual.Material">
<Version>4.2.0.815419</Version>
</PackageReference>
<PackageReference Include="Xamarin.iOS.MaterialComponents">
<Version>72.2.0.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand All @@ -139,4 +145,4 @@
<Name>CarouselViewChallenge</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
3 changes: 3 additions & 0 deletions CarouselViewChallenge/CarouselViewChallenge/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using CarouselViewChallenge.Views;
using MPD.Services;

namespace CarouselViewChallenge
{
Expand All @@ -12,6 +13,8 @@ public App()
{
InitializeComponent();

DependencyService.Register<MockDataStore>();

MainPage = new AppShell();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.3.0.819712-pre2" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Models\" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.0" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="4.2.0.815419" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 16 additions & 0 deletions CarouselViewChallenge/CarouselViewChallenge/Models/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;

namespace CarouselViewChallenge.Models
{
public class Item
{
public string Id { get; set; }
public string Text { get; set; }
public string Description { get; set; }

public string Emoji { get; set; }
}
}
15 changes: 15 additions & 0 deletions CarouselViewChallenge/CarouselViewChallenge/Services/IDataStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace MPD.Services
{
public interface IDataStore<T>
{
Task<bool> AddItemAsync(T item);
Task<bool> UpdateItemAsync(T item);
Task<bool> DeleteItemAsync(string id);
Task<T> GetItemAsync(string id);
Task<IEnumerable<T>> GetItemsAsync(bool forceRefresh = false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using CarouselViewChallenge.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace MPD.Services
{
public class MockDataStore : IDataStore<Item>
{
List<Item> items;

public MockDataStore()
{
items = new List<Item>();
//new Image { Source = ImageSource.FromResource("CarouselViewChallenge.veg1.jpg", typeof(EmbeddedImages).GetTypeInfo().Assembly)
var mockItems = new List<Item>
{
new Item { Id = Guid.NewGuid().ToString(), Text = "First item", Description="This is an item description.",Emoji="😀" } ,
new Item { Id = Guid.NewGuid().ToString(), Text = "Second item", Description="This is an item description.",Emoji="👱" },
new Item { Id = Guid.NewGuid().ToString(), Text = "Third item", Description="This is an item description.",Emoji="🤓" },
new Item { Id = Guid.NewGuid().ToString(), Text = "Fourth item", Description="This is an item description.",Emoji="👨" },
new Item { Id = Guid.NewGuid().ToString(), Text = "Fifth item", Description="This is an item description.",Emoji="👨‍⚕️" },
new Item { Id = Guid.NewGuid().ToString(), Text = "Sixth item", Description="This is an item description.",Emoji="👌" }


};

foreach (var item in mockItems)
{
items.Add(item);
}
}

public async Task<bool> AddItemAsync(Item item)
{
items.Add(item);

return await Task.FromResult(true);
}

public async Task<bool> UpdateItemAsync(Item item)
{
var oldItem = items.Where((Item arg) => arg.Id == item.Id).FirstOrDefault();
items.Remove(oldItem);
items.Add(item);

return await Task.FromResult(true);
}

public async Task<bool> DeleteItemAsync(string id)
{
var oldItem = items.Where((Item arg) => arg.Id == id).FirstOrDefault();
items.Remove(oldItem);

return await Task.FromResult(true);
}

public async Task<Item> GetItemAsync(string id)
{
return await Task.FromResult(items.FirstOrDefault(s => s.Id == id));
}

public async Task<IEnumerable<Item>> GetItemsAsync(bool forceRefresh = false)
{
return await Task.FromResult(items);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using CarouselViewChallenge.Models;
using MPD.Services;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace CarouselViewChallenge.ViewModels
{
public class CarouselViewChallengeViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

private void OnPropertyChanged(PropertyChangedEventArgs eventArgs)
{
PropertyChanged?.Invoke(this, eventArgs);
}

public ObservableCollection<Item> Items { get; set; }

public Item currentItem { get; set; }

public IDataStore<Item> DataStore => DependencyService.Get<IDataStore<Item>>() ?? new MockDataStore();
public Command LoadItemsCommand { get; set; }
public CarouselViewChallengeViewModel()
{
Items = new ObservableCollection<Item>();
LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());
}

public async Task ExecuteLoadItemsCommand()
{
//if (IsBusy)
// return;

//IsBusy = true;
//return;
try
{
Items.Clear();
var items = await DataStore.GetItemsAsync(true);
foreach (var item in items)
{
Items.Add(item);
if (item.Text.Equals("Fourth item"))
currentItem = item;
}

}
catch (Exception ex)
{
//Debug.WriteLine(ex);
}
finally
{
//IsBusy = false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ private void OnPropertyChanged(PropertyChangedEventArgs eventArgs)
{
PropertyChanged?.Invoke(this, eventArgs);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,83 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="CarouselViewChallenge.Views.CarouselViewChallengePage">
<ContentPage.Resources>
<ResourceDictionary>
<Color x:Key="BlackColor">#000000</Color>
<Style x:Key="ItemTitleStyle" TargetType="Label">
<Setter Property="FontSize" Value="30" />
<Setter Property="TextColor" Value="{StaticResource BlackColor}" />
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="WidthRequest" Value="250" />
<Setter Property="Margin" Value="12, 12, 12, 6" />
</Style>
<Style x:Key="ItemEmojiStyle" TargetType="Label">
<Setter Property="FontSize" Value="150" />
<Setter Property="TextColor" Value="{StaticResource BlackColor}" />
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="WidthRequest" Value="200" />
<Setter Property="Margin" Value="12, 12, 12, 6" />
</Style>
<DataTemplate x:Key="PostItemTemplate">
<StackLayout BackgroundColor="{StaticResource BlackColor}">
<Frame BorderColor="Gray" Margin="8" HasShadow="True" HeightRequest="450" VerticalOptions="CenterAndExpand">
<StackLayout>
<Label
Grid.Row="0"
Text="{Binding Text}"
Style="{StaticResource ItemTitleStyle}"
/>
<Label
Grid.Row="1"
Text="{Binding Emoji}"
Style="{StaticResource ItemEmojiStyle}" >
<Label.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnTapGestureRecognizerTapped"
NumberOfTapsRequired="2" />
</Label.GestureRecognizers>
</Label>
<Label
Grid.Row="2"
Text="{Binding Description}" />

</StackLayout>
</Frame>
</StackLayout>
</DataTemplate>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout BackgroundColor="#cfd8dc">
<Label Text="You can use this page for the CarouselView Challenge!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
<CarouselView
CurrentItem="{Binding currentItem, Mode=TwoWay}"
ItemsSource="{Binding Items}"
ItemTemplate="{StaticResource PostItemTemplate}"
VerticalOptions="End"
x:Name="Carousel"
Visual="Material"
FlowDirection="LeftToRight"
PeekAreaInsets="50"
>
<CarouselView.EmptyView>
<Label Text="No data to be displayed!"/>
</CarouselView.EmptyView>

<CarouselView.Margin>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="12, 48, 0, 0" />
<On Platform="Android" Value="12, 24, 12, 12" />
</OnPlatform>
</CarouselView.Margin>
<!--<CarouselView.PeekAreaInsets>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="0, 0, 200, 0" />
<On Platform="Android" Value="0, 200, 200, 0" />
</OnPlatform>
</CarouselView.PeekAreaInsets>-->
</CarouselView>
</StackLayout>
</ContentPage.Content>

</ContentPage>
Loading