Share target updates (including pics!)
Still need to work out the "multiple windows" type issue.
This commit is contained in:
parent
63d844e7a3
commit
f2025df922
6 changed files with 126 additions and 33 deletions
|
@ -20,12 +20,10 @@
|
|||
|
||||
private void IntentRecieved(object? sender = null, EventArgs? e = null) {
|
||||
if (!string.IsNullOrEmpty(State.ShareString)) {
|
||||
NavigationManager.NavigateTo($"/sharetext/{State.ShareString}");
|
||||
State.ShareString = null;
|
||||
NavigationManager.NavigateTo($"/sharetext");
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(State.SharePhoto)) {
|
||||
NavigationManager.NavigateTo($"/sharepic/{State.SharePhoto}");
|
||||
State.SharePhoto = null;
|
||||
NavigationManager.NavigateTo($"/sharepic");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
@inject IJSRuntime JS
|
||||
@inject State State
|
||||
@inject RestService api
|
||||
@inject NavigationManager navigationManager
|
||||
|
||||
<div class="overlay" data-ui="#@id"></div>
|
||||
<dialog id="@id">
|
||||
<div class="overlay @(Active ? "active" : string.Empty)" data-ui="#@id"></div>
|
||||
<dialog id="@id" class="@(Active ? "active" : string.Empty)" open="@Active">
|
||||
<h5>Share a picture</h5>
|
||||
<div class="row">
|
||||
<button @onclick="PicFromMedia"><i class="fa-solid fa-image"></i> Select a picture</button>
|
||||
|
@ -14,10 +15,12 @@
|
|||
<input type="text">
|
||||
<label>Select a picture</label>
|
||||
</div> *@
|
||||
@if(File != null && Base64File != null && FileSize != null){
|
||||
</div>
|
||||
<div class="row">
|
||||
@if(Base64File != null && FileSize != null){
|
||||
<img class="extra" src="@Base64Url">
|
||||
<small>
|
||||
@File.ContentType (@formatSizeUnits(FileSize))
|
||||
@FileContentType (@formatSizeUnits(FileSize))
|
||||
</small>
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
// }
|
||||
|
@ -107,6 +126,7 @@
|
|||
}
|
||||
|
||||
private async Task PopulateFileDetails() {
|
||||
FileContentType = File.ContentType;
|
||||
FileSize = await Utilities.FileSize(File);
|
||||
Base64File = await Utilities.Base64FromFile(File);
|
||||
}
|
||||
|
|
51
Components/Pages/SharePic.razor
Normal file
51
Components/Pages/SharePic.razor
Normal file
|
@ -0,0 +1,51 @@
|
|||
@page "/sharepic"
|
||||
@inject NavigationManager navigationManager
|
||||
@inject AuthenticationStateProvider AuthStateProvider
|
||||
@inject State State
|
||||
|
||||
<PageHeading title="Some.pics" icon="fa-solid fa-images">
|
||||
<Description>Upload an image to <a href="https://some.pics/">some.pics</a></Description>
|
||||
</PageHeading>
|
||||
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<button class="fab circle extra large-elevate" data-ui="#post-modal">
|
||||
<i class="fa-solid fa-camera-retro"></i>
|
||||
</button>
|
||||
<NewPicDialog id="post-modal" Active="true" Base64File="@SharePhoto" FileSize="@SharePhotoSize" FileContentType="@SharePhotoContentType" Description="@SharePhotoText"></NewPicDialog>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
|
||||
@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<bool> 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
@page "/sharetext/{Text}"
|
||||
@page "/sharetext"
|
||||
@inject NavigationManager navigationManager
|
||||
@inject AuthenticationStateProvider AuthStateProvider
|
||||
@inject State State
|
||||
|
||||
<PageHeading title="Status.lol" icon="fa-solid fa-message-smile">
|
||||
<Description>Share a post to <a href="https://status.lol">status.lol</a></Description>
|
||||
|
@ -16,19 +17,20 @@
|
|||
</AuthorizeView>
|
||||
|
||||
@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<bool> checkLogin() {
|
||||
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>()!;
|
||||
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>()!;
|
||||
state.SharePhotoContentType = intent.Type;
|
||||
state.SharePhotoSize = bytes.Length;
|
||||
state.SharePhotoText = shareString;
|
||||
state.SharePhoto = base64String;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (intent.Type.Equals(Intent.ActionSendMultiple)) //Multiple file
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue