Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chat.rocket.android.chatroom.presentation

import android.graphics.Bitmap
import android.net.Uri
import android.view.KeyEvent
import chat.rocket.android.R
import chat.rocket.android.analytics.AnalyticsManager
import chat.rocket.android.analytics.event.SubscriptionTypeEvent
Expand All @@ -20,9 +21,11 @@ import chat.rocket.android.core.behaviours.showMessage
import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.db.DatabaseManager
import chat.rocket.android.emoji.EmojiRepository
import chat.rocket.android.emoji.PhysicalKeyboardConfig
import chat.rocket.android.helper.MessageHelper
import chat.rocket.android.helper.UserHelper
import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.preferences.interactor.PhysicalKeyboardConfigInteractor
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.JobSchedulerInteractor
Expand Down Expand Up @@ -103,10 +106,12 @@ class ChatRoomPresenter @Inject constructor(
private val jobSchedulerInteractor: JobSchedulerInteractor,
private val messageHelper: MessageHelper,
private val dbManager: DatabaseManager,
private val physicalKeyboardConfigInteractor: PhysicalKeyboardConfigInteractor,
getSettingsInteractor: GetSettingsInteractor,
serverInteractor: GetCurrentServerInteractor,
factory: ConnectionManagerFactory
) {

private val currentServer = serverInteractor.get()!!
private val manager = factory.create(currentServer)
private val client = manager.client
Expand Down Expand Up @@ -1301,6 +1306,7 @@ class ChatRoomPresenter @Inject constructor(
fun clearDraftMessage() {
localRepository.clear(draftKey)
}

/**
* Get unfinished message from local repository, when user left chat room without
* sending a message and now the user is back.
Expand All @@ -1310,4 +1316,36 @@ class ChatRoomPresenter @Inject constructor(
fun getDraftUnfinishedMessage(): String? {
return localRepository.get(draftKey)
}

fun onKeyEvent(keyCode: Int, keyEvent: KeyEvent): Boolean {
return when (keyCode) {
KeyEvent.KEYCODE_ENTER -> {
when (physicalKeyboardConfigInteractor.getConfig()) {
is PhysicalKeyboardConfig.Enter -> {
if (!keyEvent.isShiftPressed && !keyEvent.isCtrlPressed) {
view.sendMessage()
true
} else {
false
}
}
is PhysicalKeyboardConfig.EnterPlusControl -> {
if (keyEvent.isCtrlPressed) {
view.sendMessage()
}
true
}
is PhysicalKeyboardConfig.EnterPlusShift -> {
if (keyEvent.isShiftPressed) {
view.sendMessage()
}
true
}
else -> false
}
}
else -> false
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import chat.rocket.android.chatrooms.adapter.model.RoomUiModel
import chat.rocket.android.core.behaviours.LoadingView
import chat.rocket.android.core.behaviours.MessageView
import chat.rocket.core.internal.realtime.socket.model.State
import chat.rocket.core.model.ChatRoom

interface ChatRoomView : LoadingView, MessageView {

Expand Down Expand Up @@ -42,6 +41,8 @@ interface ChatRoomView : LoadingView, MessageView {
*/
fun sendMessage(text: String)

fun sendMessage()

/**
* Shows the username(s) of the user(s) who is/are typing in the chat room.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
text_message.addTextChangedListener(EmojiKeyboardPopup.EmojiTextWatcher(text_message))
text_message.setOnKeyListener { _, keyCode, event -> presenter.onKeyEvent(keyCode, event) }
}

override fun onDestroyView() {
Expand Down Expand Up @@ -462,7 +463,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}


override fun sendMessage(text: String) {
ui {
if (!text.isBlank()) {
Expand All @@ -475,6 +475,12 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}

override fun sendMessage() {
var textMessage = citation ?: ""
textMessage += text_message.textContent
sendMessage(textMessage)
}

override fun showTypingStatus(usernameList: List<String>) {
ui {
when (usernameList.size) {
Expand Down Expand Up @@ -514,7 +520,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}


override fun clearMessageComposition(deleteMessage: Boolean) {
ui {
citation = null
Expand Down Expand Up @@ -866,9 +871,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}

button_send.setOnClickListener {
var textMessage = citation ?: ""
textMessage += text_message.textContent
sendMessage(textMessage)
sendMessage()
}

button_show_attachment_options.setOnClickListener {
Expand Down
44 changes: 30 additions & 14 deletions app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,29 @@ import chat.rocket.android.db.DatabaseManagerFactory
import chat.rocket.android.helper.MessageParser
import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.infrastructure.SharedPreferencesLocalRepository
import chat.rocket.android.preferences.repository.PhysicalKeyboardConfigRepository
import chat.rocket.android.preferences.repository.SharedPrefPhysicalKeyboardConfigRepository
import chat.rocket.android.push.GroupedPush
import chat.rocket.android.push.PushManager
import chat.rocket.android.server.domain.AccountsRepository
import chat.rocket.android.server.domain.AnalyticsTrackingInteractor
import chat.rocket.android.server.domain.AnalyticsTrackingRepository
import chat.rocket.android.server.domain.BasicAuthRepository
import chat.rocket.android.server.domain.ChatRoomsRepository
import chat.rocket.android.server.domain.CurrentServerRepository
import chat.rocket.android.server.domain.GetAccountInteractor
import chat.rocket.android.server.domain.GetAccountsInteractor
import chat.rocket.android.server.domain.GetBasicAuthInteractor
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.JobSchedulerInteractor
import chat.rocket.android.server.domain.MessagesRepository
import chat.rocket.android.server.domain.MultiServerTokenRepository
import chat.rocket.android.server.domain.PermissionsRepository
import chat.rocket.android.server.domain.SaveBasicAuthInteractor
import chat.rocket.android.server.domain.SettingsRepository
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.domain.UsersRepository
import chat.rocket.android.server.domain.BasicAuthRepository
import chat.rocket.android.server.domain.GetBasicAuthInteractor
import chat.rocket.android.server.domain.SaveBasicAuthInteractor
import chat.rocket.android.server.infraestructure.SharedPrefsBasicAuthRepository
import chat.rocket.android.server.infraestructure.DatabaseMessageMapper
import chat.rocket.android.server.infraestructure.DatabaseMessagesRepository
import chat.rocket.android.server.infraestructure.JobSchedulerInteractorImpl
Expand All @@ -53,17 +54,17 @@ import chat.rocket.android.server.infraestructure.SharedPreferencesAccountsRepos
import chat.rocket.android.server.infraestructure.SharedPreferencesPermissionsRepository
import chat.rocket.android.server.infraestructure.SharedPreferencesSettingsRepository
import chat.rocket.android.server.infraestructure.SharedPrefsAnalyticsTrackingRepository
import chat.rocket.android.server.infraestructure.SharedPrefsBasicAuthRepository
import chat.rocket.android.server.infraestructure.SharedPrefsConnectingServerRepository
import chat.rocket.android.server.infraestructure.SharedPrefsCurrentServerRepository
import chat.rocket.android.util.AppJsonAdapterFactory
import chat.rocket.android.util.HttpLoggingInterceptor
import chat.rocket.android.util.BasicAuthenticatorInterceptor
import chat.rocket.android.util.HttpLoggingInterceptor
import chat.rocket.android.util.TimberLogger
import chat.rocket.common.internal.FallbackSealedClassJsonAdapter
import chat.rocket.common.internal.ISO8601Date
import chat.rocket.common.model.TimestampAdapter
import chat.rocket.common.util.CalendarISO8601Converter
import chat.rocket.common.util.Logger
import chat.rocket.common.util.NoOpLogger
import chat.rocket.common.util.PlatformLogger
import chat.rocket.core.internal.AttachmentAdapterFactory
Expand Down Expand Up @@ -124,7 +125,10 @@ class AppModule {

@Provides
@Singleton
fun provideOkHttpClient(logger: HttpLoggingInterceptor, basicAuthenticator: BasicAuthenticatorInterceptor): OkHttpClient {
fun provideOkHttpClient(
logger: HttpLoggingInterceptor,
basicAuthenticator: BasicAuthenticatorInterceptor
): OkHttpClient {
return OkHttpClient.Builder()
.addInterceptor(logger)
.addInterceptor(basicAuthenticator)
Expand All @@ -145,13 +149,16 @@ class AppModule {
return OkHttpImagePipelineConfigFactory.newBuilder(context, okHttpClient)
.setRequestListeners(listeners)
.setDownsampleEnabled(true)
.experiment().setPartialImageCachingEnabled(true).build()
.experiment()
.setPartialImageCachingEnabled(true)
.build()
}

@Provides
@Singleton
fun provideDraweeConfig(): DraweeConfig {
return DraweeConfig.newBuilder().build()
return DraweeConfig.newBuilder()
.build()
}

@Provides
Expand All @@ -168,9 +175,10 @@ class AppModule {

@Provides
@Singleton
fun provideSharedPreferences(context: Application) =
context.getSharedPreferences("rocket.chat", Context.MODE_PRIVATE)

fun provideSharedPreferences(context: Application) = context.getSharedPreferences(
"rocket.chat",
Context.MODE_PRIVATE
)

@Provides
@ForMessages
Expand All @@ -195,6 +203,14 @@ class AppModule {
return SharedPrefsAnalyticsTrackingRepository(prefs)
}

@Provides
@Singleton
fun provideSharedPrefPhysicalKeyboardConfigRepository(
prefs: SharedPreferences
): PhysicalKeyboardConfigRepository {
return SharedPrefPhysicalKeyboardConfigRepository(prefs)
}

@Provides
@ForAuthentication
fun provideConnectingServerRepository(prefs: SharedPreferences): CurrentServerRepository {
Expand Down Expand Up @@ -294,10 +310,10 @@ class AppModule {

@Provides
@Singleton
fun provideBasicAuthRepository (
fun provideBasicAuthRepository(
preferences: SharedPreferences,
moshi: Moshi
): BasicAuthRepository =
): BasicAuthRepository =
SharedPrefsBasicAuthRepository(preferences, moshi)

@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package chat.rocket.android.preferences.interactor

import chat.rocket.android.emoji.PhysicalKeyboardConfig
import chat.rocket.android.preferences.repository.PhysicalKeyboardConfigRepository
import javax.inject.Inject

class PhysicalKeyboardConfigInteractor @Inject constructor(
private val physicalKeyboardConfigRepository: PhysicalKeyboardConfigRepository
) {

fun getConfig() = physicalKeyboardConfigRepository.getConfig()

fun saveConfig(physicalKeyboardConfig: PhysicalKeyboardConfig) {
physicalKeyboardConfigRepository.saveConfig(physicalKeyboardConfig)
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package chat.rocket.android.preferences.presentation

import chat.rocket.android.R
import chat.rocket.android.emoji.PhysicalKeyboardConfig
import chat.rocket.android.preferences.interactor.PhysicalKeyboardConfigInteractor
import chat.rocket.android.server.domain.AnalyticsTrackingInteractor
import javax.inject.Inject

class PreferencesPresenter @Inject constructor(
private val view: PreferencesView,
private val analyticsTrackingInteractor: AnalyticsTrackingInteractor
private val analyticsTrackingInteractor: AnalyticsTrackingInteractor,
private val physicalKeyboardConfigInteractor: PhysicalKeyboardConfigInteractor
) {

private var physicalKeyboardConfig: PhysicalKeyboardConfig = PhysicalKeyboardConfig.EnterPlusControl
set(value) {
field = value
physicalKeyboardConfigInteractor.saveConfig(value)
}
get() = physicalKeyboardConfigInteractor.getConfig()

private var tempPhysicalKeyboardConfig = physicalKeyboardConfig

fun loadAnalyticsTrackingInformation() {
view.setupAnalyticsTrackingView(analyticsTrackingInteractor.get())
}
Expand All @@ -19,4 +32,27 @@ class PreferencesPresenter @Inject constructor(
fun disableAnalyticsTracking() {
analyticsTrackingInteractor.save(false)
}
}

fun getPhysicalKeyboardRadioId(): Int {
return when (physicalKeyboardConfig) {
PhysicalKeyboardConfig.Enter -> R.id.radio_physical_keyboard_enter
PhysicalKeyboardConfig.EnterPlusShift -> R.id.radio_physical_keyboard_enter_shift
PhysicalKeyboardConfig.EnterPlusControl -> R.id.radio_physical_keyboard_enter_control
else -> R.id.radio_physical_keyboard_disabled
}
}

fun onPhysicalKeyboardRadioChange(checkedId: Int) {
tempPhysicalKeyboardConfig = when (checkedId) {
R.id.radio_physical_keyboard_enter -> PhysicalKeyboardConfig.Enter
R.id.radio_physical_keyboard_enter_shift -> PhysicalKeyboardConfig.EnterPlusShift
R.id.radio_physical_keyboard_enter_control -> PhysicalKeyboardConfig.EnterPlusControl
else -> PhysicalKeyboardConfig.Disable
}
}

fun onPhysicalKeyboardDialogOkClicked() {
physicalKeyboardConfig = tempPhysicalKeyboardConfig
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package chat.rocket.android.preferences.repository

import chat.rocket.android.emoji.PhysicalKeyboardConfig

interface PhysicalKeyboardConfigRepository {

fun getConfig(): PhysicalKeyboardConfig

fun saveConfig(physicalKeyboardConfig: PhysicalKeyboardConfig)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package chat.rocket.android.preferences.repository

import android.content.SharedPreferences
import chat.rocket.android.emoji.PhysicalKeyboardConfig
import javax.inject.Inject

class SharedPrefPhysicalKeyboardConfigRepository @Inject constructor(
private val sharedPreferences: SharedPreferences
) : PhysicalKeyboardConfigRepository {

override fun saveConfig(physicalKeyboardConfig: PhysicalKeyboardConfig) {
sharedPreferences.edit()
.putInt(PHYSICAL_KEYBOARD_CONFIG_KEY, physicalKeyboardConfig.state)
.apply()
}

override fun getConfig(): PhysicalKeyboardConfig {
return PhysicalKeyboardConfig.Disable.stateToConfig(
sharedPreferences.getInt(
PHYSICAL_KEYBOARD_CONFIG_KEY,
PhysicalKeyboardConfig.EnterPlusControl.state
)
)
}

companion object {
const val PHYSICAL_KEYBOARD_CONFIG_KEY = "PHYSICAL_KEYBOARD_CONFIG_KEY"
}

}
Loading