Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Material 3 SearchBar #74

Merged
merged 2 commits into from
Oct 27, 2023
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
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ android {

dependencies {
implementation libs.androidx.lifecycle.runtimeKtx
implementation libs.androidx.lifecycle.runtimeCompose
implementation libs.androidx.lifecycle.viewmodelCompose

implementation libs.androidx.room.runtime
Expand All @@ -88,8 +89,6 @@ dependencies {

implementation libs.androidx.core.ktx
implementation libs.androidx.activity.compose
implementation libs.androidx.navigation.compose
implementation libs.androidx.hilt.navigationCompose
implementation libs.plrapps.mapcompose

testImplementation libs.junit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package ru.spbu.depnav.data.db

import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
Expand Down Expand Up @@ -61,7 +60,7 @@ class SearchHistoryDaoTest : AppDatabaseDaoTest() {
searchHistoryDao.insertNotExceeding(SearchHistoryEntry(expectedId, 1L), 10)
}

val actual = runBlocking { searchHistoryDao.loadByMap(expectedMap.name).first() }
val actual = runBlocking { searchHistoryDao.loadByMap(expectedMap.name) }

assertTrue("Loaded entry list is empty", actual.isNotEmpty())
actual.forEach { assertEquals(expectedId, it.markerId) }
Expand All @@ -78,7 +77,7 @@ class SearchHistoryDaoTest : AppDatabaseDaoTest() {
expected.sortBy { it.timestamp }
while (expected.size > maxEntriesNum) expected.removeFirst()

val actual = runBlocking { searchHistoryDao.loadByMap(INSERTED_MAP.name).first() }
val actual = runBlocking { searchHistoryDao.loadByMap(INSERTED_MAP.name) }

assertEquals(expected.size, actual.size)
for (entry in actual) {
Expand Down Expand Up @@ -151,7 +150,7 @@ class SearchHistoryDaoTest : AppDatabaseDaoTest() {
}
}

val actual = runBlocking { searchHistoryDao.loadByMap(INSERTED_MAP.name).first() }
val actual = runBlocking { searchHistoryDao.loadByMap(INSERTED_MAP.name) }

assertEquals(maxEntriesNum, actual.size)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.DepNav">
<activity
android:name=".MainActivity"
android:name=".ui.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/ru/spbu/depnav/data/db/SearchHistoryDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import kotlinx.coroutines.flow.Flow
import ru.spbu.depnav.data.model.SearchHistoryEntry

/** DAO fot the table containing [marker search history entries][SearchHistoryEntry]. */
Expand Down Expand Up @@ -86,5 +85,5 @@ abstract class SearchHistoryDao {
ORDER BY timestamp ASC
"""
)
abstract fun loadByMap(mapName: String): Flow<List<SearchHistoryEntry>>
abstract suspend fun loadByMap(mapName: String): List<SearchHistoryEntry>
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ class SearchHistoryRepo @Inject constructor(private val dao: SearchHistoryDao) {
dao.insertNotExceeding(entry, maxEntriesNum)

/** Loads the current entries for the specified map sorted by timestamps (older first). */
fun loadByMap(mapName: String) = dao.loadByMap(mapName)
suspend fun loadByMap(mapName: String) = dao.loadByMap(mapName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,25 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package ru.spbu.depnav
package ru.spbu.depnav.ui

import android.graphics.Color
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.LaunchedEffect
import androidx.lifecycle.viewModelScope
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import ru.spbu.depnav.ui.NavDestination
import ru.spbu.depnav.ui.map.MapScreen
import ru.spbu.depnav.ui.map.MapScreenViewModel
import ru.spbu.depnav.ui.search.SearchScreen
import ru.spbu.depnav.ui.screen.MapScreen
import ru.spbu.depnav.ui.theme.DepNavTheme
import ru.spbu.depnav.utils.preferences.PreferencesManager
import javax.inject.Inject

@AndroidEntryPoint
@Suppress("UndocumentedPublicClass") // Class name is self-explanatory
class MainActivity : ComponentActivity() {
private val mapScreenVm: MapScreenViewModel by viewModels()

/** User preferences. */
@Inject
lateinit var prefs: PreferencesManager
Expand All @@ -66,33 +55,7 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge(systemBarStyle, systemBarStyle)
}

DepNavTheme(darkTheme = darkTheme) {
val navController = rememberNavController()

NavHost(navController = navController, startDestination = NavDestination.MAP.name) {
composable(NavDestination.MAP.name) {
MapScreen(vm = mapScreenVm) {
navController.navigate(NavDestination.SEARCH.name)
}
}
composable(NavDestination.SEARCH.name) {
fun navigateToMap() {
navController.popBackStack(
route = NavDestination.MAP.name,
inclusive = false
)
}

SearchScreen(
onResultClick = {
with(mapScreenVm) { viewModelScope.launch { focusOnMarker(it) } }
navigateToMap()
},
onNavigateBack = ::navigateToMap
)
}
}
}
DepNavTheme(darkTheme = darkTheme) { MapScreen() }
}
}
}
22 changes: 0 additions & 22 deletions app/src/main/java/ru/spbu/depnav/ui/NavDestination.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package ru.spbu.depnav.ui.map
package ru.spbu.depnav.ui.component

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.SizeTransform
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
Expand All @@ -43,11 +42,12 @@ import androidx.compose.ui.tooling.preview.Preview
import ru.spbu.depnav.R
import ru.spbu.depnav.ui.theme.DepNavTheme

private const val MIN_FLOOR = 1

/** Two buttons to switch the current map one floor up or down. */
@Composable
fun FloorSwitch(
floor: Int,
minFloor: Int,
maxFloor: Int,
modifier: Modifier = Modifier,
onClick: (new: Int) -> Unit
Expand Down Expand Up @@ -85,7 +85,7 @@ fun FloorSwitch(

IconButton(
onClick = { onClick(floor - 1) },
enabled = floor > minFloor
enabled = floor > MIN_FLOOR
) {
Icon(
Icons.Rounded.KeyboardArrowDown,
Expand All @@ -103,7 +103,6 @@ private fun FloorSwitchPreview() {
DepNavTheme {
FloorSwitch(
floor = 1,
minFloor = 1,
maxFloor = 2,
onClick = {}
)
Expand Down
Loading