Search in sources :

Example 1 with RocketChatCache

use of chat.rocket.android.RocketChatCache in project Rocket.Chat.Android by RocketChat.

the class SidebarMainFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = getArguments();
    hostname = args == null ? null : args.getString(HOSTNAME);
    methodCallHelper = new MethodCallHelper(getContext(), hostname);
    realmSpotlightRoomRepository = new RealmSpotlightRoomRepository(hostname);
    RealmUserRepository userRepository = new RealmUserRepository(hostname);
    AbsoluteUrlHelper absoluteUrlHelper = new AbsoluteUrlHelper(hostname, new RealmServerInfoRepository(), userRepository, new SessionInteractor(new RealmSessionRepository(hostname)));
    presenter = new SidebarMainPresenter(hostname, new RoomInteractor(new RealmRoomRepository(hostname)), userRepository, new RocketChatCache(getContext()), absoluteUrlHelper, TextUtils.isEmpty(hostname) ? null : new MethodCallHelper(getContext(), hostname));
}
Also used : SessionInteractor(chat.rocket.core.interactors.SessionInteractor) MethodCallHelper(chat.rocket.android.api.MethodCallHelper) RealmSpotlightRoomRepository(chat.rocket.persistence.realm.repositories.RealmSpotlightRoomRepository) AbsoluteUrlHelper(chat.rocket.android.helper.AbsoluteUrlHelper) RealmSessionRepository(chat.rocket.persistence.realm.repositories.RealmSessionRepository) RoomInteractor(chat.rocket.core.interactors.RoomInteractor) Bundle(android.os.Bundle) RocketChatCache(chat.rocket.android.RocketChatCache) RealmRoomRepository(chat.rocket.persistence.realm.repositories.RealmRoomRepository) RealmServerInfoRepository(chat.rocket.persistence.realm.repositories.RealmServerInfoRepository) RealmUserRepository(chat.rocket.persistence.realm.repositories.RealmUserRepository)

Example 2 with RocketChatCache

use of chat.rocket.android.RocketChatCache in project Rocket.Chat.Android by RocketChat.

the class MessageOptionsDialogFragment method setUpDialog.

private void setUpDialog(final BottomSheetDialog bottomSheetDialog, String messageId) {
    RocketChatCache cache = new RocketChatCache(bottomSheetDialog.getContext());
    String hostname = cache.getSelectedServerHostname();
    EditMessageInteractor editMessageInteractor = getEditMessageInteractor(hostname);
    MessageRepository messageRepository = new RealmMessageRepository(hostname);
    Disposable disposable = messageRepository.getById(messageId).flatMap(it -> {
        if (!it.isPresent()) {
            return Single.just(Pair.<Message, Boolean>create(null, false));
        }
        Message message = it.get();
        return Single.zip(Single.just(message), editMessageInteractor.isAllowed(message), Pair::create);
    }).subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(pair -> {
        if (pair.second) {
            bottomSheetDialog.findViewById(R.id.message_options_info).setVisibility(View.GONE);
            View editView = bottomSheetDialog.findViewById(R.id.message_options_edit_action);
            editView.setVisibility(View.VISIBLE);
            editView.setOnClickListener(view -> internalListener.onEdit(pair.first));
        } else {
            ((TextView) bottomSheetDialog.findViewById(R.id.message_options_info)).setText(R.string.message_options_no_permissions_info);
        }
    }, throwable -> {
        ((TextView) bottomSheetDialog.findViewById(R.id.message_options_info)).setText(R.string.message_options_no_message_info);
        Logger.report(throwable);
    });
    compositeDisposable.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) MessageRepository(chat.rocket.core.repositories.MessageRepository) BottomSheetDialog(android.support.design.widget.BottomSheetDialog) RealmPublicSettingRepository(chat.rocket.persistence.realm.repositories.RealmPublicSettingRepository) Bundle(android.os.Bundle) UserRepository(chat.rocket.core.repositories.UserRepository) RocketChatCache(chat.rocket.android.RocketChatCache) RoomRepository(chat.rocket.core.repositories.RoomRepository) Dialog(android.app.Dialog) NonNull(android.support.annotation.NonNull) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) RealmRoomRoleRepository(chat.rocket.persistence.realm.repositories.RealmRoomRoleRepository) PermissionRepository(chat.rocket.core.repositories.PermissionRepository) PublicSettingRepository(chat.rocket.core.repositories.PublicSettingRepository) PermissionInteractor(chat.rocket.core.interactors.PermissionInteractor) View(android.view.View) RoomRoleRepository(chat.rocket.core.repositories.RoomRoleRepository) R(chat.rocket.android.R) RealmRoomRepository(chat.rocket.persistence.realm.repositories.RealmRoomRepository) BottomSheetDialogFragment(android.support.design.widget.BottomSheetDialogFragment) DialogInterface(android.content.DialogInterface) Logger(chat.rocket.android.helper.Logger) EditMessageInteractor(chat.rocket.core.interactors.EditMessageInteractor) Message(chat.rocket.core.models.Message) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) Pair(android.support.v4.util.Pair) RealmUserRepository(chat.rocket.persistence.realm.repositories.RealmUserRepository) BackgroundLooper(chat.rocket.android.BackgroundLooper) RealmPermissionRepository(chat.rocket.persistence.realm.repositories.RealmPermissionRepository) Message(chat.rocket.core.models.Message) EditMessageInteractor(chat.rocket.core.interactors.EditMessageInteractor) RocketChatCache(chat.rocket.android.RocketChatCache) MessageRepository(chat.rocket.core.repositories.MessageRepository) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView)

