Skip to content

Commit c784292

Browse files
committed
Navigate to Search Result
1 parent 4db256c commit c784292

File tree

5 files changed

+81
-3
lines changed

5 files changed

+81
-3
lines changed

dev/ViewModels/QuranViewModel/QuranViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void SearchSurah(AutoSuggestBox sender)
8585
}
8686
}
8787

88-
private void AddNewSurahTab(TabView tabView, ChapterProperty chapterProperty)
88+
public void AddNewSurahTab(TabView tabView, ChapterProperty chapterProperty, QuranSearch2 quranSearch2 = null)
8989
{
9090
this.tabview = tabView;
9191
var currentTabViewItem = tabView.TabItems?.Where(tabViewItem => (tabViewItem as QuranTabViewItem)?.Chapter?.Id == chapterProperty.Id)?.FirstOrDefault();
@@ -98,6 +98,7 @@ private void AddNewSurahTab(TabView tabView, ChapterProperty chapterProperty)
9898
var item = new QuranTabViewItem();
9999
item.Header = $"{chapterProperty.Id} - {chapterProperty.Name} - {chapterProperty.Ayas} آیه - {chapterProperty.Type}";
100100
item.Chapter = chapterProperty;
101+
item.QuranSearch2 = quranSearch2;
101102
tabView.TabItems.Add(item);
102103
item.CloseRequested += TabViewItem_CloseRequested;
103104
tabView.SelectedIndex = tabView.TabItems.Count - 1;

dev/Views/MainPage.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
QuerySubmitted="AutoSuggestBox_QuerySubmitted"
3737
TextChanged="AutoSuggestBox_TextChanged" />
3838
<CommandBar x:Name="cmbSearch"
39+
Background="Transparent"
3940
DefaultLabelPosition="Collapsed"
4041
Visibility="Collapsed">
4142
<CommandBar.SecondaryCommands>

dev/Views/Search/QuranSearchItem.xaml renamed to dev/Views/QuranSearchItem.xaml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
xmlns:local="using:AlAnvar.Common"
1010
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1111
xmlns:tables="using:AlAnvar.Database.Tables"
12+
xmlns:wuc="using:WinUICommunity"
1213
Loaded="TabViewItem_Loaded"
1314
mc:Ignorable="d">
1415
<TabViewItem.IconSource>
@@ -18,7 +19,10 @@
1819
<TabViewItem.Resources>
1920
<DataTemplate x:Key="QuranTemplate"
2021
x:DataType="tables:QuranSearch2">
21-
<community:DataRow HorizontalAlignment="Left">
22+
<community:DataRow HorizontalAlignment="Left"
23+
DoubleTapped="DataRow_DoubleTapped"
24+
IsDoubleTapEnabled="True"
25+
Tag="{x:Bind}">
2226
<TextBlock VerticalAlignment="Center"
2327
Text="{x:Bind Id}" />
2428
<TextBlock VerticalAlignment="Center"
@@ -27,12 +31,25 @@
2731
Text="{x:Bind AyahNumber}" />
2832
<TextBlock VerticalAlignment="Center"
2933
Text="{x:Bind Text}" />
34+
<community:DataRow.ContextFlyout>
35+
<MenuFlyout>
36+
<MenuFlyoutItem Margin="5"
37+
Click="MenuGoToSurah_Click"
38+
CornerRadius="{ThemeResource ControlCornerRadius}"
39+
Icon="{wuc:BitmapIcon Source=Assets/Fluent/external.png}"
40+
Tag="{x:Bind}"
41+
Text="برو به سوره موردنظر" />
42+
</MenuFlyout>
43+
</community:DataRow.ContextFlyout>
3044
</community:DataRow>
3145
</DataTemplate>
3246
<DataTemplate x:Key="TranslationTemplate"
3347
x:DataType="tables:QuranSearch2">
3448
<community:DataRow HorizontalAlignment="Left"
35-
Background="{ThemeResource InfoBarWarningSeverityBackgroundBrush}">
49+
Background="{ThemeResource InfoBarWarningSeverityBackgroundBrush}"
50+
DoubleTapped="DataRow_DoubleTapped"
51+
IsDoubleTapEnabled="True"
52+
Tag="{x:Bind}">
3653
<TextBlock VerticalAlignment="Center"
3754
Text="{x:Bind Id}" />
3855
<TextBlock VerticalAlignment="Center"
@@ -41,6 +58,16 @@
4158
Text="{x:Bind AyahNumber}" />
4259
<TextBlock VerticalAlignment="Center"
4360
Text="{x:Bind Text}" />
61+
<community:DataRow.ContextFlyout>
62+
<MenuFlyout>
63+
<MenuFlyoutItem Margin="5"
64+
Click="MenuGoToSurah_Click"
65+
CornerRadius="{ThemeResource ControlCornerRadius}"
66+
Icon="{wuc:BitmapIcon Source=Assets/Fluent/external.png}"
67+
Tag="{x:Bind}"
68+
Text="برو به سوره موردنظر" />
69+
</MenuFlyout>
70+
</community:DataRow.ContextFlyout>
4471
</community:DataRow>
4572
</DataTemplate>
4673

dev/Views/Search/QuranSearchItem.xaml.cs renamed to dev/Views/QuranSearchItem.xaml.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,38 @@ await Task.Run(() =>
103103
});
104104
});
105105
}
106+
107+
private void MenuGoToSurah_Click(object sender, RoutedEventArgs e)
108+
{
109+
var menu = sender as MenuFlyoutItem;
110+
if (menu != null && menu.Tag != null)
111+
{
112+
GoToSurah(menu.Tag as QuranSearch2);
113+
}
114+
}
115+
116+
private void DataRow_DoubleTapped(object sender, Microsoft.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
117+
{
118+
var dataRow = sender as DataRow;
119+
if (dataRow != null && dataRow.Tag != null)
120+
{
121+
GoToSurah(dataRow.Tag as QuranSearch2);
122+
}
123+
}
124+
125+
private async void GoToSurah(QuranSearch2 quranSearch2)
126+
{
127+
if (quranSearch2 != null)
128+
{
129+
if (QuranPage.Instance != null)
130+
{
131+
using var db = new AlAnvarDBContext();
132+
var chapter = await db.Chapters.Where(x=> x.Name == quranSearch2.SurahName).FirstOrDefaultAsync();
133+
if (chapter != null)
134+
{
135+
QuranPage.Instance.ViewModel.AddNewSurahTab(QuranPage.Instance.GetTabView(), chapter, quranSearch2);
136+
}
137+
}
138+
}
139+
}
106140
}

