Skip to content

Commit

Permalink
#235: Listview context menu - mark as completed
Browse files Browse the repository at this point in the history
  • Loading branch information
OudomMunint committed Aug 4, 2024
1 parent c7830b0 commit dfe9e5a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Views/TodoListPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@
</MenuItem.Text>
</MenuItem>

<MenuItem x:Name="markasdoneitem" Clicked="markasdoneitem_Clicked">
<MenuItem.IconImageSource>
<OnPlatform x:TypeArguments="ImageSource">
<On Platform="Android">done.png</On>
</OnPlatform>
</MenuItem.IconImageSource>
<MenuItem.Text>
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS">Completed</On>
</OnPlatform>
</MenuItem.Text>
</MenuItem>

</ViewCell.ContextActions>
<Border Padding="5,0,0,0" Margin="5">
<Grid RowSpacing="0" ColumnSpacing="0" Margin="-5">
Expand Down
29 changes: 29 additions & 0 deletions Views/TodoListPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,5 +568,34 @@ private async void deleteitem_Clicked(object sender, EventArgs e)
}
}
}

private async void markasdoneitem_Clicked(System.Object sender, System.EventArgs e)
{
HapticFeedback.Perform(HapticFeedbackType.Click);
var menuItem = sender as MenuItem;
if (menuItem != null)
{
var todoItem = menuItem.BindingContext as Todoitem;
if (todoItem != null)
{
if (todoItem.Done == true)
{
await DisplayAlert("Task already completed", null, "OK");
}

else
{
todoItem.Done = true;

TodoitemDatabase database = await TodoitemDatabase.Instance;
await database.SaveItemAsync(todoItem);

await UpdateListView();

await Toast.Make(todoItem.Name + " Marked as complete", ToastDuration.Long).Show();
}
}
}
}
}
}

0 comments on commit dfe9e5a

Please sign in to comment.