Example 3 with RocketChatCache

use of chat.rocket.android.RocketChatCache in project Rocket.Chat.Android by RocketChat.

the class InputHostnameFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Context appContext = getContext().getApplicationContext();
    presenter = new InputHostnamePresenter(new RocketChatCache(appContext), ConnectivityManager.getInstance(appContext));
}
Also used : Context(android.content.Context) RocketChatCache(chat.rocket.android.RocketChatCache)

Example 4 with RocketChatCache

use of chat.rocket.android.RocketChatCache in project Rocket.Chat.Android by RocketChat.

the class SessionObserver method onLogin.

@DebugLog
private void onLogin() {
    streamNotifyMessage.register();
    // update push info
    pushHelper.pushSetUser(new RocketChatCache(context).getOrCreatePushId()).continueWith(new LogIfError());
}
Also used : RocketChatCache(chat.rocket.android.RocketChatCache) LogIfError(chat.rocket.android.helper.LogIfError) DebugLog(hugo.weaving.DebugLog)

Example 5 with RocketChatCache

use of chat.rocket.android.RocketChatCache in project Rocket.Chat.Android by RocketChat.

the class GcmPushRegistrationObserver method registerGcmTokenForServer.

private Task<Void> registerGcmTokenForServer() throws IOException {
    final String gcmToken = getGcmToken(getSenderId());
    final RealmUser currentUser = realmHelper.executeTransactionForRead(realm -> RealmUser.queryCurrentUser(realm).findFirst());
    final String userId = currentUser != null ? currentUser.getId() : null;
    final String pushId = new RocketChatCache(context).getOrCreatePushId();
    return new RaixPushHelper(realmHelper, ddpClientRef).pushUpdate(pushId, gcmToken, userId);
}
Also used : RealmUser(chat.rocket.persistence.realm.models.ddp.RealmUser) RocketChatCache(chat.rocket.android.RocketChatCache) RaixPushHelper(chat.rocket.android.api.RaixPushHelper)

Aggregations

RocketChatCache (chat.rocket.android.RocketChatCache)7 RealmRoomRepository (chat.rocket.persistence.realm.repositories.RealmRoomRepository)3 RealmUserRepository (chat.rocket.persistence.realm.repositories.RealmUserRepository)3 Bundle (android.os.Bundle)2 MethodCallHelper (chat.rocket.android.api.MethodCallHelper)2 RoomInteractor (chat.rocket.core.interactors.RoomInteractor)2 SessionInteractor (chat.rocket.core.interactors.SessionInteractor)2 RealmSessionRepository (chat.rocket.persistence.realm.repositories.RealmSessionRepository)2 DebugLog (hugo.weaving.DebugLog)2 Dialog (android.app.Dialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 NonNull (android.support.annotation.NonNull)1 BottomSheetDialog (android.support.design.widget.BottomSheetDialog)1 BottomSheetDialogFragment (android.support.design.widget.BottomSheetDialogFragment)1 Pair (android.support.v4.util.Pair)1 View (android.view.View)1 TextView (android.widget.TextView)1 BackgroundLooper (chat.rocket.android.BackgroundLooper)1 R (chat.rocket.android.R)1