Skip to content

Commit

Permalink
Merge pull request #205 from garymathews/fixes
Browse files Browse the repository at this point in the history
fix(android): lifecycleContainer
  • Loading branch information
garymathews authored Jan 21, 2021
2 parents c826bee + 6751145 commit 0e44b0e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 46 deletions.
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 11.0.0
version: 11.0.1
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: facebook
Expand Down
80 changes: 36 additions & 44 deletions android/src/facebook/ActivityWorkerProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Please see the LICENSE included with this distribution for details.
*
* Appcelerator Titanium Mobile
* Copyright (c) 2015 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2020 by Axway, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*
Expand All @@ -13,81 +13,73 @@

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.facebook.*;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiLifecycle.OnActivityResultEvent;
import org.appcelerator.titanium.TiLifecycle.OnInstanceStateEvent;

@Kroll.proxy(creatableInModule = TiFacebookModule.class)
public class ActivityWorkerProxy extends KrollProxy implements OnActivityResultEvent, OnInstanceStateEvent
public class ActivityWorkerProxy extends KrollProxy implements OnActivityResultEvent
{
private static final String TAG = "ActivityWorkerProxy";
AccessTokenTracker accessTokenTracker;

// Constructor
private AccessTokenTracker accessTokenTracker;

public ActivityWorkerProxy()
{
super();
}

// Handle creation options
@Override
public void handleCreationDict(KrollDict options)
{
super.handleCreationDict(options);
}

@Override
public void onCreate(Activity activity, Bundle savedInstanceState)
{
Log.d(TAG, "onCreate called for ActivityWorkerProxy");
((TiBaseActivity) activity).addOnActivityResultListener(this);
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken)
{
if (currentAccessToken == null) {
// User logged out
TiFacebookModule.getFacebookModule().fireEvent(TiFacebookModule.EVENT_LOGOUT, null);
} else {
// AccessToken refreshed
if (TiFacebookModule.getFacebookModule().isAccessTokenRefreshCalled()) {
TiFacebookModule.getFacebookModule().setAccessTokenRefreshCalled(false);
TiFacebookModule.getFacebookModule().fireEvent(TiFacebookModule.EVENT_TOKEN_UPDATED, null);
// If `lifecycleContainer` was set, this will be our proxy activity.
final Activity activity = getActivity();

if (activity instanceof TiBaseActivity) {
final TiBaseActivity baseActivity = (TiBaseActivity) activity;

// Obtain activity result.
baseActivity.addOnActivityResultListener(this);

// Create access token tracker.
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken)
{
if (currentAccessToken == null) {

// User logged out.
TiFacebookModule.getFacebookModule().fireEvent(TiFacebookModule.EVENT_LOGOUT, null);
} else {

// AccessToken updated.
if (TiFacebookModule.getFacebookModule().isAccessTokenRefreshCalled()) {
TiFacebookModule.getFacebookModule().setAccessTokenRefreshCalled(false);
TiFacebookModule.getFacebookModule().fireEvent(TiFacebookModule.EVENT_TOKEN_UPDATED, null);
}
}
}
}
};
}

@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data)
{
Log.d(TAG, "ActivityWorkerProxy onActivityResult");
TiFacebookModule.getFacebookModule().getCallbackManager().onActivityResult(requestCode, resultCode, data);
};
}
}

@Override
public void onDestroy(Activity activity)
{
Log.d(TAG, "ActivityWorkerProxy onDestroy");
Log.d(TAG, "onDestroy");
accessTokenTracker.stopTracking();
}

@Override
public void onSaveInstanceState(Bundle outState)
{
Log.d(TAG, "ActivityWorkerProxy onSaveInstanceState");
}

@Override
public void onRestoreInstanceState(Bundle inState)
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data)
{
Log.d(TAG, "ActivityWorkerProxy onRestoreInstanceState");
Log.d(TAG, "onActivityResult");
TiFacebookModule.getFacebookModule().getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
}
}
4 changes: 3 additions & 1 deletion android/src/facebook/TiFacebookModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,14 @@ public void logPushNotificationOpen(KrollDict parameters, @Kroll.argument(option
}

@Kroll.method
public void logCustomEvent(String event, @Kroll.argument(optional = true) Double valueToSum,
public void logCustomEvent(String event, @Kroll.argument(optional = true) Object value,
@Kroll.argument(optional = true) KrollDict parameters)
{
Activity activity = TiApplication.getInstance().getCurrentActivity();
AppEventsLogger logger = AppEventsLogger.newLogger(activity);
Bundle paramBundle = parameters != null ? Utils.mapToBundle(parameters) : null;
Double valueToSum = value != null ? TiConvert.toDouble(value) : null;

if (logger != null) {
if (valueToSum == null) {
logger.logEvent(event, paramBundle);
Expand Down

0 comments on commit 0e44b0e

Please sign in to comment.