Skip to content

Commit

Permalink
Merge pull request #563 from adjust/v500_sdk2079
Browse files Browse the repository at this point in the history
[android] API renaming setEnable onCreate and setOfflineMode
  • Loading branch information
MahdiZTD authored May 30, 2024
2 parents a942610 + 662bfb9 commit 69f3b98
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,25 @@ <h1 style="width:400px;height:35px;text-align:center;">Adjust Facebook Pixel Dem
var btnEnableOfflineMode = document.getElementById('btnEnableOfflineMode')
btnEnableOfflineMode.onclick = function(e) {
e.preventDefault();
Adjust.setOfflineMode(true);
Adjust.switchToOfflineMode();
}

var btnDisableOfflineMode = document.getElementById('btnDisableOfflineMode')
btnDisableOfflineMode.onclick = function(e) {
e.preventDefault();
Adjust.setOfflineMode(false);
Adjust.switchBackToOnlineMode();
}

var btnEnableSdk = document.getElementById('btnEnableSdk')
btnEnableSdk.onclick = function(e) {
e.preventDefault()
Adjust.setEnabled(true)
Adjust.enable()
}

var btnDisableSdk = document.getElementById('btnDisableSdk')
btnDisableSdk.onclick = function(e) {
e.preventDefault();
Adjust.setEnabled(false);
Adjust.disable();
}

var btnIsSdkEnabled = document.getElementById('btnIsSdkEnabled')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public boolean launchReceivedDeeplink(Uri deeplink) {
// AdjustOaid.readOaid();

// Initialise the adjust SDK.
Adjust.onCreate(config);
Adjust.initSdk(config);



Expand Down Expand Up @@ -195,10 +195,10 @@ public void onFail(String message) {
});

// Put the SDK in offline mode.
// Adjust.setOfflineMode(true);
// Adjust.switchToOfflineMode();

// Disable the SDK
// Adjust.setEnabled(false);
// Adjust.disable();

// Send push notification token.
// Adjust.setPushToken("token");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import androidx.appcompat.app.AppCompatActivity;

import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -15,10 +14,7 @@

import com.adjust.sdk.Adjust;
import com.adjust.sdk.AdjustEvent;
import com.adjust.sdk.AdjustPurchase;
import com.adjust.sdk.AdjustPurchaseVerificationResult;
import com.adjust.sdk.OnIsEnabledListener;
import com.adjust.sdk.OnPurchaseVerificationFinishedListener;

