Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feed page #39

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions src/BeerTrade/BeerTrade.Android/BeerTrade.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<PackageReference Include="Xamarin.Forms">
<Version>4.0.0.394984-pre10</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading.Transformations">
<Version>2.4.11.982</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading.Forms">
<Version>2.4.11.982</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/BeerTrade/BeerTrade.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected override void OnCreate(Bundle savedInstanceState)
base.OnCreate(savedInstanceState);

global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: false);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
Expand Down
5 changes: 5 additions & 0 deletions src/BeerTrade/BeerTrade.Android/linker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@
<type fullname="BeerTrade.ViewModels.*PageViewModel">
<method name=".ctor" />
</type>
<type fullname="BeerTrade.Services.*">
<method name=".ctor" />
</type>
<type fullname="BeerTrade.Models.*" />
<type fullname="BeerTrade.Interfaces.*" />
</assembly>
</linker>
1 change: 1 addition & 0 deletions src/BeerTrade/BeerTrade.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Xamarin.Calabash.Start();
global::Xamarin.Forms.Forms.Init();
FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
LoadApplication(new App());

return base.FinishedLaunching(app, options);
Expand Down
6 changes: 6 additions & 0 deletions src/BeerTrade/BeerTrade.iOS/BeerTrade.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@
<PackageReference Include="Xamarin.Forms">
<Version>4.0.0.394984-pre10</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading.Forms">
<Version>2.4.11.982</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading.Transformations">
<Version>2.4.11.982</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/BeerTrade/BeerTrade.iOS/linker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@
<type fullname="BeerTrade.ViewModels.*PageViewModel">
<method name=".ctor" />
</type>
<type fullname="BeerTrade.Services.*">
<method name=".ctor" />
</type>
<type fullname="BeerTrade.Models.*" />
<type fullname="BeerTrade.Interfaces.*" />
</assembly>
</linker>
3 changes: 3 additions & 0 deletions src/BeerTrade/BeerTrade/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Threading.Tasks;
using BeerTrade.Interfaces;
using BeerTrade.Services;
using BeerTrade.ViewModels;
using BeerTrade.Views;
using Prism;
Expand Down Expand Up @@ -31,6 +33,7 @@ protected override void RegisterTypes(IContainerRegistry containerRegistry)
containerRegistry.RegisterForNavigation<BeersPage, BeersPageViewModel>();
containerRegistry.RegisterForNavigation<TradesPage, TradesPageViewModel>();
containerRegistry.RegisterForNavigation<ProfilePage, ProfilePageViewModel>();
containerRegistry.RegisterSingleton<IApi, ApiServiceFake>();
}

protected override void OnStart()
Expand Down
8 changes: 8 additions & 0 deletions src/BeerTrade/BeerTrade/BeerTrade.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<LangVersion>latest</LangVersion>
<DebugType></DebugType>
<DefineConstants>TRACE;RELEASE;NETSTANDARD;NETSTANDARD2_0;DISABLE_XAMARINFORMSLIVE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Prism.DryIoc.Forms" Version="7.1.0.431" />
<PackageReference Include="Xamarin.Forms" Version="4.0.0.394984-pre10" />
<PackageReference Include="LiveXAML" Version="2.1.72" />
<PackageReference Include="Xamarin.FFImageLoading.Forms" Version="2.4.11.982" />
<PackageReference Include="Xamarin.FFImageLoading.Transformations" Version="2.4.11.982" />
</ItemGroup>
<ItemGroup>
<Folder Include="Views\" />
<Folder Include="ViewModels\" />
<Folder Include="ViewModels\Base\" />
<Folder Include="Models\" />
<Folder Include="Interfaces\" />
<Folder Include="Services\" />
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions src/BeerTrade/BeerTrade/Interfaces/IApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using BeerTrade.Models;

namespace BeerTrade.Interfaces
{
public interface IApi
{
Task<IList<FeedItem>> GetFeed();
}
}
12 changes: 12 additions & 0 deletions src/BeerTrade/BeerTrade/Models/FeedItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace BeerTrade.Models
{
public class FeedItem
{
public string BeerPhoto { get; set; }
public string AvatarPhoto { get; set; }
public string Nickname { get; set; }
public string Location { get; set; }
}
}
42 changes: 42 additions & 0 deletions src/BeerTrade/BeerTrade/Services/ApiServiceFake.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using BeerTrade.Interfaces;
using BeerTrade.Models;

