Skip to content

Commit

Permalink
format code and remove unused colors
Browse files Browse the repository at this point in the history
Signed-off-by: sowjanyakch <[email protected]>
  • Loading branch information
sowjanyakch committed Dec 9, 2024
1 parent 0e8753f commit ca9225d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 47 deletions.
59 changes: 23 additions & 36 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,10 @@ import java.io.File
import java.io.IOException
import java.net.HttpURLConnection
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date
import java.util.Locale
import java.util.concurrent.ExecutionException
import javax.inject.Inject
import kotlin.String
import kotlin.collections.set
import kotlin.math.roundToInt

Expand Down Expand Up @@ -621,18 +619,6 @@ 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
)
}
}

logConversationInfos("GetRoomSuccessState")

if (adapter == null) {
Expand Down Expand Up @@ -701,16 +687,17 @@ class ChatActivity :
loadAvatarForStatusBar()
setupSwipeToReply()
setActionBarTitle()

checkShowCallButtons()
checkLobbyState()
if (currentConversation?.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) {
if (currentConversation?.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL &&
currentConversation?.status == "dnd"
) {
conversationUser?.let { user ->
val credentials = ApiUtils.getCredentials(user.username, user.token)
chatViewModel.outOfOfficeStatusOfUser(
credentials!!,
user.baseUrl!!,
currentConversation!!.displayName
currentConversation!!.name
)
}
}
Expand Down Expand Up @@ -1101,29 +1088,26 @@ class ChatActivity :
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 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
)
if (dateUtils.isSameDate(startDate, endDate)) {
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.userAbsenceShortMessage).text =
String.format(
context.resources.getString(R.string.user_absence),
uiState.userAbsence.userId
)

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

if (uiState.userAbsence.replacementUserDisplayName != null) {
Expand All @@ -1146,7 +1130,8 @@ class ChatActivity :
)
)
}
binding.outOfOfficeContainer.findViewById<TextView>(R.id.absenceReplacement).text = context.resources.getString(R.string.user_absence_replacement)
binding.outOfOfficeContainer.findViewById<TextView>(R.id.absenceReplacement).text =
context.resources.getString(R.string.user_absence_replacement)
binding.outOfOfficeContainer.findViewById<ImageView>(R.id.replacement_user_avatar)
.load(imageUri) {
transformations(CircleCropTransformation())
Expand All @@ -1157,9 +1142,11 @@ class ChatActivity :
binding.outOfOfficeContainer.findViewById<TextView>(R.id.replacement_user_name).text =
uiState.userAbsence.replacementUserDisplayName
} else {
binding.outOfOfficeContainer.findViewById<TextView>(R.id.absenceReplacement).visibility = View.GONE
binding.outOfOfficeContainer.findViewById<TextView>(R.id.absenceReplacement).visibility =
View.GONE
}
binding.outOfOfficeContainer.findViewById<TextView>(R.id.userAbsenceLongMessage).text = uiState.userAbsence.message
binding.outOfOfficeContainer.findViewById<TextView>(R.id.userAbsenceLongMessage).text =
uiState.userAbsence.message
binding.outOfOfficeContainer.findViewById<CardView>(R.id.avatar_chip).setOnClickListener {
joinOneToOneConversation(uiState.userAbsence.replacementUserId!!)
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/nextcloud/talk/utils/DateUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class DateUtils(val context: Context) {
return formatTime.format(Date(timestampSeconds * DateConstants.SECOND_DIVIDER))
}

fun isSameDate(date1: Date, date2: Date): Boolean {
val startDateCalendar = Calendar.getInstance().apply { time = date1 }
val endDateCalendar = Calendar.getInstance().apply { time = date2 }
val isSameDay = startDateCalendar.get(Calendar.YEAR) == endDateCalendar.get(Calendar.YEAR) &&
startDateCalendar.get(Calendar.DAY_OF_YEAR) == endDateCalendar.get(Calendar.DAY_OF_YEAR)
return isSameDay
}

fun getTimeDifferenceInSeconds(time2: Long, time1: Long): Long {
val difference = (time2 - time1)
return abs(difference)
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,4 @@

<color name="icon_on_bg_default">#99FFFFFF</color>

<color name="scrollview_out_of_office_background">#cee7fe</color>
<color name="scrollview_out_of_office_text">#5e95b4</color>

</resources>
3 changes: 0 additions & 3 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,4 @@
<color name="badge_color">#EF3B02</color>
<color name="secondary_button_background">#DBE2E9</color>

<color name="scrollview_out_of_office_background">#cee5fd</color>
<color name="scrollview_out_of_office_text">#08486e</color>

</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -842,5 +842,5 @@ How to translate with transifex:

<string name="user_absence">%1$s is out of office and might not respond</string>
<string name="user_absence_for_one_day">%1$s is out of office today</string>
<string name="user_absence_replacement">Replacement</string>
<string name="user_absence_replacement">Replacement: </string>
</resources>
4 changes: 0 additions & 4 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,4 @@
<item name="cornerSize">50%</item>
</style>

<style name="ScrollViewStyle">
<item name="android:background">@color/scrollview_out_of_office_background</item>
</style>

</resources>

0 comments on commit ca9225d

Please sign in to comment.