Skip to content

Commit

Permalink
IHttpService.GetImageAsync use Polly & AppLogo Update SVG & Mobile UI…
Browse files Browse the repository at this point in the history
… MyPage
  • Loading branch information
AigioL committed Jun 9, 2021
1 parent c3fbeb3 commit 3eff9a4
Show file tree
Hide file tree
Showing 20 changed files with 169 additions and 21 deletions.
Binary file removed resources/AppIcon/Logo.png
Binary file not shown.
5 changes: 5 additions & 0 deletions resources/AppIcon/Logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/AppIcon/Logo_1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/AppIcon/Logo_256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/AppIcon/VisualElements_150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/AppIcon/VisualElements_70.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/ST.Client.Desktop.Avalonia/Application/UI/Assets/Icon.ico
Binary file not shown.
Binary file modified src/ST.Client.Desktop.Avalonia/Application/UI/Assets/Icon_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//using Android.Content;
//using Xamarin.Forms;
//using Xamarin.Forms.Platform.Android;
//using ARecyclerView = AndroidX.RecyclerView.Widget.RecyclerView;
//using XFRecyclerView = System.Application.UI.Views.Controls.RecyclerView;

//namespace System.Application.UI.Views.Controls
//{
// partial class RecyclerViewRenderer : ViewRenderer<XFRecyclerView, ARecyclerView>
// {
// TableViewModelRenderer _adapter;
// bool _disposed;

// public RecyclerViewRenderer(Context context) : base(context)
// {
// AutoPackage = false;
// }

// protected virtual TableViewModelRenderer GetModelRenderer(ARecyclerView listView, XFRecyclerView view)
// {
// return new TableViewModelRenderer(Context, listView, view);
// }

// protected override Size MinimumSize()
// {
// return new Size(20, 20);
// }

// protected override ARecyclerView CreateNativeControl()
// {
// return new ARecyclerView(Context);
// }

// protected override void OnElementChanged(ElementChangedEventArgs<XFRecyclerView> e)
// {
// base.OnElementChanged(e);

// var listView = Control;
// if (listView == null)
// {
// listView = CreateNativeControl();
// SetNativeControl(listView);
// }

// listView.Focusable = false;
// listView.DescendantFocusability = DescendantFocusability.AfterDescendants;

// var view = e.NewElement;

// _adapter = GetModelRenderer(listView, view);
// listView.Adapter = _adapter;
// }

// protected override void OnAttachedToWindow()
// {
// base.OnAttachedToWindow();

// if (Forms.IsLollipopOrNewer && Control != null)
// Control.NestedScrollingEnabled = (Parent.GetParentOfType<NestedScrollView>() != null);
// }

// class CellAdapter : ARecyclerView.Adapter
// {
// readonly Context context;

// public CellAdapter(Context context)
// {
// this.context = context;
// }
// }

// class TableViewModelRenderer : CellAdapter
// {
// public TableViewModelRenderer(Context context, ARecyclerView listView, XFRecyclerView view) : base(context)
// {
// }
// }
// }
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Application.UI.Views.Controls;
using Xamarin.Forms;
using XFRecyclerView = System.Application.UI.Views.Controls.RecyclerView;

[assembly: ExportRenderer(typeof(XFRecyclerView), typeof(RecyclerViewRenderer))]

namespace System.Application.UI.Views.Controls
{
internal partial class RecyclerViewRenderer
{
}
}
5 changes: 1 addition & 4 deletions src/ST.Client.Mobile/ST.Client.Mobile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Identity.Client" Version="4.31.0" />
<PackageReference Include="Xam.Plugins.Forms.ImageCircle" Version="3.0.0.5" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="5.0.0.2012" />
<PackageReference Include="StatefulModel.Standard" Version="0.1.0" />
Expand Down Expand Up @@ -107,8 +108,4 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Folder Include="UI\Views\Controls\" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions src/ST.Client.Mobile/UI/Views/Controls/RecyclerView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;