namespace BeerTrade.Services
{
public class ApiServiceFake : IApi
{
public async Task<IList<FeedItem>> GetFeed()
{
var feed = new List<FeedItem>();

feed.Add(new FeedItem
{
BeerPhoto = "https://cdn-b.william-reed.com/var/wrbm_gb_hospitality/storage/images/publications/hospitality/bighospitality.co.uk/article/2018/04/26/beer-quiz-25-questions-to-test-your-knowledge/2807204-1-eng-GB/Beer-quiz-25-questions-to-test-your-knowledge_wrbm_large.jpg",
AvatarPhoto = "https://avatars3.githubusercontent.com/u/519642?v=4&s=460",
Nickname = "ionixjunior",
Location = "Joinville, SC, Brazil"
});

feed.Add(new FeedItem
{
BeerPhoto = "https://cdn-b.william-reed.com/var/wrbm_gb_hospitality/storage/images/publications/hospitality/bighospitality.co.uk/article/2018/04/26/beer-quiz-25-questions-to-test-your-knowledge/2807204-1-eng-GB/Beer-quiz-25-questions-to-test-your-knowledge_wrbm_large.jpg",
AvatarPhoto = "https://avatars3.githubusercontent.com/u/519642?v=4&s=460",
Nickname = "ionixjunior",
Location = "Joinville, SC, Brazil"
});

feed.Add(new FeedItem
{
BeerPhoto = "https://cdn-b.william-reed.com/var/wrbm_gb_hospitality/storage/images/publications/hospitality/bighospitality.co.uk/article/2018/04/26/beer-quiz-25-questions-to-test-your-knowledge/2807204-1-eng-GB/Beer-quiz-25-questions-to-test-your-knowledge_wrbm_large.jpg",
AvatarPhoto = "https://avatars3.githubusercontent.com/u/519642?v=4&s=460",
Nickname = "ionixjunior",
Location = "Joinville, SC, Brazil"
});

return await Task.FromResult(feed);
}
}
}
56 changes: 52 additions & 4 deletions src/BeerTrade/BeerTrade/ViewModels/FeedPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
using Prism.Navigation;
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using BeerTrade.Interfaces;
using BeerTrade.Models;
using Prism;
using Prism.Navigation;

namespace BeerTrade.ViewModels
{
public sealed class FeedPageViewModel : BaseViewModel
{
public FeedPageViewModel(INavigationService navigationService)
public class FeedPageViewModel : BaseViewModel, IActiveAware
{
private readonly IApi _api;

public ObservableCollection<FeedItem> Items { get; private set; }

public FeedPageViewModel(
INavigationService navigationService,
IApi api)
: base(navigationService)
{
_api = api;
Items = new ObservableCollection<FeedItem>();
}

public event EventHandler IsActiveChanged;

private bool _isActive;
public bool IsActive
{
get { return _isActive; }
set { SetProperty(ref _isActive, value, RaiseIsActiveChanged); }
}

protected virtual async void RaiseIsActiveChanged()
{
IsActiveChanged?.Invoke(this, EventArgs.Empty);

if (IsActive)
await GetFeed();
}

private async Task GetFeed()
{
try
{
var feed = await _api.GetFeed();

Items.Clear();

foreach (var item in feed)
Items.Add(item);
}
catch (Exception exception)
{
System.Diagnostics.Debug.WriteLine(exception.Message);
}
}
}
}
76 changes: 75 additions & 1 deletion src/BeerTrade/BeerTrade/Views/FeedPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,83 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
xmlns:fftransformations="clr-namespace:FFImageLoading.Transformations;assembly=FFImageLoading.Transformations"
x:Class="BeerTrade.Views.FeedPage"
Title="Home">
<ContentPage.Content>

<ListView
ItemsSource="{Binding Items}"
HasUnevenRows="true"
SeparatorVisibility="None"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Frame
HeightRequest="270"
Margin="20,10"
Padding="0"
>
<Grid
RowSpacing="0"
>
<Grid.RowDefinitions>
<RowDefinition Height="180" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<Image
Grid.Row="0"
Source="{Binding BeerPhoto}"
Aspect="AspectFill"
/>

<Grid
Grid.Row="1"
ColumnSpacing="15"
Margin="20"
>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<ffimageloading:CachedImage
Grid.Column="0"
Source="{Binding AvatarPhoto}"
HeightRequest="50"
WidthRequest="50"
>
<ffimageloading:CachedImage.Transformations>
<fftransformations:CircleTransformation/>
</ffimageloading:CachedImage.Transformations>
</ffimageloading:CachedImage>

<StackLayout
Grid.Column="1"
VerticalOptions="Center"
Spacing="0"
>
<Label
Text="{Binding Nickname}"
FontAttributes="Bold"
TextColor="Black"
/>

<Label
Text="{Binding Location}"
TextColor="Gray"
/>
</StackLayout>
</Grid>
</Grid>
</Frame>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>