diff --git a/src/MAUI/Maui.Samples/ApiKeyPage.xaml b/src/MAUI/Maui.Samples/ApiKeyPage.xaml new file mode 100644 index 0000000000..7f05d57d68 --- /dev/null +++ b/src/MAUI/Maui.Samples/ApiKeyPage.xaml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/src/MAUI/Maui.Samples/ApiKeyPage.xaml.cs b/src/MAUI/Maui.Samples/ApiKeyPage.xaml.cs new file mode 100644 index 0000000000..6f64c1dcd3 --- /dev/null +++ b/src/MAUI/Maui.Samples/ApiKeyPage.xaml.cs @@ -0,0 +1,9 @@ +namespace ArcGIS; + +public partial class ApiKeyPage : ContentPage +{ + public ApiKeyPage() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/src/MAUI/Maui.Samples/ApiKeyPrompt.xaml b/src/MAUI/Maui.Samples/ApiKeyView.xaml similarity index 90% rename from src/MAUI/Maui.Samples/ApiKeyPrompt.xaml rename to src/MAUI/Maui.Samples/ApiKeyView.xaml index ddbe60678a..4459114c12 100644 --- a/src/MAUI/Maui.Samples/ApiKeyPrompt.xaml +++ b/src/MAUI/Maui.Samples/ApiKeyView.xaml @@ -1,10 +1,9 @@  - - + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> + - \ No newline at end of file + + \ No newline at end of file diff --git a/src/MAUI/Maui.Samples/ApiKeyPrompt.xaml.cs b/src/MAUI/Maui.Samples/ApiKeyView.xaml.cs similarity index 96% rename from src/MAUI/Maui.Samples/ApiKeyPrompt.xaml.cs rename to src/MAUI/Maui.Samples/ApiKeyView.xaml.cs index a65c494047..da0db8a983 100644 --- a/src/MAUI/Maui.Samples/ApiKeyPrompt.xaml.cs +++ b/src/MAUI/Maui.Samples/ApiKeyView.xaml.cs @@ -12,9 +12,9 @@ namespace ArcGIS { [XamlCompilation(XamlCompilationOptions.Compile)] - public partial class ApiKeyPrompt : ContentPage + public partial class ApiKeyView : ContentView { - public ApiKeyPrompt() + public ApiKeyView() { InitializeComponent(); Initialize(); diff --git a/src/MAUI/Maui.Samples/App.xaml b/src/MAUI/Maui.Samples/App.xaml index d75733a79c..ac106cb5c9 100644 --- a/src/MAUI/Maui.Samples/App.xaml +++ b/src/MAUI/Maui.Samples/App.xaml @@ -1,8 +1,8 @@ - - + + diff --git a/src/MAUI/Maui.Samples/App.xaml.cs b/src/MAUI/Maui.Samples/App.xaml.cs index d793b4318a..facf5d1464 100644 --- a/src/MAUI/Maui.Samples/App.xaml.cs +++ b/src/MAUI/Maui.Samples/App.xaml.cs @@ -8,7 +8,7 @@ public App() { InitializeComponent(); - MainPage = new NavigationPage(new CategoryListPage() { }); + MainPage = new AppShell(); Current = this; } } \ No newline at end of file diff --git a/src/MAUI/Maui.Samples/AppShell.xaml b/src/MAUI/Maui.Samples/AppShell.xaml new file mode 100644 index 0000000000..8f698a62a5 --- /dev/null +++ b/src/MAUI/Maui.Samples/AppShell.xaml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/src/MAUI/Maui.Samples/AppShell.xaml.cs b/src/MAUI/Maui.Samples/AppShell.xaml.cs new file mode 100644 index 0000000000..0f3bf21822 --- /dev/null +++ b/src/MAUI/Maui.Samples/AppShell.xaml.cs @@ -0,0 +1,64 @@ +using ArcGIS.Samples.Managers; +using ArcGIS.Samples.Shared.Managers; +using ArcGIS.Samples.Shared.Models; + +namespace ArcGIS; + +public partial class AppShell : Shell +{ + public AppShell() + { + InitializeComponent(); + + Initialize(); + } + + private void Initialize() + { + this.Appearing += FirstLoaded; + + SampleManager.Current.Initialize(); + + var samplesCategories = SampleManager.Current.FullTree.Items.OfType().ToList(); + var allSamples = SampleManager.Current.AllSamples.ToList(); + + List flyoutItems = new List(); + + foreach (var category in samplesCategories) + { + FlyoutItem flyoutItem = new FlyoutItem(); + flyoutItem.Title = category.Name; + + ShellContent shellContent = new ShellContent(); + //shellContent.Title = category.Name; + shellContent.Content = new CategoryPage(category); + shellContent.Route = $"{nameof(CategoryPage)}_{category.Name}"; + + flyoutItem.Items.Add(shellContent); + + this.Items.Add(flyoutItem); + } + } + + #region Check API Key + private void FirstLoaded(object sender, EventArgs e) + { + this.Appearing -= FirstLoaded; + + _ = CheckApiKey(); + } + + private async Task CheckApiKey() + { + // Attempt to load a locally stored API key. + await ApiKeyManager.TrySetLocalKey(); + + // Check that the current API key is valid. + ApiKeyStatus status = await ApiKeyManager.CheckKeyValidity(); + if (status != ApiKeyStatus.Valid) + { + await Navigation.PushAsync(new ApiKeyPage(), true); + } + } + #endregion +} \ No newline at end of file diff --git a/src/MAUI/Maui.Samples/ArcGIS.Samples.Maui.csproj b/src/MAUI/Maui.Samples/ArcGIS.Samples.Maui.csproj index c20ad90a57..db491be66a 100644 --- a/src/MAUI/Maui.Samples/ArcGIS.Samples.Maui.csproj +++ b/src/MAUI/Maui.Samples/ArcGIS.Samples.Maui.csproj @@ -61,8 +61,8 @@ - - + + @@ -82,23 +82,20 @@ - - - - - - + + + - + @@ -106,11 +103,19 @@ + + + + + + + + PreserveNewest @@ -128,10 +133,13 @@ - - - + + + + + + @@ -145,6 +153,38 @@ + + ApiKeyView.xaml + + + AppShell.xaml + + + ScreenshotView.xaml + + + SettingsPage.xaml + + + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + PreserveNewest diff --git a/src/MAUI/Maui.Samples/CategoryListPage.xaml b/src/MAUI/Maui.Samples/CategoryListPage.xaml deleted file mode 100644 index 8dd06e04bb..0000000000 --- a/src/MAUI/Maui.Samples/CategoryListPage.xaml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/MAUI/Maui.Samples/CategoryListPage.xaml.cs b/src/MAUI/Maui.Samples/CategoryListPage.xaml.cs deleted file mode 100644 index 4286b23269..0000000000 --- a/src/MAUI/Maui.Samples/CategoryListPage.xaml.cs +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2022 Esri. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific -// language governing permissions and limitations under the License. - -using ArcGIS.Helpers; -using ArcGIS.Samples.Managers; -using ArcGIS.Samples.Shared.Managers; -using ArcGIS.Samples.Shared.Models; -using System.ComponentModel; -using System.Runtime.CompilerServices; - -namespace ArcGIS -{ - public partial class CategoryListPage - { - public CategoryListPage() - { - Initialize(); - InitializeComponent(); - } - - private void Initialize() - { - this.Appearing += FirstLoaded; - - // Initialize the sample manager. - SampleManager.Current.Initialize(); - - ViewModel = new SamplesSearchViewModel(); - - // Update the binding. - BindingContext = ViewModel; - -#if MACCATALYST || IOS - // Workaround visibility binding bug on Mac Catalyst. Binding for visibility that starts as false does not behave correctly on iOS and Mac. - ViewModel.PropertyChanged += MacVisibilityHandler; -#endif - } - - private void MacVisibilityHandler(object sender, PropertyChangedEventArgs e) - { - if (e.PropertyName == "IsSearchOpen") - { - SampleSearchResultList.IsVisible = ((SamplesSearchViewModel)sender).IsSearchOpen; - } - } - - private void FirstLoaded(object sender, EventArgs e) - { - this.Appearing -= FirstLoaded; - - _ = CheckApiKey(); - } - - private async Task CheckApiKey() - { - // Attempt to load a locally stored API key. - await ApiKeyManager.TrySetLocalKey(); - - // Check that the current API key is valid. - ApiKeyStatus status = await ApiKeyManager.CheckKeyValidity(); - if (status != ApiKeyStatus.Valid) - { - await Navigation.PushAsync(new ApiKeyPrompt(), true); - } - } - - private async void OnItemTapped(object sender, ItemTappedEventArgs e) - { - // Get the selected category. - var category = e.Item as SearchableTreeNode; - var sample = e.Item as SampleInfo; - if (category != null) - { - // Navigate to the listing page for the category. - await Navigation.PushAsync(new SampleListPage(category.Name)); - } - else if (sample != null) - { - // Navigate to the sample page - _ = SampleLoader.LoadSample(sample, this); - } - } - - public SamplesSearchViewModel ViewModel { get; set; } - - private async void SettingsClicked(object sender, EventArgs e) - { - await Navigation.PushAsync(new SettingsPage(), true); - } - } - - public class SamplesSearchViewModel : INotifyPropertyChanged - { - public List SampleCategories { get; } - public List SearchResults => _allSamples.Where(SearchFunction).ToList(); - private readonly List _allSamples; - private string _query = ""; - - public SamplesSearchViewModel() - { - SampleCategories = SampleManager.Current.FullTree.Items.OfType().ToList(); - _allSamples = SampleManager.Current.AllSamples.ToList(); - } - - public string SearchQuery - { - get { return _query; } - set - { - if (value != _query) - { - _query = value ?? ""; // Need to guard against null on X.F ios - happens when canceling search. - OnPropertyChanged(); - OnPropertyChanged(nameof(SearchResults)); - OnPropertyChanged(nameof(IsSearchOpen)); - OnPropertyChanged(nameof(IsCategoriesOpen)); - } - } - } - - public bool IsSearchOpen => !string.IsNullOrWhiteSpace(_query); - public bool IsCategoriesOpen => string.IsNullOrWhiteSpace(_query); - - private bool SearchFunction(SampleInfo sample) - { - return SampleManager.Current.SampleSearchFunc(sample, SearchQuery); - } - - public event PropertyChangedEventHandler PropertyChanged; - - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - } -} \ No newline at end of file diff --git a/src/MAUI/Maui.Samples/CategoryPage.xaml b/src/MAUI/Maui.Samples/CategoryPage.xaml new file mode 100644 index 0000000000..a526d323a8 --- /dev/null +++ b/src/MAUI/Maui.Samples/CategoryPage.xaml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +