Commit a3830e75 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Fix bug with lateinit property being not initialized.

parent 49eb678e
......@@ -123,7 +123,7 @@ class ChatRoomPresenter @Inject constructor(
private var lastState = manager.state
private var typingStatusList = arrayListOf<String>()
private val roomChangesChannel = Channel<Room>(Channel.CONFLATED)
private lateinit var unfinishedMessageKey: String
private lateinit var draftKey: String
fun setupChatRoom(
roomId: String,
......@@ -131,17 +131,17 @@ class ChatRoomPresenter @Inject constructor(
roomType: String,
chatRoomMessage: String? = null
) {
launch(CommonPool + strategy.jobs) {
try {
unfinishedMessageKey = "${currentServer}_${LocalRepository.UNFINISHED_MSG_KEY}$roomId"
draftKey = "${currentServer}_${LocalRepository.DRAFT_KEY}$roomId"
chatRoomId = roomId
chatRoomType = roomType
launch(CommonPool + strategy.jobs) {
try {
chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) {
client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName)
} else {
emptyList()
}
} catch (ex: RocketChatException) {
} catch (ex: Exception) {
Timber.e(ex)
chatRoles = emptyList()
} finally {
......@@ -187,7 +187,6 @@ class ChatRoomPresenter @Inject constructor(
}
}
}
}
}
......@@ -919,7 +918,7 @@ class ChatRoomPresenter @Inject constructor(
navigator.toChatDetails(chatRoomId, chatRoomType, isSubscribed, isMenuDisabled)
}
fun loadChatRooms() {
fun loadChatRoomsSuggestions() {
launchUI(strategy) {
try {
val chatRooms = getChatRoomsAsync()
......@@ -1297,12 +1296,12 @@ class ChatRoomPresenter @Inject constructor(
*/
fun saveUnfinishedMessage(unfinishedMessage: String) {
if (unfinishedMessage.isNotBlank()) {
localRepository.save(unfinishedMessageKey, unfinishedMessage)
localRepository.save(draftKey, unfinishedMessage)
}
}
fun clearUnfinishedMessage() {
localRepository.clear(unfinishedMessageKey)
localRepository.clear(draftKey)
}
/**
* Get unfinished message from local repository, when user left chat room without
......@@ -1311,6 +1310,6 @@ class ChatRoomPresenter @Inject constructor(
* @return Returns the unfinished message, null otherwise.
*/
fun getUnfinishedMessage(): String? {
return localRepository.get(unfinishedMessageKey)
return localRepository.get(draftKey)
}
}
......@@ -176,6 +176,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
internal var isSearchTermQueried = false
private val dismissStatus = { text_connection_status.fadeOut() }
// For reveal and unreveal anim.
private val hypotenuse by lazy {
Math.hypot(
......@@ -204,6 +206,65 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
internal val textFile by lazy { dialogView.findViewById<TextView>(R.id.text_file_name) }
private var takenPhotoUri: Uri? = null
private val layoutChangeListener =
View.OnLayoutChangeListener { _, _, _, _, bottom, _, _, _, oldBottom ->
val y = oldBottom - bottom
if (Math.abs(y) > 0 && isAdded) {
// if y is positive the keyboard is up else it's down
recycler_view.post {
if (y > 0 || Math.abs(verticalScrollOffset.get()) >= Math.abs(y)) {
ui { recycler_view.scrollBy(0, y) }
} else {
ui { recycler_view.scrollBy(0, verticalScrollOffset.get()) }
}
}
}
}
private lateinit var endlessRecyclerViewScrollListener: EndlessRecyclerViewScrollListener
private val onScrollListener = object : RecyclerView.OnScrollListener() {
var state = AtomicInteger(RecyclerView.SCROLL_STATE_IDLE)
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
state.compareAndSet(RecyclerView.SCROLL_STATE_IDLE, newState)
when (newState) {
RecyclerView.SCROLL_STATE_IDLE -> {
if (!state.compareAndSet(RecyclerView.SCROLL_STATE_SETTLING, newState)) {
state.compareAndSet(RecyclerView.SCROLL_STATE_DRAGGING, newState)
}
}
RecyclerView.SCROLL_STATE_DRAGGING -> {
state.compareAndSet(RecyclerView.SCROLL_STATE_IDLE, newState)
}
RecyclerView.SCROLL_STATE_SETTLING -> {
state.compareAndSet(RecyclerView.SCROLL_STATE_DRAGGING, newState)
}
}
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (state.get() != RecyclerView.SCROLL_STATE_IDLE) {
verticalScrollOffset.getAndAdd(dy)
}
}
}
private val fabScrollListener = object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (!recyclerView.canScrollVertically(1)) {
text_count.isVisible = false
button_fab.hide()
newMessageCount = 0
} else {
if (dy < 0 && !button_fab.isVisible) {
button_fab.show()
if (newMessageCount != 0) text_count.isVisible = true
}
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
......@@ -231,25 +292,23 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return container?.inflate(R.layout.fragment_chat_room)
}
): View? = container?.inflate(R.layout.fragment_chat_room)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupToolbar(chatRoomName)
presenter.setupChatRoom(chatRoomId, chatRoomName, chatRoomType, chatRoomMessage)
presenter.loadChatRooms()
getUnfinishedMessage()
presenter.loadChatRoomsSuggestions()
setupRecyclerView()
setupFab()
setupSuggestionsView()
setupActionSnackbar()
(activity as ChatRoomActivity).let {
it.showToolbarTitle(chatRoomName)
it.showToolbarChatRoomIcon(chatRoomType)
with(activity as ChatRoomActivity) {
showToolbarTitle(chatRoomName)
showToolbarChatRoomIcon(chatRoomType)
}
getUnfinishedMessage()
analyticsManager.logScreenView(ScreenViewEvent.ChatRoom)
}
......@@ -266,13 +325,11 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
presenter.saveUnfinishedMessage(text_message.text.toString())
handler.removeCallbacksAndMessages(null)
presenter.disconnect()
unsubscribeComposeTextMessage()
presenter.disconnect()
// Hides the keyboard (if it's opened) before going to any view.
activity?.apply {
hideKeyboard()
}
activity?.apply { hideKeyboard() }
super.onDestroyView()
}
......@@ -282,15 +339,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
activity?.invalidateOptionsMenu()
}
fun dismissEmojiKeyboard() {
// Check if the keyboard was ever initialized.
// It may be the case when you are looking a not joined room
if (::emojiKeyboardPopup.isInitialized) {
emojiKeyboardPopup.dismiss()
setReactionButtonIcon(R.drawable.ic_reaction_24dp)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
if (resultCode == Activity.RESULT_OK) {
when (requestCode) {
......@@ -413,64 +461,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
private val layoutChangeListener =
View.OnLayoutChangeListener { _, _, _, _, bottom, _, _, _, oldBottom ->
val y = oldBottom - bottom
if (Math.abs(y) > 0 && isAdded) {
// if y is positive the keyboard is up else it's down
recycler_view.post {
if (y > 0 || Math.abs(verticalScrollOffset.get()) >= Math.abs(y)) {
ui { recycler_view.scrollBy(0, y) }
} else {
ui { recycler_view.scrollBy(0, verticalScrollOffset.get()) }
}
}
}
}
private lateinit var endlessRecyclerViewScrollListener: EndlessRecyclerViewScrollListener
private val onScrollListener = object : RecyclerView.OnScrollListener() {
var state = AtomicInteger(RecyclerView.SCROLL_STATE_IDLE)
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
state.compareAndSet(RecyclerView.SCROLL_STATE_IDLE, newState)
when (newState) {
RecyclerView.SCROLL_STATE_IDLE -> {
if (!state.compareAndSet(RecyclerView.SCROLL_STATE_SETTLING, newState)) {
state.compareAndSet(RecyclerView.SCROLL_STATE_DRAGGING, newState)
}
}
RecyclerView.SCROLL_STATE_DRAGGING -> {
state.compareAndSet(RecyclerView.SCROLL_STATE_IDLE, newState)
}
RecyclerView.SCROLL_STATE_SETTLING -> {
state.compareAndSet(RecyclerView.SCROLL_STATE_DRAGGING, newState)
}
}
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (state.get() != RecyclerView.SCROLL_STATE_IDLE) {
verticalScrollOffset.getAndAdd(dy)
}
}
}
private val fabScrollListener = object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (!recyclerView.canScrollVertically(1)) {
text_count.isVisible = false
button_fab.hide()
newMessageCount = 0
} else {
if (dy < 0 && !button_fab.isVisible) {
button_fab.show()
if (newMessageCount != 0) text_count.isVisible = true
}
}
}
}
override fun sendMessage(text: String) {
ui {
......@@ -505,9 +495,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
override fun hideTypingStatusView() {
ui {
text_typing_status.isVisible = false
}
ui { text_typing_status.isVisible = false }
}
override fun showInvalidFileMessage() {
......@@ -534,9 +522,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
override fun disableSendMessageButton() {
ui {
button_send.isEnabled = false
}
ui { button_send.isEnabled = false }
}
override fun enableSendMessageButton() {
......@@ -792,10 +778,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
private val dismissStatus = {
text_connection_status.fadeOut()
}
private fun setupRecyclerView() {
// Initialize the endlessRecyclerViewScrollListener so we don't NPE at onDestroyView
val linearLayoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, true)
......@@ -973,7 +955,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
.addSuggestionProviderAction("#") { query ->
if (query.isNotEmpty()) {
presenter.loadChatRooms()
presenter.loadChatRoomsSuggestions()
}
}
.addSuggestionProviderAction("/") {
......@@ -1166,4 +1148,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
presenter.reportMessage(messageId = id,
description = "This message was reported by a user from the Android app")
}
fun dismissEmojiKeyboard() {
// Check if the keyboard was ever initialized.
// It may be the case when you are looking a not joined room
if (::emojiKeyboardPopup.isInitialized) {
emojiKeyboardPopup.dismiss()
setReactionButtonIcon(R.drawable.ic_reaction_24dp)
}
}
}
......@@ -27,7 +27,7 @@ interface LocalRepository {
const val SETTINGS_KEY = "settings_"
const val PERMISSIONS_KEY = "permissions_"
const val USER_KEY = "user_"
const val UNFINISHED_MSG_KEY = "unfinished_msg_"
const val DRAFT_KEY = "draft"
const val CURRENT_USERNAME_KEY = "username_"
const val LAST_CHATROOMS_REFRESH = "_chatrooms_refresh"
}
......
......@@ -146,7 +146,7 @@
<string name="msg_send">Sende</string>
<string name="msg_sent_attachment">Sende Anhang</string>
<string name="msg_welcome_to_rocket_chat">Willkommen bei Rocket.Chat</string>
<string name="msg_team_communication">Open Source-Kommunikation</string>
<string name="msg_team_communication">Team Communication</string> <!-- TODO Translate -->
<string name="msg_login_with_email">Einloggen mit <b>e-mail</b></string>
<string name="msg_create_account">Ein Konto erstellen</string>
<string name="msg_continue_with_facebook">Weitermachen mit <b>Facebook</b></string>
......
......@@ -146,7 +146,7 @@
<string name="msg_delete_description">Seguro que quieres borrar este mensaje</string>
<string name="msg_no_search_found">No se han encontrado resultados</string>
<string name="msg_welcome_to_rocket_chat">Welcome to Rocket.Chat</string> <!-- TODO Add translation -->
<string name="msg_team_communication">Open Source Communication</string> <!-- TODO Add translation -->
<string name="msg_team_communication">Team Communication</string> <!-- TODO Translate -->
<string name="msg_login_with_email">Login with <b>e-mail</b></string> <!-- TODO Add translation -->
<string name="msg_create_account">Create an account</string> <!-- TODO Add translation -->
<string name="msg_continue_with_facebook">Continue with <b>Facebook</b></string> <!-- TODO Add translation -->
......
......@@ -150,7 +150,7 @@
<string name="msg_delete_message">Supprimer Message</string>
<string name="msg_delete_description">Êtes-vous sûr de vouloir supprimer ce message</string>
<string name="msg_welcome_to_rocket_chat">Welcome to Rocket.Chat</string> <!-- TODO Add translation -->
<string name="msg_team_communication">Open Source Communication</string> <!-- TODO Add translation -->
<string name="msg_team_communication">Team Communication</string> <!-- TODO Translate -->
<string name="msg_login_with_email">Login with <b>e-mail</b></string> <!-- TODO Add translation -->
<string name="msg_create_account">Create an account</string> <!-- TODO Add translation -->
<string name="msg_continue_with_facebook">Continue with <b>Facebook</b></string> <!-- TODO Add translation -->
......
......@@ -152,7 +152,7 @@
<string name="msg_delete_message">संदेश को हटाएं</string>
<string name="msg_delete_description">क्या आप निश्चित रूप से यह संदेश हटाना चाहते हैं</string>
<string name="msg_welcome_to_rocket_chat">Rocket.Chat में आपका स्वागत है</string>
<string name="msg_team_communication">ओपन सोर्स कम्युनिकेशन</string>
<string name="msg_team_communication">Team Communication</string> <!-- TODO Translate -->
<string name="msg_login_with_email">ई-मेल के साथ लॉगिन करें</string>
<string name="msg_create_account">खाता बनाएं</string>
<string name="msg_continue_with_facebook"><b>Facebook</b> के साथ जारी रखें</string>
......
......@@ -146,7 +146,7 @@
<string name="msg_send">Inviare</string>
<string name="msg_sent_attachment">Inviato allegato</string>
<string name="msg_welcome_to_rocket_chat">Benvenuto in Rocket.Chat </string>
<string name="msg_team_communication">Team Communication</string>
<string name="msg_team_communication">Team Communication</string> <!-- TODO Translate -->
<string name="msg_login_with_email">Accedi con <b>e-mail</b></string>
<string name="msg_create_account">Crea un utente</string>
<string name="msg_continue_with_facebook">Continua con <b>Facebook</b></string>
......
......@@ -151,7 +151,7 @@
<string name="msg_send">送信</string>
<string name="msg_sent_attachment">添付ファイルを送信しました</string>
<string name="msg_welcome_to_rocket_chat">Rocket.Chatへようこそ</string>
<string name="msg_team_communication">チームコミュニケーション</string>
<string name="msg_team_communication">Team Communication</string> <!-- TODO Translate -->
<string name="msg_login_with_email"><b>e-mail</b>でログイン</string>
<string name="msg_create_account">アカウントを作成</string>
<string name="msg_continue_with_facebook"><b>Facebook</b>でログイン</string>
......
......@@ -151,7 +151,7 @@
<string name="msg_delete_message">Remove mensagem</string>
<string name="msg_delete_description">Tem certeza que quer apagar esta mensagem?</string>
<string name="msg_welcome_to_rocket_chat">Bem-vindo ao Rocket.Chat</string>
<string name="msg_team_communication">Comunicação Open Source</string>
<string name="msg_team_communication">Comunicação para equipes</string>
<string name="msg_login_with_email">Fazer login com <b>e-mail</b></string>
<string name="msg_create_account">Criar conta</string>
<string name="msg_continue_with_facebook">Continuar com <b>Facebook</b></string>
......
......@@ -149,7 +149,7 @@
<string name="msg_channel_name">Название канала</string>
<string name="msg_search">Поиск</string>
<string name="msg_welcome_to_rocket_chat">Rocket.Chat</string>
<string name="msg_team_communication">Чат с открытым исходным кодом</string>
<string name="msg_team_communication">Team Communication</string> <!-- TODO Translate -->
<string name="msg_login_with_email">Войти с помощью <b>e-mail</b></string>
<string name="msg_create_account">Создать аккаунт</string>
<string name="msg_continue_with_facebook">Войти с помощью <b>Facebook</b></string>
......
......@@ -150,7 +150,7 @@
<string name="msg_send">Gönder</string>
<string name="msg_sent_attachment">Bir dosya eki gönderildi</string>
<string name="msg_welcome_to_rocket_chat">Welcome to Rocket.Chat</string> <!-- TODO Add translation -->
<string name="msg_team_communication">Team Communication</string> <!-- TODO Add translation -->
<string name="msg_team_communication">Team Communication</string> <!-- TODO Translate -->
<string name="msg_login_with_email">Login with <b>e-mail</b></string> <!-- TODO Add translation -->
<string name="msg_create_account">Create an account</string> <!-- TODO Add translation -->
<string name="msg_continue_with_facebook">Continue with <b>Facebook</b></string> <!-- TODO Add translation -->
......
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