Skip to content
Merged
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
@@ -1,6 +1,7 @@
package com.moscow.tudee.presentation.screen.task

import SwipeToDeleteItem
import android.content.Context
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
Expand All @@ -27,6 +28,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -102,7 +104,7 @@ fun TaskScreen(
val index = uiState.monthDays.indexOf(uiState.selectedDate.date)
if (index >= 0) lazyListState.animateScrollToItem(index)
}

LaunchedEffect(Unit) {
addTaskBottomSheetViewModel.uiEvent.collect { event ->
when (event) {
Expand Down Expand Up @@ -151,6 +153,7 @@ private fun TaskContent(
allTabs: List<TabItem>,
lazyListState: LazyListState
) {
val context = LocalContext.current
Scaffold(
containerColor = Theme.colors.surface,
topBar = {
Expand Down Expand Up @@ -196,7 +199,7 @@ private fun TaskContent(
TextStyle.FULL,
Locale.getDefault()
)
}, ${uiState.currentYear}",
}, ${context.localizeNumber(uiState.currentYear)}",
onBackClick = interactionListener::previousMonth,
onNextClick = interactionListener::nextMonth,
onDownClick = interactionListener::showDatePicker
Expand All @@ -214,12 +217,12 @@ private fun TaskContent(
)
) {
items(uiState.monthDays) { date ->
val dayName = date.dayOfWeek.name.take(3).lowercase()
.replaceFirstChar { it.titlecase(Locale.ROOT) }
val dayName = context.getLocalizedDayName(date.dayOfWeek.value)
val dayDate = context.localizeNumber(date.dayOfMonth)

DayItem(
day = dayName,
dayDate = date.dayOfMonth,
dayDate = dayDate,
isSelected = date == uiState.selectedDate.date,
onDayClick = { interactionListener.selectDate(date) },
isToday = date == uiState.selectedDate.date
Expand Down Expand Up @@ -324,4 +327,29 @@ private fun TaskContent(
)
}
}
}

fun Context.getLocalizedDayName(dayOfWeek: Int): String {
val fullName = when (dayOfWeek) {
1 -> getString(R.string.monday)
2 -> getString(R.string.tuesday)
3 -> getString(R.string.wednesday)
4 -> getString(R.string.thursday)
5 -> getString(R.string.friday)
6 -> getString(R.string.saturday)
7 -> getString(R.string.sunday)
else -> ""
}

val currentLang = resources.configuration.locales[0].language
return if (currentLang == "en") {
fullName.take(3).replaceFirstChar { it.uppercaseChar() }
} else {
fullName
}
}

fun Context.localizeNumber(number: Int): String {
val locale = resources.configuration.locales[0]
return String.format(locale, "%d", number)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.moscow.tudee.presentation.designSystem.theme.Theme.textStyle
fun DayItem(
modifier: Modifier = Modifier,
day: String,
dayDate: Int,
dayDate: String,
isSelected: Boolean,
onDayClick: () -> Unit,
isToday: Boolean = false
Expand All @@ -43,7 +43,7 @@ fun DayItem(
verticalArrangement = Arrangement.spacedBy(2.dp)
) {
Text(
text = "$dayDate",
text = dayDate,
color = if (isSelected || isToday) colors.onPrimary else colors.body,
style = textStyle.title.medium,

Expand All @@ -60,8 +60,8 @@ fun DayItem(
@Composable
fun PreviewDay() {
DayItem(
day = "Mon",
dayDate = 12,
day = "الخميس",
dayDate = "12",
isSelected = true,
onDayClick = { }
)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,11 @@
<string name="no_tasks_for_today">لا يوجد مهام اليوم</string>
<string name="upload">تحميل</string>
<string name="add">إضافة</string>
<string name="monday">الاثنين</string>
<string name="tuesday">الثلاثاء</string>
<string name="wednesday">الأربعاء</string>
<string name="thursday">الخميس</string>
<string name="friday">الجمعة</string>
<string name="saturday">السبت</string>
<string name="sunday">الأحد</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,11 @@
<string name="no_tasks_for_today">No tasks for today!</string>
<string name="upload">Upload</string>
<string name="add">Add</string>
<string name="monday">Monday</string>
<string name="tuesday">Tuesday</string>
<string name="wednesday">Wednesday</string>
<string name="thursday">Thursday</string>
<string name="friday">Friday</string>
<string name="saturday">Saturday</string>
<string name="sunday">Sunday</string>
</resources>
Loading