Commit b1514363 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Convert HomeFragment, RoomContract and RoomPresenter to Kotlin

parent ada461e5
package chat.rocket.android.fragment.chatroom;
import chat.rocket.android.R;
public class HomeFragment extends AbstractChatRoomFragment {
public HomeFragment() {}
@Override
protected int getLayout() {
return R.layout.fragment_home;
}
@Override
protected void onSetupView() {
setToolbarTitle(getText(R.string.home_fragment_title));
}
}
\ No newline at end of file
package chat.rocket.android.fragment.chatroom
import chat.rocket.android.R
class HomeFragment : AbstractChatRoomFragment() {
override fun getLayout(): Int {
return R.layout.fragment_home
}
override fun onSetupView() {
setToolbarTitle(getText(R.string.home_fragment_title))
}
}
\ No newline at end of file
package chat.rocket.android.fragment.chatroom;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.List;
import chat.rocket.android.shared.BaseContract;
import chat.rocket.android.widget.AbsoluteUrl;
import chat.rocket.core.models.Message;
import chat.rocket.core.models.Room;
import chat.rocket.core.models.User;
public interface RoomContract {
interface View extends BaseContract.View {
void setupWith(RocketChatAbsoluteUrl rocketChatAbsoluteUrl);
void render(Room room);
void showUserStatus(User user);
void updateHistoryState(boolean hasNext, boolean isLoaded);
void onMessageSendSuccessfully();
void disableMessageInput();
void enableMessageInput();
void showUnreadCount(int count);
void showMessages(List<Message> messages);
void showMessageSendFailure(Message message);
void showMessageDeleteFailure(Message message);
void autoloadImages();
void manualLoadImages();
void onReply(AbsoluteUrl absoluteUrl, String markdown, Message message);
void onCopy(String message);
void showMessageActions(Message message);
}
interface Presenter extends BaseContract.Presenter<View> {
void loadMessages();
void loadMoreMessages();
void onMessageSelected(@Nullable Message message);
void onMessageTap(@Nullable Message message);
void sendMessage(String messageText);
void resendMessage(@NonNull Message message);
void updateMessage(@NonNull Message message, String content);
void deleteMessage(@NonNull Message message);
void onUnreadCount();
void onMarkAsRead();
void refreshRoom();
void replyMessage(@NonNull Message message, boolean justQuote);
void acceptMessageDeleteFailure(Message message);
void loadMissedMessages();
}
}
package chat.rocket.android.fragment.chatroom
import chat.rocket.android.shared.BaseContract
import chat.rocket.android.widget.AbsoluteUrl
import chat.rocket.core.models.Message
import chat.rocket.core.models.Room
import chat.rocket.core.models.User
interface RoomContract {
interface View : BaseContract.View {
fun setupWith(rocketChatAbsoluteUrl: RocketChatAbsoluteUrl)
fun render(room: Room)
fun showUserStatus(user: User)
fun updateHistoryState(hasNext: Boolean, isLoaded: Boolean)
fun onMessageSendSuccessfully()
fun disableMessageInput()
fun enableMessageInput()
fun showUnreadCount(count: Int)
fun showMessages(messages: List<Message>)
fun showMessageSendFailure(message: Message)
fun showMessageDeleteFailure(message: Message)
fun autoloadImages()
fun manualLoadImages()
fun onReply(absoluteUrl: AbsoluteUrl, markdown: String, message: Message)
fun onCopy(message: String)
fun showMessageActions(message: Message)
}
interface Presenter : BaseContract.Presenter<View> {
fun loadMessages()
fun loadMoreMessages()
fun onMessageSelected(message: Message?)
fun onMessageTap(message: Message?)
fun sendMessage(messageText: String)
fun resendMessage(message: Message)
fun updateMessage(message: Message, content: String)
fun deleteMessage(message: Message)
fun onUnreadCount()
fun onMarkAsRead()
fun refreshRoom()
fun replyMessage(message: Message, justQuote: Boolean)
fun acceptMessageDeleteFailure(message: Message)
fun loadMissedMessages()
}
}
package chat.rocket.android.fragment.chatroom;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.Pair;
import com.hadisatrio.optional.Optional;
import org.json.JSONException;
import org.json.JSONObject;
import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.RocketChatApplication;
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.log.RCLog;
import chat.rocket.android.service.ConnectivityManagerApi;
import chat.rocket.android.shared.BasePresenter;
import chat.rocket.core.SyncState;
import chat.rocket.core.interactors.MessageInteractor;
import chat.rocket.core.models.Message;
import chat.rocket.core.models.Room;
import chat.rocket.core.models.Settings;
import chat.rocket.core.models.User;
import chat.rocket.core.repositories.RoomRepository;
import chat.rocket.core.repositories.UserRepository;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
public class RoomPresenter extends BasePresenter<RoomContract.View>
implements RoomContract.Presenter {
private final String roomId;
private final MessageInteractor messageInteractor;
private final UserRepository userRepository;
private final RoomRepository roomRepository;
private final AbsoluteUrlHelper absoluteUrlHelper;
private final MethodCallHelper methodCallHelper;
private final ConnectivityManagerApi connectivityManagerApi;
private Room currentRoom;
/* package */RoomPresenter(String roomId,
UserRepository userRepository,
MessageInteractor messageInteractor,
RoomRepository roomRepository,
AbsoluteUrlHelper absoluteUrlHelper,
MethodCallHelper methodCallHelper,
ConnectivityManagerApi connectivityManagerApi) {
this.roomId = roomId;
this.userRepository = userRepository;
this.messageInteractor = messageInteractor;
this.roomRepository = roomRepository;
this.absoluteUrlHelper = absoluteUrlHelper;
this.methodCallHelper = methodCallHelper;
this.connectivityManagerApi = connectivityManagerApi;
}
@Override
public void bindView(@NonNull RoomContract.View view) {
super.bindView(view);
refreshRoom();
}
@Override
public void refreshRoom() {
getRoomRoles();
getRoomInfo();
getRoomHistoryStateInfo();
getMessages();
getUserPreferences();
}
@Override
public void loadMessages() {
final Disposable subscription = getSingleRoom()
.flatMap(messageInteractor::loadMessages)
package chat.rocket.android.fragment.chatroom
import android.support.v4.util.Pair
import com.hadisatrio.optional.Optional
import org.json.JSONException
import org.json.JSONObject
import chat.rocket.android.BackgroundLooper
import chat.rocket.android.RocketChatApplication
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.log.RCLog
import chat.rocket.android.service.ConnectivityManagerApi
import chat.rocket.android.shared.BasePresenter
import chat.rocket.core.SyncState
import chat.rocket.core.interactors.MessageInteractor
import chat.rocket.core.models.Message
import chat.rocket.core.models.Room
import chat.rocket.core.models.Settings
import chat.rocket.core.models.User
import chat.rocket.core.repositories.RoomRepository
import chat.rocket.core.repositories.UserRepository
import io.reactivex.Flowable
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
class RoomPresenter/* package */ internal constructor(private val roomId: String,
private val userRepository: UserRepository,
private val messageInteractor: MessageInteractor,
private val roomRepository: RoomRepository,
private val absoluteUrlHelper: AbsoluteUrlHelper,
private val methodCallHelper: MethodCallHelper,
private val connectivityManagerApi: ConnectivityManagerApi) : BasePresenter<RoomContract.View>(), RoomContract.Presenter {
private var currentRoom: Room? = null
private val roomUserPair: Single<Pair<Room, User>>
get() = Single.zip(
singleRoom,
currentUser,
BiFunction<Room, User, Pair<Room, User>> { first, second -> Pair(first, second) }
)
private val singleRoom: Single<Room>
get() = roomRepository.getById(roomId)
.filter(Predicate<Optional<Room>> { it.isPresent() })
.map<Room>(Function<Optional<Room>, Room> { it.get() })
.firstElement()
.toSingle()
private val currentUser: Single<User>
get() = userRepository.getCurrent()
.filter(Predicate<Optional<User>> { it.isPresent() })
.map<User>(Function<Optional<User>, User> { it.get() })
.firstElement()
.toSingle()
override fun bindView(view: RoomContract.View) {
super.bindView(view)
refreshRoom()
}
override fun refreshRoom() {
getRoomRoles()
getRoomInfo()
getRoomHistoryStateInfo()
getMessages()
getUserPreferences()
}
override fun loadMessages() {
val subscription = singleRoom
.flatMap<Boolean>(Function<Room, SingleSource<out Boolean>> { messageInteractor.loadMessages(it) })
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
success -> {
{ success ->
if (!success) {
connectivityManagerApi.keepAliveServer();
connectivityManagerApi.keepAliveServer()
}
},
Logger.INSTANCE::report
);
Consumer<Throwable> { Logger.report(it) }
)
addSubscription(subscription);
addSubscription(subscription)
}
@Override
public void loadMoreMessages() {
final Disposable subscription = getSingleRoom()
.flatMap(messageInteractor::loadMoreMessages)
override fun loadMoreMessages() {
val subscription = singleRoom
.flatMap<Boolean>(Function<Room, SingleSource<out Boolean>> { messageInteractor.loadMoreMessages(it) })
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
success -> {
{ success ->
if (!success) {
connectivityManagerApi.keepAliveServer();
connectivityManagerApi.keepAliveServer()
}
},
Logger.INSTANCE::report
);
Consumer<Throwable> { Logger.report(it) }
)
addSubscription(subscription);
addSubscription(subscription)
}
@Override
public void onMessageSelected(@Nullable Message message) {
override fun onMessageSelected(message: Message?) {
if (message == null) {
return;
return
}
if (message.getSyncState() == SyncState.DELETE_FAILED) {
view.showMessageDeleteFailure(message);
} else if (message.getSyncState() == SyncState.FAILED) {
view.showMessageSendFailure(message);
} else if (message.getType() == null && message.getSyncState() == SyncState.SYNCED) {
if (message.syncState == SyncState.DELETE_FAILED) {
view.showMessageDeleteFailure(message)
} else if (message.syncState == SyncState.FAILED) {
view.showMessageSendFailure(message)
} else if (message.type == null && message.syncState == SyncState.SYNCED) {
// If message is not a system message show applicable actions.
view.showMessageActions(message);
view.showMessageActions(message)
}
}
@Override
public void onMessageTap(@Nullable Message message) {
override fun onMessageTap(message: Message?) {
if (message == null) {
return;
return
}
if (message.getSyncState() == SyncState.FAILED) {
view.showMessageSendFailure(message);
if (message.syncState == SyncState.FAILED) {
view.showMessageSendFailure(message)
}
}
@Override
public void replyMessage(@NonNull Message message, boolean justQuote) {
final Disposable subscription = this.absoluteUrlHelper.getRocketChatAbsoluteUrl()
override fun replyMessage(message: Message, justQuote: Boolean) {
val subscription = this.absoluteUrlHelper.rocketChatAbsoluteUrl
.cache()
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
serverUrl -> {
if (serverUrl.isPresent()) {
RocketChatAbsoluteUrl absoluteUrl = serverUrl.get();
String baseUrl = absoluteUrl.getBaseUrl();
view.onReply(absoluteUrl, buildReplyOrQuoteMarkdown(baseUrl, message, justQuote), message);
{ serverUrl ->
if (serverUrl.isPresent) {
val absoluteUrl = serverUrl.get()
val baseUrl = absoluteUrl.baseUrl
view.onReply(absoluteUrl, buildReplyOrQuoteMarkdown(baseUrl, message, justQuote), message)
}
},
Logger.INSTANCE::report
);
Consumer<Throwable> { Logger.report(it) }
)
addSubscription(subscription);
addSubscription(subscription)
}
public void acceptMessageDeleteFailure(Message message) {
final Disposable subscription = messageInteractor.acceptDeleteFailure(message)
override fun acceptMessageDeleteFailure(message: Message) {
val subscription = messageInteractor.acceptDeleteFailure(message)
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
.subscribe()
addSubscription(subscription);
addSubscription(subscription)
}
@Override
public void loadMissedMessages() {
RocketChatApplication appContext = RocketChatApplication.getInstance();
JSONObject openedRooms = new RocketChatCache(appContext).getOpenedRooms();
override fun loadMissedMessages() {
val appContext = RocketChatApplication.getInstance()
val openedRooms = RocketChatCache(appContext).openedRooms
if (openedRooms.has(roomId)) {
try {
JSONObject room = openedRooms.getJSONObject(roomId);
String rid = room.optString("rid");
long ls = room.optLong("ls");
val room = openedRooms.getJSONObject(roomId)
val rid = room.optString("rid")
val ls = room.optLong("ls")
methodCallHelper.loadMissedMessages(rid, ls)
.continueWith(new LogIfError());
} catch (JSONException e) {
RCLog.e(e);
.continueWith(LogIfError())
} catch (e: JSONException) {
RCLog.e(e)
}
}
}
private String buildReplyOrQuoteMarkdown(String baseUrl, Message message, boolean justQuote) {
if (currentRoom == null || message.getUser() == null) {
return "";
private fun buildReplyOrQuoteMarkdown(baseUrl: String, message: Message, justQuote: Boolean): String {
if (currentRoom == null || message.user == null) {
return ""
}
if (currentRoom.isDirectMessage()) {
return String.format("[ ](%s/direct/%s?msg=%s) ", baseUrl,
message.getUser().getUsername(),
message.getId());
return if (currentRoom!!.isDirectMessage) {
String.format("[ ](%s/direct/%s?msg=%s) ", baseUrl,
message.user!!.username,
message.id)
} else {
return String.format("[ ](%s/channel/%s?msg=%s) %s", baseUrl,
currentRoom.getName(),
message.getId(),
justQuote ? "" : "@" + message.getUser().getUsername() + " ");
String.format("[ ](%s/channel/%s?msg=%s) %s", baseUrl,
currentRoom!!.name,
message.id,
if (justQuote) "" else "@" + message.user!!.username + " ")
}
}
@Override
public void sendMessage(String messageText) {
view.disableMessageInput();
final Disposable subscription = getRoomUserPair()
.flatMap(pair -> messageInteractor.send(pair.first, pair.second, messageText))
override fun sendMessage(messageText: String) {
view.disableMessageInput()
val subscription = roomUserPair
.flatMap { pair -> messageInteractor.send(pair.first!!, pair.second!!, messageText) }
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
success -> {
{ success ->
if (success) {
view.onMessageSendSuccessfully();
view.onMessageSendSuccessfully()
}
view.enableMessageInput();
},
throwable -> {
view.enableMessageInput();
Logger.INSTANCE.report(throwable);
view.enableMessageInput()
}
) { throwable ->
view.enableMessageInput()
Logger.report(throwable)
}
);
addSubscription(subscription);
addSubscription(subscription)
}
@Override
public void resendMessage(@NonNull Message message) {
final Disposable subscription = getCurrentUser()
.flatMap(user -> messageInteractor.resend(message, user))
override fun resendMessage(message: Message) {
val subscription = currentUser
.flatMap { user -> messageInteractor.resend(message, user) }
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
.subscribe()
addSubscription(subscription);
addSubscription(subscription)
}
@Override
public void updateMessage(@NonNull Message message, String content) {
view.disableMessageInput();
final Disposable subscription = getCurrentUser()
.flatMap(user -> messageInteractor.update(message, user, content))
override fun updateMessage(message: Message, content: String) {
view.disableMessageInput()
val subscription = currentUser
.flatMap { user -> messageInteractor.update(message, user, content) }
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
success -> {
{ success ->
if (success) {
view.onMessageSendSuccessfully();
view.onMessageSendSuccessfully()
}
view.enableMessageInput();
},
throwable -> {
view.enableMessageInput();
Logger.INSTANCE.report(throwable);
view.enableMessageInput()
}
) { throwable ->
view.enableMessageInput()
Logger.report(throwable)
}
);
addSubscription(subscription);
addSubscription(subscription)
}
@Override
public void deleteMessage(@NonNull Message message) {
final Disposable subscription = messageInteractor.delete(message)
override fun deleteMessage(message: Message) {
val subscription = messageInteractor.delete(message)
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
.subscribe()
addSubscription(subscription);
addSubscription(subscription)
}
@Override
public void onUnreadCount() {
final Disposable subscription = getRoomUserPair()
.flatMap(roomUserPair -> messageInteractor
.unreadCountFor(roomUserPair.first, roomUserPair.second))
override fun onUnreadCount() {
val subscription = roomUserPair
.flatMap { roomUserPair ->
messageInteractor
.unreadCountFor(roomUserPair.first!!, roomUserPair.second!!)
}
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
count -> view.showUnreadCount(count),
Logger.INSTANCE::report
);
{ count -> view.showUnreadCount(count) },
Consumer<Throwable> { Logger.report(it) }
)
addSubscription(subscription);
addSubscription(subscription)
}
@Override
public void onMarkAsRead() {
final Disposable subscription = roomRepository.getById(roomId)
.filter(Optional::isPresent)
.map(Optional::get)
override fun onMarkAsRead() {
val subscription = roomRepository.getById(roomId)
.filter(Predicate<Optional<Room>> { it.isPresent() })
.map<Room>(Function<Optional<Room>, Room> { it.get() })
.firstElement()
.filter(Room::isAlert)
.filter(Predicate<Room> { it.isAlert() })
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
room -> methodCallHelper.readMessages(room.getRoomId())
.continueWith(new LogIfError()),
Logger.INSTANCE::report
);
{ room ->
methodCallHelper.readMessages(room.roomId)
.continueWith(LogIfError())
},
Consumer<Throwable> { Logger.report(it) }
)
addSubscription(subscription);
addSubscription(subscription)
}
private void getRoomRoles() {
methodCallHelper.getRoomRoles(roomId);
private fun getRoomRoles() {
methodCallHelper.getRoomRoles(roomId)
}
private void getRoomInfo() {
final Disposable subscription = roomRepository.getById(roomId)
private fun getRoomInfo() {
val subscription = roomRepository.getById(roomId)
.distinctUntilChanged()
.filter(Optional::isPresent)
.map(Optional::get)
.filter(Predicate<Optional<Room>> { it.isPresent() })
.map<Room>(Function<Optional<Room>, Room> { it.get() })
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::processRoom, Logger.INSTANCE::report);
addSubscription(subscription);
.subscribe(Consumer<Room> { this.processRoom(it) }, Consumer<Throwable> { Logger.report(it) })
addSubscription(subscription)
}
private void processRoom(Room room) {
this.currentRoom = room;
view.render(room);
private fun processRoom(room: Room) {
this.currentRoom = room
view.render(room)
if (room.isDirectMessage()) {
getUserByUsername(room.getName());
if (room.isDirectMessage) {
getUserByUsername(room.name)
}
}
private void getUserByUsername(String username) {
final Disposable disposable = userRepository.getByUsername(username)
private fun getUserByUsername(username: String) {
val disposable = userRepository.getByUsername(username)
.distinctUntilChanged()
.filter(Optional::isPresent)
.map(Optional::get)
.filter(Predicate<Optional<User>> { it.isPresent() })
.map<User>(Function<Optional<User>, User> { it.get() })
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(view::showUserStatus, Logger.INSTANCE::report);
addSubscription(disposable);
.subscribe(Consumer<User> { view.showUserStatus(it) }, Consumer<Throwable> { Logger.report(it) })
addSubscription(disposable)
}
private void getRoomHistoryStateInfo() {
final Disposable subscription = roomRepository.getHistoryStateByRoomId(roomId)
private fun getRoomHistoryStateInfo() {
val subscription = roomRepository.getHistoryStateByRoomId(roomId)
.distinctUntilChanged()
.filter(Optional::isPresent)
.map(Optional::get)
.filter(Predicate<Optional<RoomHistoryState>> { it.isPresent() })
.map<RoomHistoryState>(Function<Optional<RoomHistoryState>, RoomHistoryState> { it.get() })
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
roomHistoryState -> {
int syncState = roomHistoryState.getSyncState();
{ roomHistoryState ->
val syncState = roomHistoryState.getSyncState()
view.updateHistoryState(
!roomHistoryState.isComplete(),
syncState == SyncState.SYNCED || syncState == SyncState.FAILED
);
)
},
Logger.INSTANCE::report
);
Consumer<Throwable> { Logger.report(it) }
)
addSubscription(subscription);
addSubscription(subscription)
}
private void getMessages() {
final Disposable subscription = Flowable.zip(roomRepository.getById(roomId),
absoluteUrlHelper.getRocketChatAbsoluteUrl().toFlowable().cache(), Pair::new)
private fun getMessages() {
val subscription = Flowable.zip<Optional<Room>, Optional<RocketChatAbsoluteUrl>, Pair<Optional<Room>, Optional<RocketChatAbsoluteUrl>>>(roomRepository.getById(roomId),
absoluteUrlHelper.rocketChatAbsoluteUrl.toFlowable().cache(), BiFunction<Optional<Room>, Optional<RocketChatAbsoluteUrl>, Pair<Optional<Room>, Optional<RocketChatAbsoluteUrl>>> { first, second -> Pair(first, second) })
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.map(pair -> {
view.setupWith(pair.second.orNull());
return pair.first;
})
.filter(Optional::isPresent)
.map(Optional::get)
.map(room -> {
new RocketChatCache(RocketChatApplication.getInstance())
.addOpenedRoom(room.getRoomId(), room.getLastSeen());
return room;
})
.flatMap(messageInteractor::getAllFrom)
.map<Optional<Room>> { pair ->
view.setupWith(pair.second!!.orNull())
pair.first
}
.filter(Predicate<Optional<Room>> { it.isPresent() })
.map<Room>(Function<Optional<Room>, Room> { it.get() })
.map { room ->
RocketChatCache(RocketChatApplication.getInstance())
.addOpenedRoom(room.roomId, room.lastSeen)
room
}
.flatMap<List<Message>>(Function<Room, Publisher<out List<Message>>> { messageInteractor.getAllFrom(it) })
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
view::showMessages,
Logger.INSTANCE::report
);
Consumer<List<Message>> { view.showMessages(it) },
Consumer<Throwable> { Logger.report(it) }
)
addSubscription(subscription);
addSubscription(subscription)
}
private void getUserPreferences() {
final Disposable subscription = userRepository.getCurrent()
.filter(Optional::isPresent)
.map(Optional::get)
.filter(user -> user.getSettings() != null)
.map(User::getSettings)
.filter(settings -> settings.getPreferences() != null)
.map(Settings::getPreferences)
private fun getUserPreferences() {
val subscription = userRepository.getCurrent()
.filter(Predicate<Optional<User>> { it.isPresent() })
.map<User>(Function<Optional<User>, User> { it.get() })
.filter { user -> user.settings != null }
.map<Settings>(Function<User, Settings> { it.getSettings() })
.filter { settings -> settings.preferences != null }
.map<Preferences>(Function<Settings, Preferences> { it.getPreferences() })
.distinctUntilChanged()
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
preferences -> {
{ preferences ->
if (preferences.isAutoImageLoad()) {
view.autoloadImages();
view.autoloadImages()
} else {
view.manualLoadImages();
view.manualLoadImages()
}
},
Logger.INSTANCE::report
);
Consumer<Throwable> { Logger.report(it) }
)
addSubscription(subscription);
addSubscription(subscription)
}
private void getAbsoluteUrl() {
final Disposable subscription = absoluteUrlHelper.getRocketChatAbsoluteUrl()
private fun getAbsoluteUrl() {
val subscription = absoluteUrlHelper.rocketChatAbsoluteUrl
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
it -> view.setupWith(it.orNull()),
Logger.INSTANCE::report
);
{ it -> view.setupWith(it.orNull()) },
Consumer<Throwable> { Logger.report(it) }
)
addSubscription(subscription);
}
private Single<Pair<Room, User>> getRoomUserPair() {
return Single.zip(
getSingleRoom(),
getCurrentUser(),
Pair::new
);
}
private Single<Room> getSingleRoom() {
return roomRepository.getById(roomId)
.filter(Optional::isPresent)
.map(Optional::get)
.firstElement()
.toSingle();
}
private Single<User> getCurrentUser() {
return userRepository.getCurrent()
.filter(Optional::isPresent)
.map(Optional::get)
.firstElement()
.toSingle();
addSubscription(subscription)
}
}
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