public class MainActivity extends AppCompatActivity {
private static final String EVENT_TOKEN_SIMPLE = "g3mfiw";
Expand Down Expand Up @@ -115,10 +111,10 @@ public void onTrackPartnerEventClick(View v) {
public void onEnableDisableOfflineModeClick(View v) {
if (((Button) v).getText().equals(
getApplicationContext().getResources().getString(R.string.txt_enable_offline_mode))) {
Adjust.setOfflineMode(true);
Adjust.switchToOfflineMode();
((Button) v).setText(R.string.txt_disable_offline_mode);
} else {
Adjust.setOfflineMode(false);
Adjust.switchBackToOnlineMode();
((Button) v).setText(R.string.txt_enable_offline_mode);
}
}
Expand All @@ -128,10 +124,10 @@ public void onEnableDisableSDKClick(View v) {
@Override
public void onIsEnabledRead(boolean isEnabled) {
if (isEnabled) {
Adjust.setEnabled(false);
Adjust.disable();
((Button) v).setText(R.string.txt_enable_sdk);
} else {
Adjust.setEnabled(true);
Adjust.enable();
((Button) v).setText(R.string.txt_disable_sdk);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("example", "ServiceExample onStartCommand");

if (flip) {
Adjust.setEnabled(false);
Adjust.disable();
flip = false;
} else {
Adjust.setEnabled(true);
Adjust.enable();
flip = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ public boolean launchReceivedDeeplink(Uri deeplink) {
// AdjustOaid.readOaid();

// Initialise the adjust SDK.
Adjust.onCreate(config);
Adjust.initSdk(config);

// Register onResume and onPause events of all activities
// for applications with minSdkVersion >= 14.
registerActivityLifecycleCallbacks(new AdjustLifecycleCallbacks());

// Put the SDK in offline mode.
// Adjust.setOfflineMode(true);
// Adjust.switchToOfflineMode();

// Disable the SDK
// Adjust.setEnabled(false);
// Adjust.disable();

// Send push notification token.
// Adjust.setPushToken("token");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ class GlobalApplication : Application() {
// AdjustOaid.readOaid()

// Initialise the adjust SDK.
Adjust.onCreate(config)
Adjust.initSdk(config)

// Register onResume and onPause events of all activities
// for applications with minSdkVersion >= 14.
registerActivityLifecycleCallbacks(AdjustLifecycleCallbacks())

// Put the SDK in offline mode.
// Adjust.setOfflineMode(true);
// Adjust.switchToOfflineMode();

// Disable the SDK
// Adjust.setEnabled(false);
// Adjust.disable();

// Send push notification token.
// Adjust.setPushToken("token");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,21 @@ class MainActivity : AppCompatActivity() {

fun onEnableDisableOfflineModeClick(v: View) {
if ((v as Button).text == applicationContext.resources.getString(R.string.txt_enable_offline_mode)) {
Adjust.setOfflineMode(true)
Adjust.switchToOfflineMode()
v.setText(R.string.txt_disable_offline_mode)
} else {
Adjust.setOfflineMode(false)
Adjust.switchBackToOnlineMode()
v.setText(R.string.txt_enable_offline_mode)
}
}

fun onEnableDisableSDKClick(v: View) {
Adjust.isEnabled(this, OnIsEnabledListener {
if (it) {
Adjust.setEnabled(false)
Adjust.disable()
(v as Button).setText(R.string.txt_enable_sdk)
} else {
Adjust.setEnabled(true)
Adjust.enable()
(v as Button).setText(R.string.txt_disable_sdk)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class ServiceExample : Service() {
Log.d("example", "ServiceExample onStartCommand")

if (flip) {
Adjust.setEnabled(false)
Adjust.disable()
flip = false
} else {
Adjust.setEnabled(true)
Adjust.enable()
flip = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ public boolean launchReceivedDeeplink(Uri deeplink) {
Adjust.removeGlobalPartnerParameters();

// Initialise the adjust SDK.
Adjust.onCreate(config);
Adjust.initSdk(config);

// Register onResume and onPause events of all activities
// for applications with minSdkVersion >= 14.
registerActivityLifecycleCallbacks(new AdjustLifecycleCallbacks());

// Put the SDK in offline mode.
// Adjust.setOfflineMode(true);
// Adjust.switchToOfflineMode();

// Disable the SDK
// Adjust.setEnabled(false);
// Adjust.disable();

// Send push notification token.
// Adjust.setPushToken("token");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public void onTrackPartnerEventClick(View v) {
public void onEnableDisableOfflineModeClick(View v) {
if (((Button) v).getText().equals(
getApplicationContext().getResources().getString(R.string.txt_enable_offline_mode))) {
Adjust.setOfflineMode(true);
Adjust.switchToOfflineMode();
((Button) v).setText(R.string.txt_disable_offline_mode);
} else {
Adjust.setOfflineMode(false);
Adjust.switchBackToOnlineMode();
((Button) v).setText(R.string.txt_enable_offline_mode);
}
}
Expand All @@ -100,10 +100,10 @@ public void onEnableDisableSDKClick(View v) {
@Override
public void onIsEnabledRead(boolean isEnabled) {
if (isEnabled) {
Adjust.setEnabled(false);
Adjust.disable();
((Button) v).setText(R.string.txt_enable_sdk);
} else {
Adjust.setEnabled(true);
Adjust.enable();
((Button) v).setText(R.string.txt_disable_sdk);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h1 style="width:400px;height:35px;text-align:center;">Adjust Web View SDK Demo
adjustConfig.setSessionFailureCallback(sessionFailureCallback);
adjustConfig.setDeferredDeeplinkCallback(deferredDeeplinkCallback);

Adjust.onCreate(adjustConfig);
Adjust.initSdk(adjustConfig);

window.onload = function() {
var btnTrackSimpleEvent = document.getElementById('btnTrackSimpleEvent')
Expand Down Expand Up @@ -114,25 +114,25 @@ <h1 style="width:400px;height:35px;text-align:center;">Adjust Web View SDK Demo
var btnEnableOfflineMode = document.getElementById('btnEnableOfflineMode')
btnEnableOfflineMode.onclick = function(e) {
e.preventDefault();
Adjust.setOfflineMode(true);
Adjust.switchToOfflineMode();
}

var btnDisableOfflineMode = document.getElementById('btnDisableOfflineMode')
btnDisableOfflineMode.onclick = function(e) {
e.preventDefault();
Adjust.setOfflineMode(false);
Adjust.switchBackToOnlineMode();
}

var btnEnableSdk = document.getElementById('btnEnableSdk')
btnEnableSdk.onclick = function(e) {
e.preventDefault()
Adjust.setEnabled(true)
Adjust.enable();
}

var btnDisableSdk = document.getElementById('btnDisableSdk')
btnDisableSdk.onclick = function(e) {
e.preventDefault();
Adjust.setEnabled(false);
Adjust.disable();
}

var btnIsSdkEnabled = document.getElementById('btnIsSdkEnabled')
Expand Down
40 changes: 25 additions & 15 deletions Adjust/sdk-core/src/main/java/com/adjust/sdk/Adjust.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public static synchronized AdjustInstance getDefaultInstance() {
*
* @param adjustConfig AdjustConfig object used for SDK initialisation
*/
public static void onCreate(AdjustConfig adjustConfig) {
public static void initSdk(AdjustConfig adjustConfig) {
AdjustInstance adjustInstance = Adjust.getDefaultInstance();
adjustInstance.onCreate(adjustConfig);
adjustInstance.initSdk(adjustConfig);
}

/**
Expand Down Expand Up @@ -77,13 +77,20 @@ public static void onPause() {
}

/**
* Called to disable/enable SDK.
* Called to enable SDK.
*
* @param enabled boolean indicating whether SDK should be enabled or disabled
*/
public static void setEnabled(boolean enabled) {
public static void enable() {
AdjustInstance adjustInstance = Adjust.getDefaultInstance();
adjustInstance.setEnabled(enabled);
adjustInstance.enable();
}
/**
* Called to disable SDK.
*
*/
public static void disable() {
AdjustInstance adjustInstance = Adjust.getDefaultInstance();
adjustInstance.disable();
}

/**
Expand Down Expand Up @@ -150,13 +157,20 @@ public static void setReferrer(String referrer, Context context) {
}

/**
* Called to set SDK to offline or online mode.
* Called to set SDK to offline mode.
*
*/
public static void switchToOfflineMode() {
AdjustInstance adjustInstance = Adjust.getDefaultInstance();
adjustInstance.switchToOfflineMode();
}
/**
* Called to set SDK to online mode.
*
* @param enabled boolean indicating should SDK be in offline mode (true) or not (false)
*/
public static void setOfflineMode(boolean enabled) {
public static void switchBackToOnlineMode() {
AdjustInstance adjustInstance = Adjust.getDefaultInstance();
adjustInstance.setOfflineMode(enabled);
adjustInstance.switchBackToOnlineMode();
}

/**
Expand Down Expand Up @@ -419,11 +433,7 @@ public static void getSdkVersion(final OnSdkVersionReadListener onSdkVersionRead
*/
public static void verifyPurchase(final AdjustPurchase purchase, final OnPurchaseVerificationFinishedListener callback) {
if (callback == null) {
AdjustFactory.getLogger().error("callback cannot be null");
return;
}
if (purchase == null) {
AdjustFactory.getLogger().error("purchase cannot be null");
AdjustFactory.getLogger().error("Purchase verification aborted because verification callback is null");
return;
}
AdjustInstance adjustInstance = Adjust.getDefaultInstance();
Expand Down
Loading

0 comments on commit 69f3b98

Please sign in to comment.