public static ChatSDK initialize (Configuration config, BaseNetworkAdapter networkAdapter, InterfaceAdapter interfaceAdapter) throws ChatSDKException { shared().setContext(config.context.get()); shared().config = config; DaoCore.init(shared().context()); if(interfaceAdapter != null) { InterfaceManager.shared().a = interfaceAdapter; } else { shared().activateModule("UserInterfaceModule", "activate", new MethodArgument(Context.class, shared().context())); } if (networkAdapter != null) { NetworkManager.shared().a = networkAdapter; } else { shared().activateModule("FirebaseModule", "activate"); } shared().handleLocalNotifications(); // Monitor the app so if it goes into the background we know AppBackgroundMonitor.shared().setEnabled(true); if (config().debug) { Timber.plant(new Timber.DebugTree()); } return shared(); }
if(!ChatSDK.config().inboundPushHandlingEnabled) { return; if (ChatSDK.auth() == null || !ChatSDK.auth().userAuthenticatedThisSession() || ChatSDK.config().backgroundPushTestModeEnabled) { appIntent = new Intent(context, ChatSDK.ui().getLoginActivity()); } else if (AppBackgroundMonitor.shared().inBackground() && ChatSDK.auth().userAuthenticatedThisSession()) { appIntent = new Intent(context, ChatSDK.ui().getChatActivity()); ChatSDK.ui().notificationDisplayHandler().createMessageNotification(context, appIntent, userEntityID, title, body);
public Map<String, ?> getLoginInfo() { return ChatSDK.shared().getPreferences().getAll(); }
public Boolean accountTypeEnabled(AccountDetails.Type type) { if (type == AccountDetails.Type.Anonymous) { return ChatSDK.config().anonymousLoginEnabled; } else if (type == AccountDetails.Type.Username || type == AccountDetails.Type.Register) { return true; } else if (ChatSDK.socialLogin() != null) { return ChatSDK.socialLogin().accountTypeEnabled(type); } else { return false; } }
protected void addProfilePicture() { if (ChatSDK.profilePictures().fromUser(getUser()).size() >= maxPictures && maxPictures > 0) { if (!limitWarning.isEmpty()) { ToastHelper.show(this, limitWarning); File compress = new Compressor(ChatSDK.shared().context()) .setMaxHeight(ChatSDK.config().imageMaxThumbnailDimension) .setMaxWidth(ChatSDK.config().imageMaxThumbnailDimension) .compressToFile(new File(result)); File file = ImageUtils.compressImageToFile(ChatSDK.shared().context(), bitmap, getUser().getEntityID(), ".png"); ChatSDK.profilePictures().addPicture(getUser(), imagePath); updateGallery(); if (ChatSDK.profilePictures().fromUser(getUser()).size() == 1) { disposableList.add(ChatSDK.core().pushUser() .observeOn(AndroidSchedulers.mainThread()) .subscribe(() -> { ChatSDK.logError(e); Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
public static String getMapImageURL (LatLng location, int width, int height) { String googleMapsAPIKey = ChatSDK.config().googleMapsApiKey; String api = "https://maps.googleapis.com/maps/api/staticmap"; String markers = "markers="+location.latitude+","+location.longitude; String size = "zoom=18&size="+width+"x"+ height; String key = "key=" + googleMapsAPIKey; return api + "?" + markers + "&" + size + "&" + key; }
public void handleLocalNotifications () { if (localNotificationDisposable != null) { localNotificationDisposable.dispose(); } // TODO: Check this localNotificationDisposable = ChatSDK.events().sourceOnMain() .filter(NetworkEvent.filterType(EventType.MessageAdded)) .subscribe(networkEvent -> { Message message = networkEvent.message; Thread thread = networkEvent.thread; if(message != null && !AppBackgroundMonitor.shared().inBackground()) { if (thread.typeIs(ThreadType.Private) || (thread.typeIs(ThreadType.Public) && ChatSDK.config().pushNotificationsForPublicChatRoomsEnabled)) { if(!message.getSender().isMe() && ChatSDK.ui().showLocalNotifications(message.getThread())) { ReadStatus status = message.readStatusForUser(ChatSDK.currentUser()); if (!message.isRead() && !status.is(ReadStatus.delivered())) { // Only show the alert if we'recyclerView not on the private threads tab ChatSDK.ui().notificationDisplayHandler().createMessageNotification(message); } } } } }); }
e.onNext(new MessageSendProgress(message)); File compress = new Compressor(ChatSDK.shared().context()) .setMaxHeight(ChatSDK.config().imageMaxHeight) .setMaxWidth(ChatSDK.config().imageMaxWidth) .compressToFile(new File(filePath)); e.onError(new Throwable(ChatSDK.shared().context().getString(R.string.unable_to_save_image_to_disk))); return; ChatSDK.upload().uploadImage(image).subscribe(new Observer<FileUploadResult>() { @Override public void onSubscribe(Disposable d) {}
File avatar = new File(new URI(path).getPath()); Bitmap bitmap = BitmapFactory.decodeFile(avatar.getPath()); if (bitmap != null && ChatSDK.upload() != null) { ChatSDK.upload().uploadImage(bitmap).subscribe(new Observer<FileUploadResult>() { @Override public void onSubscribe(@NonNull Disposable d) {} ToastHelper.show(ChatSDK.shared().context(), "Error: bitmap is null"); e.onComplete(); }).concatWith(ChatSDK.core().pushUser());
public void startChat () { if (startingChat) { return; } startingChat = true; showProgressDialog(getString(R.string.creating_thread)); disposableList.add(ChatSDK.thread().createThread("", user, ChatSDK.currentUser()) .observeOn(AndroidSchedulers.mainThread()) .doFinally(() -> { dismissProgressDialog(); startingChat = false; }) .subscribe(thread -> { ChatSDK.ui().startChatActivityForID(getApplicationContext(), thread.getEntityID()); }, throwable -> { ToastHelper.show(getApplicationContext(), throwable.getLocalizedMessage()); })); }
public Completable logout() { return Completable.create( emitter-> { final User user = ChatSDK.currentUser(); ChatSDK.core().setUserOffline().subscribe(()->{ ChatSDK.events().source().onNext(NetworkEvent.logout()); if (ChatSDK.socialLogin() != null) { ChatSDK.socialLogin().logout(); if (ChatSDK.hook() != null) { HashMap<String, Object> data = new HashMap<>(); data.put(BaseHookHandler.User, user); ChatSDK.hook().executeHook(BaseHookHandler.DidLogout, data);
protected void logout () { disposableList.add(ChatSDK.auth().logout() .observeOn(AndroidSchedulers.mainThread()) .subscribe(() -> ChatSDK.ui().startLoginActivity(getApplicationContext(), false), throwable -> { ChatSDK.logError(throwable); Toast.makeText(EditProfileActivity.this, throwable.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); })); }
public void createMessageNotification(Message message) { Context context = ChatSDK.shared().context(); String threadID = message.getThread().getEntityID(); Intent openChatIntent = new Intent(context, ChatSDK.ui().getChatActivity()); openChatIntent.putExtra(InterfaceManager.THREAD_ENTITY_ID, threadID); openChatIntent.setAction(threadID); openChatIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); createMessageNotification(context, openChatIntent, message.getSender().getEntityID(), message.getSender().getName(), message.getText()); }
protected void afterLogin() { // We pass the extras in case this activity was laucned by a push. In that case // we can load up the thread the message belongs to ChatSDK.ui().startMainActivity(this, extras); }
btnResetPassword = findViewById(R.id.chat_sdk_btn_reset_password); btnResetPassword.setVisibility(ChatSDK.config().resetPasswordEnabled ? View.VISIBLE : View.INVISIBLE); if(!ChatSDK.auth().accountTypeEnabled(AccountDetails.Type.Facebook)) { ((ViewGroup) btnFacebook.getParent()).removeView(btnFacebook); if(!ChatSDK.auth().accountTypeEnabled(AccountDetails.Type.Twitter)) { ((ViewGroup) btnTwitter.getParent()).removeView(btnTwitter); if(!ChatSDK.auth().accountTypeEnabled(AccountDetails.Type.Google)) { ((ViewGroup) btnGoogle.getParent()).removeView(btnGoogle); if(!ChatSDK.auth().accountTypeEnabled(AccountDetails.Type.Anonymous)) { ((ViewGroup) btnAnonymous.getParent()).removeView(btnAnonymous); if(!StringChecker.isNullOrEmpty(ChatSDK.config().debugUsername)) { usernameEditText.setText(ChatSDK.config().debugUsername); if(!StringChecker.isNullOrEmpty(ChatSDK.config().debugPassword)) { passwordEditText.setText(ChatSDK.config().debugPassword); if(ChatSDK.config().loginScreenDrawableResourceID > 0) { appIconImage.setImageResource(ChatSDK.config().loginScreenDrawableResourceID);
@Override public void deleteContactLocal(User user, ConnectionType type) { if (ChatSDK.currentUser() != null && !user.isMe()) { ChatSDK.currentUser().deleteContact(user, type); ChatSDK.core().userOff(user); } }
protected void authenticateWithCachedToken () { showProgressDialog(getString(R.string.authenticating)); signInButton.setEnabled(false); ChatSDK.auth().authenticateWithCachedToken() .observeOn(AndroidSchedulers.mainThread()) .doFinally(() -> { signInButton.setEnabled(true); dismissProgressDialog(); }) .subscribe(() -> { ChatSDK.ui().startMainActivity(SplashScreenActivity.this); }, throwable -> { // startAuthenticationActivity(); }); }