Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Improve exercises screen
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitSuda committed Nov 22, 2022
1 parent 6327048 commit 72937b3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fun TopSearchBar(
Icon(
imageVector = Icons.Outlined.ArrowBack,
contentDescription = stringResource(R.string.back),
tint = /*if (backgroundColor.isDark()) Color.White else*/ Color.Black,
tint = /*if (backgroundColor.isDark()) Color.White else*/ ReboundTheme.colors.onBackground,
)
}
// TextField
Expand Down Expand Up @@ -298,5 +298,9 @@ fun TopBarIconButton(

@Composable
fun TopBarBackIconButton(onClick: () -> Unit) {
TopBarIconButton(icon = Icons.Outlined.ArrowBack, title = stringResource(R.string.back), onClick = onClick)
TopBarIconButton(
icon = Icons.Outlined.ArrowBack,
title = stringResource(R.string.back),
onClick = onClick
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.ankitsuda.rebound.domain.entities.*
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.util.concurrent.Executors

@Database(
entities = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ interface ExercisesDao {
FROM exercise_workout_junctions ewj
JOIN workouts w ON ewj.workout_id = w.id AND e.exercise_id = ewj.exercise_id
WHERE w.id = ewj.workout_id AND w.is_hidden = 0 AND w.in_progress = 0) as logs_count
FROM exercises e ORDER BY name COLLATE NOCASE ASC
FROM exercises e WHERE CASE WHEN :searchQuery IS NOT NULL
THEN e.name LIKE '%' || :searchQuery || '%'
ELSE 1
END ORDER BY e.name COLLATE NOCASE ASC
"""
)
fun getAllExercisesWithExtraInfoPaged(searchQuery: String?): PagingSource<Int, ExerciseWithExtraInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ class ExercisesRepository @Inject constructor(
list
}

fun getExercisesWithExtraInfoPaged(searchQuery: String? = null) = Pager(PagingConfig(pageSize = 15)) {
exercisesDao.getAllExercisesWithExtraInfoPaged(searchQuery = searchQuery)
}.flow
fun getExercisesWithExtraInfoPaged(searchQuery: String? = null) =
Pager(PagingConfig(pageSize = 15)) {
// if (searchQuery != null) {
exercisesDao.getAllExercisesWithExtraInfoPaged(searchQuery = searchQuery)
// } else {
// exercisesDao.getAllExercisesWithExtraInfoPaged()
// }
}.flow


suspend fun createExercise(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.ankitsuda.rebound.ui.exercises

import androidx.activity.compose.BackHandler
import androidx.compose.animation.*
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
Expand Down Expand Up @@ -55,8 +56,8 @@ fun ExercisesScreen(
navigator: Navigator = LocalNavigator.current,
viewModel: ExercisesScreenViewModel = hiltViewModel()
) {
val isSearchMode by viewModel.isSearchMode.observeAsState(false)
val searchTerm by viewModel.searchTerm.observeAsState("")
val isSearchMode by viewModel.isSearchMode.collectAsState(false)
val searchTerm by viewModel.searchTerm.collectAsState("")

val exercisesPaged = viewModel.exercisesPaged.collectAsLazyPagingItems()

Expand Down Expand Up @@ -99,6 +100,10 @@ private fun ExercisesScreenContent(
) {
val collapsingState = rememberCollapsingToolbarScaffoldState()

BackHandler(isSearchMode) {
onToggleSearchMode()
}

Column {
CollapsingToolbarScaffold(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@

package com.ankitsuda.rebound.ui.exercises

import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import androidx.paging.insertSeparators
import com.ankitsuda.base.utils.extensions.shareWhileObserved
import com.ankitsuda.rebound.data.repositories.ExercisesRepository
import com.ankitsuda.rebound.data.repositories.MusclesRepository
import com.ankitsuda.rebound.domain.entities.ExerciseWithExtraInfo
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import timber.log.Timber
import java.util.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -74,26 +70,4 @@ class ExercisesScreenViewModel @Inject constructor(
fun setSearchTerm(term: String) {
_searchTerm.value = term
}

// private fun filterExercises() {
// viewModelScope.launch {
// _filteredExercises.clear()
// if (_isSearchMode.value == true) {
// _filteredExercises.addAll(allExercises.filter {
// it.exercise.name?.contains(
// _searchTerm.value!!,
// true
// ) == true
// })
// } else {
// _filteredExercises.addAll(allExercises)
// }
//
// _groupedExercises.emit(_filteredExercises.groupBy {
// (it.exercise.name?.firstOrNull() ?: "#").toString().uppercase(Locale.getDefault())
// })
//// }
// }
// }

}

0 comments on commit 72937b3

Please sign in to comment.