Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced BeginnersSeries sample (MauiApp2) to be more beginner's friendly #439

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31611.283
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiApp2", "MauiApp2\MauiApp2.csproj", "{E00D4313-A6CA-4A1D-A1DB-C242961F1D15}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeginnersTask", "BeginnersTask\BeginnersTask.csproj", "{E00D4313-A6CA-4A1D-A1DB-C242961F1D15}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp2"
x:Class="MauiApp2.App">
xmlns:local="clr-namespace:BeginnersTasks"
x:Class="BeginnersTasks.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MauiApp2;
namespace BeginnersTasks;

public partial class App : Application
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MauiApp2.AppShell"
x:Class="BeginnersTasks.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp2"
xmlns:local="clr-namespace:BeginnersTasks"
Shell.FlyoutBehavior="Disabled">
<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MauiApp2;
namespace BeginnersTasks;

public partial class AppShell : Shell
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

<OutputType>Exe</OutputType>
<RootNamespace>MauiApp2</RootNamespace>
<RootNamespace>BeginnersTasks</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

<!-- Display name -->
<ApplicationTitle>MauiApp2</ApplicationTitle>
<ApplicationTitle>BeginnersTasks</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.mauiapp2</ApplicationId>
<ApplicationId>com.companyname.BeginnersTasks</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp2.DetailPage"
xmlns:viewmodel="clr-namespace:MauiApp2.ViewModel"
x:Class="BeginnersTasks.DetailPage"
xmlns:viewmodel="clr-namespace:BeginnersTasks.ViewModel"
x:DataType="viewmodel:DetailViewModel"
Title="DetailPage">
<StackLayout Padding="20">
<Label Text="{Binding Text}"
FontSize="25"
VerticalOptions="Center"
HorizontalOptions="Center" />
VerticalOptions="Center"
HorizontalOptions="Center" />

<Button Text="Go Back"
Command="{Binding GoBackCommand}"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MauiApp2.ViewModel;
using BeginnersTasks.ViewModel;

namespace MauiApp2;
namespace BeginnersTasks;

public partial class DetailPage : ContentPage
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp2.MainPage"
xmlns:viewmodel="clr-namespace:MauiApp2.ViewModel"
x:Class="BeginnersTasks.MainPage"
xmlns:viewmodel="clr-namespace:BeginnersTasks.ViewModel"
x:DataType="viewmodel:MainViewModel">

<Grid RowDefinitions="100, Auto, *"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MauiApp2.ViewModel;
using BeginnersTasks.ViewModel;

namespace MauiApp2;
namespace BeginnersTasks;

public partial class MainPage : ContentPage
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MauiApp2.ViewModel;
using BeginnersTasks.ViewModel;

namespace MauiApp2;
namespace BeginnersTasks;

public static class MauiProgram
{
Expand All @@ -14,13 +14,15 @@ public static MauiApp CreateMauiApp()
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});


// See https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection#service-lifetimes
// to understand the differences between [AddSingleton] and [AddTransient].

builder.Services.AddSingleton<IConnectivity>(Connectivity.Current);

builder.Services.AddSingleton<MainPage>();
builder.Services.AddSingleton<MainViewModel>();


builder.Services.AddTransient<DetailPage>();
builder.Services.AddTransient<DetailViewModel>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Android.Content.PM;
using Android.OS;

namespace MauiApp2;
namespace BeginnersTasks;

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Android.App;
using Android.Runtime;

namespace MauiApp2;
namespace BeginnersTasks;

[Application]
public class MainApplication : MauiApplication
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Foundation;

namespace MauiApp2;
namespace BeginnersTasks;

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ObjCRuntime;
using UIKit;

namespace MauiApp2;
namespace BeginnersTasks;

public class Program
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.Maui;
using Microsoft.Maui.Hosting;

namespace MauiApp2;
namespace BeginnersTasks;

class Program : MauiApplication
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.companyname.MauiApp2" version="1.0.0" api-version="7" xmlns="http://tizen.org/ns/packages">
<manifest package="com.companyname.BeginnersTask" version="1.0.0" api-version="7" xmlns="http://tizen.org/ns/packages">
<profile name="common" />
<ui-application appid="com.companyname.MauiApp2" exec="MauiApp2.dll" multiple="false" nodisplay="false" taskmanage="true" type="dotnet" launch_mode="single">
<label>MauiApp2</label>
<ui-application appid="com.companyname.BeginnersTask" exec="BeginnersTask.dll" multiple="false" nodisplay="false" taskmanage="true" type="dotnet" launch_mode="single">
<label>BeginnersTask</label>
<icon>appicon.xhigh.png</icon>
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
</ui-application>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<maui:MauiWinUIApplication
x:Class="MauiApp2.WinUI.App"
x:Class="BeginnersTasks.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:MauiApp2.WinUI">
xmlns:local="using:BeginnersTasks.WinUI">

</maui:MauiWinUIApplication>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace MauiApp2.WinUI;
namespace BeginnersTasks.WinUI;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MauiApp2.WinUI.app"/>
<assemblyIdentity version="1.0.0.0" name="BeginnersTasks.WinUI.app"/>

<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Foundation;

namespace MauiApp2;
namespace BeginnersTasks;

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ObjCRuntime;
using UIKit;

namespace MauiApp2;
namespace BeginnersTasks;

public class Program
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace MauiApp2.ViewModel;
namespace BeginnersTasks.ViewModel;

[QueryProperty("Text", "Text")]
public partial class DetailViewModel : ObservableObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace MauiApp2.ViewModel;
namespace BeginnersTasks.ViewModel;

public partial class MainViewModel : ObservableObject
{
IConnectivity connectivity;
readonly IConnectivity connectivity;
public MainViewModel(IConnectivity connectivity)
{
Items = new ObservableCollection<string>();
Items = [];
this.connectivity = connectivity;
}

Expand All @@ -23,23 +23,30 @@ public MainViewModel(IConnectivity connectivity)
[RelayCommand]
async Task Add()
{
// Assure text is not empty
if (string.IsNullOrWhiteSpace(Text))
return;

// Assure there's an internet connection
// else show an alert
if(connectivity.NetworkAccess != NetworkAccess.Internet)
{
await Shell.Current.DisplayAlert("Uh Oh!", "No Internet", "OK");
return;
}

// Add text to list of todos
Items.Add(Text);
// add our item

// Reset Text
Text = string.Empty;
}

[RelayCommand]
void Delete(string s)
{
// If the list of todos contains
// given string, remove it from list
if(Items.Contains(s))
{
Items.Remove(s);
Expand All @@ -49,7 +56,9 @@ void Delete(string s)
[RelayCommand]
async Task Tap(string s)
{
// Trigger a navigation to the detail page
// - See [AppShell] for how to add a routing to the app's navigation
// - See [DetailViewModel] for how to resolve the 'Text' query parameter
await Shell.Current.GoToAsync($"{nameof(DetailPage)}?Text={s}");
}

}
Loading