Skip to content

Commit

Permalink
Merge pull request #55 from egvijayanand/working
Browse files Browse the repository at this point in the history
C# version of News App
  • Loading branch information
egvijayanand authored Sep 29, 2022
2 parents 8298901 + e10d1f5 commit 015f237
Show file tree
Hide file tree
Showing 54 changed files with 8,870 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ Available under the `src` directory:
- [Bottom Sheets](https://github.com/PremSaiVarada/DemoCustomSheets)
- [MyTasks](https://github.com/jsuarezruiz/netmaui-mytasks-app-challenge)
- [MonkeyFinder](https://github.com/dotnet-presentations/dotnet-maui-workshop) - Designed as part of .NET MAUI - Workshop by James Montemagno
- [News App](https://github.com/henduck/MAUINewsApp)
* There's some issue in making use of FlexLayout as a BindableLayout in C# Markup hence replaced it with StackLayout and Grid on two of the pages
27 changes: 27 additions & 0 deletions src/C#-Samples/MAUINewsApp/MAUIDemo.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 17.0.31611.283
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MAUIDemo", "MAUIDemo\MAUIDemo.csproj", "{C2486E33-3658-4D5D-829F-ACAF6ECCED7C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C2486E33-3658-4D5D-829F-ACAF6ECCED7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2486E33-3658-4D5D-829F-ACAF6ECCED7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2486E33-3658-4D5D-829F-ACAF6ECCED7C}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{C2486E33-3658-4D5D-829F-ACAF6ECCED7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2486E33-3658-4D5D-829F-ACAF6ECCED7C}.Release|Any CPU.Build.0 = Release|Any CPU
{C2486E33-3658-4D5D-829F-ACAF6ECCED7C}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions src/C#-Samples/MAUINewsApp/MAUIDemo/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace MAUIDemo;

public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new AppShell();
}
}

11 changes: 11 additions & 0 deletions src/C#-Samples/MAUINewsApp/MAUIDemo/App.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/C#-Samples/MAUINewsApp/MAUIDemo/AppShell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using MAUIDemo.Views;

namespace MAUIDemo;

public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();

Routing.RegisterRoute("article", typeof(ArticlePage));

HomeTab.Icon = ImageSource.FromResource("MAUIDemo.Resources.Images.home.png", this.GetType().Assembly);
SectionsTab.Icon = ImageSource.FromResource("MAUIDemo.Resources.Images.categories.png", this.GetType().Assembly);
BookmarksTab.Icon = ImageSource.FromResource("MAUIDemo.Resources.Images.bookmarks.png", this.GetType().Assembly);
ProfileTab.Icon = ImageSource.FromResource("MAUIDemo.Resources.Images.profile.png", this.GetType().Assembly);
}
}
67 changes: 67 additions & 0 deletions src/C#-Samples/MAUINewsApp/MAUIDemo/AppShell.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/C#-Samples/MAUINewsApp/MAUIDemo/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
global using MAUIDemo;
global using MAUIDemo.Models;
global using MAUIDemo.Services;
global using MAUIDemo.ViewModels;
global using MAUIDemo.Views;
global using Microsoft.Maui.Devices;
global using Microsoft.Maui.Graphics;
global using Microsoft.Maui.Layouts;
// Aliases
global using MauiFrame = Microsoft.Maui.Controls.Frame;
8 changes: 8 additions & 0 deletions src/C#-Samples/MAUINewsApp/MAUIDemo/Imports.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global using CommunityToolkit.Maui.Markup;
global using VijayAnand.Toolkit.Markup;

global using static Microsoft.Maui.Graphics.Colors;
global using static CommunityToolkit.Maui.Markup.GridRowsColumns;
global using static VijayAnand.Toolkit.Markup.ResourceHelper;
global using static VijayAnand.Toolkit.Markup.SwipeViewHelper;
global using static VijayAnand.Toolkit.Markup.VisualStateHelper;
104 changes: 104 additions & 0 deletions src/C#-Samples/MAUINewsApp/MAUIDemo/MAUIDemo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!--<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>-->
<TargetFrameworks>net6.0-android;net6.0-ios</TargetFrameworks>
<!--<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.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);net6.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>MAUIDemo</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

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

<!-- App Identifier -->
<ApplicationId>com.companyname.mauidemo</ApplicationId>
<ApplicationIdGuid>0329e02f-11cd-4807-9229-ff63b99b87d8</ApplicationIdGuid>

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

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.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>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-ios|AnyCPU'">
<EnableCodeSigning>false</EnableCodeSigning>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" Color="#477ee5" />

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

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

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

