Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions DeviceTests/DeviceTests.Shared/AppActions_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ public void IsSupported()

#if __ANDROID_25__ || __IOS__
[Fact]
public void GetSetItems()
public async Task GetSetItems()
{
if (AppActions.IsSupported)
if (!AppActions.IsSupported)
return;

var actions = new List<AppAction>
{
AppActions.Actions = new List<AppAction>
{
new AppAction("TEST1", "Test 1", "This is a test", new System.Uri("myapp://test1")),
new AppAction("TEST2", "Test 2", "This is a test 2", new System.Uri("myapp://test2")),
};

Assert.Contains(AppActions.Actions, a => a.ActionType == "TEST1");
}
new AppAction("TEST1", "Test 1", "This is a test", "myapp://test1"),
new AppAction("TEST2", "Test 2", "This is a test 2", "myapp://test2"),
};

await AppActions.SetAsync(actions);

var get = await AppActions.GetAsync();

Assert.Contains(get, a => a.Id == "TEST1");
}
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions Samples/Samples/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ protected override async void OnStart()
}

await AppActions.SetAsync(
new AppAction("App Info", id: "app_info", icon: "app_info_action_icon"),
new AppAction("Battery Info", id: "battery_info"));
new AppAction("app_info", "App Info", icon: "app_info_action_icon"),
new AppAction("battery_info", "Battery Info"));
}

void AppActions_OnAppAction(object sender, AppActionEventArgs e)
Expand Down
8 changes: 3 additions & 5 deletions Tests/AppActions_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using Xamarin.Essentials;
using Xunit;

Expand All @@ -10,11 +8,11 @@ public class AppActions_Tests
{
[Fact]
public void AppActions_SetActions() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => AppActions.Actions = new List<AppAction>());
Assert.ThrowsAsync<NotImplementedInReferenceAssemblyException>(() => AppActions.SetAsync(new List<AppAction>()));

[Fact]
public void AppActions_GetActions() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => AppActions.Actions);
Assert.ThrowsAsync<NotImplementedInReferenceAssemblyException>(() => AppActions.GetAsync());

[Fact]
public void AppActions_IsSupported() =>
Expand Down
9 changes: 3 additions & 6 deletions Xamarin.Essentials/AppActions/AppActions.android.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Android.Content;
using Android.Content.PM;
using Android.Content.Res;
using Android.Graphics.Drawables;
using AndroidUri = Android.Net.Uri;

namespace Xamarin.Essentials
{
Expand Down Expand Up @@ -39,7 +36,7 @@ static Task PlatformSetAsync(IEnumerable<AppAction> actions)
}

static AppAction ToAppAction(this ShortcutInfo shortcutInfo) =>
new AppAction(shortcutInfo.ShortLabel, shortcutInfo.LongLabel, shortcutInfo.Id);
new AppAction(shortcutInfo.Id, shortcutInfo.ShortLabel, shortcutInfo.LongLabel);

const string extraAppActionId = "EXTRA_XE_APP_ACTION_ID";
const string extraAppActionTitle = "EXTRA_XE_APP_ACTION_TITLE";
Expand All @@ -48,8 +45,8 @@ static AppAction ToAppAction(this ShortcutInfo shortcutInfo) =>

internal static AppAction ToAppAction(this Intent intent)
=> new AppAction(
intent.GetStringExtra(extraAppActionTitle),
intent.GetStringExtra(extraAppActionId),
intent.GetStringExtra(extraAppActionTitle),
intent.GetStringExtra(extraAppActionSubtitle),
intent.GetStringExtra(extraAppActionIcon));

Expand Down
28 changes: 24 additions & 4 deletions Xamarin.Essentials/AppActions/AppActions.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,35 @@ internal static AppAction ToAppAction(this UIApplicationShortcutItem shortcutIte
if (shortcutItem.UserInfo.TryGetValue((NSString)"id", out var idObj))
id = idObj?.ToString();

return new AppAction(shortcutItem.Type, id, shortcutItem.LocalizedTitle, shortcutItem.LocalizedSubtitle);
string icon = null;
if (shortcutItem.UserInfo.TryGetValue((NSString)"icon", out var iconObj))
icon = iconObj?.ToString();

return new AppAction(id, shortcutItem.LocalizedTitle, shortcutItem.LocalizedSubtitle, icon);
}

static UIApplicationShortcutItem ToShortcutItem(this AppAction action) =>
new UIApplicationShortcutItem(
static UIApplicationShortcutItem ToShortcutItem(this AppAction action)
{
var keys = new List<NSString>();
var values = new List<NSObject>();

// id
keys.Add((NSString)"id");
values.Add((NSString)action.Id);

// icon
if (!string.IsNullOrEmpty(action.Icon))
{
keys.Add((NSString)"icon");
values.Add((NSString)action.Icon);
}

return new UIApplicationShortcutItem(
AppActions.Type,
action.Title,
action.Subtitle,
action.Icon != null ? UIApplicationShortcutIcon.FromTemplateImageName(action.Icon) : null,
new NSDictionary<NSString, NSObject>((NSString)"id", (NSString)action.Id.ToString()));
new NSDictionary<NSString, NSObject>(keys.ToArray(), values.ToArray()));
}
}
}
7 changes: 4 additions & 3 deletions Xamarin.Essentials/AppActions/AppActions.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ public AppActionEventArgs(AppAction appAction)

public class AppAction
{
public AppAction(string title, string id, string subtitle = null, string icon = null)
public AppAction(string id, string title, string subtitle = null, string icon = null)
{
Title = title;
Id = id ?? throw new ArgumentNullException(nameof(id));
Title = title ?? throw new ArgumentNullException(nameof(title));

Subtitle = subtitle;
Icon = icon;
Id = id;
}

public string Title { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Essentials/AppActions/AppActions.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static async Task PlatformSetAsync(IEnumerable<AppAction> actions)
}

static AppAction ToAction(this JumpListItem item)
=> new AppAction(item.DisplayName, ArgumentsToId(item.Arguments), item.Description);
=> new AppAction(ArgumentsToId(item.Arguments), item.DisplayName, item.Description);

static string ArgumentsToId(string arguments)
{
Expand Down