Commit c68d0a66 authored by Tiago Cunha's avatar Tiago Cunha Committed by GitHub

Merge pull request #246 from RocketChat/fix/on-error

Adds a simple RxJava linter and fix missin on error implementations (…
parents 5086f6ac 050b61f6
...@@ -114,6 +114,8 @@ dependencies { ...@@ -114,6 +114,8 @@ dependencies {
compile "com.trello.rxlifecycle2:rxlifecycle-android:$rxlifecycleVersion" compile "com.trello.rxlifecycle2:rxlifecycle-android:$rxlifecycleVersion"
compile "com.trello.rxlifecycle2:rxlifecycle-components:$rxlifecycleVersion" compile "com.trello.rxlifecycle2:rxlifecycle-components:$rxlifecycleVersion"
compile 'nl.littlerobots.rxlint:rxlint:1.2'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile "frankiesardo:icepick:$icepickVersion" compile "frankiesardo:icepick:$icepickVersion"
......
...@@ -11,6 +11,7 @@ import io.reactivex.schedulers.Schedulers; ...@@ -11,6 +11,7 @@ import io.reactivex.schedulers.Schedulers;
import java.util.List; import java.util.List;
import chat.rocket.android.LaunchUtil; import chat.rocket.android.LaunchUtil;
import chat.rocket.android.RocketChatCache; import chat.rocket.android.RocketChatCache;
import chat.rocket.android.helper.Logger;
import chat.rocket.persistence.realm.models.ddp.RealmRoom; import chat.rocket.persistence.realm.models.ddp.RealmRoom;
import chat.rocket.android.push.PushConstants; import chat.rocket.android.push.PushConstants;
import chat.rocket.android.push.PushNotificationHandler; import chat.rocket.android.push.PushNotificationHandler;
...@@ -173,7 +174,10 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity { ...@@ -173,7 +174,10 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
.distinctUntilChanged() .distinctUntilChanged()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::updateHostnameIfNeeded) .subscribe(
this::updateHostnameIfNeeded,
Logger::report
)
); );
compositeDisposable.add( compositeDisposable.add(
...@@ -181,7 +185,10 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity { ...@@ -181,7 +185,10 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
.distinctUntilChanged() .distinctUntilChanged()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::updateRoomIdIfNeeded) .subscribe(
this::updateRoomIdIfNeeded,
Logger::report
)
); );
} }
} }
...@@ -6,6 +6,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers; ...@@ -6,6 +6,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import chat.rocket.android.BackgroundLooper; import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.service.ConnectivityManagerApi; import chat.rocket.android.service.ConnectivityManagerApi;
import chat.rocket.android.shared.BasePresenter; import chat.rocket.android.shared.BasePresenter;
import chat.rocket.core.interactors.SessionInteractor; import chat.rocket.core.interactors.SessionInteractor;
...@@ -50,21 +51,24 @@ public class LoginPresenter extends BasePresenter<LoginContract.View> ...@@ -50,21 +51,24 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
.distinctUntilChanged() .distinctUntilChanged()
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(state -> { .subscribe(
switch (state) { state -> {
case UNAVAILABLE: switch (state) {
isLogging = true; case UNAVAILABLE:
view.showLogin(hostname); isLogging = true;
break; view.showLogin(hostname);
case INVALID: break;
isLogging = false; case INVALID:
view.showRetryLogin(hostname); isLogging = false;
break; view.showRetryLogin(hostname);
case VALID: break;
isLogging = false; case VALID:
view.closeView(); isLogging = false;
} view.closeView();
}); }
},
Logger::report
);
addSubscription(subscription); addSubscription(subscription);
} }
......
...@@ -11,6 +11,7 @@ import chat.rocket.android.BackgroundLooper; ...@@ -11,6 +11,7 @@ import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.RocketChatCache; import chat.rocket.android.RocketChatCache;
import chat.rocket.android.api.MethodCallHelper; import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.helper.LogIfError; import chat.rocket.android.helper.LogIfError;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.service.ConnectivityManagerApi; import chat.rocket.android.service.ConnectivityManagerApi;
import chat.rocket.android.shared.BasePresenter; import chat.rocket.android.shared.BasePresenter;
import chat.rocket.core.interactors.CanCreateRoomInteractor; import chat.rocket.core.interactors.CanCreateRoomInteractor;
...@@ -71,13 +72,16 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -71,13 +72,16 @@ public class MainPresenter extends BasePresenter<MainContract.View>
final Disposable subscription = canCreateRoomInteractor.canCreate(roomId) final Disposable subscription = canCreateRoomInteractor.canCreate(roomId)
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(allowed -> { .subscribe(
if (allowed) { allowed -> {
view.showRoom(hostname, roomId); if (allowed) {
} else { view.showRoom(hostname, roomId);
view.showHome(); } else {
} view.showHome();
}); }
},
Logger::report
);
addSubscription(subscription); addSubscription(subscription);
} }
...@@ -110,7 +114,10 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -110,7 +114,10 @@ public class MainPresenter extends BasePresenter<MainContract.View>
) )
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(pair -> view.showUnreadCount(pair.first, pair.second)); .subscribe(
pair -> view.showUnreadCount(pair.first, pair.second),
Logger::report
);
addSubscription(subscription); addSubscription(subscription);
} }
...@@ -119,26 +126,29 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -119,26 +126,29 @@ public class MainPresenter extends BasePresenter<MainContract.View>
final Disposable subscription = sessionInteractor.getDefault() final Disposable subscription = sessionInteractor.getDefault()
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(sessionOptional -> { .subscribe(
Session session = sessionOptional.orNull(); sessionOptional -> {
if (session == null || session.getToken() == null) { Session session = sessionOptional.orNull();
view.showLoginScreen(); if (session == null || session.getToken() == null) {
return; view.showLoginScreen();
} return;
}
String error = session.getError();
if (error != null && error.length() != 0) { String error = session.getError();
view.showConnectionError(); if (error != null && error.length() != 0) {
return; view.showConnectionError();
} return;
}
if (!session.isTokenVerified()) {
view.showConnecting(); if (!session.isTokenVerified()) {
return; view.showConnecting();
} return;
}
view.showConnectionOk();
}); view.showConnectionOk();
},
Logger::report
);
addSubscription(subscription); addSubscription(subscription);
} }
......
package chat.rocket.android.fragment.chatroom; package chat.rocket.android.fragment.chatroom;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
...@@ -32,6 +33,7 @@ import chat.rocket.android.fragment.chatroom.dialog.UsersOfRoomDialogFragment; ...@@ -32,6 +33,7 @@ import chat.rocket.android.fragment.chatroom.dialog.UsersOfRoomDialogFragment;
import chat.rocket.android.helper.AbsoluteUrlHelper; import chat.rocket.android.helper.AbsoluteUrlHelper;
import chat.rocket.android.helper.FileUploadHelper; import chat.rocket.android.helper.FileUploadHelper;
import chat.rocket.android.helper.LoadMoreScrollListener; import chat.rocket.android.helper.LoadMoreScrollListener;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.helper.OnBackPressListener; import chat.rocket.android.helper.OnBackPressListener;
import chat.rocket.android.helper.RecyclerViewAutoScrollManager; import chat.rocket.android.helper.RecyclerViewAutoScrollManager;
import chat.rocket.android.helper.RecyclerViewScrolledToBottomListener; import chat.rocket.android.helper.RecyclerViewScrolledToBottomListener;
...@@ -244,6 +246,7 @@ public class RoomFragment extends AbstractChatRoomFragment ...@@ -244,6 +246,7 @@ public class RoomFragment extends AbstractChatRoomFragment
presenter.onMessageSelected(pairedMessage.target); presenter.onMessageSelected(pairedMessage.target);
} }
@SuppressLint("RxLeakedSubscription")
private void setupSideMenu() { private void setupSideMenu() {
View sideMenu = rootView.findViewById(R.id.room_side_menu); View sideMenu = rootView.findViewById(R.id.room_side_menu);
sideMenu.findViewById(R.id.btn_users).setOnClickListener(view -> { sideMenu.findViewById(R.id.btn_users).setOnClickListener(view -> {
...@@ -257,15 +260,18 @@ public class RoomFragment extends AbstractChatRoomFragment ...@@ -257,15 +260,18 @@ public class RoomFragment extends AbstractChatRoomFragment
if (drawerLayout != null && pane != null) { if (drawerLayout != null && pane != null) {
RxDrawerLayout.drawerOpen(drawerLayout, GravityCompat.END) RxDrawerLayout.drawerOpen(drawerLayout, GravityCompat.END)
.compose(bindToLifecycle()) .compose(bindToLifecycle())
.subscribe(opened -> { .subscribe(
try { opened -> {
Field fieldSlidable = pane.getClass().getDeclaredField("mCanSlide"); try {
fieldSlidable.setAccessible(true); Field fieldSlidable = pane.getClass().getDeclaredField("mCanSlide");
fieldSlidable.setBoolean(pane, !opened); fieldSlidable.setAccessible(true);
} catch (Exception exception) { fieldSlidable.setBoolean(pane, !opened);
RCLog.w(exception); } catch (Exception exception) {
} RCLog.w(exception);
}); }
},
Logger::report
);
} }
} }
......
...@@ -13,6 +13,7 @@ import chat.rocket.android.BackgroundLooper; ...@@ -13,6 +13,7 @@ import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.api.MethodCallHelper; import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.helper.AbsoluteUrlHelper; import chat.rocket.android.helper.AbsoluteUrlHelper;
import chat.rocket.android.helper.LogIfError; import chat.rocket.android.helper.LogIfError;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.shared.BasePresenter; import chat.rocket.android.shared.BasePresenter;
import chat.rocket.core.SyncState; import chat.rocket.core.SyncState;
import chat.rocket.core.interactors.MessageInteractor; import chat.rocket.core.interactors.MessageInteractor;
...@@ -68,11 +69,14 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -68,11 +69,14 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.flatMap(messageInteractor::loadMessages) .flatMap(messageInteractor::loadMessages)
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(success -> { .subscribe(
if (success) { success -> {
connectivityManagerApi.keepAliveServer(); if (success) {
} connectivityManagerApi.keepAliveServer();
}); }
},
Logger::report
);
addSubscription(subscription); addSubscription(subscription);
} }
...@@ -84,11 +88,14 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -84,11 +88,14 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.flatMap(messageInteractor::loadMoreMessages) .flatMap(messageInteractor::loadMoreMessages)
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(success -> { .subscribe(
if (success) { success -> {
connectivityManagerApi.keepAliveServer(); if (success) {
} connectivityManagerApi.keepAliveServer();
}); }
},
Logger::report
);
addSubscription(subscription); addSubscription(subscription);
} }
...@@ -110,11 +117,14 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -110,11 +117,14 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.flatMap(pair -> messageInteractor.send(pair.first, pair.second, messageText)) .flatMap(pair -> messageInteractor.send(pair.first, pair.second, messageText))
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(success -> { .subscribe(
if (success) { success -> {
view.onMessageSendSuccessfully(); if (success) {
} view.onMessageSendSuccessfully();
}); }
},
Logger::report
);
addSubscription(subscription); addSubscription(subscription);
} }
...@@ -148,7 +158,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -148,7 +158,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
count -> view.showUnreadCount(count) count -> view.showUnreadCount(count),
Logger::report
); );
addSubscription(subscription); addSubscription(subscription);
...@@ -165,7 +176,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -165,7 +176,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
room -> methodCallHelper.readMessages(room.getRoomId()) room -> methodCallHelper.readMessages(room.getRoomId())
.continueWith(new LogIfError()) .continueWith(new LogIfError()),
Logger::report
); );
addSubscription(subscription); addSubscription(subscription);
...@@ -179,7 +191,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -179,7 +191,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
room -> view.render(room) room -> view.render(room),
Logger::report
); );
addSubscription(subscription); addSubscription(subscription);
...@@ -199,7 +212,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -199,7 +212,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
!roomHistoryState.isComplete(), !roomHistoryState.isComplete(),
syncState == SyncState.SYNCED || syncState == SyncState.FAILED syncState == SyncState.SYNCED || syncState == SyncState.FAILED
); );
} },
Logger::report
); );
addSubscription(subscription); addSubscription(subscription);
...@@ -212,7 +226,10 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -212,7 +226,10 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.flatMap(messageInteractor::getAllFrom) .flatMap(messageInteractor::getAllFrom)
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(messages -> view.showMessages(messages)); .subscribe(
messages -> view.showMessages(messages),
Logger::report
);
addSubscription(subscription); addSubscription(subscription);
} }
...@@ -228,13 +245,16 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -228,13 +245,16 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.distinctUntilChanged() .distinctUntilChanged()
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(preferences -> { .subscribe(
if (preferences.isAutoImageLoad()) { preferences -> {
view.autoloadImages(); if (preferences.isAutoImageLoad()) {
} else { view.autoloadImages();
view.manualLoadImages(); } else {
} view.manualLoadImages();
}); }
},
Logger::report
);
addSubscription(subscription); addSubscription(subscription);
} }
...@@ -243,7 +263,10 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -243,7 +263,10 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
final Disposable subscription = absoluteUrlHelper.getRocketChatAbsoluteUrl() final Disposable subscription = absoluteUrlHelper.getRocketChatAbsoluteUrl()
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(it -> view.setupWith(it.orNull())); .subscribe(
it -> view.setupWith(it.orNull()),
Logger::report
);
addSubscription(subscription); addSubscription(subscription);
} }
......
...@@ -21,6 +21,7 @@ import chat.rocket.android.R; ...@@ -21,6 +21,7 @@ import chat.rocket.android.R;
import chat.rocket.android.fragment.chatroom.RocketChatAbsoluteUrl; import chat.rocket.android.fragment.chatroom.RocketChatAbsoluteUrl;
import chat.rocket.android.helper.AbsoluteUrlHelper; import chat.rocket.android.helper.AbsoluteUrlHelper;
import chat.rocket.android.helper.LogIfError; import chat.rocket.android.helper.LogIfError;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.layouthelper.chatroom.dialog.RoomUserAdapter; import chat.rocket.android.layouthelper.chatroom.dialog.RoomUserAdapter;
import chat.rocket.android.log.RCLog; import chat.rocket.android.log.RCLog;
import chat.rocket.core.SyncState; import chat.rocket.core.SyncState;
...@@ -99,7 +100,10 @@ public class UsersOfRoomDialogFragment extends AbstractChatRoomDialogFragment { ...@@ -99,7 +100,10 @@ public class UsersOfRoomDialogFragment extends AbstractChatRoomDialogFragment {
absoluteUrlHelper.getRocketChatAbsoluteUrl() absoluteUrlHelper.getRocketChatAbsoluteUrl()
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::setupView) .subscribe(
this::setupView,
Logger::report
)
); );
} }
......
...@@ -6,6 +6,7 @@ import org.json.JSONObject; ...@@ -6,6 +6,7 @@ import org.json.JSONObject;
import chat.rocket.android.BackgroundLooper; import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.api.MethodCallHelper; import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.helper.LogIfError; import chat.rocket.android.helper.LogIfError;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.shared.BasePresenter; import chat.rocket.android.shared.BasePresenter;
import chat.rocket.core.repositories.LoginServiceConfigurationRepository; import chat.rocket.core.repositories.LoginServiceConfigurationRepository;
...@@ -28,13 +29,16 @@ public class OAuthPresenter extends BasePresenter<OAuthContract.View> ...@@ -28,13 +29,16 @@ public class OAuthPresenter extends BasePresenter<OAuthContract.View>
loginServiceConfigurationRepository.getByName(serviceName) loginServiceConfigurationRepository.getByName(serviceName)
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(optional -> { .subscribe(
if (optional.isPresent()) { optional -> {
view.showService(optional.get()); if (optional.isPresent()) {
} else { view.showService(optional.get());
view.close(); } else {
} view.close();
}) }
},
Logger::report
)
); );
} }
......
...@@ -28,7 +28,6 @@ abstract class AbstractServerConfigFragment extends AbstractFragment { ...@@ -28,7 +28,6 @@ abstract class AbstractServerConfigFragment extends AbstractFragment {
} }
} }
protected void showFragment(Fragment fragment) { protected void showFragment(Fragment fragment) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
.add(R.id.content, fragment) .add(R.id.content, fragment)
......
...@@ -8,6 +8,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers; ...@@ -8,6 +8,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import bolts.Task; import bolts.Task;
import chat.rocket.android.BackgroundLooper; import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.api.MethodCallHelper; import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.shared.BasePresenter; import chat.rocket.android.shared.BasePresenter;
import chat.rocket.core.PublicSettingsConstants; import chat.rocket.core.PublicSettingsConstants;
...@@ -49,7 +50,10 @@ public class LoginPresenter extends BasePresenter<LoginContract.View> ...@@ -49,7 +50,10 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
publicSettingRepository.getById(PublicSettingsConstants.LDAP.ENABLE) publicSettingRepository.getById(PublicSettingsConstants.LDAP.ENABLE)
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(publicSettingOptional -> doLogin(username, password, publicSettingOptional)) .subscribe(
publicSettingOptional -> doLogin(username, password, publicSettingOptional),
Logger::report
)
); );
} }
...@@ -59,7 +63,9 @@ public class LoginPresenter extends BasePresenter<LoginContract.View> ...@@ -59,7 +63,9 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
loginServiceConfigurations -> view.showLoginServices(loginServiceConfigurations)) loginServiceConfigurations -> view.showLoginServices(loginServiceConfigurations),
Logger::report
)
); );
} }
......
...@@ -7,6 +7,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers; ...@@ -7,6 +7,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import chat.rocket.android.BackgroundLooper; import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.api.MethodCallHelper; import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.shared.BasePresenter; import chat.rocket.android.shared.BasePresenter;
import chat.rocket.core.interactors.SessionInteractor; import chat.rocket.core.interactors.SessionInteractor;
...@@ -49,7 +50,10 @@ public class RetryLoginPresenter extends BasePresenter<RetryLoginContract.View> ...@@ -49,7 +50,10 @@ public class RetryLoginPresenter extends BasePresenter<RetryLoginContract.View>
sessionInteractor.getDefault() sessionInteractor.getDefault()
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onSession) .subscribe(
this::onSession,
Logger::report
)
); );
} }
......
package chat.rocket.android.fragment.sidebar; package chat.rocket.android.fragment.sidebar;
import android.annotation.SuppressLint;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
...@@ -24,6 +25,7 @@ import chat.rocket.android.fragment.chatroom.RocketChatAbsoluteUrl; ...@@ -24,6 +25,7 @@ import chat.rocket.android.fragment.chatroom.RocketChatAbsoluteUrl;
import chat.rocket.android.fragment.sidebar.dialog.AddChannelDialogFragment; import chat.rocket.android.fragment.sidebar.dialog.AddChannelDialogFragment;
import chat.rocket.android.fragment.sidebar.dialog.AddDirectMessageDialogFragment; import chat.rocket.android.fragment.sidebar.dialog.AddDirectMessageDialogFragment;
import chat.rocket.android.helper.AbsoluteUrlHelper; import chat.rocket.android.helper.AbsoluteUrlHelper;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.layouthelper.chatroom.roomlist.ChannelRoomListHeader; import chat.rocket.android.layouthelper.chatroom.roomlist.ChannelRoomListHeader;
import chat.rocket.android.layouthelper.chatroom.roomlist.DirectMessageRoomListHeader; import chat.rocket.android.layouthelper.chatroom.roomlist.DirectMessageRoomListHeader;
...@@ -127,6 +129,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -127,6 +129,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
} }
@SuppressLint("RxLeakedSubscription")
private void setupUserActionToggle() { private void setupUserActionToggle() {
final CompoundButton toggleUserAction = final CompoundButton toggleUserAction =
((CompoundButton) rootView.findViewById(R.id.toggle_user_action)); ((CompoundButton) rootView.findViewById(R.id.toggle_user_action));
...@@ -137,8 +140,11 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -137,8 +140,11 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
RxCompoundButton.checkedChanges(toggleUserAction) RxCompoundButton.checkedChanges(toggleUserAction)
.compose(bindToLifecycle()) .compose(bindToLifecycle())
.subscribe(aBoolean -> rootView.findViewById(R.id.user_action_outer_container) .subscribe(
.setVisibility(aBoolean ? View.VISIBLE : View.GONE)); aBoolean -> rootView.findViewById(R.id.user_action_outer_container)
.setVisibility(aBoolean ? View.VISIBLE : View.GONE),
Logger::report
);
} }
private void setupUserStatusButtons() { private void setupUserStatusButtons() {
......
...@@ -12,6 +12,7 @@ import chat.rocket.android.RocketChatCache; ...@@ -12,6 +12,7 @@ import chat.rocket.android.RocketChatCache;
import chat.rocket.android.api.MethodCallHelper; import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.helper.AbsoluteUrlHelper; import chat.rocket.android.helper.AbsoluteUrlHelper;
import chat.rocket.android.helper.LogIfError; import chat.rocket.android.helper.LogIfError;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.shared.BasePresenter; import chat.rocket.android.shared.BasePresenter;
import chat.rocket.core.interactors.RoomInteractor; import chat.rocket.core.interactors.RoomInteractor;
...@@ -62,7 +63,10 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View ...@@ -62,7 +63,10 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
) )
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(pair -> view.show(pair.first.orNull(), pair.second.orNull())); .subscribe(
pair -> view.show(pair.first.orNull(), pair.second.orNull()),
Logger::report
);
addSubscription(subscription); addSubscription(subscription);
} }
...@@ -105,7 +109,8 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View ...@@ -105,7 +109,8 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
rooms -> view.showRoomList(rooms) rooms -> view.showRoomList(rooms),
Logger::report
); );
addSubscription(subscription); addSubscription(subscription);
......
package chat.rocket.android.fragment.sidebar.dialog; package chat.rocket.android.fragment.sidebar.dialog;
import android.annotation.SuppressLint;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.CompoundButton; import android.widget.CompoundButton;
...@@ -9,12 +10,14 @@ import com.jakewharton.rxbinding2.widget.RxTextView; ...@@ -9,12 +10,14 @@ import com.jakewharton.rxbinding2.widget.RxTextView;
import bolts.Task; import bolts.Task;
import chat.rocket.android.R; import chat.rocket.android.R;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
/** /**
* add Channel, add Private-group. * add Channel, add Private-group.
*/ */
public class AddChannelDialogFragment extends AbstractAddRoomDialogFragment { public class AddChannelDialogFragment extends AbstractAddRoomDialogFragment {
public AddChannelDialogFragment() { public AddChannelDialogFragment() {
} }
...@@ -32,14 +35,18 @@ public class AddChannelDialogFragment extends AbstractAddRoomDialogFragment { ...@@ -32,14 +35,18 @@ public class AddChannelDialogFragment extends AbstractAddRoomDialogFragment {
return R.layout.dialog_add_channel; return R.layout.dialog_add_channel;
} }
@SuppressLint("RxLeakedSubscription")
@Override @Override
protected void onSetupDialog() { protected void onSetupDialog() {
View buttonAddChannel = getDialog().findViewById(R.id.btn_add_channel); View buttonAddChannel = getDialog().findViewById(R.id.btn_add_channel);
RxTextView.textChanges((TextView) getDialog().findViewById(R.id.editor_channel_name)) RxTextView.textChanges((TextView) getDialog().findViewById(R.id.editor_channel_name))
.map(text -> !TextUtils.isEmpty(text)) .map(text -> !TextUtils.isEmpty(text))
.compose(bindToLifecycle()) .compose(bindToLifecycle())
.subscribe(buttonAddChannel::setEnabled); .subscribe(
buttonAddChannel::setEnabled,
Logger::report
);
buttonAddChannel.setOnClickListener(view -> createRoom()); buttonAddChannel.setOnClickListener(view -> createRoom());
} }
......
package chat.rocket.android.fragment.sidebar.dialog; package chat.rocket.android.fragment.sidebar.dialog;
import android.annotation.SuppressLint;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
...@@ -15,6 +16,7 @@ import chat.rocket.android.BackgroundLooper; ...@@ -15,6 +16,7 @@ import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.R; import chat.rocket.android.R;
import chat.rocket.android.fragment.chatroom.RocketChatAbsoluteUrl; import chat.rocket.android.fragment.chatroom.RocketChatAbsoluteUrl;
import chat.rocket.android.helper.AbsoluteUrlHelper; import chat.rocket.android.helper.AbsoluteUrlHelper;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.layouthelper.sidebar.dialog.SuggestUserAdapter; import chat.rocket.android.layouthelper.sidebar.dialog.SuggestUserAdapter;
import chat.rocket.core.interactors.SessionInteractor; import chat.rocket.core.interactors.SessionInteractor;
...@@ -45,6 +47,7 @@ public class AddDirectMessageDialogFragment extends AbstractAddRoomDialogFragmen ...@@ -45,6 +47,7 @@ public class AddDirectMessageDialogFragment extends AbstractAddRoomDialogFragmen
return R.layout.dialog_add_direct_message; return R.layout.dialog_add_direct_message;
} }
@SuppressLint("RxLeakedSubscription")
@Override @Override
protected void onSetupDialog() { protected void onSetupDialog() {
View buttonAddDirectMessage = getDialog().findViewById(R.id.btn_add_direct_message); View buttonAddDirectMessage = getDialog().findViewById(R.id.btn_add_direct_message);
...@@ -62,13 +65,19 @@ public class AddDirectMessageDialogFragment extends AbstractAddRoomDialogFragmen ...@@ -62,13 +65,19 @@ public class AddDirectMessageDialogFragment extends AbstractAddRoomDialogFragmen
absoluteUrlHelper.getRocketChatAbsoluteUrl() absoluteUrlHelper.getRocketChatAbsoluteUrl()
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::setupView) .subscribe(
this::setupView,
Logger::report
)
); );
RxTextView.textChanges(autoCompleteTextView) RxTextView.textChanges(autoCompleteTextView)
.map(text -> !TextUtils.isEmpty(text)) .map(text -> !TextUtils.isEmpty(text))
.compose(bindToLifecycle()) .compose(bindToLifecycle())
.subscribe(buttonAddDirectMessage::setEnabled); .subscribe(
buttonAddDirectMessage::setEnabled,
Logger::report
);
buttonAddDirectMessage.setOnClickListener(view -> createRoom()); buttonAddDirectMessage.setOnClickListener(view -> createRoom());
} }
......
package chat.rocket.android.helper;
import com.google.firebase.crash.FirebaseCrash;
public class Logger {
public static void report(Throwable throwable) {
FirebaseCrash.report(throwable);
}
}
...@@ -56,6 +56,7 @@ public class RocketChatAvatar extends FrameLayout { ...@@ -56,6 +56,7 @@ public class RocketChatAvatar extends FrameLayout {
public void loadImage(String url, Drawable placeholder) { public void loadImage(String url, Drawable placeholder) {
final GenericDraweeHierarchy hierarchy = draweeView.getHierarchy(); final GenericDraweeHierarchy hierarchy = draweeView.getHierarchy();
hierarchy.setPlaceholderImage(placeholder); hierarchy.setPlaceholderImage(placeholder);
hierarchy.setFailureImage(placeholder);
final DraweeController controller = Fresco.newDraweeControllerBuilder() final DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(Uri.parse(url)) .setUri(Uri.parse(url))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment