Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
Signed-off-by: sowjanyakch <[email protected]>
  • Loading branch information
sowjanyakch committed Dec 5, 2024
1 parent 9d4b617 commit 5d7fb6f
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 65 deletions.
6 changes: 2 additions & 4 deletions app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ interface NcApiCoroutines {

@GET
suspend fun getOutOfOfficeStatusForUser(
@Header("Authorization") authorization:String,
@Url url:String
@Header("Authorization") authorization: String,
@Url url: String
): UserAbsenceOverall


}
96 changes: 49 additions & 47 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,15 @@ class ChatActivity :
urlForChatting
)

if(currentConversation?.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL &&
currentConversation?.status == "dnd"){
conversationUser?.let{ user ->
chatViewModel.outOfOfficeStatusOfUser(credentials, user.baseUrl!!, currentConversation!!.name)
if (currentConversation?.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL &&
currentConversation?.status == "dnd"
) {
conversationUser?.let { user ->
chatViewModel.outOfOfficeStatusOfUser(
credentials,
user.baseUrl!!,
currentConversation!!.name
)
}
}

Expand Down Expand Up @@ -695,11 +700,14 @@ class ChatActivity :

checkShowCallButtons()
checkLobbyState()
if(currentConversation?.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL){
conversationUser?.let{ user ->
if (currentConversation?.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) {
conversationUser?.let { user ->
val credentials = ApiUtils.getCredentials(user.username, user.token)
chatViewModel.outOfOfficeStatusOfUser(credentials!!, user.baseUrl!!,
currentConversation!!.displayName)
chatViewModel.outOfOfficeStatusOfUser(
credentials!!,
user.baseUrl!!,
currentConversation!!.displayName
)
}
}

Expand Down Expand Up @@ -1070,63 +1078,58 @@ class ChatActivity :
binding.voiceRecordingLock.y -= y
}

chatViewModel.outOfOfficeViewState.observe(this){uiState ->
when(uiState){
chatViewModel.outOfOfficeViewState.observe(this) { uiState ->
when (uiState) {
is ChatViewModel.OutOfOfficeUIState.Error -> {
Log.e(TAG, "Error in outOfOfficeState",uiState.exception)

Log.e(TAG, "Error in outOfOfficeState", uiState.exception)
}
ChatViewModel.OutOfOfficeUIState.None -> {

}
is ChatViewModel.OutOfOfficeUIState.Success -> {
binding.outOfOfficeContainer.visibility = View.VISIBLE

val startDateTimestamp: Long = uiState.userAbsence.startDate.toLong()
val endDateTimestamp: Long = uiState.userAbsence.endDate.toLong()

val startDateTimestamp:Long = uiState.userAbsence.startDate.toLong()
val endDateTimestamp:Long = uiState.userAbsence.endDate.toLong()

val startDate = Date(startDateTimestamp * 1000)
val endDate = Date(endDateTimestamp * 1000)
val startDate = Date(startDateTimestamp * 1000)
val endDate = Date(endDateTimestamp * 1000)

val date1 = Calendar.getInstance().apply{time = startDate}
val date2 = Calendar.getInstance().apply{time = endDate}
val date1 = Calendar.getInstance().apply { time = startDate }
val date2 = Calendar.getInstance().apply { time = endDate }

val isSameDay = date1.get(Calendar.YEAR) == date2.get(Calendar.YEAR) &&
date1.get(Calendar.DAY_OF_YEAR) == date2.get(Calendar.DAY_OF_YEAR)

if (isSameDay) {
binding.outOfOfficeContainer.findViewById<TextView>(R.id.userAbsenceShortMessage).text = String.format(
context.resources.getString(R.string.user_absence_for_one_day),
uiState.userAbsence.userId
)
binding.outOfOfficeContainer.findViewById<TextView>(R.id.userAbsencePeriod).visibility =
View.GONE
} else {
val dateFormatter = SimpleDateFormat("MMM d, yyyy", Locale.getDefault())
val startDateString = dateFormatter.format(startDate)
val endDateString = dateFormatter.format(endDate)
binding.outOfOfficeContainer.findViewById<TextView>(R.id.userAbsenceShortMessage).text = String.format(
context.resources.getString(R.string.user_absence),
uiState.userAbsence.userId
)
val isSameDay = date1.get(Calendar.YEAR) == date2.get(Calendar.YEAR) &&
date1.get(Calendar.DAY_OF_YEAR) == date2.get(Calendar.DAY_OF_YEAR)

binding.outOfOfficeContainer.findViewById<TextView>(R.id.userAbsencePeriod).text = "$startDateString - $endDateString"
}
if (isSameDay) {
binding.outOfOfficeContainer.findViewById<TextView>(R.id.userAbsenceShortMessage).text = String.format(
context.resources.getString(R.string.user_absence_for_one_day),
uiState.userAbsence.userId
)
binding.outOfOfficeContainer.findViewById<TextView>(R.id.userAbsencePeriod).visibility =
View.GONE
} else {
val dateFormatter = SimpleDateFormat("MMM d, yyyy", Locale.getDefault())
val startDateString = dateFormatter.format(startDate)
val endDateString = dateFormatter.format(endDate)
binding.outOfOfficeContainer.findViewById<TextView>(R.id.userAbsenceShortMessage).text = String.format(
context.resources.getString(R.string.user_absence),
uiState.userAbsence.userId
)

binding.outOfOfficeContainer.findViewById<TextView>(R.id.userAbsencePeriod).text = "$startDateString - $endDateString"
}

if(uiState.userAbsence.replacementUserDisplayName != null){
if (uiState.userAbsence.replacementUserDisplayName != null) {
binding.outOfOfficeContainer.findViewById<TextView>(R.id.absenceReplacement).text = String.format(
context.resources.getString(R.string.user_absence_replacement),
uiState.userAbsence.replacementUserDisplayName
)
}else{
} else {
binding.outOfOfficeContainer.findViewById<TextView>(R.id.absenceReplacement).visibility = View.GONE
}
binding.outOfOfficeContainer.findViewById<TextView>(R.id.userAbsenceLongMessage).text = uiState.userAbsence.message
}
}

}
}

Expand Down Expand Up @@ -3183,7 +3186,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 ||
Expand All @@ -3193,7 +3196,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
Expand Down Expand Up @@ -3490,7 +3493,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\"}"
}

when (type) {
Expand Down Expand Up @@ -3937,4 +3940,3 @@ class ChatActivity :
const val NO_OFFLINE_MESSAGES_FOUND = "NO_OFFLINE_MESSAGES_FOUND"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,5 @@ interface ChatNetworkDataSource {
fun createRoom(credentials: String, url: String, map: Map<String, String>): Observable<RoomOverall>
fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int): Observable<GenericOverall>
fun editChatMessage(credentials: String, url: String, text: String): Observable<ChatOverallSingleMessage>
suspend fun getOutOfOfficeStatusForUser (credentials:String,baseUrl:String, userId:String): UserAbsenceOverall

suspend fun getOutOfOfficeStatusForUser(credentials: String, baseUrl: String, userId: String): UserAbsenceOverall
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.nextcloud.talk.utils.ApiUtils
import io.reactivex.Observable
import retrofit2.Response

class RetrofitChatNetwork(private val ncApi: NcApi, private val ncApiCoroutines:NcApiCoroutines) : ChatNetworkDataSource {
class RetrofitChatNetwork(private val ncApi: NcApi, private val ncApiCoroutines: NcApiCoroutines) : ChatNetworkDataSource {
override fun getRoom(user: User, roomToken: String): Observable<ConversationModel> {
val credentials: String = ApiUtils.getCredentials(user.username, user.token)!!
val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1))
Expand Down Expand Up @@ -181,9 +181,14 @@ class RetrofitChatNetwork(private val ncApi: NcApi, private val ncApiCoroutines:
return ncApi.editChatMessage(credentials, url, text).map { it }
}

override suspend fun getOutOfOfficeStatusForUser(credentials: String, baseUrl: String, userId:String):
UserAbsenceOverall {
return ncApiCoroutines.getOutOfOfficeStatusForUser(credentials,
ApiUtils.getUrlForOutOfOffice(baseUrl,userId))
override suspend fun getOutOfOfficeStatusForUser(
credentials: String,
baseUrl: String,
userId: String
): UserAbsenceOverall {
return ncApiCoroutines.getOutOfOfficeStatusForUser(
credentials,
ApiUtils.getUrlForOutOfOffice(baseUrl, userId)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ class ChatViewModel @Inject constructor(
}
}

fun outOfOfficeStatusOfUser(credentials:String, baseUrl: String, userId: String) {
fun outOfOfficeStatusOfUser(credentials: String, baseUrl: String, userId: String) {
viewModelScope.launch {
try {
val response = chatNetworkDataSource.getOutOfOfficeStatusForUser(credentials, baseUrl, userId)
Expand All @@ -787,7 +787,6 @@ class ChatViewModel @Inject constructor(
const val JOIN_ROOM_RETRY_COUNT: Long = 3
}


sealed class OutOfOfficeUIState {
data object None : OutOfOfficeUIState()
data class Success(val userAbsence: UserAbsenceData) : OutOfOfficeUIState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class RepositoryModule {

@Provides
fun provideChatNetworkDataSource(ncApi: NcApi, ncApiCoroutines: NcApiCoroutines): ChatNetworkDataSource {
return RetrofitChatNetwork(ncApi,ncApiCoroutines)
return RetrofitChatNetwork(ncApi, ncApiCoroutines)
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ data class UserAbsenceData(
@JsonField(name = ["replacementUserId"])
var replacementUserId: String?,
@JsonField(name = ["replacementUserDisplayName"])
var replacementUserDisplayName: String?,
var replacementUserDisplayName: String?
) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ data class UserAbsenceOCS(
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(null, null)
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ data class UserAbsenceOverall(
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(null)
}

2 changes: 1 addition & 1 deletion app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ object ApiUtils {
return "${getUrlForRoom(version, baseUrl, token)}/archive"
}

fun getUrlForOutOfOffice(baseUrl:String, userId:String):String{
fun getUrlForOutOfOffice(baseUrl: String, userId: String): String {
return "$baseUrl$OCS_API_VERSION/apps/dav/api/v1/outOfOffice/$userId/now"
}
}

0 comments on commit 5d7fb6f

Please sign in to comment.