namespace System.Application.UI.Views.Controls
{
public class RecyclerView : TableView
{
}
}
46 changes: 30 additions & 16 deletions src/ST.Client.Mobile/UI/Views/MyPage.xaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xfp_controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
xmlns:resx="clr-namespace:System.Application.UI.Resx"
x:Class="System.Application.UI.Views.MyPage"
BackgroundColor="{DynamicResource WindowBackground}"
Title="{x:Static resx:AppResources.My}">
<ContentPage.Resources>
<OnPlatform x:Key="baseline_phone_black_24"
x:TypeArguments="FileImageSource"
<OnPlatform x:Key="baseline_phone_black_24"
x:TypeArguments="FileImageSource"
Default="baseline_phone_iphone_black_24">
<OnPlatform.Platforms>
<!--<On Platform="iOS" Value="baseline_phone_iphone_black_24" />-->
<On Platform="Android" Value="baseline_phone_android_black_24" />
<On Platform="Android" Value="baseline_phone_android_black_24"/>
</OnPlatform.Platforms>
</OnPlatform>
</ContentPage.Resources>
<ContentPage.Content>
<TableView>
<TableRoot>
<TableSection>
<ImageCell ImageSource="baseline_person_black_24" Text="NickName" />
<ImageCell ImageSource="baseline_account_box_black_24" Text="{x:Static resx:AppResources.User_EditProfile}" />
<ImageCell ImageSource="{x:StaticResource Key=baseline_phone_black_24}" Text="{x:Static resx:AppResources.User_BindPhoneNum}" />
<ImageCell ImageSource="{x:StaticResource Key=baseline_phone_black_24}" Text="{x:Static resx:AppResources.User_ChangePhoneNum}" />
<ImageCell ImageSource="baseline_settings_black_24" Text="{x:Static resx:AppResources.Settings}" />
<ImageCell ImageSource="baseline_info_black_24" Text="{x:Static resx:AppResources.About}" />
</TableSection>
</TableRoot>
</TableView>
<StackLayout Orientation="Vertical">
<xfp_controls:CircleImage Source="avater_default"
HeightRequest="100"
WidthRequest="100"
BorderColor="#C0C0C0"
BorderThickness="0.5"
Aspect="AspectFill"
HorizontalOptions="Center"
Margin="0,24,0,4"/>
<Label HorizontalOptions="Center"
Text="{x:Static resx:AppResources.LoginAndRegister}"
Margin="0,0,0,4"
FontSize="24"/>
<TableView>
<TableRoot>
<TableSection>
<ImageCell ImageSource="baseline_account_box_black_24" Text="{x:Static resx:AppResources.User_EditProfile}"/>
<ImageCell ImageSource="{x:StaticResource Key=baseline_phone_black_24}" Text="{x:Static resx:AppResources.User_BindPhoneNum}"/>
<ImageCell ImageSource="{x:StaticResource Key=baseline_phone_black_24}" Text="{x:Static resx:AppResources.User_ChangePhoneNum}"/>
<ImageCell ImageSource="baseline_settings_black_24" Text="{x:Static resx:AppResources.Settings}"/>
<ImageCell ImageSource="baseline_info_black_24" Text="{x:Static resx:AppResources.About}"/>
</TableSection>
</TableRoot>
</TableView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
31 changes: 30 additions & 1 deletion src/ST.Client/Services/Implementation/HttpServiceImpl.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Polly;
using System.Collections.Concurrent;
using System.IO;
using System.IO.FileFormats;
Expand Down Expand Up @@ -307,7 +308,35 @@ public HttpServiceImpl(
return string.IsNullOrEmpty(file) ? null : File.OpenRead(file);
}

public async Task<string?> GetImageAsync(string requestUri, string channelType, CancellationToken cancellationToken)
#region Polly

const int numRetries = 5;

static TimeSpan PollyRetryAttempt(int attemptNumber)
{
var powY = attemptNumber % numRetries;
var timeSpan = TimeSpan.FromMilliseconds(Math.Pow(2, powY));
int addS = attemptNumber / numRetries;
if (addS > 0) timeSpan = timeSpan.Add(TimeSpan.FromSeconds(addS));
return timeSpan;
}

#endregion

Task<string?> IHttpService.GetImageAsync(string requestUri, string channelType, CancellationToken cancellationToken)
{
return GetImageLocalFilePathByPollyAsync(requestUri, channelType, cancellationToken);
}

public async Task<string?> GetImageLocalFilePathByPollyAsync(string requestUri, string channelType, CancellationToken cancellationToken)
{
var r = await Policy.HandleResult<string?>(string.IsNullOrWhiteSpace)
.WaitAndRetryAsync(numRetries, PollyRetryAttempt)
.ExecuteAsync(ct => GetImageLocalFilePathAsync(requestUri, channelType, ct), cancellationToken);
return r;
}

public async Task<string?> GetImageLocalFilePathAsync(string requestUri, string channelType, CancellationToken cancellationToken)
{
if (!IsHttpUrl(requestUri)) return null;

Expand Down
1 change: 1 addition & 0 deletions src/ST/Services/IHttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public interface IHttpService
/// <param name="requestUri"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete]
Task<Stream?> GetImageStreamAsync(string requestUri, CancellationToken cancellationToken = default);
}

Expand Down

0 comments on commit 3eff9a4

Please sign in to comment.