More reorg, cleaning up some warnings

This commit is contained in:
Gordon Pedersen 2024-07-02 10:01:06 +10:00
parent 1b0155d064
commit fd0300fccb
10 changed files with 50 additions and 48 deletions

View file

@ -1,8 +1,5 @@
using Microsoft.AspNetCore.Components.Authorization;
using Neighbourhood.omg.lol.Models;
using System.Security.Claims;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Neighbourhood.omg.lol {
public class CustomAuthenticationStateProvider : AuthenticationStateProvider {

5
Classes/FeatureFlags.cs Normal file
View file

@ -0,0 +1,5 @@
namespace Neighbourhood.omg.lol {
public static class FeatureFlags {
public static bool Following { get; } = false;
}
}

View file

@ -1,12 +1,7 @@
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Neighbourhood.omg.lol {
public class NavigatorService {
internal NavigationManager NavigationManager { get; set; }
internal NavigationManager? NavigationManager { get; set; }
}
}

View file

@ -3,11 +3,20 @@ using System.ComponentModel;
using System.Globalization;
using System.Text.Json;
using Neighbourhood.omg.lol.Models;
using System.Runtime.CompilerServices;
namespace Neighbourhood.omg.lol {
public class State : INotifyPropertyChanged {
// Feature flags
public bool FeatureFollowing { get; } = false;
// Events
public event EventHandler<EventArgs>? IntentReceived;
public event PropertyChangedEventHandler? PropertyChanged;
// Create the OnPropertyChanged method to raise the event
// The calling member's name will be used as the parameter.
protected void OnPropertyChanged([CallerMemberName] string? name = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
protected void OnIntentRecieved() => IntentReceived?.Invoke(this, EventArgs.Empty);
// Main data lists
public List<Status>? Statuses { get; set; }
public List<Pic>? Pics { get; set; }
@ -43,6 +52,7 @@ namespace Neighbourhood.omg.lol {
else {
string selectedAddressJson = JsonSerializer.Serialize(_selectedAddress);
Preferences.Default.Set("selectedaddress", selectedAddressJson);
OnPropertyChanged();
}
}
}
@ -69,13 +79,12 @@ namespace Neighbourhood.omg.lol {
}
// share intent stuff
public event EventHandler<EventArgs>? IntentReceived;
private string? _shareString;
public string? ShareString {
get => _shareString;
set {
_shareString = value;
IntentReceived?.Invoke(this, EventArgs.Empty);
OnIntentRecieved();
}
}
public string? ShareStringSubject { get; set; }
@ -85,7 +94,7 @@ namespace Neighbourhood.omg.lol {
get => _sharePhoto;
set {
_sharePhoto = value;
IntentReceived?.Invoke(this, EventArgs.Empty);
OnIntentRecieved();
}
}
public long? SharePhotoSize { get; set; }
@ -93,13 +102,12 @@ namespace Neighbourhood.omg.lol {
public string? SharePhotoText { get; set; }
// refreshing
public event PropertyChangedEventHandler? PropertyChanged;
private bool _isRefreshing;
public bool IsRefreshing {
get => _isRefreshing;
private set {
_isRefreshing = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsRefreshing)));
OnPropertyChanged();
}
}
@ -133,7 +141,7 @@ namespace Neighbourhood.omg.lol {
get => _canRefresh;
set {
_canRefresh = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CanRefresh)));
OnPropertyChanged();
}
}
@ -179,12 +187,14 @@ namespace Neighbourhood.omg.lol {
}
public async Task RemoveAccountDetails() {
Preferences.Default.Clear();
AccountInfo = null;
AddressList = null;
SelectedAddress = null;
Following = null;
api.RemoveToken();
await Task.Run(() => {
Preferences.Default.Clear();
AccountInfo = null;
AddressList = null;
SelectedAddress = null;
Following = null;
api.RemoveToken();
});
}
public bool IsFollowing(string address) => Following?.Contains(address) ?? false;
@ -218,7 +228,7 @@ namespace Neighbourhood.omg.lol {
public async Task<List<string>?> GetDirectory(bool forceRefresh = false) {
if (forceRefresh || this.AddressDirectory == null || this.AddressDirectory.Count == 0) {
IdnMapping idn = new IdnMapping();
this.AddressDirectory = (await api.Directory()).Select(s => {
this.AddressDirectory = (await api.Directory())?.Select(s => {
if (s.StartsWith("xn--")) return idn.GetUnicode(s);
else return s;
}).ToList();

View file

@ -1,10 +1,5 @@
using Markdig;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Neighbourhood.omg.lol
{

View file

@ -32,7 +32,7 @@
</a>
}
}
@if (State.FeatureFollowing && State.IsAuthorized) {
@if (FeatureFlags.Following && State.IsAuthorized) {
<a class="m s row" href="/feed">
<i class="square fa-solid fa-list-timeline"></i>
<span>Feed</span>

View file

@ -21,7 +21,7 @@
<i class="square fa-duotone fa-address-book"></i>
<div class="label">Address Directory</div>
</NavLink>
@if (State.FeatureFollowing) {
@if (FeatureFlags.Following) {
<AuthorizeView>
<Authorized>
<NavLink class="l nav-link" href="/feed">

View file

@ -11,8 +11,7 @@
<div class="row center-align">
<img class="profile avatar" src="https://profiles.cache.lol/@Address/picture" alt="@Address" />
</div>
@if (State.FeatureFollowing)
{
@if (FeatureFlags.Following) {
<div class="row center-align">
@if (State.IsFollowing(Address)) {
<button id="follow-button" @onclick="() => {State.Unfollow(Address);InvokeAsync(StateHasChanged);}">

View file

@ -1,9 +1,6 @@
using Markdig;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Neighbourhood.omg.lol.Models;
using System.Reflection;
namespace Neighbourhood.omg.lol {
public static class MauiProgram {
@ -22,8 +19,6 @@ namespace Neighbourhood.omg.lol {
builder.Services.AddSingleton<State>();
builder.Services.AddSingleton<NavigatorService>();
//ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
//builder.Services.AddSingleton<IConfiguration>(configurationBuilder.AddUserSecrets<App>().Build());
using Stream stream = App.Assembly.GetManifestResourceStream($"{App.Name}.appsettings.json")!;
var config = new ConfigurationBuilder().AddJsonStream(stream).Build();
builder.Configuration.AddConfiguration(config);

View file

@ -2,10 +2,9 @@
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Net;
using Android.OS;
using Microsoft.Extensions.DependencyInjection;
using Neighbourhood.omg.lol.Models;
using Android.Views;
using System.Diagnostics;
namespace Neighbourhood.omg.lol {
[Activity(Exported = true, Theme = "@style/Maui.SplashTheme", LaunchMode = LaunchMode.SingleTop, MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
@ -13,14 +12,13 @@ namespace Neighbourhood.omg.lol {
[IntentFilter([Intent.ActionSend], Categories = [Intent.CategoryDefault], DataMimeType = "*/*")]
public class MainActivity : MauiAppCompatActivity {
protected override void OnCreate(Bundle savedInstanceState) {
protected override void OnCreate(Bundle? savedInstanceState) {
base.OnCreate(savedInstanceState);
// In case the app was opened (on first load) with an `ActionView` intent
OnNewIntent(this.Intent);
}
protected override void OnNewIntent(Intent? intent) {
base.OnNewIntent(intent);
if (intent != null && intent.Type != null) {
@ -37,9 +35,13 @@ namespace Neighbourhood.omg.lol {
else if (intent.Type.StartsWith("image/")) //image
{
string? shareString = intent.GetStringExtra(Intent.ExtraText);
var extra = intent.GetParcelableExtra(Intent.ExtraStream);
Java.Lang.Object? extra;
if (OperatingSystem.IsAndroidVersionAtLeast(33))
extra = intent.GetParcelableExtra(Intent.ExtraStream, Java.Lang.Class.FromType(typeof(Android.Net.Uri)));
else extra = intent.GetParcelableExtra(Intent.ExtraStream);
if (extra is Android.Net.Uri) {
Stream? stream = ContentResolver?.OpenInputStream(extra as Android.Net.Uri);
Stream? stream = ContentResolver?.OpenInputStream((Android.Net.Uri)extra);
byte[] bytes = new byte[stream?.Length ?? 0];
stream?.Read(bytes, 0, bytes.Length);
string base64String = Convert.ToBase64String(bytes);
@ -52,9 +54,13 @@ namespace Neighbourhood.omg.lol {
}
}
}
else if (intent.Type.Equals(Intent.ActionSendMultiple)) //Multiple file
else if (intent.Type.Equals(Intent.ActionSendMultiple)) //Multiple files
{
var uriList = intent.GetParcelableArrayListExtra(Intent.ExtraStream);
// TODO: we don't really support this at the moment.
//System.Collections.IList? uriList;
//if (OperatingSystem.IsAndroidVersionAtLeast(33))
// uriList = intent.GetParcelableArrayListExtra(Intent.ExtraStream, Java.Lang.Class.FromType(typeof(Android.Net.Uri)));
//else uriList = intent.GetParcelableArrayListExtra(Intent.ExtraStream);
}
}
}