Fixes the rating control

main
Paul Schneider 9 years ago
parent a4c3a9afea
commit 4ee886b8bc
10 changed files with 157 additions and 58 deletions

@ -87,8 +87,7 @@ namespace BookAStar.Behaviors
BindableProperty.Create("IsStarred",
typeof(bool),
typeof(StarBehavior),
false,
propertyChanged: OnIsStarredChanged);
false);
public bool IsStarred
{
@ -100,8 +99,7 @@ namespace BookAStar.Behaviors
{
StarBehavior behavior = (StarBehavior)bindable;
if ((bool)newValue)
{
string groupName = behavior.GroupName;
List<StarBehavior> behaviors = null;
@ -126,8 +124,14 @@ namespace BookAStar.Behaviors
if (item == behavior)
{
itemReached = true;
item.IsStarred = true;
position = count;
// whould try to call this method again
// Assert item.IsStarred == newValue;
// There are **6** positions, from 0 to five stars.
if ((bool)newValue)
position = count;
else position = count - 1;
}
if (item != behavior && itemReached)
item.IsStarred = false;
@ -135,8 +139,7 @@ namespace BookAStar.Behaviors
item.Rating = position;
count++;
}
}
}
@ -158,12 +161,14 @@ namespace BookAStar.Behaviors
view.GestureRecognizers.Remove(tapRecognizer);
tapRecognizer.Tapped -= OnTapRecognizerTapped;
}
void OnTapRecognizerTapped(object sender, EventArgs args)
{
// TODO HACK: PropertyChange does not fire, if the value is not changed :-(
IsStarred = false;
IsStarred = true;
bool currentIsStarred = (bool) GetValue(IsStarredProperty);
SetValue(IsStarredProperty, !currentIsStarred);
// does not lead to the call of:
OnIsStarredChanged(this,currentIsStarred,!currentIsStarred);
}
}
}

@ -314,10 +314,10 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="Images\Validation\error.png" />
<Content Include="Images\Validation\star_outline.png" />
<Content Include="Images\Validation\star_selected.png" />
<Content Include="Images\Validation\success.png" />
<EmbeddedResource Include="Images\Validation\error.png" />
<EmbeddedResource Include="Images\Validation\star_outline.png" />
<EmbeddedResource Include="Images\Validation\star_selected.png" />
<EmbeddedResource Include="Images\Validation\success.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Views\RatingView.xaml">

@ -22,12 +22,12 @@ namespace BookAStar.Model.Workflow
/// In db, they are separated by <c>:</c>
/// </summary>
/// <returns></returns>
public List<string> AttachedGraphicList { get; set; }
public List<string> AttachedGraphics { get; set; }
public string AttachedGraphicsString
{
get { return AttachedGraphicList==null?null:string.Join(":", AttachedGraphicList); }
set { AttachedGraphicList = value.Split(':').ToList(); }
get { return AttachedGraphics==null?null:string.Join(":", AttachedGraphics); }
set { AttachedGraphics = value.Split(':').ToList(); }
}
/// <summary>
/// List of attached files

@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BookAStar;assembly=BookAStar"
xmlns:views="clr-namespace:BookAStar.Views;assembly=BookAStar"
xmlns:extensions="clr-namespace:BookAStar.Extensions;assembly=BookAStar"
x:Class="BookAStar.Pages.DashboardPage"
xmlns:lc="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
xmlns:lb="clr-namespace:XLabs.Forms.Behaviors;assembly=XLabs.Forms"
@ -19,26 +20,35 @@
</ContentPage.Resources>
<ScrollView>
<StackLayout Orientation="Vertical" >
<Label Text="Compte utilisateur" StyleClass="Header">
</Label>
<lc:GesturesContentView>
<Frame>
<Label Text="Compte utilisateur" StyleClass="Header">
</Label>
<lb:Gestures.Interests>
<lb:GestureCollection>
<lb:GestureInterest GestureType="LongPress"
GestureCommand="{Binding UserNameGesture}"
GestureParameter="LongPress" />
</lb:GestureCollection>
<StackLayout>
<Frame>
<lb:Gestures.Interests>
<lb:GestureCollection>
<lb:GestureInterest GestureType="LongPress"
GestureCommand="{Binding UserNameGesture}"
/>
</lb:GestureCollection>
</lb:Gestures.Interests>
<StackLayout>
<Image Source="{Binding Avatar}" Aspect="AspectFit" VisualElement.HeightRequest="{StaticResource BigUserAvatarSize}" />
<Label Text="{Binding UserName}" Style="{StaticResource LabelPageHeadingStyle}"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap" XAlign="Center"
></Label>
<views:RatingView Rating="{Binding Rating}"/>
</lb:Gestures.Interests>
</Frame>
</StackLayout>
</Frame>
<views:RatingView Rating="{Binding Rating}"/>
</StackLayout>
</lc:GesturesContentView>
<Button Text="{Binding PerformerStatus}" Clicked="OnViewPerformerStatus" />
<Button Text="{Binding UserQueries}" Clicked="OnViewUserQueries" />
<StackLayout Orientation="Horizontal" >

