Skip to content
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
22 changes: 22 additions & 0 deletions ChatApplication/ChatApplication.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35521.163 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatApplication", "ChatApplication\ChatApplication.csproj", "{6BE82A5A-80DD-4553-A26D-FF454EB100EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6BE82A5A-80DD-4553-A26D-FF454EB100EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BE82A5A-80DD-4553-A26D-FF454EB100EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BE82A5A-80DD-4553-A26D-FF454EB100EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BE82A5A-80DD-4553-A26D-FF454EB100EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions ChatApplication/ChatApplication/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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:ChatApplication"
x:Class="ChatApplication.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
15 changes: 15 additions & 0 deletions ChatApplication/ChatApplication/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace ChatApplication
{
public partial class App : Application
{
public App()
{
InitializeComponent();
}

protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new AppShell());
}
}
}
14 changes: 14 additions & 0 deletions ChatApplication/ChatApplication/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="ChatApplication.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ChatApplication"
Shell.FlyoutBehavior="Flyout"
Title="ChatApplication">

<ShellContent
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
10 changes: 10 additions & 0 deletions ChatApplication/ChatApplication/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ChatApplication
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
68 changes: 68 additions & 0 deletions ChatApplication/ChatApplication/ChatApplication.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->

<!-- Note for MacCatalyst:
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

<OutputType>Exe</OutputType>
<RootNamespace>ChatApplication</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!-- Display name -->
<ApplicationTitle>ChatApplication</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.chatapplication</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.21" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Syncfusion.Maui.ListView" Version="*" />
</ItemGroup>

</Project>
76 changes: 76 additions & 0 deletions ChatApplication/ChatApplication/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?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"
xmlns:listView="clr-namespace:Syncfusion.Maui.ListView;assembly=Syncfusion.Maui.ListView"
xmlns:local="clr-namespace:ChatApplication"
x:Class="ChatApplication.MainPage">

<ContentPage.BindingContext>
<local:ViewModel/>
</ContentPage.BindingContext>

<ContentPage.Resources>
<ResourceDictionary>
<DataTemplate x:Key="IncomingMessage">
<Grid Padding="10,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Image WidthRequest="40" HeightRequest="40" HorizontalOptions="Start"
VerticalOptions="Start" Margin="5"
Source="{Binding ProfilePicture}">
</Image>

<StackLayout Grid.Column="1" Orientation="Vertical" Padding="5,0">
<Label Text="{Binding Name}" TextColor="Gray" FontSize="12"
FontAttributes="Bold" HorizontalOptions="Start"/>
<Label Text="{Binding Text}" TextColor="Black" BackgroundColor="LightGray"
Padding="10" MaximumWidthRequest="250"
HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
<Label Text="{Binding Timestamp, StringFormat='{0:HH:mm}'}"
TextColor="Gray" FontSize="10" HorizontalOptions="Start"/>
</StackLayout>
</Grid>
</DataTemplate>

<DataTemplate x:Key="OutgoingMessage">
<Grid Padding="10,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<StackLayout Grid.Column="1" Orientation="Vertical" Padding="5,0"
VerticalOptions="CenterAndExpand">
<Label Text="{Binding Name}" TextColor="Gray" FontSize="12"
FontAttributes="Bold" HorizontalOptions="End" />
<Label Text="{Binding Text}" TextColor="White"
BackgroundColor="DodgerBlue" Padding="10"
HorizontalOptions="EndAndExpand" VerticalOptions="Center"
MaximumWidthRequest="250" />
<Label Text="{Binding Timestamp, StringFormat='{0:HH:mm}'}"
TextColor="Gray" FontSize="10" HorizontalOptions="End"/>
</StackLayout>

<Image Grid.Column="2" WidthRequest="40" HeightRequest="40" Margin="5"
HorizontalOptions="End" VerticalOptions="Start"
Source="{Binding ProfilePicture}">
</Image>
</Grid>
</DataTemplate>

