Skip to content

Commit

Permalink
Add cat GIF to settings screen
Browse files Browse the repository at this point in the history
  • Loading branch information
vafeen committed Oct 22, 2024
1 parent a6e5066 commit b18e395
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 51 deletions.
9 changes: 9 additions & 0 deletions data/src/main/res/drawable/cat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M249.7,56.5c0,0 -2.2,-13.1 -5.2,-17.1c-3.8,-5.1 -16.4,-12.1 -16.4,-12.1c-2.6,3.7 3.6,-9.8 7.3,-22.7c0,0 -24.2,3.2 -46.8,27.6c-6.4,7 -17.8,38.6 -17.8,38.6l-44.7,20.5c-31.1,12.9 -82.7,26.2 -82.7,97.7v30.5c-2.5,-1.7 -15.7,-12.7 -15.5,-29.9c0.1,-13.6 1.9,-27.5 3.6,-39.9c3.1,-22.7 5.5,-47.1 -3.7,-57.6c-4.2,-4.8 -10.2,-7.3 -17.7,-7.3c-4.9,0 -8.9,4 -8.9,8.9c0,4.9 4,8.9 8.9,8.9c2.2,0 3.6,0.4 4.3,1.2c3.8,4.4 1.5,28.1 -0.6,43.4c-1.7,12.9 -3.7,27.5 -3.7,42.2c0,16.2 5.6,31.4 15.7,42.8c11.5,12.9 27.7,19.7 46.8,19.7c0,0 0,0 0,0h62.5h8.9h17.9c4.9,0 8.9,-4 8.9,-8.9s-4,-8.9 -8.9,-8.9l-19.6,0l9.5,-31.3c0,-4.5 -1,-8.8 -2.7,-12.6c-7.1,-12.1 -19.9,-19.6 -34,-19.6c-6.2,0 -12,1.4 -17.5,4.1l-2.9,-5.8c6.4,-3.2 13.2,-4.8 20.4,-4.8c16.8,0 32.3,9.2 40.3,24l0,0l0,0c0,0 33.1,50.7 36.4,57.9c0,0.1 0.1,0.1 0.1,0.2c0.9,2.7 3.1,4.7 5.9,5.3c0.1,0 0.2,0 0.3,0.1c0.5,0.1 0.9,0.3 1.4,0.3h9.8c4.4,0 8.1,-3.6 8.1,-8.1c0,-4.4 -3.6,-8.1 -8.1,-8.1h0.2c0,0 -26.6,-47.4 -21.4,-64.2c23.7,-37.2 36.5,-72.5 36.5,-72.5c5.1,-11.6 18.2,-20.5 20,-21.7c4,-2.7 9.5,-6.1 10,-11.3C254.8,63.7 251,58.7 249.7,56.5z"
android:fillColor="#000000"/>
</vector>
4 changes: 4 additions & 0 deletions data/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@
<string name="every_2_weeks">Every 2 weeks</string>
<string name="no_apps_to_send">No apps to send</string>
<string name="report_a_bug">Report a bug</string>
<string name="interface_str">Interface</string>
<string name="cats_on_ui">Cats on the UI</string>
<string name="weekend_cat">Weekend cat</string>
<string name="cat_in_settings">Cat in settings</string>
</resources>
4 changes: 4 additions & 0 deletions data/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@
<string name="every_2_weeks">Каждые 2 недели</string>
<string name="no_apps_to_send">Нет приложений для отправки</string>
<string name="report_a_bug">Сообщить об ошибке</string>
<string name="interface_str">Интерфейс</string>
<string name="cats_on_ui">Котики на UI</string>
<string name="weekend_cat">Котик выходного дня</string>
<string name="cat_in_settings">Котик в настройках</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ data class Settings(
val link: String? = null,
val isSelectedFrequencyCorrespondsToTheWeekNumbers: Boolean? = null,
val lastDemonstratedVersion: Int? = null,
val weekendCat: Boolean = false,
val catInSettings: Boolean = false,
) {
fun toJsonString(): String = Gson().toJson(this)
override fun toString(): String {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ internal fun MainScreen(
}
}
}
if (lessonsOfThisDay.isEmpty())
if (lessonsOfThisDay.isEmpty() && settings.weekendCat)
GifPlayer(
size = 150.dp,
modifier = Modifier.align(Alignment.BottomCenter),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package ru.vafeen.universityschedule.presentation.components.screens

import android.net.Uri
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand All @@ -14,9 +17,13 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Done
import androidx.compose.material3.AssistChip
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CheckboxDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
Expand All @@ -26,7 +33,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand All @@ -39,17 +45,17 @@ import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import org.koin.androidx.compose.koinViewModel
import ru.vafeen.universityschedule.data.R
import ru.vafeen.universityschedule.data.utils.GSheetsServiceRequestStatus
import ru.vafeen.universityschedule.data.utils.getIconByRequestStatus
import ru.vafeen.universityschedule.data.utils.openLink
import ru.vafeen.universityschedule.domain.utils.getMainColorForThisTheme
import ru.vafeen.universityschedule.domain.utils.getVersionName
import ru.vafeen.universityschedule.domain.utils.save
import ru.vafeen.universityschedule.presentation.components.bottom_bar.BottomBar
import ru.vafeen.universityschedule.presentation.components.ui_utils.CardOfSettings
import ru.vafeen.universityschedule.presentation.components.ui_utils.ColorPickerDialog
import ru.vafeen.universityschedule.presentation.components.ui_utils.EditLinkDialog
import ru.vafeen.universityschedule.presentation.components.ui_utils.TextForThisTheme
import ru.vafeen.universityschedule.presentation.components.video.AssetsInfo
import ru.vafeen.universityschedule.presentation.components.video.GifPlayer
import ru.vafeen.universityschedule.presentation.components.viewModels.SettingsScreenViewModel
import ru.vafeen.universityschedule.presentation.navigation.Screen
import ru.vafeen.universityschedule.presentation.theme.FontSize
Expand Down Expand Up @@ -93,10 +99,17 @@ internal fun SettingsScreen(
navController.popBackStack()
navController.navigate(Screen.Main.route)
}

val checkBoxColors = CheckboxDefaults.colors(
checkedColor = Theme.colors.oppositeTheme,
checkmarkColor = Theme.colors.singleTheme,
uncheckedColor = Theme.colors.oppositeTheme
)
var subGroupIsChanging by remember {
mutableStateOf(false)
}
var catsOnUIIsChanging by remember {
mutableStateOf(false)
}
val subGroupLazyRowState = rememberLazyListState()
val networkState by viewModel.gSheetsServiceRequestStatusFlow.collectAsState()

Expand Down Expand Up @@ -158,30 +171,36 @@ internal fun SettingsScreen(
firstColor = settings.getMainColorForThisTheme(isDark = dark)
?: Theme.colors.mainColor,
onDismissRequest = { colorIsEditable = false }) {
viewModel.sharedPreferences.save(
viewModel.saveSettingsToSharedPreferences(
if (dark) settings.copy(
darkThemeColor = it
) else settings.copy(lightThemeColor = it)
)

}

Spacer(modifier = Modifier.height(30.dp))
Column(
modifier = Modifier
.weight(1f)
.padding(horizontal = 20.dp),
.padding(horizontal = 20.dp)
.verticalScroll(rememberScrollState()),
) {

// name of section
TextForThisTheme(
modifier = Modifier
.padding(10.dp)
.align(Alignment.CenterHorizontally),
fontSize = FontSize.big22,
text = stringResource(R.string.general)
)

Box(modifier = Modifier.fillMaxWidth()) {
// name of section
TextForThisTheme(
modifier = Modifier
.padding(10.dp)
.align(Alignment.Center),
fontSize = FontSize.big22,
text = stringResource(R.string.general)
)
if (settings.catInSettings)
GifPlayer(
size = 80.dp,
modifier = Modifier.align(Alignment.CenterEnd),
imageUri = Uri.parse(AssetsInfo.FUNNY_SETTINGS_CAT)
)
}
// Edit link
CardOfSettings(
text = stringResource(R.string.link_to_table),
Expand Down Expand Up @@ -210,19 +229,6 @@ internal fun SettingsScreen(

}

// Color
CardOfSettings(
text = stringResource(R.string.interface_color),
icon = {
Icon(
painter = painterResource(id = R.drawable.palette),
contentDescription = "change color of interface",
tint = it.suitableColor()
)
}, onClick = { colorIsEditable = true }
)


// Subgroup
if (subgroupList.isNotEmpty()) {
CardOfSettings(
Expand All @@ -239,8 +245,7 @@ internal fun SettingsScreen(
LazyRow(
state = subGroupLazyRowState, modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 10.dp)

.padding(horizontal = it)
) {
items(subgroupList) { subgroup ->
AssistChip(
Expand All @@ -253,7 +258,7 @@ internal fun SettingsScreen(
},
modifier = Modifier.padding(horizontal = 3.dp),
onClick = {
viewModel.sharedPreferences.save(
viewModel.saveSettingsToSharedPreferences(
settings.copy(
subgroup = if (settings.subgroup != subgroup) subgroup else null
)
Expand All @@ -268,6 +273,96 @@ internal fun SettingsScreen(

}

// name of section
TextForThisTheme(
modifier = Modifier
.padding(10.dp)
.align(Alignment.CenterHorizontally),
fontSize = FontSize.big22,
text = stringResource(R.string.interface_str)
)
// Color
CardOfSettings(
text = stringResource(R.string.interface_color),
icon = {
Icon(
painter = painterResource(id = R.drawable.palette),
contentDescription = "change color of interface",
tint = it.suitableColor()
)
}, onClick = { colorIsEditable = true }
)
// cats in interface
CardOfSettings(
text = stringResource(R.string.cats_on_ui),
icon = {
Icon(
painter = painterResource(id = R.drawable.cat),
contentDescription = "cats in interface",
tint = it.suitableColor()
)
}, onClick = { catsOnUIIsChanging = !catsOnUIIsChanging },
additionalContentIsVisible = catsOnUIIsChanging,
additionalContent = {
Column {
val onCheckedChangeWeekendCat = {
viewModel.saveSettingsToSharedPreferences(
settings = settings.copy(
weekendCat = !settings.weekendCat
)
)
}
val onCheckedChangeCatInSettings = {
viewModel.saveSettingsToSharedPreferences(
settings = settings.copy(
catInSettings = !settings.catInSettings
)
)
}
Row(
modifier = Modifier
.fillMaxWidth()
.clickable { onCheckedChangeWeekendCat() }
.padding(horizontal = it),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
TextForThisTheme(
text = stringResource(R.string.weekend_cat),
fontSize = FontSize.medium19
)
Checkbox(
checked = settings.weekendCat,
onCheckedChange = {
onCheckedChangeWeekendCat()
}, colors = checkBoxColors
)
}
Row(
modifier = Modifier
.fillMaxWidth()
.clickable { onCheckedChangeCatInSettings() }
.padding(horizontal = it),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
TextForThisTheme(
text = stringResource(R.string.cat_in_settings),
fontSize = FontSize.medium19
)
Checkbox(
checked = settings.catInSettings,
onCheckedChange = {
onCheckedChangeCatInSettings()
}, colors = checkBoxColors
)
}

}
}
)


// name of section
TextForThisTheme(
modifier = Modifier
Expand Down Expand Up @@ -305,17 +400,16 @@ internal fun SettingsScreen(
context.sendEmail(email = Link.EMAIL)
}
)
// version
TextForThisTheme(
modifier = Modifier
.padding(10.dp)
.padding(bottom = 20.dp)
.align(Alignment.End),
fontSize = FontSize.small17,
text = "${stringResource(R.string.version)} ${LocalContext.current.getVersionName()}"
)
}

// version
TextForThisTheme(
modifier = Modifier
.padding(10.dp)
.padding(bottom = 20.dp)
.align(Alignment.End),
fontSize = FontSize.small17,
text = "${stringResource(R.string.version)} ${LocalContext.current.getVersionName()}"
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import ru.vafeen.universityschedule.data.R
import ru.vafeen.universityschedule.presentation.theme.FontSize
Expand All @@ -31,21 +32,23 @@ fun CardOfSettings(
icon: @Composable (Color) -> Unit,
onClick: () -> Unit,
additionalContentIsVisible: Boolean? = null,
additionalContent: @Composable (() -> Unit)? = null
additionalContent: @Composable ((padding: Dp) -> Unit)? = null
) {
val color = generateRandomColor()
val contentPadding = 10.dp
Card(
modifier = Modifier.padding(vertical = 15.dp),
colors = CardDefaults.cardColors(
containerColor = Theme.colors.buttonColor,
),
elevation = CardDefaults.cardElevation(defaultElevation = 10.dp)
elevation = CardDefaults.cardElevation(defaultElevation = contentPadding)
) {
Column(modifier = Modifier.clickable(onClick = onClick)) {
Column {
Row(
modifier = Modifier
.padding(horizontal = 10.dp)
.fillMaxWidth(),
.fillMaxWidth()
.clickable(onClick = onClick)
.padding(horizontal = 10.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Expand All @@ -72,7 +75,7 @@ fun CardOfSettings(
)
}
if (additionalContentIsVisible == true)
additionalContent?.let { it() }
additionalContent?.let { it(contentPadding) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package ru.vafeen.universityschedule.presentation.components.video
object AssetsInfo {
private const val PREFIX = "file:///android_asset"
const val DANCING_CAT = "$PREFIX/dancing_cat.gif"
const val FUNNY_SETTINGS_CAT = "$PREFIX/funny_settings_cat.gif"
}
Loading

0 comments on commit b18e395

Please sign in to comment.