Skip to content

Commit

Permalink
Navigate to Search Result
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Oct 14, 2023
1 parent 4db256c commit c784292
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dev/ViewModels/QuranViewModel/QuranViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void SearchSurah(AutoSuggestBox sender)
}
}

private void AddNewSurahTab(TabView tabView, ChapterProperty chapterProperty)
public void AddNewSurahTab(TabView tabView, ChapterProperty chapterProperty, QuranSearch2 quranSearch2 = null)
{
this.tabview = tabView;
var currentTabViewItem = tabView.TabItems?.Where(tabViewItem => (tabViewItem as QuranTabViewItem)?.Chapter?.Id == chapterProperty.Id)?.FirstOrDefault();
Expand All @@ -98,6 +98,7 @@ private void AddNewSurahTab(TabView tabView, ChapterProperty chapterProperty)
var item = new QuranTabViewItem();
item.Header = $"{chapterProperty.Id} - {chapterProperty.Name} - {chapterProperty.Ayas} آیه - {chapterProperty.Type}";
item.Chapter = chapterProperty;
item.QuranSearch2 = quranSearch2;
tabView.TabItems.Add(item);
item.CloseRequested += TabViewItem_CloseRequested;
tabView.SelectedIndex = tabView.TabItems.Count - 1;
Expand Down
1 change: 1 addition & 0 deletions dev/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
QuerySubmitted="AutoSuggestBox_QuerySubmitted"
TextChanged="AutoSuggestBox_TextChanged" />
<CommandBar x:Name="cmbSearch"
Background="Transparent"
DefaultLabelPosition="Collapsed"
Visibility="Collapsed">
<CommandBar.SecondaryCommands>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xmlns:local="using:AlAnvar.Common"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tables="using:AlAnvar.Database.Tables"
xmlns:wuc="using:WinUICommunity"
Loaded="TabViewItem_Loaded"
mc:Ignorable="d">
<TabViewItem.IconSource>
Expand All @@ -18,7 +19,10 @@
<TabViewItem.Resources>
<DataTemplate x:Key="QuranTemplate"
x:DataType="tables:QuranSearch2">
<community:DataRow HorizontalAlignment="Left">
<community:DataRow HorizontalAlignment="Left"
DoubleTapped="DataRow_DoubleTapped"
IsDoubleTapEnabled="True"
Tag="{x:Bind}">
<TextBlock VerticalAlignment="Center"
Text="{x:Bind Id}" />
<TextBlock VerticalAlignment="Center"
Expand All @@ -27,12 +31,25 @@
Text="{x:Bind AyahNumber}" />
<TextBlock VerticalAlignment="Center"
Text="{x:Bind Text}" />
<community:DataRow.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Margin="5"
Click="MenuGoToSurah_Click"
CornerRadius="{ThemeResource ControlCornerRadius}"
Icon="{wuc:BitmapIcon Source=Assets/Fluent/external.png}"
Tag="{x:Bind}"
Text="برو به سوره موردنظر" />
</MenuFlyout>
</community:DataRow.ContextFlyout>
</community:DataRow>
</DataTemplate>
<DataTemplate x:Key="TranslationTemplate"
x:DataType="tables:QuranSearch2">
<community:DataRow HorizontalAlignment="Left"
Background="{ThemeResource InfoBarWarningSeverityBackgroundBrush}">
Background="{ThemeResource InfoBarWarningSeverityBackgroundBrush}"
DoubleTapped="DataRow_DoubleTapped"
IsDoubleTapEnabled="True"
Tag="{x:Bind}">
<TextBlock VerticalAlignment="Center"
Text="{x:Bind Id}" />
<TextBlock VerticalAlignment="Center"
Expand All @@ -41,6 +58,16 @@
Text="{x:Bind AyahNumber}" />
<TextBlock VerticalAlignment="Center"
Text="{x:Bind Text}" />
<community:DataRow.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Margin="5"
Click="MenuGoToSurah_Click"
CornerRadius="{ThemeResource ControlCornerRadius}"
Icon="{wuc:BitmapIcon Source=Assets/Fluent/external.png}"
Tag="{x:Bind}"
Text="برو به سوره موردنظر" />
</MenuFlyout>
</community:DataRow.ContextFlyout>
</community:DataRow>
</DataTemplate>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,38 @@ await Task.Run(() =>
});
});
}

private void MenuGoToSurah_Click(object sender, RoutedEventArgs e)
{
var menu = sender as MenuFlyoutItem;
if (menu != null && menu.Tag != null)
{
GoToSurah(menu.Tag as QuranSearch2);
}
}

private void DataRow_DoubleTapped(object sender, Microsoft.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
{
var dataRow = sender as DataRow;
if (dataRow != null && dataRow.Tag != null)
{
GoToSurah(dataRow.Tag as QuranSearch2);
}
}

private async void GoToSurah(QuranSearch2 quranSearch2)
{
if (quranSearch2 != null)
{
if (QuranPage.Instance != null)
{
using var db = new AlAnvarDBContext();
var chapter = await db.Chapters.Where(x=> x.Name == quranSearch2.SurahName).FirstOrDefaultAsync();
if (chapter != null)
{
QuranPage.Instance.ViewModel.AddNewSurahTab(QuranPage.Instance.GetTabView(), chapter, quranSearch2);
}
}
}
}
}
15 changes: 15 additions & 0 deletions dev/Views/QuranTabViewItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ public ChapterProperty Chapter
set => SetValue(ChapterProperty, value);
}

public static readonly DependencyProperty QuranSearch2Property =
DependencyProperty.Register("QuranSearch2", typeof(QuranSearch2), typeof(QuranTabViewItem),
new PropertyMetadata(null));

public QuranSearch2 QuranSearch2
{
get => (QuranSearch2) GetValue(QuranSearch2Property);
set => SetValue(QuranSearch2Property, value);
}

public ObservableCollection<QuranItem> QuranCollection { get; set; } = new ObservableCollection<QuranItem>();
private List<TranslationItem> TranslationCollection { get; set; } = new List<TranslationItem>();
private List<Quran> AyahCollection { get; set; } = new List<Quran>();
Expand Down Expand Up @@ -97,6 +107,11 @@ await Task.Run(() =>
prgLoading.IsActive = false;
nbxRange1.Maximum = Chapter.Ayas;
nbxRange2.Maximum = Chapter.Ayas;

if (QuranSearch2 != null)
{
ScrollIntoView(QuranSearch2.AyahNumber - 1);
}
}

private void LoadQaris()
Expand Down

0 comments on commit c784292

Please sign in to comment.