<local:MyDataTemplateSelector x:Key="dataTemplateSelector"
IncomingDataTemplate="{StaticResource IncomingMessage}"
OutgoingDataTemplate="{StaticResource OutgoingMessage}"/>
</ResourceDictionary>
</ContentPage.Resources>

<listView:SfListView ItemsSource="{Binding Messages}"
ItemTemplate="{StaticResource dataTemplateSelector}"
AutoFitMode="Height">
</listView:SfListView>

</ContentPage>
56 changes: 56 additions & 0 deletions ChatApplication/ChatApplication/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.ObjectModel;

namespace ChatApplication
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}

public class Message
{
public string? Name { get; set; }
public string? Text { get; set; }
public bool IsIncoming { get; set; }
public string? ProfilePicture { get; set; }
public DateTime Timestamp { get; set; }
}

public class ViewModel
{
public ObservableCollection<Message> Messages { get; set; }

public ViewModel()
{
Messages = new ObservableCollection<Message>
{
new Message { Name = "You", Text = "Hi everyone! I'm very excited to share the news that our team is launching a new mobile application.", IsIncoming = false, ProfilePicture = "andrea.png", Timestamp = DateTime.Now.AddMinutes(-2)},
new Message { Name = "Harrison", Text = "Oh, that's great!", IsIncoming = true, ProfilePicture = "harrison.png", Timestamp = DateTime.Now.AddMinutes(-1)},
new Message { Name = "Margaret", Text = "That is a good news.", IsIncoming = true, ProfilePicture = "margaret.png", Timestamp = DateTime.Now.AddMinutes(2)},
new Message { Name = "Nancy", Text = "Are we going to develop the app natively or as a hybrid?", IsIncoming = true, ProfilePicture = "nancy.png", Timestamp = DateTime.Now.AddMinutes(3)},
new Message { Name = "You", Text = "We should develop this app using .NET MAUI, as it offers a native experience and performance while allowing for seamless cross-platform development.", IsIncoming = false, ProfilePicture = "andrea.png", Timestamp = DateTime.Now.AddMinutes(5)},
new Message { Name = "Steven", Text = "I haven't heard of .NET MAUI. What's .NET MAUI?", IsIncoming = true, ProfilePicture = "steven.png", Timestamp = DateTime.Now.AddMinutes(7)},
new Message { Name = "You", Text = ".NET MAUI is a new library that allows you to build native user interfaces for Android, iOS, macOS, and Windows from a single shared C# codebase.", IsIncoming = false, ProfilePicture = "andrea.png", Timestamp = DateTime.Now.AddMinutes(9)},
new Message { Name = "David", Text = "That's impressive.", IsIncoming = true, ProfilePicture = "david.png", Timestamp = DateTime.Now.AddMinutes(10)},
};
}
}

public class MyDataTemplateSelector : DataTemplateSelector
{
public DataTemplate? IncomingDataTemplate { get; set; }
public DataTemplate? OutgoingDataTemplate { get; set; }
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
if (item is Message message)
{
return message.IsIncoming ? IncomingDataTemplate : OutgoingDataTemplate;
}

return null;
}
}
}
27 changes: 27 additions & 0 deletions ChatApplication/ChatApplication/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
using Syncfusion.Maui.Core.Hosting;

namespace ChatApplication
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureSyncfusionCore()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +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>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
11 changes: 11 additions & 0 deletions ChatApplication/ChatApplication/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

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

namespace ChatApplication
{
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Foundation;

namespace ChatApplication
{
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- See https://aka.ms/maui-publish-app-store#add-entitlements for more information about adding entitlements.-->
<dict>
<!-- App Sandbox must be enabled to distribute a MacCatalyst app through the Mac App Store. -->
<key>com.apple.security.app-sandbox</key>
<true/>
<!-- When App Sandbox is enabled, this value is required to open outgoing network connections. -->
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

Loading