Skip to content

Commit

Permalink
#17 in progress - translations and stringResources
Browse files Browse the repository at this point in the history
  • Loading branch information
mjureczko committed May 29, 2024
1 parent 4bdedd7 commit a94abdb
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 85 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ GPLv3 (https://www.gnu.org/licenses/gpl-3.0.html)


TODO:
- add all translations
- w introduction dodać widok-instrukcję z kodem QR
- remove dead code
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,15 @@ fun CommemorativeScreen(
topBar = { TopBar(navController, stringResource(R.string.app_name), onClickOnGuide, goToFacebook) },
content = {
CommemorativeScreenBody(
navController,
shareViewModelStoreOwner(navBackStackEntry, navController),
scaffoldState
shareViewModelStoreOwner(navBackStackEntry, navController)
)
}
)
}

@Composable
fun CommemorativeScreenBody(
navController: NavController,
viewModelStoreOwner: NavBackStackEntry,
scaffoldState: ScaffoldState
viewModelStoreOwner: NavBackStackEntry
) {
val sharedViewModel: CommemorativeSharedViewModel = getViewModel(viewModelStoreOwner)
val sharedState = sharedViewModel.state.value as CommemorativeSharedState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.core.content.FileProvider
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
import pl.marianjureczko.poszukiwacz.R
import pl.marianjureczko.poszukiwacz.activity.facebook.ElementDescription
Expand All @@ -61,19 +60,18 @@ import java.io.FileOutputStream
@Composable
fun FacebookScreen(
navController: NavController,
navBackStackEntry: NavBackStackEntry,
onClickOnGuide: () -> Unit
) {
val scaffoldState: ScaffoldState = rememberScaffoldState()
Scaffold(
scaffoldState = scaffoldState,
topBar = { TopBar(navController, stringResource(R.string.title_activity_facebook), onClickOnGuide, {}) },
content = { FacebookScreenBody(navController) }
content = { FacebookScreenBody() }
)
}

@Composable
fun FacebookScreenBody(navController: NavController) {
fun FacebookScreenBody() {
val viewModel: FacebookViewModel = hiltViewModel()
val state: FacebookState = viewModel.state.value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ private fun ComposeRoot(settings: Settings, resources: Resources, onClickGuide:
SearchingScreen(
navController = navController,
isClassicMode = settings.isClassicMode(),
resources = resources,
onClickOnGuide = onClickGuide,
goToTipPhoto = { navController.navigate("tipPhoto/$it") },
goToResult = { resultType, treasureId -> navController.navigate("$RESULTS_PATH/$resultType/$treasureId") },
Expand Down Expand Up @@ -151,7 +150,6 @@ private fun ComposeRoot(settings: Settings, resources: Resources, onClickGuide:
MapScreen(
navController = navController,
onClickOnGuide = onClickGuide,
resources = resources,
onClickOnFacebook = goToFacebook
)
}
Expand All @@ -162,7 +160,6 @@ private fun ComposeRoot(settings: Settings, resources: Resources, onClickGuide:
SelectorScreen(
navController,
navBackStackEntry,
resources,
onClickGuide,
goToResult = { treasureId -> navController.navigate("$RESULTS_PATH/${ResultType.TREASURE}/$treasureId") },
goToCommemorative = { treasureId -> navController.navigate("$COMMEMORATIVE_PATH/$treasureId") },
Expand All @@ -175,6 +172,6 @@ private fun ComposeRoot(settings: Settings, resources: Resources, onClickGuide:
) { navBackStackEntry -> CommemorativeScreen(navController, navBackStackEntry, onClickGuide, goToFacebook) }
composable(
route = FACEBOOK_ROUTE,
) { navBackStackEntry -> FacebookScreen(navController, navBackStackEntry, onClickGuide) }
) { navBackStackEntry -> FacebookScreen(navController, onClickGuide) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MapActivity : ActivityWithAdsAndBackButton() {

model.setup(intent.getSerializableExtra(MAP) as MapInputData)
mapView = binding.mapView
MapHelper.renderTreasures(model.route, mapView, this.resources)
MapHelper.renderTreasures(model.route, mapView)
hideRoads()

setContentView(binding.root)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pl.marianjureczko.poszukiwacz.activity.map.n

import android.annotation.SuppressLint
import android.content.res.Resources
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
Expand All @@ -23,31 +22,29 @@ import pl.marianjureczko.poszukiwacz.ui.components.TopBar
@Composable
fun MapScreen(
navController: NavController,
//TODO t: use StringResource instead
resources: Resources,
onClickOnGuide: () -> Unit,
onClickOnFacebook: () -> Unit
) {
Scaffold(
topBar = { TopBar(navController, stringResource(R.string.map_activity_title), onClickOnGuide, onClickOnFacebook) },
content = {
MapScreenBody(resources)
MapScreenBody()
}
)
}

@Composable
fun MapScreenBody(resources: Resources) {
fun MapScreenBody() {
val viewModel: MapViewModel = hiltViewModel()
val state = viewModel.state.value
MapboxMap(state.route, resources)
MapboxMap(state.route)
}

@Composable
fun MapboxMap(route: Route, resources: Resources) {
fun MapboxMap(route: Route) {
val mapView = MapView(App.getAppContext())

MapHelper.renderTreasures(route, mapView, resources)
MapHelper.renderTreasures(route, mapView)
mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) { style -> hideRoads(style) }

AndroidView({ mapView }, Modifier.fillMaxSize())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -68,7 +67,6 @@ fun ResultScreenBody(viewModelStoreOwner: NavBackStackEntry) {
val localState: ResultState = localViewModel.state.value
val sharedViewModel: ResultSharedViewModel = getViewModel(viewModelStoreOwner)
sharedViewModel.resultPresented()
val snackbarCoroutineScope = rememberCoroutineScope()
Column(Modifier.background(SecondaryBackground)) {
Spacer(
modifier = Modifier
Expand Down Expand Up @@ -141,7 +139,7 @@ private fun Movie(
val videoView: VideoView = remember { VideoView(context) }
Video(videoView, subtitlesPath, updateSubtitlesLine, movieController, moviePath, localesWithSubtitles)
PlayButton(isPlayVisible, videoView, movieController)
//TODO t: merge conditions, and maybe move to state
//TODO t: merge conditions, and maybe move to the state
if (localesWithSubtitles) {
subtitlesLine?.let {
Text(
Expand Down Expand Up @@ -239,11 +237,3 @@ private fun getViewModel(viewModelStoreOwner: NavBackStackEntry): ResultSharedVi
val viewModelDoNotInline: SharedViewModel = hiltViewModel(viewModelStoreOwner)
return viewModelDoNotInline
}

//@Preview(showBackground = true, apiLevel = 31)
//@Composable
//fun ResultDefaultPreview() {
// AppTheme {
// ResultScreenBody(App.getResources())
// }
//}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pl.marianjureczko.poszukiwacz.activity.searching.n

import android.annotation.SuppressLint
import android.content.res.Resources
import android.media.MediaPlayer
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.compose.foundation.Image
Expand Down Expand Up @@ -62,7 +61,6 @@ import java.net.URLEncoder
fun SearchingScreen(
navController: NavController,
isClassicMode: Boolean,
resources: Resources,
onClickOnGuide: () -> Unit,
goToTipPhoto: (String) -> Unit,
goToResult: (ResultType, Int) -> Unit,
Expand All @@ -81,7 +79,6 @@ fun SearchingScreen(
navController,
isClassicMode,
viewModel,
resources,
scaffoldState,
goToTipPhoto,
goToResult,
Expand All @@ -98,7 +95,6 @@ private fun SearchingScreenBody(
navController: NavController,
isClassicMode: Boolean,
viewModel: SearchingViewModel,
resources: Resources,
scaffoldState: ScaffoldState,
goToTipPhoto: (String) -> Unit,
goToResult: (ResultType, Int) -> Unit,
Expand All @@ -119,9 +115,10 @@ private fun SearchingScreenBody(
goToResult(resultType, treasureId)
}
)
val prompt = stringResource(R.string.qr_scanner_msg)
val scanQrCallback: () -> Unit = {
val scanOptions = ScanOptions()
scanOptions.setPrompt(resources.getString(R.string.qr_scanner_msg))
scanOptions.setPrompt(prompt)
scanQrLauncher.launch(scanOptions)
}
Column(Modifier.background(SecondaryBackground)) {
Expand All @@ -133,12 +130,10 @@ private fun SearchingScreenBody(
state.currentTreasure,
state.route,
scaffoldState,
resources,
state.mediaPlayer,
goToTipPhoto,
goToMap,
{goToTreasureSelector(NOTHING_FOUND_TREASURE_ID)}
)
goToMap
) { goToTreasureSelector(NOTHING_FOUND_TREASURE_ID) }
Spacer(
modifier = Modifier
.weight(0.01f)
Expand Down Expand Up @@ -266,7 +261,6 @@ fun Buttons(
currentTreasure: TreasureDescription,
route: Route,
scaffoldState: ScaffoldState,
resources: Resources,
mediaPlayer: MediaPlayer,
goToTipPhoto: (String) -> Unit,
goToMap: (String) -> Unit,
Expand All @@ -289,8 +283,8 @@ fun Buttons(
ScanTreasureButton(scanQrCallback)
}
Column(modifier = Modifier.width(0.2.dw)) {
PhotoTipButton(currentTreasure, scaffoldState, snackbarCoroutineScope, resources, goToTipPhoto)
SoundTipButton(currentTreasure, scaffoldState, snackbarCoroutineScope, resources, mediaPlayer)
PhotoTipButton(currentTreasure, scaffoldState, snackbarCoroutineScope, goToTipPhoto)
SoundTipButton(currentTreasure, scaffoldState, snackbarCoroutineScope, mediaPlayer)
}
}
}
Expand Down Expand Up @@ -336,9 +330,9 @@ private fun PhotoTipButton(
currentTreasure: TreasureDescription,
scaffoldState: ScaffoldState,
snackbarCoroutineScope: CoroutineScope,
resources: Resources,
goToTipPhoto: (String) -> Unit
) {
val noPhotoToShowMsg = stringResource(R.string.no_photo_to_show)
Image(
painterResource(R.drawable.show_photo),
modifier = Modifier
Expand All @@ -350,7 +344,7 @@ private fun PhotoTipButton(
} else {
errorTone()
snackbarCoroutineScope.launch {
scaffoldState.snackbarHostState.showSnackbar(resources.getString(R.string.no_photo_to_show))
scaffoldState.snackbarHostState.showSnackbar(noPhotoToShowMsg)
}
}
},
Expand All @@ -364,9 +358,9 @@ private fun SoundTipButton(
currentTreasure: TreasureDescription,
scaffoldState: ScaffoldState,
snackbarCoroutineScope: CoroutineScope,
resources: Resources,
mediaPlayer: MediaPlayer
) {
val noTipToPlayMsg = stringResource(R.string.no_tip_to_play)
Image(
painterResource(R.drawable.megaphone),
modifier = Modifier
Expand All @@ -377,7 +371,7 @@ private fun SoundTipButton(
} else {
errorTone()
snackbarCoroutineScope.launch {
scaffoldState.snackbarHostState.showSnackbar(resources.getString(R.string.no_tip_to_play))
scaffoldState.snackbarHostState.showSnackbar(noTipToPlayMsg)
}
}
},
Expand All @@ -391,11 +385,3 @@ private fun getViewModel(): SearchingViewModel {
val viewModelDoNotInline: SharedViewModel = hiltViewModel()
return viewModelDoNotInline
}

//@Preview(showBackground = true, apiLevel = 31)
//@Composable
//fun SearchingDefaultPreview() {
// AppTheme {
// SearchingScreen(null, false, App.getResources(), {}, {}, { _, _ -> }, {}, { s: String, i: Int? -> })
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class TreasuresEditorActivity : PermissionActivity(), RouteNameDialog.Callback,
handler.post(presenter)

mapView = binding.mapView
MapHelper.renderTreasures(model.getRoute(), mapView, this.resources)
MapHelper.renderTreasures(model.getRoute(), mapView)

setContentView(binding.root)
setUpAds(binding.adView)
Expand Down Expand Up @@ -130,7 +130,7 @@ class TreasuresEditorActivity : PermissionActivity(), RouteNameDialog.Callback,
)
model.addTreasure(treasure, storageHelper)
treasureAdapter.notifyDataSetChanged()
MapHelper.addTreasureToMap(treasure, mapView, this.resources)
MapHelper.addTreasureToMap(treasure, mapView)
MapHelper.positionMapOnTreasures(model.getRoute(), mapView, 0.0)
}

Expand Down Expand Up @@ -199,7 +199,7 @@ class TreasuresEditorActivity : PermissionActivity(), RouteNameDialog.Callback,
override fun remove(treasureToRemove: TreasureDescription) {
model.removeTreasure(treasureToRemove, storageHelper)
treasureAdapter.notifyDataSetChanged()
MapHelper.renderTreasures(model.getRoute(), mapView, this.resources)
MapHelper.renderTreasures(model.getRoute(), mapView)
MapHelper.positionMapOnTreasures(model.getRoute(), mapView, 0.0)
}
}
Loading

0 comments on commit a94abdb

Please sign in to comment.