Skip to content

Commit

Permalink
Added tool for clearing list activities
Browse files Browse the repository at this point in the history
Included the API method, the app bar button, async action, command, and
use of the MessageBoxService to create a confirmation dialog.
  • Loading branch information
xdumaine committed Mar 13, 2013
1 parent 4abb1cf commit 2c54009
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 7 deletions.
18 changes: 17 additions & 1 deletion Avocado/Common/StandardStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,11 @@
<Setter Property="AutomationProperties.Name" Value="Remove"/>
<Setter Property="Content" Value="&#xE108;"/>
</Style>
<Style x:Key="AddAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource AppBarButtonStyle}">
<Style x:Key="AddAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource
}">
<Setter Property="AutomationProperties.AutomationId" Value="AddAppBarButton"/>
<Setter Property="AutomationProperties.Name" Value="Add"/>
<Setter Property="Content" Value="&#xE109;"/>
Expand Down Expand Up @@ -1923,4 +1927,16 @@
</Setter.Value>
</Setter>
</Style>

<Style x:Key="ClearAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource AppBarButtonStyle}">
<Setter Property="AutomationProperties.AutomationId" Value="ClearAppBarButton"/>
<Setter Property="AutomationProperties.Name" Value="Clear List Activities"/>
<Setter Property="Content" Value="&#xE107;"/>
</Style>

<Style x:Key="UploadPhotoAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource AppBarButtonStyle}">
<Setter Property="AutomationProperties.AutomationId" Value="UploadAppBarButton"/>
<Setter Property="AutomationProperties.Name" Value="Upload Photo"/>
<Setter Property="Content" Value="&#xE11C;"/>
</Style>
</ResourceDictionary>
7 changes: 7 additions & 0 deletions Avocado/Models/Activity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public bool IsMessage
return Type == "message";
}
}
public bool IsEvent
{
get
{
return Type == "event";
}
}
#endregion

public DateTime date;
Expand Down
9 changes: 9 additions & 0 deletions Avocado/Models/AuthClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ public void UploadPhoto(string photoContents)
response.EnsureSuccessStatusCode();
}

public void DeleteActivity(string id)
{
var uri = new Uri(string.Format("{0}/{1}/delete", API_URL_ACTIVITIES, id));
var body = new FormUrlEncodedContent(new KeyValuePair<string, string>[] { });

var response = Post(uri, body);
response.EnsureSuccessStatusCode();
}

#endregion
}
}
41 changes: 41 additions & 0 deletions Avocado/ViewModels/Activities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,47 @@ public ICommand AddPhotoCommand
public Activities()
{
DispatcherHelper.Initialize();

}

public void ClearListActivities()
{
DispatcherHelper.CheckBeginInvokeOnUI(ConfirmClearListActivities);
}

public async void ConfirmClearListActivities()
{
var messageBox = MessageBoxService.Default;

var result = await messageBox.ShowAsync("Are you sure you want to clear all activities about lists?", "Are you sure?", GenericMessageBoxButton.OkCancel);
if (result == GenericMessageBoxResult.Cancel)
{
return;
}

IsLoading = true;
var task = ThreadPool.RunAsync(t => ClearListActivitesAsync());

task.Completed = RunOnComplete(Update);
}

public async void ClearListActivitesAsync()
{
var listActivities = (from a in ActivityList
where a.IsList == true
select a).ToList();
foreach (var listActivity in listActivities)
{
AuthClient.DeleteActivity(listActivity.Id);
}
}

public ICommand ClearListActivitiesCommand
{
get
{
return new RelayCommand(() => { DispatcherHelper.CheckBeginInvokeOnUI(ClearListActivities); });
}
}

public AsyncActionCompletedHandler RunOnComplete(Action method)
Expand Down
3 changes: 2 additions & 1 deletion Avocado/Views/Activities.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<AppBar>
<StackPanel Orientation="Horizontal">
<Button Style="{StaticResource RefreshAppBarButtonStyle}" Command="{Binding RefreshCommand}"/>
<Button Style="{StaticResource UploadAppBarButtonStyle}" Command="{Binding AddPhotoCommand}" Visibility="{Binding IsMediaTabActive,Converter={StaticResource BooleanToVisibilityConverter}}" />
<Button Style="{StaticResource UploadPhotoAppBarButtonStyle}" Command="{Binding AddPhotoCommand}" Visibility="{Binding IsMediaTabActive,Converter={StaticResource BooleanToVisibilityConverter}}" />
<Button Style="{StaticResource ClearAppBarButtonStyle}" Command="{Binding ClearListActivitiesCommand}" Visibility="{Binding IsActivityTabActive, Converter={StaticResource BooleanToVisibilityConverter}}" />
</StackPanel>
</AppBar>
</Page.BottomAppBar>
Expand Down
3 changes: 1 addition & 2 deletions Avocado/Views/Partial/AvocadoStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,5 @@
</Setter.Value>
</Setter>
</Style>



</ResourceDictionary>
5 changes: 2 additions & 3 deletions metromvvm/MessageBoxService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ public async Task<GenericMessageBoxResult> ShowAsync(string message, string capt
{
MessageDialog msg = new MessageDialog(message, caption);

Windows.ApplicationModel.Resources.ResourceLoader rl = new Windows.ApplicationModel.Resources.ResourceLoader();
try
{
m_OkString = rl.GetString("OK");
m_OkString = "OK";
}
catch (Exception)
{
Expand All @@ -57,7 +56,7 @@ public async Task<GenericMessageBoxResult> ShowAsync(string message, string capt

try
{
m_CancelString = rl.GetString("Cancel");
m_CancelString = "Cancel";
}
catch (Exception)
{
Expand Down

0 comments on commit 2c54009

Please sign in to comment.