Skip to content

Commit

Permalink
replace asset util with asset provider
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-mh committed Aug 25, 2023
1 parent fc10baf commit a2d5bfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 51 deletions.
20 changes: 13 additions & 7 deletions AuthenticatorPro.Droid/src/Activity/AboutActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Android.OS;
using Android.Views;
using Android.Webkit;
using AuthenticatorPro.Core;
using AuthenticatorPro.Droid.Util;
using Google.Android.Material.AppBar;
using Google.Android.Material.Color;
Expand All @@ -16,7 +17,12 @@ namespace AuthenticatorPro.Droid.Activity
[Activity]
internal class AboutActivity : BaseActivity
{
public AboutActivity() : base(Resource.Layout.activityAbout) { }
private readonly IAssetProvider _assetProvider;

public AboutActivity() : base(Resource.Layout.activityAbout)
{
_assetProvider = Dependencies.Resolve<IAssetProvider>();
}

protected override async void OnCreate(Bundle savedInstanceState)
{
Expand Down Expand Up @@ -46,29 +52,29 @@ protected override async void OnCreate(Bundle savedInstanceState)
Logger.Error(e);
version = "unknown";
}

var surface = MaterialColors.GetColor(this, Resource.Attribute.colorSurface, 0);
var onSurface = MaterialColors.GetColor(this, Resource.Attribute.colorOnSurface, 0);
var primary = MaterialColors.GetColor(this, Resource.Attribute.colorPrimary, 0);

var icon = await AssetUtil.ReadAllBytes(Assets, "icon.png");
var icon = await _assetProvider.ReadBytesAsync("icon.png");

#if FDROID
const string extraLicenseFile = "license.extra.fdroid.html";
#else
const string extraLicenseFile = "license.extra.html";
#endif

var extraLicense = await AssetUtil.ReadAllTextAsync(Assets, extraLicenseFile);
var extraLicense = await _assetProvider.ReadStringAsync(extraLicenseFile);

var html = (await AssetUtil.ReadAllTextAsync(Assets, "about.html"))
var html = (await _assetProvider.ReadStringAsync("about.html"))
.Replace("%ICON", $"data:image/png;base64,{Convert.ToBase64String(icon)}")
.Replace("%VERSION", version)
.Replace("%LICENSE", extraLicense)
.Replace("%SURFACE", ColourToHexString(surface))
.Replace("%ON_SURFACE", ColourToHexString(onSurface))
.Replace("%PRIMARY", ColourToHexString(primary));

var webView = FindViewById<WebView>(Resource.Id.webView);
webView.LoadDataWithBaseURL("file:///android_asset", html, "text/html", "utf-8", null);
}
Expand Down
44 changes: 0 additions & 44 deletions AuthenticatorPro.Droid/src/Util/AssetUtil.cs

This file was deleted.

0 comments on commit a2d5bfc

Please sign in to comment.