+ @if(Base64File != null && FileSize != null){
- @File.ContentType (@formatSizeUnits(FileSize))
+ @FileContentType (@formatSizeUnits(FileSize))
}
@@ -43,26 +46,35 @@
@code {
// private IBrowserFile? File { get; set; }
- private FileResult? File { get; set; }
- private string? Base64File { get; set; }
- private long? FileSize { get; set; }
- private string? Base64Url {
- get {
- if(File == null || Base64File == null) return null;
-
- return $"data:{File.ContentType};base64,{Base64File}";
- }
- }
- private string Description { get; set; }
- private bool loading = false;
+ [Parameter]
+ public string? Base64File { get; set; }
+ [Parameter]
+ public long? FileSize { get; set; }
+ [Parameter]
+ public string? FileContentType { get; set; }
+ [Parameter]
+ public string? Description { get; set; }
[Parameter]
public string id { get; set; }
+ [Parameter]
+ public bool Active { get; set; }
+
+ private bool loading = false;
+
+ private FileResult? File { get; set; }
+ private string? Base64Url {
+ get {
+ if (FileContentType == null || Base64File == null) return null;
+
+ return $"data:{FileContentType};base64,{Base64File}";
+ }
+ }
public async Task PostPic() {
loading = true;
await InvokeAsync(StateHasChanged);
- PutPicResponseData? response = await api.PutPic(State.SelectedAddressName, File);
+ PutPicResponseData? response = await api.PutPic(State.SelectedAddressName, Base64File);
if(!string.IsNullOrEmpty(Description) && response != null && !string.IsNullOrEmpty(response.Id)) {
await api.PostPicDescription(State.SelectedAddressName, response.Id, Description);
await State.RefreshPics();
@@ -78,6 +90,13 @@
}
+ protected override async Task OnAfterRenderAsync(bool firstRender) {
+ await base.OnAfterRenderAsync(firstRender);
+ if (firstRender) {
+ string tmp = "tmp";
+ }
+ }
+
// private async Task ChangeFile(InputFileChangeEventArgs e){
// File = e.File;
// }
@@ -94,7 +113,7 @@
return formatted;
}
-
+
private async Task PicFromMedia(EventArgs e) {
File = await MediaPicker.Default.PickPhotoAsync();
@@ -107,6 +126,7 @@
}
private async Task PopulateFileDetails() {
+ FileContentType = File.ContentType;
FileSize = await Utilities.FileSize(File);
Base64File = await Utilities.Base64FromFile(File);
}
diff --git a/Components/Pages/SharePic.razor b/Components/Pages/SharePic.razor
new file mode 100644
index 0000000..e0a3059
--- /dev/null
+++ b/Components/Pages/SharePic.razor
@@ -0,0 +1,51 @@
+@page "/sharepic"
+@inject NavigationManager navigationManager
+@inject AuthenticationStateProvider AuthStateProvider
+@inject State State
+
+
+ Upload an image to some.pics
+
+
+
+
+
+
+
+
+
+@code {
+ public string SharePhoto { get; set; }
+ public long? SharePhotoSize { get; set; }
+ public string? SharePhotoContentType { get; set; }
+ public string? SharePhotoText { get; set; }
+
+ protected override async Task OnInitializedAsync() {
+ await checkLogin();
+
+ SharePhoto = State.SharePhoto;
+ SharePhotoContentType = State.SharePhotoContentType;
+ SharePhotoSize = State.SharePhotoSize;
+ SharePhotoText = State.SharePhotoText;
+
+ State.SharePhoto = null;
+ State.SharePhotoContentType = null;
+ State.SharePhotoSize = null;
+ State.SharePhotoText = null;
+ }
+
+ private async Task
checkLogin() {
+ var authState = await AuthStateProvider.GetAuthenticationStateAsync();
+ var user = authState.User;
+
+ if (user.Identity is not null && user.Identity.IsAuthenticated) {
+ return true;
+ }
+ else {
+ navigationManager.NavigateTo("/login");
+ return false;
+ }
+ }
+}
diff --git a/Components/Pages/ShareText.razor b/Components/Pages/ShareText.razor
index 1bf1b97..bf73415 100644
--- a/Components/Pages/ShareText.razor
+++ b/Components/Pages/ShareText.razor
@@ -1,6 +1,7 @@
-@page "/sharetext/{Text}"
+@page "/sharetext"
@inject NavigationManager navigationManager
@inject AuthenticationStateProvider AuthStateProvider
+@inject State State
Share a post to status.lol
@@ -16,19 +17,20 @@
@code {
- [Parameter]
- public string Text { get; set; }
+ public string? Text { get; set; }
protected override async Task OnInitializedAsync() {
await checkLogin();
- }
- // protected override async Task OnAfterRenderAsync(bool firstRender) {
- // await base.OnAfterRenderAsync(firstRender);
- // if (firstRender && await checkLogin()) {
- // await JS.InvokeVoidAsync("focusText");
- // }
- // }
+ Text = State.ShareString;
+
+ if (!string.IsNullOrWhiteSpace(State.ShareStringSubject)) {
+ Text = $"{State.ShareStringSubject}\n\n{State.ShareString}";
+ }
+
+ State.ShareStringSubject = null;
+ State.ShareString = null;
+ }
private async Task checkLogin() {
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
diff --git a/Models/State.cs b/Models/State.cs
index 74ca8dc..9b13e1d 100644
--- a/Models/State.cs
+++ b/Models/State.cs
@@ -49,6 +49,8 @@ namespace Neighbourhood.omg.lol.Models {
IntentReceived?.Invoke(this, EventArgs.Empty);
}
}
+ public string? ShareStringSubject { get; set; }
+
private string? _sharePhoto;
public string? SharePhoto {
get => _sharePhoto;
@@ -57,6 +59,9 @@ namespace Neighbourhood.omg.lol.Models {
IntentReceived?.Invoke(this, EventArgs.Empty);
}
}
+ public long? SharePhotoSize { get; set; }
+ public string? SharePhotoContentType { get; set; }
+ public string? SharePhotoText { get; set; }
// refreshing
public event PropertyChangedEventHandler? PropertyChanged;
diff --git a/Platforms/Android/MainActivity.cs b/Platforms/Android/MainActivity.cs
index 0fcc2b4..fd1a494 100644
--- a/Platforms/Android/MainActivity.cs
+++ b/Platforms/Android/MainActivity.cs
@@ -2,6 +2,7 @@
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;
@@ -25,15 +26,31 @@ namespace Neighbourhood.omg.lol {
if (intent != null && intent.Type != null) {
if (intent.Type.StartsWith("text/")) //string
{
+ string? subject = intent.GetStringExtra(Intent.ExtraSubject);
string? shareString = intent.GetStringExtra(Intent.ExtraText);
if (!string.IsNullOrWhiteSpace(shareString)) {
State state = IPlatformApplication.Current!.Services.GetService()!;
+ state.ShareStringSubject = subject;
state.ShareString = shareString;
}
}
else if (intent.Type.StartsWith("image/")) //image
{
- var uri = intent.GetParcelableExtra(Intent.ExtraStream);
+ string? shareString = intent.GetStringExtra(Intent.ExtraText);
+ var extra = intent.GetParcelableExtra(Intent.ExtraStream);
+ if (extra is Android.Net.Uri) {
+ Stream? stream = ContentResolver?.OpenInputStream(extra as Android.Net.Uri);
+ byte[] bytes = new byte[stream?.Length ?? 0];
+ stream?.Read(bytes, 0, bytes.Length);
+ string base64String = Convert.ToBase64String(bytes);
+ if (!string.IsNullOrWhiteSpace(base64String)) {
+ State state = IPlatformApplication.Current!.Services.GetService()!;
+ state.SharePhotoContentType = intent.Type;
+ state.SharePhotoSize = bytes.Length;
+ state.SharePhotoText = shareString;
+ state.SharePhoto = base64String;
+ }
+ }
}
else if (intent.Type.Equals(Intent.ActionSendMultiple)) //Multiple file
{