Skip to content

Commit

Permalink
Merge pull request #7 from ReticentRobot/SharpnadoCollectionView
Browse files Browse the repository at this point in the history
Sharpnado collection view
  • Loading branch information
ReticentRobot authored Aug 31, 2023
2 parents b57a364 + abcbf37 commit 5f47efe
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 104 deletions.
9 changes: 6 additions & 3 deletions Disc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
<ApplicationId>com.reticentrobot.disc</ApplicationId>
<TrimMode>link</TrimMode>
<NoWarn>1701;1702</NoWarn>
<RunAOTCompilation>True</RunAOTCompilation>
<RunAOTCompilation>False</RunAOTCompilation>
<JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0-maccatalyst|AnyCPU'">
Expand All @@ -61,7 +62,8 @@
<TrimMode>link</TrimMode>
<PublishTrimmed>True</PublishTrimmed>
<NoWarn>1701;1702</NoWarn>
<RunAOTCompilation>True</RunAOTCompilation>
<RunAOTCompilation>False</RunAOTCompilation>
<JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -117,7 +119,8 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="110.2.0" />
<PackageReference Include="Sentry.Maui" Version="3.35.1" />
<PackageReference Include="Sentry.Maui" Version="3.36.0" />
<PackageReference Include="Sharpnado.CollectionView.Maui" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CommunityToolkit.Maui;
using Disc.Services;
using Disc.Views;
using Sharpnado.CollectionView;
using System.Diagnostics;

namespace Disc;
Expand Down Expand Up @@ -38,7 +39,10 @@ public static MauiApp CreateMauiApp()
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
;
// Initialize SharpnadoCollectionVIew
.UseSharpnadoCollectionView(loggerEnable: false);
;

// TODO: Add light mode support, for now - setting app to always load in dark mode
// Application.Current.UserAppTheme = AppTheme.Dark;

Expand Down
59 changes: 3 additions & 56 deletions Models/Posts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,13 @@

