mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-07 06:39:45 +00:00
resolve codacy/ktlint warnings
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
8f1f22fd54
commit
ab007fc444
@ -119,7 +119,6 @@ class OutcomingTextMessageViewHolder(itemView: View) :
|
||||
binding.messageQuote.quotedChatMessageView.visibility = View.GONE
|
||||
}
|
||||
|
||||
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
if (message.isTemporary && !networkMonitor.isOnline.first()) {
|
||||
updateStatus(
|
||||
@ -134,12 +133,11 @@ class OutcomingTextMessageViewHolder(itemView: View) :
|
||||
binding.bubble.setOnClickListener {
|
||||
commonMessageInterface.onOpenMessageActionsDialog(message)
|
||||
}
|
||||
|
||||
} else if (message.isTemporary) {
|
||||
showSendingSpinner()
|
||||
} else if(message.readStatus == ReadStatus.READ) {
|
||||
} else if (message.readStatus == ReadStatus.READ) {
|
||||
updateStatus(R.drawable.ic_check_all, context.resources?.getString(R.string.nc_message_read))
|
||||
} else if(message.readStatus == ReadStatus.SENT) {
|
||||
} else if (message.readStatus == ReadStatus.SENT) {
|
||||
updateStatus(R.drawable.ic_check, context.resources?.getString(R.string.nc_message_sent))
|
||||
}
|
||||
}
|
||||
@ -176,8 +174,6 @@ class OutcomingTextMessageViewHolder(itemView: View) :
|
||||
viewThemeUtils.material.colorProgressBar(binding.sendingProgress)
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun longClickOnReaction(chatMessage: ChatMessage) {
|
||||
commonMessageInterface.onLongClickReactions(chatMessage)
|
||||
}
|
||||
|
@ -123,6 +123,7 @@ interface NcApiCoroutines {
|
||||
@DELETE
|
||||
suspend fun unarchiveConversation(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
suspend fun sendChatMessage(
|
||||
|
@ -1142,14 +1142,13 @@ class ChatActivity :
|
||||
private fun removeMessageById(idToDelete: String) {
|
||||
val indexToDelete = adapter?.getMessagePositionById(idToDelete)
|
||||
if (indexToDelete != null && indexToDelete != UNREAD_MESSAGES_MARKER_ID) {
|
||||
|
||||
// If user sent a message as a first message in todays chat, the temp message will be deleted when
|
||||
// messages are retrieved from server, but also the date has to be deleted as it will be added again
|
||||
// when the chat messages are added from server. Otherwise date "Today" would be shown twice.
|
||||
if (indexToDelete == 0 && (adapter?.items?.get(1))?.item is Date) {
|
||||
adapter?.items?.removeAt(0)
|
||||
adapter?.items?.removeAt(0)
|
||||
adapter?.notifyItemRangeRemoved(indexToDelete,1)
|
||||
adapter?.notifyItemRangeRemoved(indexToDelete, 1)
|
||||
} else {
|
||||
adapter?.items?.removeAt(indexToDelete)
|
||||
adapter?.notifyItemRemoved(indexToDelete)
|
||||
@ -1170,7 +1169,7 @@ class ChatActivity :
|
||||
|
||||
cancelNotificationsForCurrentConversation()
|
||||
|
||||
chatViewModel.getRoom(conversationUser!!, roomToken)
|
||||
chatViewModel.getRoom(roomToken)
|
||||
|
||||
actionBar?.show()
|
||||
|
||||
@ -1627,7 +1626,7 @@ class ChatActivity :
|
||||
}
|
||||
getRoomInfoTimerHandler?.postDelayed(
|
||||
{
|
||||
chatViewModel.getRoom(conversationUser!!, roomToken)
|
||||
chatViewModel.getRoom(roomToken)
|
||||
},
|
||||
delayForRecursiveCall
|
||||
)
|
||||
@ -2938,8 +2937,11 @@ class ChatActivity :
|
||||
private fun isScrolledToBottom(): Boolean {
|
||||
val position = layoutManager?.findFirstVisibleItemPosition()
|
||||
if (position == -1) {
|
||||
Log.w(TAG, "FirstVisibleItemPosition was -1 but true is returned for isScrolledToBottom(). This can " +
|
||||
"happen when the UI is not yet ready")
|
||||
Log.w(
|
||||
TAG,
|
||||
"FirstVisibleItemPosition was -1 but true is returned for isScrolledToBottom(). This can " +
|
||||
"happen when the UI is not yet ready"
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
@ -3294,7 +3296,7 @@ class ChatActivity :
|
||||
private fun isInfoMessageAboutDeletion(currentMessage: MutableMap.MutableEntry<String, ChatMessage>): Boolean =
|
||||
currentMessage.value.parentMessageId != null &&
|
||||
currentMessage.value.systemMessageType == ChatMessage
|
||||
.SystemMessageType.MESSAGE_DELETED
|
||||
.SystemMessageType.MESSAGE_DELETED
|
||||
|
||||
private fun isReactionsMessage(currentMessage: MutableMap.MutableEntry<String, ChatMessage>): Boolean =
|
||||
currentMessage.value.systemMessageType == ChatMessage.SystemMessageType.REACTION ||
|
||||
@ -3304,7 +3306,7 @@ class ChatActivity :
|
||||
private fun isEditMessage(currentMessage: MutableMap.MutableEntry<String, ChatMessage>): Boolean =
|
||||
currentMessage.value.parentMessageId != null &&
|
||||
currentMessage.value.systemMessageType == ChatMessage
|
||||
.SystemMessageType.MESSAGE_EDITED
|
||||
.SystemMessageType.MESSAGE_EDITED
|
||||
|
||||
private fun isPollVotedMessage(currentMessage: MutableMap.MutableEntry<String, ChatMessage>): Boolean =
|
||||
currentMessage.value.systemMessageType == ChatMessage.SystemMessageType.POLL_VOTED
|
||||
@ -3404,7 +3406,7 @@ class ChatActivity :
|
||||
this,
|
||||
message,
|
||||
conversationUser,
|
||||
currentConversation,
|
||||
currentConversation
|
||||
).show()
|
||||
} else if (hasVisibleItems(message) &&
|
||||
!isSystemMessage(message)
|
||||
@ -3614,7 +3616,7 @@ class ChatActivity :
|
||||
val lon = data["longitude"]!!
|
||||
metaData =
|
||||
"{\"type\":\"geo-location\",\"id\":\"geo:$lat,$lon\",\"latitude\":\"$lat\"," +
|
||||
"\"longitude\":\"$lon\",\"name\":\"$name\"}"
|
||||
"\"longitude\":\"$lon\",\"name\":\"$name\"}"
|
||||
}
|
||||
|
||||
shareToNotes(shareUri, roomToken, message, objectId, metaData)
|
||||
|
@ -861,7 +861,6 @@ class MessageInputFragment : Fragment() {
|
||||
|
||||
private fun sendMessage(message: String, replyTo: Int?, sendWithoutNotification: Boolean) {
|
||||
chatActivity.messageInputViewModel.sendChatMessage(
|
||||
conversationInternalId,
|
||||
chatActivity.conversationUser!!.getCredentials(),
|
||||
ApiUtils.getUrlForChat(
|
||||
chatActivity.chatApiVersion,
|
||||
|
@ -14,7 +14,6 @@ import com.nextcloud.talk.models.domain.ConversationModel
|
||||
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
|
||||
interface ChatMessageRepository : LifecycleAwareManager {
|
||||
|
||||
@ -80,6 +79,7 @@ interface ChatMessageRepository : LifecycleAwareManager {
|
||||
*/
|
||||
fun handleChatOnBackPress()
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
suspend fun sendChatMessage(
|
||||
credentials: String,
|
||||
url: String,
|
||||
@ -90,6 +90,7 @@ interface ChatMessageRepository : LifecycleAwareManager {
|
||||
referenceId: String
|
||||
): Flow<Result<ChatMessage?>>
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
suspend fun resendChatMessage(
|
||||
credentials: String,
|
||||
url: String,
|
||||
@ -111,10 +112,7 @@ interface ChatMessageRepository : LifecycleAwareManager {
|
||||
|
||||
suspend fun editTempChatMessage(message: ChatMessage, editedMessageText: String): Flow<Boolean>
|
||||
|
||||
suspend fun sendTempChatMessages(
|
||||
credentials: String,
|
||||
url: String
|
||||
)
|
||||
suspend fun sendTempChatMessages(credentials: String, url: String)
|
||||
|
||||
suspend fun deleteTempMessage(chatMessage: ChatMessage)
|
||||
}
|
||||
|
@ -115,9 +115,7 @@ data class ChatMessage(
|
||||
|
||||
var openWhenDownloaded: Boolean = true,
|
||||
|
||||
var isTemporary: Boolean = false, // TODO: replace logic from message drafts with logic from temp message sending
|
||||
|
||||
// var tempMessageId: Int = -1, // TODO: replace logic from message drafts with logic from temp message sending
|
||||
var isTemporary: Boolean = false,
|
||||
|
||||
var referenceId: String? = null,
|
||||
|
||||
|
@ -795,6 +795,7 @@ class OfflineFirstChatRepository @Inject constructor(
|
||||
scope.cancel()
|
||||
}
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
override suspend fun sendChatMessage(
|
||||
credentials: String,
|
||||
url: String,
|
||||
@ -847,6 +848,7 @@ class OfflineFirstChatRepository @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
override suspend fun resendChatMessage(
|
||||
credentials: String,
|
||||
url: String,
|
||||
@ -874,6 +876,7 @@ class OfflineFirstChatRepository @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||
override suspend fun editChatMessage(
|
||||
credentials: String,
|
||||
url: String,
|
||||
@ -892,13 +895,13 @@ class OfflineFirstChatRepository @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun editTempChatMessage(
|
||||
message: ChatMessage, editedMessageText: String
|
||||
): Flow<Boolean> =
|
||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||
override suspend fun editTempChatMessage(message: ChatMessage, editedMessageText: String): Flow<Boolean> =
|
||||
flow {
|
||||
try {
|
||||
val messageToEdit = chatDao.getChatMessageForConversation(
|
||||
internalConversationId, message.jsonMessageId
|
||||
internalConversationId,
|
||||
message.jsonMessageId
|
||||
.toLong()
|
||||
).first()
|
||||
messageToEdit.message = editedMessageText
|
||||
@ -912,10 +915,7 @@ class OfflineFirstChatRepository @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun sendTempChatMessages(
|
||||
credentials: String,
|
||||
url: String
|
||||
) {
|
||||
override suspend fun sendTempChatMessages(credentials: String, url: String) {
|
||||
val tempMessages = chatDao.getTempMessagesForConversation(internalConversationId).first()
|
||||
tempMessages.sortedBy { it.internalId }.onEach {
|
||||
sendChatMessage(
|
||||
@ -974,7 +974,6 @@ class OfflineFirstChatRepository @Inject constructor(
|
||||
message: String,
|
||||
referenceId: String
|
||||
): ChatMessageEntity {
|
||||
|
||||
val currentTimeMillies = System.currentTimeMillis()
|
||||
|
||||
val currentTimeWithoutYear = SendMessageUtils().removeYearFromTimestamp(currentTimeMillies)
|
||||
|
@ -117,7 +117,7 @@ class RetrofitChatNetwork(
|
||||
displayName,
|
||||
null,
|
||||
false,
|
||||
SendMessageUtils().generateReferenceId() // TODO add temp message before with ref id..
|
||||
SendMessageUtils().generateReferenceId()
|
||||
).map {
|
||||
it
|
||||
}
|
||||
|
@ -247,14 +247,9 @@ class ChatViewModel @Inject constructor(
|
||||
chatRepository.setData(conversationModel, credentials, urlForChatting)
|
||||
}
|
||||
|
||||
fun getRoom(user: User, token: String) {
|
||||
fun getRoom(token: String) {
|
||||
_getRoomViewState.value = GetRoomStartState
|
||||
conversationRepository.getRoom(token)
|
||||
|
||||
// chatNetworkDataSource.getRoom(user, token)
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// ?.observeOn(AndroidSchedulers.mainThread())
|
||||
// ?.subscribe(GetRoomObserver())
|
||||
}
|
||||
|
||||
fun getCapabilities(user: User, token: String, conversationModel: ConversationModel) {
|
||||
@ -677,25 +672,6 @@ class ChatViewModel @Inject constructor(
|
||||
fun getPlaybackSpeedPreference(message: ChatMessage) =
|
||||
_voiceMessagePlaybackSpeedPreferences.value?.get(message.user.id) ?: PlaybackSpeed.NORMAL
|
||||
|
||||
// inner class GetRoomObserver : Observer<ConversationModel> {
|
||||
// override fun onSubscribe(d: Disposable) {
|
||||
// // unused atm
|
||||
// }
|
||||
//
|
||||
// override fun onNext(conversationModel: ConversationModel) {
|
||||
// _getRoomViewState.value = GetRoomSuccessState(conversationModel)
|
||||
// }
|
||||
//
|
||||
// override fun onError(e: Throwable) {
|
||||
// Log.e(TAG, "Error when fetching room")
|
||||
// _getRoomViewState.value = GetRoomErrorState
|
||||
// }
|
||||
//
|
||||
// override fun onComplete() {
|
||||
// // unused atm
|
||||
// }
|
||||
// }
|
||||
|
||||
inner class JoinRoomObserver : Observer<ConversationModel> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
disposableSet.add(d)
|
||||
@ -800,10 +776,7 @@ class ChatViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun resendMessage(
|
||||
credentials: String,
|
||||
urlForChat: String,
|
||||
message: ChatMessage) {
|
||||
fun resendMessage(credentials: String, urlForChat: String, message: ChatMessage) {
|
||||
viewModelScope.launch {
|
||||
chatRepository.resendChatMessage(
|
||||
credentials,
|
||||
|
@ -14,23 +14,18 @@ import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.nextcloud.talk.chat.data.ChatMessageRepository
|
||||
import com.nextcloud.talk.chat.data.io.AudioFocusRequestManager
|
||||
import com.nextcloud.talk.chat.data.io.AudioRecorderManager
|
||||
import com.nextcloud.talk.chat.data.io.MediaPlayerManager
|
||||
import com.nextcloud.talk.chat.data.model.ChatMessage
|
||||
import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource
|
||||
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
|
||||
import com.nextcloud.talk.utils.message.SendMessageUtils
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||
import com.stfalcon.chatkit.commons.models.IMessage
|
||||
import io.reactivex.disposables.Disposable
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import java.lang.Thread.sleep
|
||||
import javax.inject.Inject
|
||||
|
||||
class MessageInputViewModel @Inject constructor(
|
||||
@ -51,7 +46,7 @@ class MessageInputViewModel @Inject constructor(
|
||||
lateinit var currentLifeCycleFlag: LifeCycleFlag
|
||||
val disposableSet = mutableSetOf<Disposable>()
|
||||
|
||||
fun setData(chatMessageRepository: ChatMessageRepository){
|
||||
fun setData(chatMessageRepository: ChatMessageRepository) {
|
||||
chatRepository = chatMessageRepository
|
||||
}
|
||||
|
||||
@ -103,9 +98,11 @@ class MessageInputViewModel @Inject constructor(
|
||||
object SendChatMessageStartState : ViewState
|
||||
class SendChatMessageSuccessState(val message: CharSequence) : ViewState
|
||||
class SendChatMessageErrorState(val message: CharSequence) : ViewState
|
||||
|
||||
private val _sendChatMessageViewState: MutableLiveData<ViewState> = MutableLiveData(SendChatMessageStartState)
|
||||
val sendChatMessageViewState: LiveData<ViewState>
|
||||
get() = _sendChatMessageViewState
|
||||
|
||||
object EditMessageErrorState : ViewState
|
||||
class EditMessageSuccessState(val messageEdited: ChatOverallSingleMessage) : ViewState
|
||||
|
||||
@ -121,9 +118,7 @@ class MessageInputViewModel @Inject constructor(
|
||||
val callStartedFlow: LiveData<Pair<ChatMessage, Boolean>>
|
||||
get() = _callStartedFlow
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
fun sendChatMessage(
|
||||
internalId: String,
|
||||
credentials: String,
|
||||
url: String,
|
||||
message: String,
|
||||
@ -172,10 +167,7 @@ class MessageInputViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun sendTempMessages(
|
||||
credentials: String,
|
||||
url: String,
|
||||
) {
|
||||
fun sendTempMessages(credentials: String, url: String) {
|
||||
viewModelScope.launch {
|
||||
chatRepository.sendTempChatMessages(
|
||||
credentials,
|
||||
|
@ -65,7 +65,6 @@ import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import okhttp3.OkHttpClient
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
class RepositoryModule {
|
||||
|
@ -66,6 +66,6 @@ data class ChatMessageEntity(
|
||||
@ColumnInfo(name = "referenceId") var referenceId: String? = null,
|
||||
@ColumnInfo(name = "sendingFailed") var sendingFailed: Boolean = false,
|
||||
@ColumnInfo(name = "systemMessage") var systemMessageType: ChatMessage.SystemMessageType,
|
||||
@ColumnInfo(name = "timestamp") var timestamp: Long = 0,
|
||||
@ColumnInfo(name = "timestamp") var timestamp: Long = 0
|
||||
// missing/not needed: silent
|
||||
)
|
||||
|
@ -87,7 +87,7 @@ class DirectReplyReceiver : BroadcastReceiver() {
|
||||
currentUser.displayName,
|
||||
null,
|
||||
false,
|
||||
SendMessageUtils().generateReferenceId() // TODO add temp chatMessage before with ref id...
|
||||
SendMessageUtils().generateReferenceId()
|
||||
)
|
||||
?.subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -58,19 +58,15 @@ class TempMessageActionsDialog(
|
||||
|
||||
viewThemeUtils.material.colorBottomSheetBackground(binding.root)
|
||||
viewThemeUtils.material.colorBottomSheetDragHandle(binding.bottomSheetDragHandle)
|
||||
|
||||
initMenuItemCopy(!message.isDeleted)
|
||||
val apiVersion = ApiUtils.getConversationApiVersion(user!!, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1))
|
||||
|
||||
|
||||
initMenuItems()
|
||||
}
|
||||
|
||||
private fun initMenuItems() {
|
||||
this.lifecycleScope.launch {
|
||||
initResendMessage(networkMonitor.isOnline.first())
|
||||
initMenuEditMessage(true)
|
||||
initMenuDeleteMessage(true)
|
||||
initMenuEditMessage()
|
||||
initMenuDeleteMessage()
|
||||
initMenuItemCopy()
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,34 +95,25 @@ class TempMessageActionsDialog(
|
||||
binding.menuResendMessage.visibility = getVisibility(visible)
|
||||
}
|
||||
|
||||
private fun initMenuDeleteMessage(visible: Boolean) {
|
||||
if (visible) {
|
||||
binding.menuDeleteMessage.setOnClickListener {
|
||||
chatActivity.chatViewModel.deleteTempMessage(message)
|
||||
dismiss()
|
||||
}
|
||||
private fun initMenuDeleteMessage() {
|
||||
binding.menuDeleteMessage.setOnClickListener {
|
||||
chatActivity.chatViewModel.deleteTempMessage(message)
|
||||
dismiss()
|
||||
}
|
||||
binding.menuDeleteMessage.visibility = getVisibility(visible)
|
||||
}
|
||||
|
||||
private fun initMenuEditMessage(visible: Boolean) {
|
||||
private fun initMenuEditMessage() {
|
||||
binding.menuEditMessage.setOnClickListener {
|
||||
chatActivity.messageInputViewModel.edit(message)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
binding.menuEditMessage.visibility = getVisibility(visible)
|
||||
}
|
||||
|
||||
private fun initMenuItemCopy(visible: Boolean) {
|
||||
if (visible) {
|
||||
binding.menuCopyMessage.setOnClickListener {
|
||||
chatActivity.copyMessage(message)
|
||||
dismiss()
|
||||
}
|
||||
private fun initMenuItemCopy() {
|
||||
binding.menuCopyMessage.setOnClickListener {
|
||||
chatActivity.copyMessage(message)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
binding.menuCopyMessage.visibility = getVisibility(visible)
|
||||
}
|
||||
|
||||
private fun getVisibility(visible: Boolean): Int {
|
||||
|
@ -17,7 +17,6 @@ import androidx.datastore.preferences.core.longPreferencesKey
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.chat.viewmodels.MessageInputViewModel
|
||||
import com.nextcloud.talk.ui.PlaybackSpeed
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.async
|
||||
|
Loading…
Reference in New Issue
Block a user