Skip to content

Commit

Permalink
#17 in progress
Browse files Browse the repository at this point in the history
- showing collected treasure in classic mode
  • Loading branch information
mjureczko committed Jan 12, 2025
1 parent cc7184e commit 747c1f9
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun Scores(modifier: Modifier = Modifier, score: TreasuresProgress) {
)
Text(
color = Color.Gray,
text = "0",
text = score.golds.toString(),
fontSize = pl.marianjureczko.poszukiwacz.ui.theme.Typography.h5.fontSize
)
Image(
Expand All @@ -45,7 +45,7 @@ fun Scores(modifier: Modifier = Modifier, score: TreasuresProgress) {
)
Text(
color = Color.Gray,
text = "0",
text = score.rubies.toString(),
fontSize = pl.marianjureczko.poszukiwacz.ui.theme.Typography.h5.fontSize
)
Image(
Expand All @@ -56,7 +56,7 @@ fun Scores(modifier: Modifier = Modifier, score: TreasuresProgress) {
)
Text(
color = Color.Gray,
text = "0",
text = score.diamonds.toString(),
fontSize = pl.marianjureczko.poszukiwacz.ui.theme.Typography.h5.fontSize
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fun ComposeRoot(onClickGuide: GoToGuide) {
navController = navController,
onClickOnGuide = onClickGuide,
goToTipPhoto = { navController.navigate("tipPhoto/$it") },
goToResult = { resultType, treasureId, amount -> navController.navigate("$RESULTS_PATH/$resultType/$treasureId/$amount") },
goToResult = { routeName, resultType, treasureId, amount -> navController.navigate("$RESULTS_PATH/$routeName/$resultType/$treasureId/$amount") },
goToMap = { navController.navigate("map/$it") },
goToTreasureSelector = { /*navController.navigate("$SELECTOR_PATH/$it")*/ },
goToFacebook = goToFacebook,
Expand All @@ -75,6 +75,9 @@ fun ComposeRoot(onClickGuide: GoToGuide) {
composable(
route = RESULTS_ROUTE,
arguments = listOf(
navArgument(pl.marianjureczko.poszukiwacz.screen.result.PARAMETER_ROUTE_NAME) {
type = NavType.StringType
},
navArgument(PARAMETER_RESULT_TYPE) { type = NavType.EnumType(ResultType::class.java) },
navArgument(PARAMETER_TREASURE_ID) { type = NavType.IntType },
navArgument(PARAMETER_TREASURE_AMOUNT) { type = NavType.IntType },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import pl.marianjureczko.poszukiwacz.activity.map.n.PARAMETER_ROUTE_NAME_2
import pl.marianjureczko.poszukiwacz.activity.photo.n.PARAMETER_TIP_PHOTO
import pl.marianjureczko.poszukiwacz.activity.photo.n.TipPhotoScreen
import pl.marianjureczko.poszukiwacz.screen.result.PARAMETER_RESULT_TYPE
import pl.marianjureczko.poszukiwacz.screen.result.PARAMETER_TREASURE_AMOUNT
import pl.marianjureczko.poszukiwacz.screen.result.PARAMETER_TREASURE_ID
import pl.marianjureczko.poszukiwacz.screen.result.PARAMETER_TREASURE_QUANTITY
import pl.marianjureczko.poszukiwacz.screen.result.ResultScreen
import pl.marianjureczko.poszukiwacz.screen.result.ResultType
import pl.marianjureczko.poszukiwacz.activity.searching.n.PARAMETER_ROUTE_NAME
Expand Down Expand Up @@ -57,7 +57,7 @@ fun ComposeRoot(onClickGuide: GoToGuide) {
navController = navController,
onClickOnGuide = onClickGuide,
goToTipPhoto = { navController.navigate("tipPhoto/$it") },
goToResult = { resultType, treasureId, amount -> navController.navigate("$RESULTS_PATH/$resultType/$treasureId/$amount") },
goToResult = { routeName, resultType, treasureId, amount -> navController.navigate("$RESULTS_PATH/$routeName/$resultType/$treasureId/$amount") },
goToMap = { navController.navigate("map/$it") },
goToTreasureSelector = { navController.navigate("$SELECTOR_PATH/$it") },
goToFacebook = goToFacebook,
Expand Down Expand Up @@ -100,8 +100,7 @@ fun ComposeRoot(onClickGuide: GoToGuide) {
navController,
navBackStackEntry,
onClickGuide,
//TODO t: doesn't support classic
goToResult = { treasureId -> navController.navigate("$RESULTS_PATH/${ResultType.TREASURE}/$treasureId") },
goToResult = { treasureId -> navController.navigate("$RESULTS_PATH/${ResultType.KNOWLEDGE}/$treasureId") },
goToCommemorative = goToCommemorative,
onClickOnFacebook = goToFacebook
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ val TREASURE_EDITOR_ROUTE = "$TREASURE_EDITOR_PATH/{$PARAMETER_ROUTE_NAME}"
val SEARCHING_PATH = "searching"
val SEARCHING_ROUTE = "$SEARCHING_PATH/{$PARAMETER_ROUTE_NAME}"
val RESULTS_PATH = "result"
val RESULTS_ROUTE = "$RESULTS_PATH/{$PARAMETER_RESULT_TYPE}/{$PARAMETER_TREASURE_ID}/{$PARAMETER_TREASURE_AMOUNT}"
val RESULTS_ROUTE = "$RESULTS_PATH/{${pl.marianjureczko.poszukiwacz.screen.result.PARAMETER_ROUTE_NAME}}/{$PARAMETER_RESULT_TYPE}/{$PARAMETER_TREASURE_ID}/{$PARAMETER_TREASURE_AMOUNT}"
val SELECTOR_PATH = "selector"
val SELECTOR_ROUTE = "$SELECTOR_PATH/{$PARAMETER_JUST_FOUND_TREASURE}"
val COMMEMORATIVE_PATH = "commemorative"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class JustFoundTreasureDescriptionFinder(
private val TAG = javaClass.simpleName

fun findTreasureDescription(
qrCode: String,
justFoundTreasure: Treasure,
selectedTreasureDescription: TreasureDescription? = null,
userLocation: Coordinates? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ private fun SearchingScreenBody(
}
val scanQrLauncher = rememberLauncherForActivityResult(
contract = ScanContract(),
onResult = viewModel.scannedTreasureCallback { resultType, treasureId, quantity ->
goToResult(resultType, treasureId, quantity)
onResult = viewModel.scannedTreasureCallback { routeName, resultType, treasureId, quantity ->
goToResult(routeName, resultType, treasureId, quantity)
}
)
val prompt = stringResource(R.string.qr_scanner_msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SharedViewModel @Inject constructor(
try {
scannedTreasure = TreasureParser().parse(newCode)
val tdFinder = JustFoundTreasureDescriptionFinder(state.value.route.treasures)
val foundTd: TreasureDescription? = tdFinder.findTreasureDescription(newCode, scannedTreasure)
val foundTd: TreasureDescription? = tdFinder.findTreasureDescription(scannedTreasure)
var treasuresProgress: TreasuresProgress = state.value.treasuresProgress
if (treasuresProgress.contains(scannedTreasure)) {
result = ResultType.ALREADY_TAKEN
Expand All @@ -119,7 +119,7 @@ class SharedViewModel @Inject constructor(
}
}
result?.let {
goToResults(it, treasureId, scannedTreasure?.quantity)
goToResults(state.value.route.name, it, treasureId, scannedTreasure?.quantity)
}
}
}
Expand Down Expand Up @@ -219,7 +219,6 @@ class SharedViewModel @Inject constructor(
}
}

//TODO t: how to handle first search, when no treasure is selected
private fun createState(): SharedState {
Log.i(TAG, "Create state")
val route = loadRoute()
Expand All @@ -228,10 +227,6 @@ class SharedViewModel @Inject constructor(
val mediaPlayer = MediaPlayer()
mediaPlayer.isLooping = false
mediaPlayer.setOnErrorListener { mp, what, extra -> handleMediaPlayerError(what, extra) }
if (treasuresProgress.selectedTreasure == null) {
treasuresProgress.selectedTreasure = route.treasures[0]
storageHelper.save(treasuresProgress)
}
return SharedState(
mediaPlayer,
route,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fun ResultScreenBody(viewModelStoreOwner: NavBackStackEntry) {
.weight(0.01f)
.background(Color.Transparent)
)
if (localState.resultType == ResultType.TREASURE && localState.moviePath != null) {
if (localState.resultType == ResultType.KNOWLEDGE && localState.moviePath != null) {
VideoPlayerWithButon(
localState.isPlayVisible,
localViewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ data class ResultState(
enum class ResultType {
NOT_A_TREASURE,
ALREADY_TAKEN,
//TODO t: rename to KNOWLEDGE
TREASURE,
KNOWLEDGE,
GOLD,
RUBY,
DIAMOND;
Expand All @@ -28,7 +27,7 @@ enum class ResultType {
TreasureType.GOLD -> GOLD
TreasureType.RUBY -> RUBY
TreasureType.DIAMOND -> DIAMOND
TreasureType.KNOWLEDGE -> TREASURE
TreasureType.KNOWLEDGE -> KNOWLEDGE
}
}

Expand All @@ -37,7 +36,7 @@ enum class ResultType {
GOLD -> TreasureType.GOLD
RUBY -> TreasureType.RUBY
DIAMOND -> TreasureType.DIAMOND
TREASURE -> TreasureType.KNOWLEDGE
KNOWLEDGE -> TreasureType.KNOWLEDGE
else -> null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import pl.marianjureczko.poszukiwacz.screen.main.CustomInitializerForRoute
import pl.marianjureczko.poszukiwacz.shared.port.StorageHelper
import java.util.Locale
import javax.inject.Inject

const val PARAMETER_ROUTE_NAME = "route_name"
const val PARAMETER_RESULT_TYPE = "result_type"
const val PARAMETER_TREASURE_ID = "treasure_id"
const val PARAMETER_TREASURE_AMOUNT = "treasure_amount"
Expand Down Expand Up @@ -52,13 +52,14 @@ class ResultViewModel @Inject constructor(
private fun createState(): ResultState {
var moviePath: String? = null
var subtitlesPath: String? = null
//TODO: conditional for custom version
val treasureDescId = stateHandle.get<Int>(PARAMETER_TREASURE_ID) ?: NOTHING_FOUND_TREASURE_ID
if (NOTHING_FOUND_TREASURE_ID != treasureDescId) {
val treasureDescription = storageHelper.loadRoute(CustomInitializerForRoute.routeName).treasures
.find { it.id == treasureDescId }
moviePath = treasureDescription?.movieFileName
subtitlesPath = treasureDescription?.subtitlesFileName
if (treasureDescriptionHasBeenIdentified(treasureDescId)) {
stateHandle.get<String>(PARAMETER_ROUTE_NAME)?.let { routeName ->
val treasureDescription = storageHelper.loadRoute(routeName).treasures
.find { it.id == treasureDescId }
moviePath = treasureDescription?.movieFileName
subtitlesPath = treasureDescription?.subtitlesFileName
}
}
val localesWithSubtitles = !"pl".equals(Locale.getDefault().language, true)
val resultType = stateHandle.get<ResultType>(PARAMETER_RESULT_TYPE) ?: ResultType.NOT_A_TREASURE
Expand All @@ -67,4 +68,10 @@ class ResultViewModel @Inject constructor(
return ResultState(resultType, treasureType, amount, moviePath, null, subtitlesPath, localesWithSubtitles)
}

/**
* It's possible to find a treasure whose TreasureDescription cannot be identified (for knowledge treasures it's
* always possible to identify the TreasureDescription), check JustFoundTreasureDescriptionFinder for details.
*/
private fun treasureDescriptionHasBeenIdentified(treasureDescId: Int) = NOTHING_FOUND_TREASURE_ID != treasureDescId

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import pl.marianjureczko.poszukiwacz.model.TreasureDescription
import pl.marianjureczko.poszukiwacz.screen.result.ResultType

typealias GoToGuide = () -> Unit
//TODO t: are nullable types supported in navigation?
typealias GoToResults = (ResultType, Int?, Int?) -> Unit
typealias GoToResults = (String, ResultType, Int?, Int?) -> Unit
typealias GoToFacebook = () -> Unit
typealias GoToSearching = (String) -> Unit
typealias GoToQrScanner = () -> Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.mockito.junit.jupiter.MockitoExtension
import pl.marianjureczko.poszukiwacz.activity.searching.LocationCalculator
import pl.marianjureczko.poszukiwacz.model.Treasure
import pl.marianjureczko.poszukiwacz.model.TreasureDescription
import pl.marianjureczko.poszukiwacz.model.TreasureDescriptionArranger
import pl.marianjureczko.poszukiwacz.model.TreasureType
import pl.marianjureczko.poszukiwacz.shared.Coordinates

Expand All @@ -28,10 +27,10 @@ class CustomJustFoundTreasureDescriptionFinderTest {
//given
val treasureDescription = some<TreasureDescription>()
val finder = JustFoundTreasureDescriptionFinder(listOf(treasureDescription))
val treasure = Treasure(someString(), somePositiveInt(10), TreasureType.KNOWLEDGE)
val treasure = Treasure(treasureDescription.qrCode!!, somePositiveInt(10), TreasureType.KNOWLEDGE)

//when
val actual = finder.findTreasureDescription(treasureDescription.qrCode!!, treasure)
val actual = finder.findTreasureDescription(treasure)

//then
assertThat(actual).isEqualTo(treasureDescription)
Expand All @@ -45,7 +44,7 @@ class CustomJustFoundTreasureDescriptionFinderTest {
val treasure = Treasure(someString(), somePositiveInt(10), TreasureType.KNOWLEDGE)

//when
val actual = finder.findTreasureDescription(TreasureDescriptionArranger.validQrCode("k"), treasure)
val actual = finder.findTreasureDescription(treasure)

//then
assertThat(actual).isNull()
Expand Down Expand Up @@ -131,7 +130,7 @@ class ClassicJustFoundTreasureDescriptionFinderTest {
//justFoundTreasure, description, userCoordinates, locationCalculator)

//when
val actual = finder.findTreasureDescription(someString(), justFoundTreasure, description, userCoordinates)
val actual = finder.findTreasureDescription(justFoundTreasure, description, userCoordinates)

//then
assertThat(actual).isEqualTo(expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class SharedViewModelTest {

//when
var wasCalled = false
val callback = viewModel.scannedTreasureCallback { _: ResultType, _: Int?, _: Int? ->
val callback = viewModel.scannedTreasureCallback {_ : String, _: ResultType, _: Int?, _: Int? ->
wasCalled = true
}
callback(qrResult)
Expand All @@ -115,7 +115,7 @@ class SharedViewModelTest {

//when & then
var wasCalled = false
val callback = viewModel.scannedTreasureCallback { actual, _, _ ->
val callback = viewModel.scannedTreasureCallback { _, actual, _, _ ->
wasCalled = true
assertThat(actual).isEqualTo(ResultType.NOT_A_TREASURE)
}
Expand All @@ -138,9 +138,9 @@ class SharedViewModelTest {

//when
var wasCalled = false
val callback = viewModel.scannedTreasureCallback { actual, _, _ ->
val callback = viewModel.scannedTreasureCallback { _, actual, _, _ ->
wasCalled = true
assertThat(actual).isEqualTo(ResultType.TREASURE)
assertThat(actual).isEqualTo(ResultType.KNOWLEDGE)
}
callback(qrResult)

Expand All @@ -162,11 +162,11 @@ class SharedViewModelTest {

//when & then
var callbackUsed = 0
val callback1 = viewModel.scannedTreasureCallback { actual, _, _ ->
val callback1 = viewModel.scannedTreasureCallback { _, actual, _, _ ->
callbackUsed++
}
callback1(qrResult)
val callback2 = viewModel.scannedTreasureCallback { actual, _, _ ->
val callback2 = viewModel.scannedTreasureCallback { _, actual, _, _ ->
callbackUsed++
assertThat(actual).isEqualTo(ResultType.ALREADY_TAKEN)
}
Expand Down
Loading

0 comments on commit 747c1f9

Please sign in to comment.