Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch committed Oct 9, 2024
1 parent 8d9bd0b commit 09d291a
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 81 deletions.
93 changes: 49 additions & 44 deletions BranchSDK/Platforms/Android/BranchAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,50 +156,55 @@ public override void InitSession(IBranchBUOSessionInterface callback)
}

public void ReInitSession(Intent intent, IBranchSessionInterface callback, Activity activity)
{
if (intent?.Data != null)
{
callbacksList.Clear();
BranchSessionListener obj = new BranchSessionListener(callback);
callbacksList.Add(obj as Object);

Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession Activity: " + activity);

intent.PutExtra("branch_force_new_session", true);
activity.Intent = intent;

AndroidNativeBranch.SessionBuilder(activity)
.WithCallback(obj)
.WithData(intent.Data)
.ReInit();
}
else
{
Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession: No URL in intent: " + intent);
}
}

public void ReInitSession(Intent intent, IBranchBUOSessionInterface callback, Activity activity)
{
if (intent?.Data != null)
{
callbacksList.Clear();
BranchBUOSessionListener obj = new BranchBUOSessionListener(callback);
callbacksList.Add(obj as Object);

intent.PutExtra("branch_force_new_session", true);
activity.Intent = intent;

AndroidNativeBranch.SessionBuilder(activity)
.WithCallback(obj)
.WithData(intent.Data)
.ReInit();
}
else
{
Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession: No URL in intent: " + intent);
}
}
// public void ReInitSession(Intent intent, IBranchSessionInterface callback, Activity activity)
// {
// if (intent?.Data != null)
// {
// callbacksList.Clear();
// BranchSessionListener obj = new BranchSessionListener(callback);
// callbacksList.Add(obj as Object);

// Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession Activity: " + activity);

// intent.PutExtra("branch_force_new_session", true);
// activity.Intent = intent;

// CurrActivity = activity;

// AndroidNativeBranch.SessionBuilder(activity)
// .WithCallback(obj)
// .WithData(intent.Data)
// .ReInit();
// }
// else
// {
// Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession: No URL in intent: " + intent);
// }
// }

// public void ReInitSession(Intent intent, IBranchBUOSessionInterface callback, Activity activity)
// {
// if (intent?.Data != null)
// {
// callbacksList.Clear();
// BranchBUOSessionListener obj = new BranchBUOSessionListener(callback);
// callbacksList.Add(obj as Object);

// intent.PutExtra("branch_force_new_session", true);
// activity.Intent = intent;

// CurrActivity = activity;

// AndroidNativeBranch.SessionBuilder(activity)
// .WithCallback(obj)
// .WithData(intent.Data)
// .ReInit();
// }
// else
// {
// Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession: No URL in intent: " + intent);
// }
// }