dev/Views/QuranTabViewItem.xaml.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ public ChapterProperty Chapter
2727
set => SetValue(ChapterProperty, value);
2828
}
2929

30+
public static readonly DependencyProperty QuranSearch2Property =
31+
DependencyProperty.Register("QuranSearch2", typeof(QuranSearch2), typeof(QuranTabViewItem),
32+
new PropertyMetadata(null));
33+
34+
public QuranSearch2 QuranSearch2
35+
{
36+
get => (QuranSearch2) GetValue(QuranSearch2Property);
37+
set => SetValue(QuranSearch2Property, value);
38+
}
39+
3040
public ObservableCollection<QuranItem> QuranCollection { get; set; } = new ObservableCollection<QuranItem>();
3141
private List<TranslationItem> TranslationCollection { get; set; } = new List<TranslationItem>();
3242
private List<Quran> AyahCollection { get; set; } = new List<Quran>();
@@ -97,6 +107,11 @@ await Task.Run(() =>
97107
prgLoading.IsActive = false;
98108
nbxRange1.Maximum = Chapter.Ayas;
99109
nbxRange2.Maximum = Chapter.Ayas;
110+
111+
if (QuranSearch2 != null)
112+
{
113+
ScrollIntoView(QuranSearch2.AyahNumber - 1);
114+
}
100115
}
101116

102117
private void LoadQaris()

0 commit comments

Comments
 (0)