Commit 75382d39 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Code refactor

parent 69270690
......@@ -18,8 +18,8 @@ android {
applicationId "chat.rocket.android"
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
versionCode 2060
versionName "3.3.0"
versionCode 2061
versionName "3.4.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
......
......@@ -22,7 +22,6 @@ import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.server.domain.AccountsRepository
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.SITE_URL
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.util.retryIO
......@@ -45,44 +44,25 @@ import javax.inject.Inject
class RocketChatApplication : Application(), HasActivityInjector, HasServiceInjector,
HasBroadcastReceiverInjector, HasWorkerInjector {
@Inject lateinit var activityDispatchingAndroidInjector: DispatchingAndroidInjector<Activity>
@Inject lateinit var serviceDispatchingAndroidInjector: DispatchingAndroidInjector<Service>
@Inject lateinit var broadcastReceiverInjector: DispatchingAndroidInjector<BroadcastReceiver>
@Inject lateinit var workerInjector: DispatchingAndroidInjector<Worker>
@Inject
lateinit var appLifecycleObserver: AppLifecycleObserver
@Inject lateinit var appLifecycleObserver: AppLifecycleObserver
@Inject
lateinit var activityDispatchingAndroidInjector: DispatchingAndroidInjector<Activity>
@Inject
lateinit var serviceDispatchingAndroidInjector: DispatchingAndroidInjector<Service>
@Inject
lateinit var broadcastReceiverInjector: DispatchingAndroidInjector<BroadcastReceiver>
@Inject
lateinit var workerInjector: DispatchingAndroidInjector<Worker>
@Inject
lateinit var imagePipelineConfig: ImagePipelineConfig
@Inject
lateinit var draweeConfig: DraweeConfig
@Inject lateinit var imagePipelineConfig: ImagePipelineConfig
@Inject lateinit var draweeConfig: DraweeConfig
// TODO - remove this from here when we have a proper service handling the connection.
@Inject
lateinit var getCurrentServerInteractor: GetCurrentServerInteractor
@Inject
lateinit var settingsInteractor: GetSettingsInteractor
@Inject
lateinit var tokenRepository: TokenRepository
@Inject
lateinit var localRepository: LocalRepository
@Inject
lateinit var accountRepository: AccountsRepository
@Inject
lateinit var factory: RocketChatClientFactory
@Inject
@field:ForMessages
lateinit var messagesPrefs: SharedPreferences
@Inject lateinit var getCurrentServerInteractor: GetCurrentServerInteractor
@Inject lateinit var settingsInteractor: GetSettingsInteractor
@Inject lateinit var tokenRepository: TokenRepository
@Inject lateinit var localRepository: LocalRepository
@Inject lateinit var accountRepository: AccountsRepository
@Inject lateinit var factory: RocketChatClientFactory
@Inject @field:ForMessages lateinit var messagesPrefs: SharedPreferences
override fun onCreate() {
super.onCreate()
......@@ -92,9 +72,7 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
.build()
.inject(this)
ProcessLifecycleOwner.get()
.lifecycle
.addObserver(appLifecycleObserver)
ProcessLifecycleOwner.get().lifecycle.addObserver(appLifecycleObserver)
context = WeakReference(applicationContext)
......@@ -111,34 +89,10 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
localRepository.setOldMessagesCleanedUp()
}
// TODO - remove REALM files.
// TODO - remove this
checkCurrentServer()
// TODO - FIXME - we need to properly inject and initialize the EmojiRepository
loadEmojis()
}
private fun checkCurrentServer() {
val currentServer = getCurrentServerInteractor.get() ?: "<unknown>"
if (currentServer == "<unknown>") {
val message = "null currentServer"
Timber.d(IllegalStateException(message), message)
}
val settings = settingsInteractor.get(currentServer)
if (settings.isEmpty()) {
val message = "Empty settings for: $currentServer"
Timber.d(IllegalStateException(message), message)
}
val baseUrl = settings[SITE_URL]
if (baseUrl == null) {
val message = "Server $currentServer SITE_URL"
Timber.d(IllegalStateException(message), message)
}
}
private fun setupFresco() {
Fresco.initialize(this, imagePipelineConfig, draweeConfig)
}
......
......@@ -54,8 +54,8 @@ class LoginFragment : Fragment(), LoginView {
private val editTextsDisposable = CompositeDisposable()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
serverName = getString(SERVER_NAME)
......
......@@ -152,8 +152,8 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
private var deepLinkInfo: LoginDeepLinkInfo? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
serverName = getString(SERVER_NAME)
......
......@@ -30,8 +30,8 @@ class OnBoardingFragment : Fragment(), OnBoardingView {
lateinit var analyticsManager: AnalyticsManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
}
override fun onCreateView(
......
......@@ -48,8 +48,8 @@ class RegisterUsernameFragment : Fragment(), RegisterUsernameView {
private lateinit var usernameDisposable: Disposable
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
userId = getString(BUNDLE_USER_ID, "")
......
......@@ -37,8 +37,8 @@ class ResetPasswordFragment : Fragment(), ResetPasswordView {
private lateinit var emailAddressDisposable: Disposable
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
}
override fun onCreateView(
......
......@@ -64,8 +64,8 @@ class ServerFragment : Fragment(), ServerView {
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
deepLinkInfo = arguments?.getParcelable(DEEP_LINK_INFO)
}
......
......@@ -40,8 +40,8 @@ class SignupFragment : Fragment(), SignupView {
private val editTextsDisposable = CompositeDisposable()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
}
override fun onCreateView(
......
......@@ -45,8 +45,8 @@ class TwoFAFragment : Fragment(), TwoFAView {
private lateinit var twoFaCodeDisposable: Disposable
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
username = getString(BUNDLE_USERNAME, "")
......
......@@ -60,14 +60,10 @@ private const val BUNDLE_IS_FAVORITE = "BUNDLE_IS_FAVORITE"
private const val BUNDLE_DISABLE_MENU = "BUNDLE_DISABLE_MENU"
class ChatDetailsFragment : Fragment(), ChatDetailsView {
@Inject
lateinit var presenter: ChatDetailsPresenter
@Inject
lateinit var factory: ChatDetailsViewModelFactory
@Inject
lateinit var serverUrl: CurrentServerRepository
@Inject
lateinit var settings: GetSettingsInteractor
@Inject lateinit var presenter: ChatDetailsPresenter
@Inject lateinit var factory: ChatDetailsViewModelFactory
@Inject lateinit var serverUrl: CurrentServerRepository
@Inject lateinit var settings: GetSettingsInteractor
private var adapter: ChatDetailsAdapter? = null
private lateinit var viewModel: ChatDetailsViewModel
......@@ -78,8 +74,8 @@ class ChatDetailsFragment : Fragment(), ChatDetailsView {
private var disableMenu: Boolean = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
chatRoomId = getString(BUNDLE_CHAT_ROOM_ID)
......@@ -154,19 +150,19 @@ class ChatDetailsFragment : Fragment(), ChatDetailsView {
adapter?.let {
if (!disableMenu) {
it.addOption(getString(R.string.title_files), R.drawable.ic_files_24dp) {
presenter.toFiles(chatRoomId!!)
presenter.toFiles(chatRoomId)
}
}
if (chatRoomType != RoomType.DIRECT_MESSAGE && !disableMenu) {
it.addOption(getString(R.string.msg_mentions), R.drawable.ic_at_black_20dp) {
presenter.toMentions(chatRoomId!!)
presenter.toMentions(chatRoomId)
}
it.addOption(
getString(R.string.title_members),
R.drawable.ic_people_outline_black_24dp
) {
presenter.toMembers(chatRoomId!!)
presenter.toMembers(chatRoomId)
}
}
......@@ -174,13 +170,13 @@ class ChatDetailsFragment : Fragment(), ChatDetailsView {
getString(R.string.title_favorite_messages),
R.drawable.ic_star_border_white_24dp
) {
presenter.toFavorites(chatRoomId!!)
presenter.toFavorites(chatRoomId)
}
it.addOption(
getString(R.string.title_pinned_messages),
R.drawable.ic_action_message_pin_24dp
) {
presenter.toPinned(chatRoomId!!)
presenter.toPinned(chatRoomId)
}
}
}
......@@ -206,11 +202,11 @@ class ChatDetailsFragment : Fragment(), ChatDetailsView {
private fun getDetails() {
if (isSubscribed)
viewModel.getDetails(chatRoomId!!).observe(viewLifecycleOwner, Observer { details ->
viewModel.getDetails(chatRoomId).observe(viewLifecycleOwner, Observer { details ->
displayDetails(details)
})
else
presenter.getDetails(chatRoomId!!, chatRoomType!!)
presenter.getDetails(chatRoomId, chatRoomType)
}
private fun setupOptions() {
......
......@@ -42,8 +42,8 @@ class MessageInfoFragment : Fragment(), MessageInfoView {
private lateinit var messageId: String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
val bundle = arguments
if (bundle != null) {
......
package chat.rocket.android.chatroom.di
import chat.rocket.android.chatroom.service.MessageService
import chat.rocket.android.dagger.module.AppModule
import dagger.Module
import dagger.android.ContributesAndroidInjector
@Module
abstract class MessageServiceProvider {
@ContributesAndroidInjector(modules = [AppModule::class])
abstract fun provideMessageService(): MessageService
}
\ No newline at end of file
......@@ -34,7 +34,6 @@ import chat.rocket.android.server.domain.uploadMaxFileSize
import chat.rocket.android.server.domain.uploadMimeTypeFilter
import chat.rocket.android.server.domain.useRealName
import chat.rocket.android.server.infraestructure.ConnectionManagerFactory
import chat.rocket.android.server.infraestructure.state
import chat.rocket.android.util.extension.getByteArray
import chat.rocket.android.util.extension.launchUI
import chat.rocket.android.util.extensions.avatarUrl
......@@ -47,7 +46,6 @@ import chat.rocket.common.model.UserStatus
import chat.rocket.common.model.roomTypeOf
import chat.rocket.common.util.ifNull
import chat.rocket.core.internal.realtime.setTypingStatus
import chat.rocket.core.internal.realtime.socket.model.State
import chat.rocket.core.internal.realtime.subscribeTypingStatus
import chat.rocket.core.internal.realtime.unsubscribe
import chat.rocket.core.internal.rest.chatRoomRoles
......@@ -112,30 +110,29 @@ class ChatRoomPresenter @Inject constructor(
private val currentLoggedUsername = userHelper.username()
private val messagesChannel = Channel<Message>()
private var chatRoomId: String? = null
private lateinit var chatRoomId: String
private lateinit var chatRoomType: String
private var chatIsBroadcast: Boolean = false
private var chatRoles = emptyList<ChatRoomRole>()
private val stateChannel = Channel<State>()
private var typingStatusSubscriptionId: String? = null
private var lastState = manager.state
private var typingStatusList = arrayListOf<String>()
private val roomChangesChannel = Channel<Room>(Channel.CONFLATED)
private lateinit var draftKey: String
fun setupChatRoom(
roomId: String,
fun setup(roomId: String, roomType: String) {
chatRoomId = roomId
chatRoomType = roomType
draftKey = "${currentServer}_${LocalRepository.DRAFT_KEY}$roomId"
}
fun loadChatRoomRolesAndMessages(
roomName: String,
roomType: String,
chatRoomMessage: String? = null
) {
draftKey = "${currentServer}_${LocalRepository.DRAFT_KEY}$roomId"
chatRoomId = roomId
chatRoomType = roomType
GlobalScope.launch(Dispatchers.IO + strategy.jobs) {
try {
chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) {
client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName)
chatRoles = if (roomTypeOf(chatRoomType) !is RoomType.DirectMessage) {
client.chatRoomRoles(roomType = roomTypeOf(chatRoomType), roomName = roomName)
} else {
emptyList()
}
......@@ -146,7 +143,7 @@ class ChatRoomPresenter @Inject constructor(
// User has at least an 'owner' or 'moderator' role.
val canModerate = isOwnerOrMod()
// Can post anyway if has the 'post-readonly' permission on server.
val room = dbManager.getRoom(roomId)
val room = dbManager.getRoom(chatRoomId)
room?.let {
chatIsBroadcast = it.chatRoom.broadcast ?: false
val roomUiModel = roomMapper.map(it, true)
......@@ -159,7 +156,7 @@ class ChatRoomPresenter @Inject constructor(
}
}
loadMessages(roomId, roomType, clearDataSet = true)
loadMessages(chatRoomId, chatRoomType, clearDataSet = true)
chatRoomMessage?.let { messageHelper.messageIdFromPermalink(it) }
?.let { messageId ->
val name = messageHelper.roomNameFromPermalink(chatRoomMessage)
......@@ -177,8 +174,7 @@ class ChatRoomPresenter @Inject constructor(
private suspend fun subscribeRoomChanges() {
withContext(Dispatchers.IO + strategy.jobs) {
chatRoomId?.let {
manager.addRoomChannel(it, roomChangesChannel)
manager.addRoomChannel(chatRoomId, roomChangesChannel)
for (room in roomChangesChannel) {
dbManager.getRoom(room.id)?.let { chatRoom ->
view.onRoomUpdated(roomMapper.map(chatRoom = chatRoom, showLastMessage = true))
......@@ -186,10 +182,9 @@ class ChatRoomPresenter @Inject constructor(
}
}
}
}
private fun unsubscribeRoomChanges() {
chatRoomId?.let { manager.removeRoomChannel(it) }
manager.removeRoomChannel(chatRoomId)
}
private fun isOwnerOrMod(): Boolean {
......@@ -248,7 +243,6 @@ class ChatRoomPresenter @Inject constructor(
}
subscribeTypingStatus()
subscribeState()
}
}
......@@ -521,16 +515,16 @@ class ChatRoomPresenter @Inject constructor(
fun sendTyping() {
GlobalScope.launch(Dispatchers.IO + strategy.jobs) {
if (chatRoomId != null && currentLoggedUsername != null) {
client.setTypingStatus(chatRoomId.toString(), currentLoggedUsername, true)
if (currentLoggedUsername != null) {
client.setTypingStatus(chatRoomId, currentLoggedUsername, true)
}
}
}
fun sendNotTyping() {
GlobalScope.launch(Dispatchers.IO + strategy.jobs) {
if (chatRoomId != null && currentLoggedUsername != null) {
client.setTypingStatus(chatRoomId.toString(), currentLoggedUsername, false)
if (currentLoggedUsername != null) {
client.setTypingStatus(chatRoomId, currentLoggedUsername, false)
}
}
}
......@@ -546,28 +540,6 @@ class ChatRoomPresenter @Inject constructor(
}
}
private suspend fun subscribeState() {
Timber.d("Subscribing to Status changes")
lastState = manager.state
manager.addStatusChannel(stateChannel)
GlobalScope.launch(Dispatchers.IO + strategy.jobs) {
for (state in stateChannel) {
Timber.d("Got new state: $state - last: $lastState")
if (state != lastState) {
launch(Dispatchers.Main) {
view.showConnectionState(state)
}
if (state is State.Connected) {
jobSchedulerInteractor.scheduleSendingMessages()
loadMissingMessages()
}
}
lastState = state
}
}
}
private fun subscribeMessages(roomId: String) {
manager.subscribeRoomMessages(roomId, messagesChannel)
......@@ -581,7 +553,6 @@ class ChatRoomPresenter @Inject constructor(
private fun loadMissingMessages() {
GlobalScope.launch(strategy.jobs) {
chatRoomId?.let { chatRoomId ->
val roomType = roomTypeOf(chatRoomType)
val lastSyncDate = messagesRepository.getLastSyncDate(chatRoomId)
// lastSyncDate or 0. LastSyncDate could be in case when we sent some messages offline(and saved them locally),
......@@ -626,7 +597,6 @@ class ChatRoomPresenter @Inject constructor(
}
}
}
}
/**
* Delete the message with the given id.
......@@ -1188,14 +1158,12 @@ class ChatRoomPresenter @Inject constructor(
fun disconnect() {
unsubscribeRoomChanges()
unsubscribeTypingStatus()
if (chatRoomId != null) {
unsubscribeMessages(chatRoomId.toString())
}
unsubscribeMessages(chatRoomId)
}
private fun subscribeTypingStatus() {
GlobalScope.launch(Dispatchers.IO + strategy.jobs) {
client.subscribeTypingStatus(chatRoomId.toString()) { _, id ->
client.subscribeTypingStatus(chatRoomId) { _, id ->
typingStatusSubscriptionId = id
}
......@@ -1237,7 +1205,6 @@ class ChatRoomPresenter @Inject constructor(
}
private fun unsubscribeMessages(chatRoomId: String) {
manager.removeStatusChannel(stateChannel)
manager.unsubscribeRoomMessages(chatRoomId)
// All messages during the subscribed period are assumed to be read,
// and lastSeen is updated as the time when the user leaves the room
......
......@@ -117,8 +117,6 @@ interface ChatRoomView : LoadingView, MessageView {
fun showInvalidFileSize(fileSize: Int, maxFileSize: Int)
fun showConnectionState(state: State)
fun populatePeopleSuggestions(members: List<PeopleSuggestionUiModel>)
fun populateRoomSuggestions(chatRooms: List<ChatRoomSuggestionUiModel>)
......
......@@ -149,7 +149,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
lateinit var analyticsManager: AnalyticsManager
@Inject
lateinit var navigator: ChatRoomNavigator
private lateinit var adapter: ChatRoomAdapter
private lateinit var chatRoomAdapter: ChatRoomAdapter
internal lateinit var chatRoomId: String
private lateinit var chatRoomName: String
internal lateinit var chatRoomType: String
......@@ -266,8 +266,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
chatRoomId = getString(BUNDLE_CHAT_ROOM_ID, "")
......@@ -282,16 +282,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
?: requireNotNull(arguments) { "no arguments supplied when the fragment was instantiated" }
adapter = ChatRoomAdapter(
roomId = chatRoomId,
roomType = chatRoomType,
roomName = chatRoomName,
actionSelectListener = this,
reactionListener = this,
navigator = navigator,
analyticsManager = analyticsManager
)
setHasOptionsMenu(true)
}
......@@ -305,8 +295,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
super.onViewCreated(view, savedInstanceState)
setupToolbar(chatRoomName)
presenter.setupChatRoom(chatRoomId, chatRoomName, chatRoomType, chatRoomMessage)
presenter.loadChatRoomsSuggestions()
presenter.setup(chatRoomId, chatRoomType)
setupRecyclerView()
setupFab()
setupSuggestionsView()
......@@ -326,6 +316,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
getDraftMessage()
subscribeComposeTextMessage()
presenter.loadChatRoomRolesAndMessages(chatRoomName, chatRoomMessage)
presenter.loadChatRoomsSuggestions()
analyticsManager.logScreenView(ScreenViewEvent.ChatRoom)
}
......@@ -381,7 +373,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
override fun showMessages(dataSet: List<BaseUiModel<*>>, clearDataSet: Boolean) {
ui {
if (clearDataSet) {
adapter.clearData()
chatRoomAdapter.clearData()
}
if (dataSet.isNotEmpty()) {
......@@ -422,8 +414,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
if (recycler_view.adapter == null) {
recycler_view.adapter = adapter
if (dataSet.size >= 30) {
recycler_view.addOnScrollListener(endlessRecyclerViewScrollListener)
}
......@@ -432,25 +422,24 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
// Load just once, on the first page...
presenter.loadActiveMembers(chatRoomId, chatRoomType, filterSelfOut = true)
}
val oldMessagesCount = adapter.itemCount
adapter.appendData(dataSet)
val oldMessagesCount = chatRoomAdapter.itemCount
chatRoomAdapter.appendData(dataSet)
if (oldMessagesCount == 0 && dataSet.isNotEmpty()) {
recycler_view.scrollToPosition(0)
verticalScrollOffset.set(0)
}
presenter.loadActiveMembers(chatRoomId, chatRoomType, filterSelfOut = true)
empty_chat_view.isVisible = adapter.itemCount == 0
empty_chat_view.isVisible = chatRoomAdapter.itemCount == 0
dismissEmojiKeyboard()
}
}
override fun showSearchedMessages(dataSet: List<BaseUiModel<*>>) {
recycler_view.removeOnScrollListener(endlessRecyclerViewScrollListener)
adapter.clearData()
adapter.prependData(dataSet)
empty_chat_view.isVisible = adapter.itemCount == 0
chatRoomAdapter.clearData()
chatRoomAdapter.prependData(dataSet)
empty_chat_view.isVisible = chatRoomAdapter.itemCount == 0
dismissEmojiKeyboard()
}
......@@ -534,7 +523,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
override fun showNewMessage(message: List<BaseUiModel<*>>, isMessageReceived: Boolean) {
ui {
adapter.prependData(message)
chatRoomAdapter.prependData(message)
if (isMessageReceived && button_fab.isVisible) {
newMessageCount++
if (newMessageCount <= 99) {
......@@ -547,7 +536,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
recycler_view.scrollToPosition(0)
}
verticalScrollOffset.set(0)
empty_chat_view.isVisible = adapter.itemCount == 0
empty_chat_view.isVisible = chatRoomAdapter.itemCount == 0
dismissEmojiKeyboard()
}
}
......@@ -557,9 +546,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
// TODO - investigate WHY we get a empty list here
if (message.isEmpty()) return@ui
if (adapter.updateItem(message.last())) {
if (chatRoomAdapter.updateItem(message.last())) {
if (message.size > 1) {
adapter.prependData(listOf(message.first()))
chatRoomAdapter.prependData(listOf(message.first()))
}
} else {
showNewMessage(message, true)
......@@ -570,7 +559,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
override fun dispatchDeleteMessage(msgId: String) {
ui {
adapter.removeItem(msgId)
chatRoomAdapter.removeItem(msgId)
}
}
......@@ -771,28 +760,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
showMessage(getString(R.string.max_file_size_exceeded, fileSize, maxFileSize))
}
override fun showConnectionState(state: State) {
ui {
text_connection_status.fadeIn()
handler.removeCallbacks(dismissStatus)
text_connection_status.text = when (state) {
is State.Connected -> {
handler.postDelayed(dismissStatus, 2000)
getString(R.string.status_connected)
}
is State.Disconnected -> getString(R.string.status_disconnected)
is State.Connecting -> getString(R.string.status_connecting)
is State.Authenticating -> getString(R.string.status_authenticating)
is State.Disconnecting -> getString(R.string.status_disconnecting)
is State.Waiting -> getString(R.string.status_waiting, state.seconds)
else -> {
handler.postDelayed(dismissStatus, 500)
""
}
}
}
}
override fun onJoined(roomUiModel: RoomUiModel) {
ui {
input_container.isVisible = true
......@@ -802,18 +769,32 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
private fun setupRecyclerView() {
chatRoomAdapter = ChatRoomAdapter(
roomId = chatRoomId,
roomType = chatRoomType,
roomName = chatRoomName,
actionSelectListener = this,
reactionListener = this,
navigator = navigator,
analyticsManager = analyticsManager
)
with (recycler_view) {
if (adapter == null) adapter = chatRoomAdapter
// Initialize the endlessRecyclerViewScrollListener so we don't NPE at onDestroyView
val linearLayoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, true)
linearLayoutManager.stackFromEnd = true
recycler_view.layoutManager = linearLayoutManager
recycler_view.itemAnimator = DefaultItemAnimator()
layoutManager = linearLayoutManager
itemAnimator = DefaultItemAnimator()
endlessRecyclerViewScrollListener = object :
EndlessRecyclerViewScrollListener(recycler_view.layoutManager as LinearLayoutManager) {
override fun onLoadMore(page: Int, totalItemsCount: Int, recyclerView: RecyclerView) {
presenter.loadMessages(chatRoomId, chatRoomType, page * 30L)
}
}
recycler_view.addOnScrollListener(fabScrollListener)
addOnScrollListener(fabScrollListener)
}
}
private fun setupFab() {
......
......@@ -402,7 +402,7 @@ class UiModelMapper @Inject constructor(
private fun attachmentUrl(url: String?): String? {
if (url.isNullOrEmpty()) return null
if (url!!.startsWith("http")) return url
if (url.startsWith("http")) return url
val fullUrl = "$baseUrl$url"
val httpUrl = HttpUrl.parse(fullUrl)
......
......@@ -108,7 +108,7 @@ class ChatRoomsPresenter @Inject constructor(
}
}
suspend fun loadChatRoom(chatRoom: ChatRoomEntity, local: Boolean = false) {
private suspend fun loadChatRoom(chatRoom: ChatRoomEntity, local: Boolean = false) {
with(chatRoom) {
val isDirectMessage = roomTypeOf(type) is RoomType.DirectMessage
val roomName =
......
......@@ -55,6 +55,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
@Inject lateinit var presenter: ChatRoomsPresenter
@Inject lateinit var factory: ChatRoomsViewModelFactory
@Inject lateinit var analyticsManager: AnalyticsManager
private val roomsAdapter = RoomsAdapter { presenter.loadChatRoom(it) }
private lateinit var viewModel: ChatRoomsViewModel
private var chatRoomId: String? = null
private var isSortByName = false
......@@ -63,8 +64,8 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
private var isGroupByFavorites = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
chatRoomId = getString(BUNDLE_CHAT_ROOM_ID)
......@@ -86,6 +87,8 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupRecyclerView()
setupListeners()
with(presenter) {
getCurrentServerName()
......@@ -94,43 +97,11 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
viewModel = ViewModelProviders.of(this, factory).get(ChatRoomsViewModel::class.java)
subscribeUi()
setupListeners()
showAllChats()
analyticsManager.logScreenView(ScreenViewEvent.ChatRooms)
}
override fun setupToolbar(serverName: String) {
with((activity as AppCompatActivity)) {
with(toolbar) {
setSupportActionBar(this)
setNavigationOnClickListener { presenter.toSettings() }
}
}
text_server_name.text = serverName
}
override fun setupSortingAndGrouping(
isSortByName: Boolean,
isUnreadOnTop: Boolean,
isGroupByType: Boolean,
isGroupByFavorites: Boolean
) {
this.isSortByName = isSortByName
this.isUnreadOnTop = isUnreadOnTop
this.isGroupByType = isGroupByType
this.isGroupByFavorites = isGroupByFavorites
if (isSortByName) {
text_sort_by.text =
getString(R.string.msg_sort_by, getString(R.string.msg_sort_by_name).toLowerCase())
} else {
text_sort_by.text = getString(
R.string.msg_sort_by,
getString(R.string.msg_sort_by_activity).toLowerCase()
)
}
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.chatrooms, menu)
......@@ -167,92 +138,104 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
return super.onOptionsItemSelected(item)
}
private fun showNoChatRoomsToDisplay() {
// ui { text_no_data_to_display.isVisible = true }
override fun setupToolbar(serverName: String) {
with((activity as AppCompatActivity)) {
with(toolbar) {
setSupportActionBar(this)
setNavigationOnClickListener { presenter.toSettings() }
}
}
text_server_name.text = serverName
}
override fun setupSortingAndGrouping(
isSortByName: Boolean,
isUnreadOnTop: Boolean,
isGroupByType: Boolean,
isGroupByFavorites: Boolean
) {
this.isSortByName = isSortByName
this.isUnreadOnTop = isUnreadOnTop
this.isGroupByType = isGroupByType
this.isGroupByFavorites = isGroupByFavorites
if (isSortByName) {
text_sort_by.text =
getString(R.string.msg_sort_by, getString(R.string.msg_sort_by_name).toLowerCase())
} else {
text_sort_by.text = getString(
R.string.msg_sort_by,
getString(R.string.msg_sort_by_activity).toLowerCase()
)
}
}
override fun showLoading() {
ui {
view_loading.isVisible = true
}
}
override fun hideLoading() {
view_loading.isVisible = false
ui { view_loading.isVisible = false }
}
override fun showMessage(resId: Int) {
ui {
showToast(resId)
}
ui { showToast(resId) }
}
override fun showMessage(message: String) {
ui {
showToast(message)
}
ui { showToast(message) }
}
override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error))
private fun showConnectionState(state: State) {
Timber.d("Got new state: $state")
// ui {
// text_connection_status.fadeIn()
// handler.removeCallbacks(dismissStatus)
// text_connection_status.text = when (state) {
// is State.Connected -> {
// handler.postDelayed(dismissStatus, 2000)
// getString(R.string.status_connected)
// }
// is State.Disconnected -> getString(R.string.status_disconnected)
// is State.Connecting -> getString(R.string.status_connecting)
// is State.Authenticating -> getString(R.string.status_authenticating)
// is State.Disconnecting -> getString(R.string.status_disconnecting)
// is State.Waiting -> getString(R.string.status_waiting, state.seconds)
// else -> {
// handler.postDelayed(dismissStatus, 500)
// ""
// }
// }
// }
}
private fun subscribeUi() {
private fun setupRecyclerView() {
ui {
val adapter = RoomsAdapter { room ->
presenter.loadChatRoom(room)
with(recycler_view) {
if (adapter == null) {
adapter = roomsAdapter
}
with(recycler_view) {
layoutManager = LinearLayoutManager(it)
layoutManager = LinearLayoutManager(context)
addItemDecoration(
DividerItemDecoration(
it,
context,
resources.getDimensionPixelSize(R.dimen.divider_item_decorator_bound_start),
resources.getDimensionPixelSize(R.dimen.divider_item_decorator_bound_end)
)
)
itemAnimator = DefaultItemAnimator()
}
}
}
viewModel.getChatRooms().observe(viewLifecycleOwner, Observer { rooms ->
rooms?.let {
adapter.values = it
if (recycler_view.adapter != adapter) {
recycler_view.adapter = adapter
private fun setupListeners() {
text_server_name.setOnClickListener {
ServersBottomSheetFragment().show(
activity?.supportFragmentManager,
chat.rocket.android.servers.ui.TAG
)
}
if (rooms.isNotEmpty()) {
// text_no_data_to_display.isVisible = false
text_sort_by.setOnClickListener {
SortingAndGroupingBottomSheetFragment().show(
activity?.supportFragmentManager,
chat.rocket.android.sortingandgrouping.ui.TAG
)
}
}
private fun subscribeUi() {
ui {
viewModel.getChatRooms().observe(viewLifecycleOwner, Observer { roomModel ->
roomModel?.let { roomsAdapter.values = it }
})
viewModel.loadingState.observe(viewLifecycleOwner, Observer { state ->
when (state) {
is LoadingState.Loading -> if (state.count == 0L) showLoading()
is LoadingState.Loaded -> {
hideLoading()
if (state.count == 0L) showNoChatRoomsToDisplay()
}
is LoadingState.Loading -> showLoading()
is LoadingState.Loaded -> hideLoading()
is LoadingState.Error -> {
hideLoading()
showGenericErrorMessage()
......@@ -260,27 +243,12 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
}
})
// Actually it is fetching the rooms. We should fix it.
viewModel.getStatus().observe(viewLifecycleOwner, Observer { status ->
status?.let { showConnectionState(status) }
})
showAllChats()
}
status?.let {
//showConnectionState(status)
}
private fun setupListeners() {
text_server_name.setOnClickListener {
ServersBottomSheetFragment().show(
activity?.supportFragmentManager,
chat.rocket.android.servers.ui.TAG
)
}
text_sort_by.setOnClickListener {
SortingAndGroupingBottomSheetFragment().show(
activity?.supportFragmentManager,
chat.rocket.android.sortingandgrouping.ui.TAG
)
})
}
}
......
......@@ -108,32 +108,22 @@ class CreateChannelFragment : Fragment(), CreateChannelView, ActionMode.Callback
}
override fun showLoading() {
ui {
view_loading.isVisible = true
}
ui { view_loading.isVisible = true }
}
override fun hideLoading() {
ui {
view_loading.isVisible = false
}
ui { view_loading.isVisible = false }
}
override fun showMessage(resId: Int) {
ui {
showToast(resId)
}
ui { showToast(resId) }
}
override fun showMessage(message: String) {
ui {
showToast(message)
}
ui { showToast(message) }
}
override fun showGenericErrorMessage() {
showMessage(getString(R.string.msg_generic_error))
}
override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error))
override fun showUserSuggestion(dataSet: List<MemberUiModel>) {
adapter.clearData()
......@@ -246,9 +236,7 @@ class CreateChannelFragment : Fragment(), CreateChannelView, ActionMode.Callback
compositeDisposable.addAll(channelNameDisposable, inviteMembersDisposable)
}
private fun unsubscribeEditTexts() {
compositeDisposable.dispose()
}
private fun unsubscribeEditTexts() = compositeDisposable.dispose()
private fun startActionMode() {
if (actionMode == null) {
......
......@@ -7,6 +7,7 @@ import dagger.multibindings.Multibinds
@Module
abstract class AndroidWorkerInjectionModule {
@Multibinds
abstract fun workerInjectorFactories(): Map<Class<out Worker>, AndroidInjector.Factory<out Worker>>
}
\ No newline at end of file
......@@ -88,13 +88,11 @@ import javax.inject.Singleton
class AppModule {
@Provides
@Singleton
fun provideContext(application: Application): Context {
return application
}
@Provides
@Singleton
fun provideHttpLoggingInterceptor(): HttpLoggingInterceptor {
val interceptor = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger {
override fun log(message: String) {
......@@ -112,19 +110,13 @@ class AppModule {
}
@Provides
@Singleton
fun provideBasicAuthenticatorInterceptor(
getBasicAuthInteractor: GetBasicAuthInteractor,
saveBasicAuthInteractor: SaveBasicAuthInteractor
): BasicAuthenticatorInterceptor {
return BasicAuthenticatorInterceptor(
getBasicAuthInteractor,
saveBasicAuthInteractor
)
}
): BasicAuthenticatorInterceptor =
BasicAuthenticatorInterceptor(getBasicAuthInteractor, saveBasicAuthInteractor)
@Provides
@Singleton
fun provideOkHttpClient(
logger: HttpLoggingInterceptor,
basicAuthenticator: BasicAuthenticatorInterceptor
......@@ -139,7 +131,6 @@ class AppModule {
}
@Provides
@Singleton
fun provideImagePipelineConfig(
context: Context,
okHttpClient: OkHttpClient
......@@ -153,92 +144,60 @@ class AppModule {
}
@Provides
@Singleton
fun provideDraweeConfig(): DraweeConfig {
return DraweeConfig.newBuilder().build()
}
fun provideDraweeConfig(): DraweeConfig = DraweeConfig.newBuilder().build()
@Provides
@Singleton
fun provideTokenRepository(prefs: SharedPreferences, moshi: Moshi): TokenRepository {
return SharedPreferencesTokenRepository(prefs, moshi)
}
fun provideTokenRepository(prefs: SharedPreferences, moshi: Moshi): TokenRepository =
SharedPreferencesTokenRepository(prefs, moshi)
@Provides
@Singleton
fun providePlatformLogger(): PlatformLogger {
return TimberLogger
}
fun providePlatformLogger(): PlatformLogger = TimberLogger
@Provides
@Singleton
fun provideSharedPreferences(context: Application) =
context.getSharedPreferences("rocket.chat", Context.MODE_PRIVATE)
@Provides
@ForMessages
fun provideMessagesSharedPreferences(context: Application) =
context.getSharedPreferences("messages", Context.MODE_PRIVATE)
@Provides
@Singleton
fun provideLocalRepository(prefs: SharedPreferences, moshi: Moshi): LocalRepository {
return SharedPreferencesLocalRepository(prefs, moshi)
}
fun provideLocalRepository(prefs: SharedPreferences, moshi: Moshi): LocalRepository =
SharedPreferencesLocalRepository(prefs, moshi)
@Provides
@Singleton
fun provideCurrentServerRepository(prefs: SharedPreferences): CurrentServerRepository {
return SharedPrefsCurrentServerRepository(prefs)
}
fun provideCurrentServerRepository(prefs: SharedPreferences): CurrentServerRepository =
SharedPrefsCurrentServerRepository(prefs)
@Provides
@Singleton
fun provideAnalyticsTrackingRepository(prefs: SharedPreferences): AnalyticsTrackingRepository {
return SharedPrefsAnalyticsTrackingRepository(prefs)
}
fun provideAnalyticsTrackingRepository(prefs: SharedPreferences): AnalyticsTrackingRepository =
SharedPrefsAnalyticsTrackingRepository(prefs)
@Provides
@Singleton
fun provideSortingAndGroupingRepository(prefs: SharedPreferences): SortingAndGroupingRepository {
return SharedPrefsSortingAndGroupingRepository(prefs)
}
fun provideSortingAndGroupingRepository(prefs: SharedPreferences): SortingAndGroupingRepository =
SharedPrefsSortingAndGroupingRepository(prefs)
@Provides
@ForAuthentication
fun provideConnectingServerRepository(prefs: SharedPreferences): CurrentServerRepository {
return SharedPrefsConnectingServerRepository(prefs)
}
fun provideConnectingServerRepository(prefs: SharedPreferences): CurrentServerRepository =
SharedPrefsConnectingServerRepository(prefs)
@Provides
@Singleton
fun provideSettingsRepository(localRepository: LocalRepository): SettingsRepository {
return SharedPreferencesSettingsRepository(localRepository)
}
fun provideSettingsRepository(localRepository: LocalRepository): SettingsRepository =
SharedPreferencesSettingsRepository(localRepository)
@Provides
@Singleton
fun providePermissionsRepository(
localRepository: LocalRepository,
moshi: Moshi
): PermissionsRepository {
return SharedPreferencesPermissionsRepository(localRepository, moshi)
}
): PermissionsRepository = SharedPreferencesPermissionsRepository(localRepository, moshi)
@Provides
@Singleton
fun provideChatRoomRepository(): ChatRoomsRepository {
return MemoryChatRoomsRepository()
}
fun provideChatRoomRepository(): ChatRoomsRepository = MemoryChatRoomsRepository()
@Provides
@Singleton
fun provideMoshi(
logger: PlatformLogger,
currentServerInteractor: GetCurrentServerInteractor
): Moshi {
val url = currentServerInteractor.get() ?: ""
fun provideMoshi(): Moshi {
return Moshi.Builder()
.add(FallbackSealedClassJsonAdapter.ADAPTER_FACTORY)
.add(AppJsonAdapterFactory.INSTANCE)
......@@ -258,27 +217,19 @@ class AppModule {
}
@Provides
@Singleton
fun provideMultiServerTokenRepository(
repository: LocalRepository,
moshi: Moshi
): MultiServerTokenRepository {
return SharedPreferencesMultiServerTokenRepository(repository, moshi)
}
): MultiServerTokenRepository = SharedPreferencesMultiServerTokenRepository(repository, moshi)
@Provides
fun provideMessageRepository(databaseManager: DatabaseManager): MessagesRepository {
return DatabaseMessagesRepository(databaseManager, DatabaseMessageMapper(databaseManager))
}
fun provideMessageRepository(databaseManager: DatabaseManager): MessagesRepository =
DatabaseMessagesRepository(databaseManager, DatabaseMessageMapper(databaseManager))
@Provides
@Singleton
fun provideUserRepository(): UsersRepository {
return MemoryUsersRepository()
}
fun provideUserRepository(): UsersRepository = MemoryUsersRepository()
@Provides
@Singleton
fun provideConfiguration(context: Application): SpannableConfiguration {
val res = context.resources
return SpannableConfiguration.builder(context)
......@@ -303,31 +254,25 @@ class AppModule {
}
@Provides
@Singleton
fun provideBasicAuthRepository(
preferences: SharedPreferences,
moshi: Moshi
): BasicAuthRepository =
SharedPrefsBasicAuthRepository(preferences, moshi)
): BasicAuthRepository = SharedPrefsBasicAuthRepository(preferences, moshi)
@Provides
@Singleton
fun provideAccountsRepository(
preferences: SharedPreferences,
moshi: Moshi
): AccountsRepository =
SharedPreferencesAccountsRepository(preferences, moshi)
): AccountsRepository = SharedPreferencesAccountsRepository(preferences, moshi)
@Provides
fun provideNotificationManager(context: Application) =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
@Provides
@Singleton
fun provideGroupedPush() = GroupedPush()
@Provides
@Singleton
fun providePushManager(
context: Application,
groupedPushes: GroupedPush,
......@@ -347,9 +292,8 @@ class AppModule {
}
@Provides
fun provideJobScheduler(context: Application): JobScheduler {
return context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
}
fun provideJobScheduler(context: Application): JobScheduler =
context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
@Provides
fun provideSendMessageJob(context: Application): JobInfo {
......@@ -365,38 +309,27 @@ class AppModule {
fun provideJobSchedulerInteractor(
jobScheduler: JobScheduler,
jobInfo: JobInfo
): JobSchedulerInteractor {
return JobSchedulerInteractorImpl(jobScheduler, jobInfo)
}
): JobSchedulerInteractor = JobSchedulerInteractorImpl(jobScheduler, jobInfo)
@Provides
@Named("currentServer")
fun provideCurrentServer(currentServerInteractor: GetCurrentServerInteractor): String {
return currentServerInteractor.get()!!
}
fun provideCurrentServer(currentServerInteractor: GetCurrentServerInteractor): String =
currentServerInteractor.get()!!
@Provides
fun provideDatabaseManager(
factory: DatabaseManagerFactory,
@Named("currentServer") currentServer: String
): DatabaseManager {
return factory.create(currentServer)
}
): DatabaseManager = factory.create(currentServer)
@Provides
@Singleton
fun provideAnswersAnalytics(): AnswersAnalytics {
return AnswersAnalytics()
}
fun provideAnswersAnalytics(): AnswersAnalytics = AnswersAnalytics()
@Provides
@Singleton
fun provideGoogleAnalyticsForFirebase(context: Application): GoogleAnalyticsForFirebase {
return GoogleAnalyticsForFirebase(context)
}
fun provideGoogleAnalyticsForFirebase(context: Application): GoogleAnalyticsForFirebase =
GoogleAnalyticsForFirebase(context)
@Provides
@Singleton
fun provideAnalyticsManager(
analyticsTrackingInteractor: AnalyticsTrackingInteractor,
getCurrentServerInteractor: GetCurrentServerInteractor,
......
......@@ -41,7 +41,7 @@ abstract class UserDao : BaseDao<UserEntity> {
users.forEach { internalUpsert(it) }
}
private inline fun internalUpsert(user: BaseUserEntity) {
private fun internalUpsert(user: BaseUserEntity) {
val count = if (user is UserStatus) {
update(user.id, user.status)
} else {
......
......@@ -43,8 +43,8 @@ class FavoriteMessagesFragment : Fragment(), FavoriteMessagesView {
private val adapter = ChatRoomAdapter(enableActions = false)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
chatRoomId = getString(INTENT_CHAT_ROOM_ID, "")
......
......@@ -50,8 +50,8 @@ class FilesFragment : Fragment(), FilesView {
private lateinit var chatRoomId: String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
chatRoomId = getString(BUNDLE_CHAT_ROOM_ID, "")
......
......@@ -17,14 +17,10 @@ import dagger.android.HasActivityInjector
import dagger.android.support.HasSupportFragmentInjector
import javax.inject.Inject
class MainActivity : AppCompatActivity(), HasActivityInjector,
HasSupportFragmentInjector {
@Inject
lateinit var activityDispatchingAndroidInjector: DispatchingAndroidInjector<Activity>
@Inject
lateinit var fagmentDispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
@Inject
lateinit var presenter: MainPresenter
class MainActivity : AppCompatActivity(), HasActivityInjector, HasSupportFragmentInjector {
@Inject lateinit var activityDispatchingAndroidInjector: DispatchingAndroidInjector<Activity>
@Inject lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
@Inject lateinit var presenter: MainPresenter
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
......@@ -51,7 +47,7 @@ class MainActivity : AppCompatActivity(), HasActivityInjector,
activityDispatchingAndroidInjector
override fun supportFragmentInjector(): AndroidInjector<Fragment> =
fagmentDispatchingAndroidInjector
fragmentDispatchingAndroidInjector
private fun clearAppNotifications() =
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancelAll()
......
......@@ -47,8 +47,8 @@ class MembersFragment : Fragment(), MembersView {
private lateinit var chatRoomId: String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
chatRoomId = getString(BUNDLE_CHAT_ROOM_ID, "")
......
......@@ -43,8 +43,8 @@ class MentionsFragment : Fragment(), MentionsView {
private val adapter = ChatRoomAdapter(enableActions = false)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
chatRoomId = getString(BUNDLE_CHAT_ROOM_ID, "")
......
......@@ -43,8 +43,8 @@ class PinnedMessagesFragment : Fragment(), PinnedMessagesView {
private val adapter = ChatRoomAdapter(enableActions = false)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
chatRoomId = getString(BUNDLE_CHAT_ROOM_ID, "")
......
......@@ -62,8 +62,8 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {
private val editTextsDisposable = CompositeDisposable()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
......
package chat.rocket.android.push
import chat.rocket.android.dagger.module.AppModule
import dagger.Module
import dagger.android.ContributesAndroidInjector
@Module
abstract class DirectReplyReceiverProvider {
@ContributesAndroidInjector(modules = [AppModule::class])
abstract fun provideDirectReplyReceiver(): DirectReplyReceiver
}
\ No newline at end of file
package chat.rocket.android.push.di
import chat.rocket.android.dagger.module.AppModule
import chat.rocket.android.push.DeleteReceiver
import dagger.Module
import dagger.android.ContributesAndroidInjector
@Module
abstract class DeleteReceiverProvider {
@ContributesAndroidInjector(modules = [AppModule::class])
abstract fun provideDeleteReceiver(): DeleteReceiver
}
\ No newline at end of file
......@@ -116,7 +116,7 @@ fun PublicSettings.messageReadReceiptStoreUsers(): Boolean = this[MESSAGE_READ_R
fun PublicSettings.uploadMimeTypeFilter(): Array<String>? {
val values = this[UPLOAD_WHITELIST_MIMETYPES]?.value as String?
if (!values.isNullOrBlank()) {
return values!!.split(",").mapToTypedArray { it.trim() }
return values.split(",").mapToTypedArray { it.trim() }
}
return null
}
......
......@@ -7,7 +7,6 @@ import chat.rocket.android.server.domain.GetAccountInteractor
import chat.rocket.android.server.domain.GetAccountsInteractor
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.SaveCurrentServerInteractor
import chat.rocket.android.server.domain.SettingsRepository
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.infraestructure.ConnectionManagerFactory
import chat.rocket.android.util.extension.launchUI
......@@ -23,7 +22,6 @@ class ChangeServerPresenter @Inject constructor(
private val getAccountInteractor: GetAccountInteractor,
private val getAccountsInteractor: GetAccountsInteractor,
private val analyticsManager: AnalyticsManager,
private val settingsRepository: SettingsRepository,
private val tokenRepository: TokenRepository,
private val localRepository: LocalRepository,
private val connectionManager: ConnectionManagerFactory
......@@ -48,11 +46,6 @@ class ChangeServerPresenter @Inject constructor(
return@launchUI
}
val settings = settingsRepository.get(serverUrl)
if (settings == null) {
// TODO - reload settings...
}
// Call disconnect on the old url if any...
getCurrentServerInteractor.get()?.let { url ->
connectionManager.get(url)?.disconnect()
......
......@@ -24,8 +24,8 @@ class ServersBottomSheetFragment : BottomSheetDialogFragment(), ServersView {
lateinit var presenter: ServersPresenter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
}
override fun onCreateView(
......
......@@ -22,6 +22,7 @@ import chat.rocket.android.settings.presentation.SettingsPresenter
import chat.rocket.android.settings.presentation.SettingsView
import chat.rocket.android.util.extensions.inflate
import chat.rocket.android.util.extensions.showToast
import chat.rocket.android.util.extensions.ui
import chat.rocket.android.util.invalidateFirebaseToken
import com.bumptech.glide.Glide
import dagger.android.support.AndroidSupportInjection
......@@ -39,8 +40,8 @@ class SettingsFragment : Fragment(), SettingsView {
@Inject lateinit var presenter: SettingsPresenter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
}
override fun onCreateView(
......@@ -65,6 +66,7 @@ class SettingsFragment : Fragment(), SettingsView {
isDeleteAccountEnabled: Boolean,
serverVersion: String
) {
ui {
context?.let { Glide.with(it).load(avatar).into(image_avatar) }
text_display_name.text = displayName
......@@ -82,14 +84,21 @@ class SettingsFragment : Fragment(), SettingsView {
text_share_this_app.setOnClickListener { shareApp() }
text_license.setOnClickListener {
presenter.toLicense(getString(R.string.license_url), getString(R.string.title_licence))
presenter.toLicense(
getString(R.string.license_url),
getString(R.string.title_licence)
)
}
text_app_version.text = getString(R.string.msg_app_version, BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
text_app_version.text = getString(
R.string.msg_app_version,
BuildConfig.VERSION_NAME,
BuildConfig.VERSION_CODE
)
text_server_version.text = getString(R.string.msg_server_version, serverVersion)
text_logout.setOnClickListener { showLogoutDialog()}
text_logout.setOnClickListener { showLogoutDialog() }
with(text_administration) {
isVisible = isAdministrationEnabled
......@@ -109,23 +118,24 @@ class SettingsFragment : Fragment(), SettingsView {
setOnClickListener { showDeleteAccountDialog() }
}
}
}
override fun invalidateToken(token: String) = invalidateFirebaseToken(token)
override fun showLoading() {
view_loading.isVisible = true
ui { view_loading.isVisible = true }
}
override fun hideLoading() {
view_loading.isVisible = false
ui { view_loading.isVisible = false }
}
override fun showMessage(resId: Int) {
showToast(resId)
ui { showToast(resId) }
}
override fun showMessage(message: String) {
showToast(message)
ui { showToast(message) }
}
override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error))
......
......@@ -37,8 +37,8 @@ class SortingAndGroupingBottomSheetFragment : BottomSheetDialogFragment(), Sorti
private val groupByFavoritesDrawable by lazy { R.drawable.ic_favorites_20dp }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
}
override fun onCreateView(
......
......@@ -47,8 +47,8 @@ class UserDetailsFragment : Fragment(), UserDetailsView {
private val handler = Handler()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
arguments?.run {
userId = getString(BUNDLE_USER_ID, "")
......
......@@ -275,7 +275,7 @@
<string name="msg_all_files_appear_here">الملفات تظهر هنا</string>
<!-- Upload Messages -->
<string name="max_file_size_exceeded">ملف كبير</string>
<string name="max_file_size_exceeded">File size %1$d bytes exceeded max upload size of %2$d bytes</string> <!-- TODO Translate -->
<!-- Socket status -->
<string name="status_connected">اتصال</string>
......
......@@ -26,7 +26,5 @@ abstract class ServiceBuilder {
@Binds
@IntoMap
@WorkerKey(TokenRegistrationWorker::class)
abstract fun bindTokenRegistrationWorkerFactory(
builder: TokenRegistrationSubComponent.Builder
): AndroidInjector.Factory<out Worker>
abstract fun bindTokenRegistrationWorkerFactory(builder: TokenRegistrationSubComponent.Builder): AndroidInjector.Factory<out Worker>
}
\ No newline at end of file
......@@ -13,13 +13,11 @@ import dagger.android.AndroidInjection
import javax.inject.Inject
class FirebaseMessagingService : FirebaseMessagingService() {
@Inject
lateinit var pushManager: PushManager
@Inject lateinit var pushManager: PushManager
override fun onCreate() {
super.onCreate()
AndroidInjection.inject(this)
super.onCreate()
}
override fun onMessageReceived(message: RemoteMessage) {
......
package chat.rocket.android.push.di
import chat.rocket.android.dagger.module.AppModule
import chat.rocket.android.push.FirebaseMessagingService
import dagger.Module
import dagger.android.ContributesAndroidInjector
@Module
abstract class FirebaseMessagingServiceProvider {
@ContributesAndroidInjector(modules = [AppModule::class])
abstract fun provideFirebaseMessagingService(): FirebaseMessagingService
}
\ No newline at end of file
......@@ -15,10 +15,8 @@ import kotlinx.coroutines.runBlocking
import timber.log.Timber
import javax.inject.Inject
class TokenRegistrationWorker @Inject constructor(
appContext: Context,
workerParams: WorkerParameters
) : Worker(appContext, workerParams) {
class TokenRegistrationWorker(appContext: Context, workerParams: WorkerParameters) :
Worker(appContext, workerParams) {
@Inject lateinit var factory: RocketChatClientFactory
@Inject lateinit var getAccountsInteractor: GetAccountsInteractor
@Inject lateinit var localRepository: LocalRepository
......
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