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