Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
khmMouna committed Jul 15, 2024
1 parent 8c3c9e7 commit af4fc56
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/Airship.Net/IAirship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ public interface IAirship
IEnumerable<string> Tags { get; }

/// <summary>
/// Gets the channel subscription list.
/// Gets the channel subscription lists.
/// </summary>
/// <value>The channel subscription list.</value>
void FetchChannelSubscriptionList(Action<object> list);
/// <value>The channel subscription lists.</value>
void FetchChannelSubscriptionLists(Action<List<string>> subscriptions);

/// <summary>
/// Gets the contact subscription list.
/// Gets the contact subscription lists.
/// </summary>
/// <value>The contact subscription list.</value>
void FetchContactSubscriptionList(Action<Dictionary<string, object>> list);
/// <value>The contact subscription lists.</value>
void FetchContactSubscriptionLists(Action<Dictionary<string, List<string>>> subscriptions);

/// <summary>
/// Get the channel ID for the device.
Expand Down
82 changes: 68 additions & 14 deletions src/Airship.Net/Platforms/Android/Airship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using static Android.Provider.CalendarContract;
using System.Collections;
using System.Collections.ObjectModel;
using Android.Util;

namespace AirshipDotNet
{
Expand Down Expand Up @@ -200,31 +201,84 @@ private static Features FeaturesFromUAFeatures(int uAFeatures)

public IEnumerable<string> Tags => UAirship.Shared().Channel.Tags;

public void FetchChannelSubscriptionList(Action<object> list)
private class ResultCallback : Java.Lang.Object, IResultCallback
{
Action<Java.Lang.Object?> action;

internal ResultCallback(Action<Java.Lang.Object?> action)
{
this.action = action;
}

public void OnResult(Java.Lang.Object? result)
{
action.Invoke(result);
}
}

private List<string> CastHashSetToList(HashSet set)
{
var list = new List<string>();

var value = set.Iterator();
if (value is not null)
{
while (value.HasNext)
{
var nextValue = (string?)value.Next();
if (nextValue is not null)
{
list.Add(nextValue);
}
}
}
return list;
}

public void FetchChannelSubscriptionLists(Action<List<string>> subscriptions)
{
PendingResult subscriptionsPendingResult = UAirship.Shared().Channel.FetchSubscriptionListsPendingResult();
var result = subscriptionsPendingResult.Result;
list(result);

subscriptionsPendingResult.AddResultCallback(new ResultCallback((result) =>
{
Console.WriteLine("-- ON RESULT!!! " + result + ", (" + result.GetType() + ")");
var list = new List<string>();
if (result is HashSet)
{
list = CastHashSetToList((HashSet)result);
}

subscriptions(list);
}));
}

public void FetchContactSubscriptionList(Action<Dictionary<string, object>> list)
public void FetchContactSubscriptionLists(Action<Dictionary<string, List<string>>> subscriptions)
{
PendingResult subscriptionsPendingResult = UAirship.Shared().Contact.FetchSubscriptionListsPendingResult();
var result = subscriptionsPendingResult.Result;
Dictionary<string, object> dictionary = new Dictionary<string, object>();
if (result is not null)

subscriptionsPendingResult.AddResultCallback(new ResultCallback((result) =>
{
HashMap map = (HashMap)result;
foreach (string key in map.KeySet())
Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
if (result is not null)
{
var value = map.Get(key);
if (value is not null)
var typedResult = (HashMap)result;
foreach (string? key in typedResult.KeySet())
{
dictionary.Add(key, value);
if (key is not null)
{
var typedValue = typedResult.Get(key);

if (typedValue is not null && typedValue is HashSet)
{
var list = CastHashSetToList((HashSet)typedValue);
dictionary.Add(key, list);
}

}
}
}
}
list(dictionary);
subscriptions(dictionary);
}));
}

public string? ChannelId => UAirship.Shared().Channel.Id;
Expand Down
40 changes: 32 additions & 8 deletions src/Airship.Net/Platforms/iOS/Airship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,35 +202,59 @@ private static Features FeaturesFromUAFeatures(UAFeatures uAFeatures)

public IEnumerable<string> Tags => UAirship.Channel.Tags;

public void FetchChannelSubscriptionList(Action<object> list)
public void FetchChannelSubscriptionLists(Action<List<string>> subscriptions)
{
UAirship.Channel.FetchSubscriptionLists((lists) =>
{
list(lists);
var list = new List<string>();
if (lists is not null)
{
foreach (string subscription in list)
{
list.Add(subscription.ToString());
}
}
subscriptions(list);
});
}

public void FetchContactSubscriptionList(Action<Dictionary<string, object>> list)
public void FetchContactSubscriptionLists(Action<Dictionary<string, List<String>>> subscriptions)
{
UAirship.Contact.FetchSubscriptionLists((lists) =>
{
var dictionary = new Dictionary<string, object>();
var dictionary = new Dictionary<string, List<string>>();
if (lists is not null)
{
foreach (KeyValuePair<NSObject, NSObject> kvp in lists)
{
string key = kvp.Key.ToString();
object value = (object)kvp.Value;
if (key is not null && value is not null)
var scopes = ((UAChannelScopes)kvp.Value).Values;

if (key is not null && scopes is not null)
{
dictionary.Add(key, value);
var list = new List<string>();
foreach (var scope in scopes)
{
list.Add(ScopeOrdinalToString(scope));
}
dictionary.Add(key, list);
}
}
}
list(dictionary);
subscriptions(dictionary);
});
}

private string ScopeOrdinalToString(NSNumber ordinal)
=> ordinal.LongValue switch
{
0 => "app",
1 => "web",
2 => "email",
3 => "sms",
_ => "unknown",
};

public string? ChannelId => UAirship.Channel.Identifier;

public void GetNamedUser(Action<string> namedUser)
Expand Down

0 comments on commit af4fc56

Please sign in to comment.