Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new callback interfaces split from DeployGateCallback #95

Merged
merged 23 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b5ac092
chore: separate each method in DeloyGateCallback to interface class
satsukies Aug 19, 2024
c75248c
feat: Add method for set each callbacks to DeployGateSdkConfiguration…
satsukies Aug 19, 2024
36e88dc
chore: add new callback interfaces to sdkMock module
satsukies Aug 19, 2024
3d46edb
feat: add register/unregister method for new callback interfaces
satsukies Aug 19, 2024
5d6efe5
chore: refactoring sample codes
satsukies Aug 19, 2024
9774b93
chore: add methods to DeployGateSdkConfiguration at sdkMock module
satsukies Aug 20, 2024
f7d85ba
test: add testcase of new interfaces
satsukies Aug 20, 2024
69bd4fc
test: add new testcase about public methods definition on DeployGateS…
satsukies Aug 20, 2024
7a6f81d
fix: remove class body
satsukies Aug 20, 2024
6bee4f7
fix: mark deprecated in sdkMock module
satsukies Aug 20, 2024
bcd6b86
fix: delete member of deprecated interface
satsukies Aug 20, 2024
41bdd9c
fix: remove 'refreshImmediately' argument
satsukies Aug 20, 2024
c361d01
chore: update sample code
satsukies Aug 20, 2024
3954e1c
chore: add javadoc
satsukies Aug 20, 2024
4062288
fix: forgot semi-colon
satsukies Aug 20, 2024
1d45993
test: add testcase of register/unregister callbacks
satsukies Aug 20, 2024
ee6bd30
fix: use deprecated callback directly when register/unregister
satsukies Aug 20, 2024
0ff07a4
chore: separate unregister logic to 'unregisterXXXInternal' private m…
satsukies Aug 20, 2024
083c8f9
fix: improve comments
satsukies Aug 20, 2024
190ef4c
fix: treat DeployGateCallback as fine-grained callbacks
satsukies Aug 20, 2024
6af347c
chore: add comment to package-private static methods
satsukies Aug 20, 2024
12883ac
chore: add no-op comment
satsukies Aug 20, 2024
7d5d76b
fix: deprecated DeployGateSdkConfiguration.Builder#setCallback in sdk…
satsukies Aug 20, 2024
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
48 changes: 18 additions & 30 deletions sample/src/main/java/com/deploygate/sample/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import com.deploygate.sdk.CustomAttributes;
import com.deploygate.sdk.DeployGate;
import com.deploygate.sdk.DeployGateCallback;
import com.deploygate.sdk.DeployGateSdkConfiguration;

import java.util.Locale;

Expand All @@ -27,12 +27,10 @@ public void onCreate() {
// Note that you also need to edit your AndroidManifest.xml to activate customized initializer.
// Refer the comment on stableReal/AndroidManifest.xml included in this sample.

DeployGate.install(this, new DeployGateCallback() {
// Please note that this callback is called iff you have removed the content provider.
// For those who wanna use the content provider, SDK provides DeployGate#registerCallback for your use-case.

@Override
public void onInitialized(boolean isServiceAvailable) {
DeployGateSdkConfiguration configuration = new DeployGateSdkConfiguration.Builder()
// Please note that these callback is called if you have removed the content provider.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iff is not a typo by the way. It's an abbreviation of if and only if.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh.. reverted this change.

// For those who wanna use the content provider, SDK provides DeployGate#registerXXXCallback for your use-case.
.setInitializeCallback(isServiceAvailable -> {
if (isServiceAvailable) {
Log.i(TAG, "SDK is available");
DeployGate.logInfo("SDK is available");
Expand All @@ -44,49 +42,39 @@ public void onInitialized(boolean isServiceAvailable) {
Log.i(TAG, "SDK is unavailable");
DeployGate.logInfo("SDK is unavailable"); // this fails silently
}
}

@Override
public void onStatusChanged(
boolean isManaged,
boolean isAuthorized,
String loginUsername,
boolean isStopped
) {
})
.setStatusChangeCallback((isManaged, isAuthorized, loginUsername, isStopped) -> {
Bundle bundle = new Bundle();
bundle.putBoolean("isManaged", isManaged);
bundle.putBoolean("isAuthorized", isAuthorized);
bundle.putString("loginUsername", loginUsername);
bundle.putBoolean("isStopped", isStopped);

String message = String.format(Locale.US, "onStatusChanged(%s)", bundle.toString());
String message = String.format(Locale.US, "onStatusChanged(%s)", bundle);

Log.i(TAG, message);
DeployGate.logInfo(message);
}

@Override
public void onUpdateAvailable(
int revision,
String versionName,
int versionCode
) {
})
.setUpdateAvailableCallback((revision, versionName, versionCode) -> {
Bundle bundle = new Bundle();
bundle.putInt("revision", revision);
bundle.putString("versionName", versionName);
bundle.putInt("versionCode", versionCode);

String message = String.format(Locale.US, "onUpdateAvailable(%s)", bundle.toString());
String message = String.format(Locale.US, "onUpdateAvailable(%s)", bundle);

Log.i(TAG, message);
DeployGate.logInfo(message);
}
}, true);
})
.setEnabledOnNonDebuggableBuild(true)
.build();

DeployGate.install(this, configuration);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use install(Context, DeployGateSdkConfiguration) because install(Application, DeployGateCallback, boolean) is deprecated.


// If you want to prevent the app distributed by someone else, specify your username on DeployGate
// as a second argument of DeployGate.install, like:
// with setAuthor method when creating DeployGate SdkConfiguration. like:
//
// DeployGate.install(this, "YOURUSERNAME");
// builder.setAuthor("YOURUSERNAME")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describe to use setAuthor(String) method defined in DeployGateSdkConfuration.Builder class because DeployGate.install(Application, String) is deprecated.

//
// You can use DeployGate.isAuthorized() later to check the installation is valid or not.
}
Expand Down
19 changes: 14 additions & 5 deletions sample/src/main/java/com/deploygate/sample/SampleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

import com.deploygate.sdk.CustomAttributes;
import com.deploygate.sdk.DeployGate;
import com.deploygate.sdk.DeployGateCallback;
import com.deploygate.sdk.DeployGateInitializeCallback;
import com.deploygate.sdk.DeployGateStatusChangeCallback;
import com.deploygate.sdk.DeployGateUpdateAvailableCallback;

public class SampleActivity extends Activity implements DeployGateCallback {
public class SampleActivity extends Activity implements DeployGateInitializeCallback, DeployGateStatusChangeCallback, DeployGateUpdateAvailableCallback {

private static final String TAG = "SampleActivity";

Expand Down Expand Up @@ -68,16 +70,23 @@ public void onCreate(Bundle savedInstanceState) {
protected void onResume() {
super.onResume();

// register for callback, also request refreshing (second argument)
DeployGate.registerCallback(this, true);
// register for callbacks
DeployGate.registerInitializeCallback(this);
DeployGate.registerStatusChangeCallback(this);
DeployGate.registerUpdateAvailableCallback(this);

// finally, call refresh() method if you want to check the status immediately
DeployGate.refresh();
}

@Override
protected void onPause() {
super.onPause();

// unregister to stop callback
DeployGate.unregisterCallback(this);
DeployGate.unregisterInitializeCallback(this);
DeployGate.unregisterStatusChangeCallback(this);
DeployGate.unregisterUpdateAvailableCallback(this);
}


Expand Down
Loading
Loading