use of com.auth0.sharelock.event.SharelockAPIErrorEvent in project sharelock-android by auth0.
the class ComposeActivity method onEvent.
public void onEvent(RequestLinkEvent event) {
final Secret secret = event.getSecret();
final EventBus bus = this.bus;
SharedPreferences preferences = getSharedPreferences(getPackageName(), MODE_PRIVATE);
client = new LinkAPIClient(preferences.getString(LinkAPIClient.SHARELOCK_ENDPOINT_KEY, LinkAPIClient.DEFAULT_URL));
client.generateLinkForSecret(secret, this, new LinkAPIClient.LinkCallback() {
@Override
public void onSuccess(final Uri link) {
Log.d(TAG, "Obtained link path " + link);
handler.postDelayed(new Runnable() {
@Override
public void run() {
bus.postSticky(new NewLinkEvent(link));
final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
final ClipData clipData = ClipData.newRawUri("sharelocked-link", link);
clipboardManager.setPrimaryClip(clipData);
Snackbar snackbar = Snackbar.with(ComposeActivity.this).text(R.string.link_in_clipboard_message).duration(Snackbar.SnackbarDuration.LENGTH_SHORT);
SnackbarManager.show(snackbar);
}
}, DELAY_MILLIS);
}
@Override
public void onError(Throwable reason) {
Log.e(TAG, "Failed to generate link", reason);
bus.post(new SharelockAPIErrorEvent());
AlertDialog dialog = new AlertDialog.Builder(ComposeActivity.this).setTitle(R.string.link_generation_failed_title).setMessage(R.string.link_generation_failed).setCancelable(true).setPositiveButton(R.string.retry_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
bus.post(new RequestLinkEvent(secret));
}
}).setNegativeButton(R.string.cancel_button, null).create();
dialog.show();
}
});
}
Aggregations