public override void NotifyNativeInit()
{
Expand Down
18 changes: 12 additions & 6 deletions BranchSDK/Platforms/Android/BranchAndroidLifeCycleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,28 @@ public void OnActivityPaused(Activity activity) { }

public void OnActivityStarted(Activity activity)
{
Console.WriteLine("BranchSDK .NET MAUI: OnActivityStarted: " + activity.LocalClassName);
BranchAndroid.getInstance().CurrActivity = activity;
IncreaseActivityCounter (activity);
IncreaseActivityCounter(activity);
}

public void OnActivityStopped(Activity activity)
{
Console.WriteLine("BranchSDK .NET MAUI: OnActivityStopped: " + activity.LocalClassName);
DecreaseActivityCounter();
}

private void IncreaseActivityCounter(Activity activity)
{
if (activeCounter == 0)
{
if (callback != null) {
BranchAndroid.getInstance ().InitSession (callback);
} else if (callbackBUO != null) {
BranchAndroid.getInstance ().InitSession (callbackBUO);
if (callback != null)
{
BranchAndroid.getInstance().InitSession(callback);
}
else if (callbackBUO != null)
{
BranchAndroid.getInstance().InitSession(callbackBUO);
}
}

Expand All @@ -55,7 +60,8 @@ private void IncreaseActivityCounter(Activity activity)

private void DecreaseActivityCounter()
{
if (activeCounter > 0) {
if (activeCounter > 0)
{
activeCounter--;
}
}
Expand Down
25 changes: 16 additions & 9 deletions BranchSDK/Platforms/Android/Helpers/BranchSessionListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,33 @@

namespace BranchSDK.Droid
{
public class BranchSessionListener: Java.Lang.Object, IO.Branch.Referral.AndroidNativeBranch.IBranchReferralInitListener
public class BranchSessionListener : Java.Lang.Object, IO.Branch.Referral.AndroidNativeBranch.IBranchReferralInitListener
{
private IBranchSessionInterface callback = null;

public BranchSessionListener(IBranchSessionInterface callback) {
public BranchSessionListener(IBranchSessionInterface callback)
{
this.callback = callback;
}

public void OnInitFinished (JSONObject data, IO.Branch.Referral.BranchError error) {
if (callback == null) {
public void OnInitFinished(JSONObject data, IO.Branch.Referral.BranchError error)
{
Console.WriteLine("BranchSessionListener: OnInitFinished with data: " + data + " error: " + error);
if (callback == null)
{
return;
}

if (error == null) {
if (error == null)
{

callback.InitSessionComplete (BranchAndroidUtils.ToDictionary(data));
} else {
callback.InitSessionComplete(BranchAndroidUtils.ToDictionary(data));
}
else
{

BranchError err = new BranchError (error.Message, error.ErrorCode);
callback.SessionRequestError (err);
BranchError err = new BranchError(error.Message, error.ErrorCode);
callback.SessionRequestError(err);
}
}
}
Expand Down
26 changes: 11 additions & 15 deletions Timber/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,30 @@ protected override void OnCreate(Bundle savedInstanceState)
base.OnCreate(savedInstanceState);
LogMessage("BRANCHSDK .NET MAUI: MainActivity.OnCreate");
BranchAndroid.Init(this, "key_live_nf8w3l1WBpzWdlC00KsLNdmbuEccK6Yr", this);

}

protected override void OnStart()
{
base.OnStart();
LogMessage("BRANCHSDK .NET MAUI: MainActivity.OnStart");
//BranchAndroid.Init(this, "key_live_nf8w3l1WBpzWdlC00KsLNdmbuEccK6Yr", this);
Branch.GetInstance().NotifyNativeToInit();

}

protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
LogMessage("BRANCHSDK .NET MAUI: MainActivity.OnNewIntent");
BranchAndroid.getInstance().ReInitSession(intent, this, this);
base.OnNewIntent(intent);
intent.PutExtra("branch_force_new_session", true);
Intent = intent;
}

public void InitSessionComplete(Dictionary<string, object> data)
{
LogMessage("BRANCHSDK .NET MAUI: InitSessionComplete: ");
foreach (var key in data.Keys)
if (data == null)
{
LogMessage(key + " : " + data[key].ToString());
LogMessage("BRANCHSDK .NET MAUI: InitSessionComplete with data: null");
}
else
{
var dataString = string.Join(", ", data.Select(kvp => $"{kvp.Key}: {kvp.Value?.ToString() ?? "null"}"));
LogMessage($"BRANCHSDK .NET MAUI: InitSessionComplete with data: {dataString}");
}
}


public void SessionRequestError(BranchError error)
{
LogMessage("BRANCHSDK .NET MAUI: SessionRequestError: ");
Expand Down
8 changes: 4 additions & 4 deletions Timber/Platforms/Android/MainApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Timber;
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

public override void OnCreate()
{
Expand Down
3 changes: 0 additions & 3 deletions Timber/Platforms/Android/Resources/branch.json

This file was deleted.

0 comments on commit 09d291a

Please sign in to comment.