<ItemGroup>
<None Remove="Views\" />
<None Remove="ViewModels\" />
<None Remove="Models\" />
<None Remove="Resources\Fonts\NotoSerif-Bold.ttf" />
<None Remove="Resources\Images\Profile.png" />
<None Remove="Resources\Images\Bookmarks.png" />
<None Remove="Resources\Images\Categories.png" />
<None Remove="Resources\Images\Home.png" />
<None Remove="Resources\Images\home.png" />
<None Remove="Resources\Images\categories.png" />
<None Remove="Resources\Images\bookmarks.png" />
<None Remove="Resources\Images\profile.png" />
<None Remove="Resources\Fonts\Poppins-Regular.ttf" />
<None Remove="Resources\Fonts\Poppins-SemiBold.ttf" />
<None Remove="Resources\Fonts\Poppins-Bold.ttf" />
<None Remove="Resources\Fonts\MaterialIconsOutlined-Regular.otf" />
<None Remove="Services\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Views\" />
<Folder Include="ViewModels\" />
<Folder Include="Models\" />
<Folder Include="Services\" />
</ItemGroup>
<ItemGroup>
<MauiXaml Update="Views\HomePage.xaml">
<SubType></SubType>
</MauiXaml>
<MauiXaml Update="Views\SectionsPage.xaml">
<SubType></SubType>
</MauiXaml>
<MauiXaml Update="Views\BookmarksPage.xaml">
<SubType></SubType>
</MauiXaml>
<MauiXaml Update="Views\ProfilePage.xaml">
<SubType></SubType>
</MauiXaml>
<MauiXaml Update="Views\ArticlePage.xaml">
<SubType></SubType>
</MauiXaml>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Images\home.png" />
<EmbeddedResource Include="Resources\Images\categories.png" />
<EmbeddedResource Include="Resources\Images\bookmarks.png" />
<EmbeddedResource Include="Resources\Images\profile.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="1.0.1" />
<PackageReference Include="VijayAnand.Toolkit.Markup" Version="1.0.1-pre1" />
</ItemGroup>
</Project>
46 changes: 46 additions & 0 deletions src/C#-Samples/MAUINewsApp/MAUIDemo/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace MAUIDemo;

public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.UseMauiApp<App>()
.RegisterAppServices()
.RegisterViewModels()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("NotoSerif-Bold.ttf", "NotoSerifBold");
fonts.AddFont("Poppins-Bold.ttf", "PoppinsBold");
fonts.AddFont("Poppins-SemiBold.ttf", "PoppinsSemibold");
fonts.AddFont("Poppins-Regular.ttf", "Poppins");
fonts.AddFont("MaterialIconsOutlined-Regular.otf", "Material");
});

return builder.Build();
}

public static MauiAppBuilder RegisterAppServices(this MauiAppBuilder builder)
{
builder.Services.AddSingleton<INewsService, MockNewsService>();

return builder;
}

public static MauiAppBuilder RegisterViewModels(this MauiAppBuilder builder)
{
builder.Services.AddTransient<HomeViewModel>();
builder.Services.AddTransient<SectionsViewModel>();
builder.Services.AddTransient<ArticleViewModel>();
builder.Services.AddTransient<BookmarksViewModel>();

builder.Services.AddTransient<HomePage>();
builder.Services.AddTransient<SectionsPage>();
builder.Services.AddTransient<ArticlePage>();
builder.Services.AddTransient<BookmarksPage>();

return builder;
}
}
27 changes: 27 additions & 0 deletions src/C#-Samples/MAUINewsApp/MAUIDemo/Models/Article.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace MAUIDemo.Models
{
public class Article
{
public string Id { get; set; }

public string Title { get; }

public string Subtitle { get; }

public string ImageURL { get; }

public string Category { get; }

public string Time { get; }

public Article(string id, string title, string subtitle, string imageUrl, string category, string time)
{
Id = id;
Title = title;
Subtitle = subtitle;
ImageURL = imageUrl;
Category = category;
Time = time;
}
}
}
24 changes: 24 additions & 0 deletions src/C#-Samples/MAUINewsApp/MAUIDemo/Models/Category.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace MAUIDemo.Models
{
public class Category
{
public string Name { get; set; }

public string MaterialIcon { get; set; }

/// <summary>Not included as part of original Xaml version,
/// since FlexLayout is having some issues, turned it into a Grid.</summary>
public int ColIndex { get; set; }

/// <summary>Not included as part of original Xaml version,
/// since FlexLayout is having some issues, turned it into a Grid.</summary>
public int RowIndex { get; set; }

public Category(string name, string icon)
{
Name = name;
MaterialIcon = icon;
}
}
}

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>
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 MAUIDemo;

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}

Loading

0 comments on commit 015f237

Please sign in to comment.