Skip to content

Commit

Permalink
Added a way to open url from the selection into the browser
Browse files Browse the repository at this point in the history
  • Loading branch information
iNoles committed Sep 16, 2023
1 parent 3964dc9 commit 7329a72
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .idea/.idea.HackerNews/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.HackerNews/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.HackerNews/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:hackerNews="clr-namespace:HackerNews"
x:Class="HackerNews.MainPage"
x:DataType="hackerNews:NewsViewModel">
<ListView x:Name="NewsListView">
<ListView x:Name="NewsListView" ItemSelected="NewsListView_OnItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell x:DataType="hackerNews:StoryModel"
Expand Down
17 changes: 17 additions & 0 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@ protected override async void OnAppearing()
base.OnAppearing();
await _newsViewModel.Refresh();
}

private async void NewsListView_OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var listView = (ListView)sender;
listView.SelectedItem = null;

if (e.SelectedItem is not StoryModel storyModel) return;
if (!string.IsNullOrEmpty(storyModel.Url))
{
var browserOptions = new BrowserLaunchOptions();
await Browser.Default.OpenAsync(storyModel.Url, browserOptions);
}
else
{
await DisplayAlert("Invalid Article", "ASK HN articles have no url", "OK");
}
}
}

0 comments on commit 7329a72

Please sign in to comment.