This commit is contained in:
@@ -15,7 +15,6 @@ import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
import androidx.navigation.NavHostController
|
||||
@@ -89,8 +88,14 @@ class MainActivity : BaseActivity() {
|
||||
composable("counter") {
|
||||
Counter(counterViewModel)
|
||||
mainViewModel.topBarActions = (listOf(
|
||||
TopBarAction(Icons.Outlined.Undo, mainViewModel.isUndoActionActive) { mainViewModel.undoLastRound() },
|
||||
TopBarAction(Icons.Outlined.Redo, mainViewModel.isRedoActionActive) { mainViewModel.redoLastRound() }
|
||||
TopBarAction(
|
||||
Icons.Outlined.Undo,
|
||||
mainViewModel.isUndoActionActive
|
||||
) { mainViewModel.undoLastRound() },
|
||||
TopBarAction(
|
||||
Icons.Outlined.Redo,
|
||||
mainViewModel.isRedoActionActive
|
||||
) { mainViewModel.redoLastRound() }
|
||||
|
||||
))
|
||||
mainViewModel.topBarIcon = Icons.Outlined.Menu
|
||||
@@ -163,7 +168,9 @@ class MainActivity : BaseActivity() {
|
||||
val scope = rememberCoroutineScope()
|
||||
val navController = rememberNavController()
|
||||
|
||||
val items = listOf(Screen.History, Screen.Settings)
|
||||
val items = listOf(
|
||||
Screen("history", Icons.Outlined.List, R.string.menu_history),Screen("settings", Icons.Outlined.Settings, R.string.menu_settings)
|
||||
)
|
||||
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
@@ -236,9 +243,5 @@ class MainActivity : BaseActivity() {
|
||||
)
|
||||
}
|
||||
|
||||
sealed class Screen(val route: String, val icon: ImageVector, @StringRes val resourceId: Int) {
|
||||
object History : Screen("history", Icons.Outlined.List, R.string.menu_history)
|
||||
object Settings : Screen("settings", Icons.Outlined.Settings, R.string.menu_settings)
|
||||
|
||||
}
|
||||
private class Screen(val route: String, val icon: ImageVector, @StringRes val resourceId: Int)
|
||||
}
|
||||
@@ -17,10 +17,10 @@ class SettingsAdapter @Inject constructor(@ApplicationContext private val contex
|
||||
val language: Language
|
||||
get() {
|
||||
var setting = sharedPreferences.getString(Language::class.simpleName, null)
|
||||
if(setting == null)
|
||||
{
|
||||
if (setting == null) {
|
||||
setCurrentLanguage()
|
||||
setting = sharedPreferences.getString(Language::class.simpleName, Language.ENGLISH.name)
|
||||
setting =
|
||||
sharedPreferences.getString(Language::class.simpleName, Language.ENGLISH.name)
|
||||
}
|
||||
return enumValueOf(setting!!)
|
||||
}
|
||||
@@ -43,6 +43,7 @@ class SettingsAdapter @Inject constructor(@ApplicationContext private val contex
|
||||
}
|
||||
setLanguage(setting)
|
||||
}
|
||||
|
||||
fun setLanguage(language: Language) {
|
||||
val editor = sharedPreferences.edit()
|
||||
editor.putString(Language::class.simpleName, language.name)
|
||||
|
||||
@@ -2,7 +2,6 @@ package me.zobrist.tichucounter.repository
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.last
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import me.zobrist.tichucounter.data.Game
|
||||
@@ -67,6 +66,7 @@ class GameRepository @Inject constructor(
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteLastRound() {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
|
||||
@@ -2,7 +2,10 @@ package me.zobrist.tichucounter.ui
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@@ -12,11 +15,13 @@ import me.zobrist.tichucounter.data.RoundDao
|
||||
import me.zobrist.tichucounter.domain.NavigationAction
|
||||
import me.zobrist.tichucounter.domain.TopBarAction
|
||||
import me.zobrist.tichucounter.repository.GameRepository
|
||||
import java.util.NoSuchElementException
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class MainViewModel @Inject constructor(private val gameRepository: GameRepository, roundDao: RoundDao) : ViewModel() {
|
||||
class MainViewModel @Inject constructor(
|
||||
private val gameRepository: GameRepository,
|
||||
roundDao: RoundDao
|
||||
) : ViewModel() {
|
||||
|
||||
private var redoRounds = mutableStateListOf<Round>()
|
||||
private var expectedRoundCount = 0
|
||||
@@ -67,8 +72,7 @@ class MainViewModel @Inject constructor(private val gameRepository: GameReposito
|
||||
redoRounds.remove(round)
|
||||
expectedRoundCount++
|
||||
gameRepository.addRoundToActiveGame(round.scoreA, round.scoreB)
|
||||
}catch (_: NoSuchElementException)
|
||||
{
|
||||
} catch (_: NoSuchElementException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,14 @@ package me.zobrist.tichucounter.ui.settings
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.ArrowDropDown
|
||||
import androidx.compose.material.icons.outlined.Check
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Alignment.Companion.CenterVertically
|
||||
import androidx.compose.ui.Alignment.Companion.End
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.InspectableModifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
@@ -82,10 +77,21 @@ fun SettingsView(
|
||||
fun BooleanSetting(name: String, value: Boolean, updateValue: (Boolean) -> Unit) {
|
||||
|
||||
Row(
|
||||
Modifier.padding(20.dp).fillMaxWidth()) {
|
||||
Modifier
|
||||
.padding(20.dp)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
Column(Modifier.weight(5f)) {
|
||||
Text(name, maxLines = 1, style = MaterialTheme.typography.bodyLarge, overflow = TextOverflow.Ellipsis)
|
||||
Text(stringResource(if(value) R.string.on else R.string.off), style = MaterialTheme.typography.labelLarge)
|
||||
Text(
|
||||
name,
|
||||
maxLines = 1,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Text(
|
||||
stringResource(if (value) R.string.on else R.string.off),
|
||||
style = MaterialTheme.typography.labelLarge
|
||||
)
|
||||
|
||||
}
|
||||
Column(Modifier.weight(1f))
|
||||
@@ -117,7 +123,8 @@ fun <T> StringSetting(name: String, map: Map<T, Int>, selected: T, onSelected: (
|
||||
Icon(
|
||||
Icons.Outlined.ArrowDropDown,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.align(End))
|
||||
modifier = Modifier.align(End)
|
||||
)
|
||||
}
|
||||
|
||||
DropdownMenu(
|
||||
|
||||
Reference in New Issue
Block a user