use of com.applozic.mobicomkit.api.notification.NotificationChannels in project Applozic-Android-SDK by AppLozic.
the class UserClientService method logout.
// Cleanup: private
// Cleanup: fromLogin is always false
/**
* Internal. This methods has a un-necessary parameter.
*
* @param fromLogin pass false
* @return logout backend api response, use {@link ApiResponse#isSuccess()} to check for success
*/
public ApiResponse logout(boolean fromLogin) {
Utils.printLog(context, TAG, "Al Logout call !!");
ApiResponse apiResponse = userLogoutResponse();
MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
final String deviceKeyString = mobiComUserPreference.getDeviceKeyString();
final String userKeyString = mobiComUserPreference.getSuUserKeyString();
String url = mobiComUserPreference.getUrl();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Applozic.Store.setCustomNotificationSound(context, null);
new NotificationChannels(context).deleteAllChannels();
}
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
mobiComUserPreference.clearAll();
ALSpecificSettings.getInstance(context).clearAll();
MessageDatabaseService.recentlyAddedMessage.clear();
MobiComDatabaseHelper.getInstance(context).delDatabase();
mobiComUserPreference.setUrl(url);
if (!fromLogin) {
ApplozicMqttWorker.enqueueWorkDisconnectPublish(context, deviceKeyString, userKeyString, false);
}
return apiResponse;
}
use of com.applozic.mobicomkit.api.notification.NotificationChannels in project Applozic-Android-SDK by AppLozic.
the class RegisterUserClientService method createAccount.
/**
* This is an internal method. Use {@link Applozic#connectUser(Context, User, AlLoginHandler)}.
*
* <p>Registers(or logs in) a {@link User} to the Applozic servers. It also initializes the SDK for that user.</p>
*
* @param user the user object to register/authenticate
* @return the {@link RegistrationResponse}, {@link RegistrationResponse#isRegistrationSuccess()} will be true in case of a successful login/register. otherwise {@link RegistrationResponse#getMessage()} will have the error message
* @throws Exception in case of empty or invalid user-id (see {@link User#isValidUserId()}, and connection errors
*/
@NonNull
public RegistrationResponse createAccount(@NonNull User user) throws Exception {
if (user.getDeviceType() == null) {
user.setDeviceType(Short.valueOf("1"));
}
user.setPrefContactAPI(Short.valueOf("2"));
user.setTimezone(TimeZone.getDefault().getID());
user.setEnableEncryption(user.isEnableEncryption());
if (!TextUtils.isEmpty(user.getAlBaseUrl())) {
ALSpecificSettings.getInstance(context).setAlBaseUrl(user.getAlBaseUrl());
}
if (!TextUtils.isEmpty(user.getKmBaseUrl())) {
ALSpecificSettings.getInstance(context).setKmBaseUrl(user.getKmBaseUrl());
}
if (TextUtils.isEmpty(user.getUserId())) {
throw new ApplozicException("userId cannot be empty");
}
if (!user.isValidUserId()) {
throw new ApplozicException("Invalid userId. Spacing and set of special characters ^!$%&*:(), are not accepted. \nOnly english language characters are accepted");
}
MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
Gson gson = new Gson();
user.setAppVersionCode(MOBICOMKIT_VERSION_CODE);
user.setApplicationId(getApplicationKey(context));
user.setRegistrationId(mobiComUserPreference.getDeviceRegistrationId());
if (getAppModuleName(context) != null) {
user.setAppModuleName(getAppModuleName(context));
}
Utils.printLog(context, TAG, "Net status" + Utils.isInternetAvailable(context.getApplicationContext()));
if (!Utils.isInternetAvailable(context.getApplicationContext())) {
throw new ConnectException("No Internet Connection");
}
HttpRequestUtils.isRefreshTokenInProgress = true;
Utils.printLog(context, TAG, "Registration json " + gson.toJson(user));
String response = httpRequestUtils.postJsonToServer(getCreateAccountUrl(), gson.toJson(user));
Utils.printLog(context, TAG, "Registration response is: " + response);
if (TextUtils.isEmpty(response) || response.contains("<html")) {
throw new Exception("503 Service Unavailable");
}
final RegistrationResponse registrationResponse = gson.fromJson(response, RegistrationResponse.class);
if (registrationResponse.isRegistrationSuccess()) {
Utils.printLog(context, "Registration response ", "is " + registrationResponse);
if (registrationResponse.getNotificationResponse() != null) {
Utils.printLog(context, "Registration response ", "" + registrationResponse.getNotificationResponse());
}
JWT.parseToken(context, registrationResponse.getAuthToken());
mobiComUserPreference.setEncryptionKey(registrationResponse.getEncryptionKey());
mobiComUserPreference.enableEncryption(user.isEnableEncryption());
mobiComUserPreference.setCountryCode(user.getCountryCode());
mobiComUserPreference.setUserId(user.getUserId());
mobiComUserPreference.setContactNumber(user.getContactNumber());
mobiComUserPreference.setEmailVerified(user.isEmailVerified());
mobiComUserPreference.setDisplayName(user.getDisplayName());
mobiComUserPreference.setMqttBrokerUrl(registrationResponse.getBrokerUrl());
mobiComUserPreference.setDeviceKeyString(registrationResponse.getDeviceKey());
mobiComUserPreference.setEmailIdValue(user.getEmail());
mobiComUserPreference.setImageLink(user.getImageLink());
mobiComUserPreference.setSuUserKeyString(registrationResponse.getUserKey());
mobiComUserPreference.setLastSyncTimeForMetadataUpdate(String.valueOf(registrationResponse.getCurrentTimeStamp()));
mobiComUserPreference.setLastSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
mobiComUserPreference.setLastSeenAtSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
mobiComUserPreference.setChannelSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
mobiComUserPreference.setUserBlockSyncTime("10000");
mobiComUserPreference.setUserDeactivated(registrationResponse.isDeactivate());
if (registrationResponse.getNotificationAfter() != null) {
ALSpecificSettings.getInstance(context).setNotificationAfterTime(registrationResponse.getNotificationAfter());
}
ApplozicClient.getInstance(context).skipDeletedGroups(user.isSkipDeletedGroups()).hideActionMessages(user.isHideActionMessages());
if (!TextUtils.isEmpty(registrationResponse.getUserEncryptionKey())) {
mobiComUserPreference.setUserEncryptionKey(registrationResponse.getUserEncryptionKey());
}
mobiComUserPreference.setPassword(user.getPassword());
mobiComUserPreference.setPricingPackage(registrationResponse.getPricingPackage());
mobiComUserPreference.setAuthenticationType(String.valueOf(user.getAuthenticationTypeId()));
if (registrationResponse.getRoleType() != null) {
mobiComUserPreference.setUserRoleType(registrationResponse.getRoleType());
}
if (user.getUserTypeId() != null) {
mobiComUserPreference.setUserTypeId(String.valueOf(user.getUserTypeId()));
}
if (!TextUtils.isEmpty(user.getNotificationSoundFilePath())) {
Applozic.getInstance(context).setCustomNotificationSound(user.getNotificationSoundFilePath());
}
Contact contact = new Contact();
contact.setUserId(user.getUserId());
contact.setFullName(registrationResponse.getDisplayName());
contact.setImageURL(registrationResponse.getImageLink());
contact.setContactNumber(registrationResponse.getContactNumber());
contact.setMetadata(registrationResponse.getMetadata());
if (user.getUserTypeId() != null) {
contact.setUserTypeId(user.getUserTypeId());
}
contact.setRoleType(user.getRoleType());
contact.setStatus(registrationResponse.getStatusMessage());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Applozic.Store.setNotificationChannelVersion(context, NotificationChannels.NOTIFICATION_CHANNEL_VERSION - 1);
new NotificationChannels(context).prepareNotificationChannels();
}
ApplozicClient.getInstance(context).setChatDisabled(contact.isChatForUserDisabled());
new AppContactService(context).upsert(contact);
ConversationWorker.enqueueWorkSync(context);
ConversationWorker.enqueueWorkMutedUserListSync(context);
ApplozicMqttWorker.enqueueWorkConnectPublish(context);
}
return registrationResponse;
}
Aggregations