@ -2,6 +2,7 @@
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BookAStar;assembly=BookAStar"
xmlns:converters="clr-namespace:BookAStar.Converters;assembly=BookAStar"
xmlns:views="clr-namespace:BookAStar.Views;assembly=BookAStar"
xmlns:behaviors="clr-namespace:BookAStar.Behaviors;assembly=BookAStar"
xmlns:extensions="clr-namespace:BookAStar.Extensions;assembly=BookAStar"
@ -15,24 +16,25 @@
<Style TargetType="Button">
<Setter Property="Style" Value="{StaticResource ButtonStyle}" />
</Style>
<local:BooleanToObjectConverter x:Key="boolToStyleImage" x:TypeArguments="Style">
<local:BooleanToObjectConverter.FalseObject>
<converters:BooleanToObjectConverter x:Key="boolToStyleImage" x:TypeArguments="Style">
<converters:BooleanToObjectConverter.FalseObject>
<Style TargetType="Image">
<Setter Property="HeightRequest" Value="20" />
<Setter Property="Source" Value="{extensions:ImageResource Samples.Images.error.png}" />
<Setter Property="Source" Value="{extensions:ImageResource BookAStar.Images.Validation.error.png}" />
</Style>
</local:BooleanToObjectConverter.FalseObject>
</converters:BooleanToObjectConverter.FalseObject>
<local:BooleanToObjectConverter.TrueObject>
<converters:BooleanToObjectConverter.TrueObject>
<Style TargetType="Image">
<Setter Property="HeightRequest" Value="20" />
<Setter Property="Source" Value="{extensions:ImageResource Samples.Images.success.png}" />
<Setter Property="Source" Value="{extensions:ImageResource BookAStar.Images.Validation.success.png}" />
</Style>
</local:BooleanToObjectConverter.TrueObject>
</local:BooleanToObjectConverter>
</converters:BooleanToObjectConverter.TrueObject>
</converters:BooleanToObjectConverter>
</ResourceDictionary>
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout x:Name="mainStackLayout">
<Label Text="Description de la ligne de facture" Style="{StaticResource InputLabelStyle}"></Label>