namespace Disc.Models
{
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class CommunityBannerImage
{
[JsonPropertyName("mimetype")] public string? Mimetype { get; set; }
[JsonPropertyName("width")] public int Width { get; set; }
[JsonPropertyName("height")] public int Height { get; set; }
[JsonPropertyName("size")] public int Size { get; set; }
[JsonPropertyName("averageColor")] public string? AverageColor { get; set; }
[JsonPropertyName("url")] public string? Url { get; set; }
[JsonPropertyName("copies")] public List<Copy>? Copies { get; set; }
}

public class CommunityProPic
{
[JsonPropertyName("mimetype")] public string? Mimetype { get; set; }
[JsonPropertyName("width")] public int Width { get; set; }
[JsonPropertyName("height")] public int Height { get; set; }
[JsonPropertyName("size")] public int Size { get; set; }
[JsonPropertyName("averageColor")] public string? AverageColor { get; set; }
[JsonPropertyName("url")] public string? Url { get; set; }
[JsonPropertyName("copies")] public List<Copy>? Copies { get; set; }
}

public class Copy
{
[JsonPropertyName("copyId")] public string? CopyId { get; set; }
[JsonPropertyName("width")] public int Width { get; set; }
[JsonPropertyName("height")] public int Height { get; set; }
[JsonPropertyName("size")] public int Size { get; set; }
[JsonPropertyName("url")] public string? Url { get; set; }
[JsonPropertyName("objectFit")] public string? ObjectFit { get; set; }
}

public class Image
{
[JsonPropertyName("mimetype")] public string? Mimetype { get; set; }
[JsonPropertyName("width")] public int Width { get; set; }
[JsonPropertyName("height")] public int Height { get; set; }
[JsonPropertyName("size")] public int Size { get; set; }
[JsonPropertyName("averageColor")] public string? AverageColor { get; set; }
[JsonPropertyName("url")] public string? ImageUrl { get; set; }
[JsonPropertyName("copies")] public List<Copy>? Copies { get; set; }
}
Expand All @@ -56,38 +23,18 @@ public class Link

public class Post
{
[JsonPropertyName("id")] public string? Id { get; set; }
[JsonPropertyName("type")] public string? Type { get; set; }
[JsonPropertyName("publicId")] public string? PublicId { get; set; }
[JsonPropertyName("userId")] public string? UserId { get; set; }
[JsonPropertyName("username")] public string? Username { get; set; }
[JsonPropertyName("userGroup")] public string? UserGroup { get; set; }
[JsonPropertyName("userDeleted")] public bool UserDeleted { get; set; }
[JsonPropertyName("isPinned")] public bool IsPinned { get; set; }
[JsonPropertyName("communityId")] public string? CommunityId { get; set; }
[JsonPropertyName("communityName")] public string? CommunityName { get; set; }
[JsonPropertyName("communityProPic")] public CommunityProPic? CommunityProPic { get; set; }
[JsonPropertyName("communityBannerImage")] public CommunityBannerImage? CommunityBannerImage { get; set; }
[JsonPropertyName("title")] public string? Title { get; set; }
[JsonPropertyName("body")] public object? Body { get; set; }
[JsonPropertyName("link")] public Link? Link { get; set; }
[JsonPropertyName("locked")] public bool Locked { get; set; }
[JsonPropertyName("lockedBy")] public object? LockedBy { get; set; }
[JsonPropertyName("lockedAt")] public object? LockedAt { get; set; }
[JsonPropertyName("upvotes")] public int Upvotes { get; set; }
[JsonPropertyName("downvotes")] public int Downvotes { get; set; }
[JsonPropertyName("hotness")] public object? Hotness { get; set; }
[JsonPropertyName("createdAt")] public DateTime CreatedAt { get; set; }
[JsonPropertyName("editedAt")] public object? EditedAt { get; set; }
[JsonPropertyName("lastActivityAt")] public DateTime LastActivityAt { get; set; }
[JsonPropertyName("deleted")] public bool Deleted { get; set; }
[JsonPropertyName("deletedAt")] public object? DeletedAt { get; set; }
[JsonPropertyName("deletedContent")] public bool DeletedContent { get; set; }
//[JsonPropertyName("editedAt")] public object? EditedAt { get; set; }
[JsonPropertyName("noComments")] public int NoComments { get; set; }
[JsonPropertyName("comments")] public object? Comments { get; set; }
[JsonPropertyName("commentsNext")] public object? CommentsNext { get; set; }
[JsonPropertyName("userVoted")] public string? UserVoted { get; set; }
[JsonPropertyName("userVotedUp")] public string? UserVotedUp { get; set; }
//[JsonPropertyName("userVoted")] public string? UserVoted { get; set; }
//[JsonPropertyName("userVotedUp")] public string? UserVotedUp { get; set; }
}


Expand Down
5 changes: 3 additions & 2 deletions Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?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>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.reticentrobot.disc" android:versionCode="1" android:versionName=".01">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true" android:label="Disc"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="33" />
</manifest>
2 changes: 1 addition & 1 deletion Platforms/Android/env.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MONO_GC_PARAMS=nursery-size=128m
MONO_GC_PARAMS=nursery-size=256m
28 changes: 5 additions & 23 deletions ViewModels/PostsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,11 @@ public partial class PostsViewModel : BaseViewModel

public ObservableCollection<Post> Posts { get; set; }

//handle refreshing
private bool listRefreshing = false;
public bool ListRefreshing
{
get => listRefreshing;
set => SetProperty(ref listRefreshing, value);
}

// constructor to initialize objects
public PostsViewModel(IServiceProvider serviceProvider)
{
Debug.WriteLine("Setting _restService to restService");
_restService = serviceProvider.GetRequiredService<RestService>();

var client = _restService.client;
Debug.WriteLine("Client Value in constructor: " + client);

Posts = new ObservableCollection<Post>();
}

Expand All @@ -79,8 +67,6 @@ public async Task LoadPosts()

var request = new RestRequest(url);
var TotalPostsBeforePull = Posts.Count; //Total number of posts before pulling new posts

Debug.WriteLine("Client Value in LoadPosts: " + client); ;
var content = await _restService.client.GetAsync(request);

//set json options
Expand All @@ -91,20 +77,16 @@ public async Task LoadPosts()

if (content.StatusCode.ToString() == "OK")
{
//IsLoadingMoreItems = true;
Data = JsonSerializer.Deserialize<Root>(content.Content, options);

var NewPosts = Data.Posts.Count; //Total number of new posts grabbed

var PostsCount = NewPosts + TotalPostsBeforePull; //Total number of posts after pulling new posts

//var Index = NewPosts - Constants.PageSize; //Get the root index of the new posts pulled in
var Index = 0;
Debug.WriteLine(Index);
while (NewPosts > Index) //while the total number of posts is greater than the total number of posts minus the limit of posts to add
// Loop through the new posts and add them to Data.Posts
var Target = 0;
while (NewPosts > Target)
{
Posts.Add(Data.Posts[Index]);
Index++;
Posts.Add(Data.Posts[Target]);
Target++;
}
}
else
Expand Down
37 changes: 21 additions & 16 deletions Views/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
Order="Primary"
IconImageSource="icon_three_dots_darkmode.png" />
</ContentPage.ToolbarItems>

<CollectionView
x:Name="PostsCollection"
ItemsSource="{Binding Posts}"
ItemsSource="{Binding Posts, Mode=OneTime}"
BackgroundColor="{AppThemeBinding Light=AntiqueWhite, Dark=#1C1D20}"
RemainingItemsThreshold="5"
RemainingItemsThresholdReached="OnCollectionViewRemainingItemsThresholdReached"
Expand All @@ -42,10 +42,11 @@
<DataTemplate x:Name="CompactView" x:DataType="models:Post">
<Grid x:Name="PostsGrid"
RowSpacing="0"
ColumnSpacing="0">
ColumnSpacing="0"
>
<Grid.RowDefinitions>
<RowDefinition Height="7" />
<RowDefinition Height="Auto" />
<RowDefinition Height="40" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
Expand Down Expand Up @@ -78,7 +79,7 @@
WidthRequest="55"
>
<Image
Source="{Binding Link.Image.ImageUrl, StringFormat='https://discuit.net{0}'}"
Source="{Binding Link.Image.ImageUrl, StringFormat='https://discuit.net{0}', Mode=OneTime}"
Aspect="AspectFill"
HeightRequest="60"
WidthRequest="60"
Expand All @@ -90,15 +91,15 @@
<!-- Define a TapGestureRecognizer and handle its Tapped event -->
<TapGestureRecognizer
Tapped="OnTapGestureRecognizerTapped"
CommandParameter="{Binding Link.LinkUrl}"/>
CommandParameter="{Binding Link.LinkUrl, Mode=OneTime}"/>
</Image.GestureRecognizers>
</Image>
</Border>
<Label
Grid.Column="2"
Grid.Row="1"
FontSize="14"
Text="{Binding Title}"
Text="{Binding Title, Mode=OneTime}"
LineBreakMode="WordWrap"
MaxLines="2"
FontAttributes="None"
Expand All @@ -112,9 +113,11 @@
Padding="0">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding CommunityName}" FontSize="11" TextColor="{Binding CommunityName, Converter={StaticResource communityNameColor}}" />
<!--<Span Text="{Binding CommunityName}" FontSize="11" TextColor="{Binding CommunityName, Converter={StaticResource communityNameColor}}" />-->
<Span Text="{Binding CommunityName, Mode=OneTime}" FontSize="11" />
<Span Text="" TextColor="Grey" FontSize="11" />
<Span Text="{Binding Username}" FontSize="11" TextColor="{Binding Username, Converter={StaticResource usernameColor}}" />
<!--<Span Text="{Binding Username}" FontSize="11" TextColor="{Binding Username, Converter={StaticResource usernameColor}}" />-->
<Span Text="{Binding Username, Mode=OneTime}" FontSize="11" />
</FormattedString>
</Label.FormattedText>
</Label>
Expand All @@ -126,9 +129,10 @@
Padding="0">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding CreatedAt, Converter={StaticResource createdAt}}" FontSize="11" />
<!--<Span Text="{Binding CreatedAt, Converter={StaticResource createdAt}}" FontSize="11" />-->
<Span Text="{Binding CreatedAt, Mode=OneTime}" FontSize="11" />
<Span Text="" TextColor="Grey" FontSize="11" />
<Span Text="{Binding Link.Hostname}" FontSize="11" />
<Span Text="{Binding Link.Hostname, Mode=OneTime}" FontSize="11" />
</FormattedString>
</Label.FormattedText>
</Label>
Expand All @@ -148,7 +152,8 @@
</MultiBinding>
</Label.Text>
</Label>
<Image
<!--Source="{Binding Type, Converter={StaticResource typeToImage}}"-->
<!--<Image
Source="{Binding Type, Converter={StaticResource typeToImage}}"
Grid.Row="2"
Grid.RowSpan="2"
Expand All @@ -162,8 +167,8 @@
<Image.Behaviors>
<toolkit:IconTintColorBehavior TintColor="White" />
</Image.Behaviors>
</Image>
<ImageButton
</Image>-->
<!--<ImageButton
Grid.Row="5"
Grid.RowSpan="2"
Grid.Column="4"
Expand Down Expand Up @@ -240,9 +245,9 @@
<Image.Behaviors>
<toolkit:IconTintColorBehavior TintColor="White" />
</Image.Behaviors>
</Image>
</Image>-->



</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
Expand Down
3 changes: 1 addition & 2 deletions Views/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ private void OnChevronClicked(object sender, EventArgs e)
Grid.SetRow(imageButton, nextRow);
}

async void OnTapGestureRecognizerTapped(object sender, TappedEventArgs args)
async void OnTapGestureRecognizerTapped(object sender, TappedEventArgs args)
{

LinkInfo linkInfo = new LinkInfo();
linkInfo.LinkUrl = args.Parameter as string;

Expand Down

0 comments on commit 5f47efe

Please sign in to comment.