@ -47,6 +47,20 @@ namespace BookAStar.ViewModels
data.Description = value;
}
}
public decimal UnitaryCost
{
get
{
return data.UnitaryCost;
}
set
{
SetProperty<decimal>(ref unitaryCost, value, "UnitaryCost");
data.UnitaryCost = value;
UnitaryCostText = value.ToString(unitCostFormat, CultureInfo.InvariantCulture);
}
}
protected int durationValue;
public int DurationValue
{

@ -15,6 +15,8 @@ namespace BookAStar.ViewModels
internal class DashboardViewModel : ViewModel
{
public int Rating { get; set; }
public string UserId
{
get

@ -13,10 +13,10 @@ namespace BookAStar.ViewModels
{
Data = data;
if (data.AttachedFiles == null) data.AttachedFiles = new List<string>();
if (data.AttachedGraphicList == null) data.AttachedGraphicList = new List<string>();
if (data.AttachedGraphics == null) data.AttachedGraphics = new List<string>();
if (data.Bill == null) data.Bill = new List<BillingLine>();
AttachedFiles = new ObservableCollection<string>(data.AttachedFiles);
AttachedGraphicList = new ObservableCollection<string>(data.AttachedGraphicList);
AttachedGraphicList = new ObservableCollection<string>(data.AttachedGraphics);
Bill = new ObservableCollection<BillingLine>(data.Bill);
}

@ -2,6 +2,7 @@
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BookAStar;assembly=BookAStar"
xmlns:extensions="clr-namespace:BookAStar.Extensions;assembly=BookAStar"
xmlns:behaviors="clr-namespace:BookAStar.Behaviors;assembly=BookAStar"
xmlns:converters="clr-namespace:BookAStar.Converters;assembly=BookAStar"
x:Class="BookAStar.Views.RatingView">
@ -13,10 +14,10 @@
<behaviors:StarBehavior x:Name="starOne" GroupName="myStar"/>
</Grid.Behaviors>
<Image x:Name="starBlankOne"
Source="{local:ImageResource BookAStar.Images.star_outline.png}" />
Source="{extensions:ImageResource BookAStar.Images.Validation.star_outline.png}" />
<Image x:Name="starSelectedOne"
Source="{local:ImageResource BookAStar.Images.star_selected.png}"
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
IsVisible="{Binding Source={x:Reference starOne},
Path=IsStarred}"/>
</Grid>
@ -25,10 +26,10 @@
<behaviors:StarBehavior x:Name="starTwo" GroupName="myStar"/>
</Grid.Behaviors>
<Image x:Name="starBlankTwo"
Source="{local:ImageResource BookAStar.Images.star_outline.png}" />
Source="{extensions:ImageResource BookAStar.Images.Validation.star_outline.png}" />
<Image x:Name="starSelectedTwo"
Source="{local:ImageResource BookAStar.Images.star_selected.png}"
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
IsVisible="{Binding Source={x:Reference starTwo},
Path=IsStarred}"/>
</Grid>
@ -37,10 +38,10 @@
<behaviors:StarBehavior x:Name="starThree" GroupName="myStar"/>
</Grid.Behaviors>
<Image x:Name="starBlankThree"
Source="{local:ImageResource BookAStar.Images.star_outline.png}" />
Source="{extensions:ImageResource BookAStar.Images.Validation.star_outline.png}" />
<Image x:Name="starSelectedThree"
Source="{local:ImageResource BookAStar.Images.star_selected.png}"
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
IsVisible="{Binding Source={x:Reference starThree},
Path=IsStarred}"/>
</Grid>
@ -49,10 +50,10 @@
<behaviors:StarBehavior x:Name="starFour" GroupName="myStar"/>
</Grid.Behaviors>
<Image x:Name="starBlankFour"
Source="{local:ImageResource BookAStar.Images.star_outline.png}" />
Source="{extensions:ImageResource BookAStar.Images.Validation.star_outline.png}" />
<Image x:Name="starSelectedFour"
Source="{local:ImageResource BookAStar.Images.star_selected.png}"
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
IsVisible="{Binding Source={x:Reference starFour},
Path=IsStarred}"/>
</Grid>
@ -61,10 +62,10 @@
<behaviors:StarBehavior x:Name="starFive" GroupName="myStar"/>
</Grid.Behaviors>
<Image x:Name="starBlankFive"
Source="{local:ImageResource BookAStar.Images.star_outline.png}" />
Source="{extensions:ImageResource BookAStar.Images.Validation.star_outline.png}" />
<Image x:Name="starSelectedFive"
Source="{local:ImageResource BookAStar.Images.star_selected.png}"
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
IsVisible="{Binding Source={x:Reference starFive},
Path=IsStarred}"/>
</Grid>
@ -72,16 +73,14 @@
<StackLayout>
<StackLayout.Resources>
<ResourceDictionary>
<local:RatingText x:Key="ratingText" />
<Style TargetType="Label" BasedOn="{StaticResource baseStyle}">
<converters:RatingText x:Key="ratingText" />
<Style TargetType="Label" BasedOn="{StaticResource LabelStyle}">
<Setter Property="TextColor" Value="#4CAF50" />
</Style>
</ResourceDictionary>
</StackLayout.Resources>
<Label Text="{Binding Source={x:Reference starFive},
Path=Rating, Converter={StaticResource ratingText}}" ></Label>
<Label Text="{Binding Source={x:Reference starFive}, Path=Rating, Converter={StaticResource ratingText}}" ></Label>
</StackLayout>
<Button Text="Submit"/>
</StackLayout>
</ContentView.Content>

@ -1,4 +1,5 @@
using System;
using BookAStar.Behaviors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -10,9 +11,75 @@ namespace BookAStar.Views
{
public partial class RatingView : ContentView
{
protected int rating;
public int Rating {
get
{
return rating;
}
set
{
if (value != rating)
{
if (value < 0 || value > 5)
{
SetValue(RatingProperty, 0);
rating = 0;
}
else
{
SetValue(RatingProperty, value);
rating = value;
}
starBehaviors[4].SetValue(StarBehavior.RatingProperty, rating);
for (int i = 0; i < rating && i < 5; i++)
starBehaviors[i].SetValue(StarBehavior.IsStarredProperty, true);
for (int i = rating; i < 5 && i >= 0; i++)
starBehaviors[i].SetValue(StarBehavior.IsStarredProperty, false);
}
}
}
private bool isStarred;
public bool IsStarred
{
get
{
return isStarred;
}
set
{
SetValue(IsStarredProperty, value);
}
}
StarBehavior[] starBehaviors;
public static BindableProperty IsStarredProperty = BindableProperty.Create(
propertyName: "IsStarred",
returnType: typeof(bool),
declaringType: typeof(RatingView),
defaultValue: false,
defaultBindingMode: BindingMode.TwoWay
);
public static BindableProperty RatingProperty = BindableProperty.Create(
propertyName: "Rating",
returnType: typeof(int),
declaringType: typeof(RatingView),
defaultValue: 0,
defaultBindingMode: BindingMode.TwoWay
);
public RatingView()
{
InitializeComponent();
starBehaviors = new StarBehavior[5]
{
starOne, starTwo, starThree, starFour, starFive
};
}
}
}

Loading…