Move hardcoded strings to resources

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-10-29 16:53:03 +05:30
parent 1be10010c8
commit e37d71fba6
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
4 changed files with 10 additions and 6 deletions

View file

@ -11,6 +11,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.Providers import androidx.compose.runtime.Providers
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.setContent import androidx.compose.ui.platform.setContent
import androidx.compose.ui.res.stringResource
import androidx.navigation.compose.KEY_ROUTE import androidx.navigation.compose.KEY_ROUTE
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
@ -67,7 +68,7 @@ fun LobstersApp(
} }
) )
}, },
label = { Text(screen.label) }, label = { Text(stringResource(id = screen.labelRes)) },
selected = currentRoute == screen.route, selected = currentRoute == screen.route,
onClick = { onClick = {
// This is the equivalent to popUpTo the start destination // This is the equivalent to popUpTo the start destination

View file

@ -1,12 +1,15 @@
package dev.msfjarvis.lobsters.ui package dev.msfjarvis.lobsters.ui
import androidx.annotation.StringRes
import dev.msfjarvis.lobsters.R
/** /**
* Destinations for navigation within the app. * Destinations for navigation within the app.
*/ */
sealed class Destination( sealed class Destination(
val route: String, val route: String,
val label: String, @StringRes val labelRes: Int,
) { ) {
object Hottest : Destination("hottest", "Hottest") object Hottest : Destination("hottest", R.string.hottest_posts)
object Saved : Destination("saved", "Saved") object Saved : Destination("saved", R.string.saved_posts)
} }

View file

@ -37,5 +37,3 @@ fun SavedPosts(
} }
} }
} }

View file

@ -2,4 +2,6 @@
<string name="app_name">lobste.rs</string> <string name="app_name">lobste.rs</string>
<string name="loading">Loading posts…</string> <string name="loading">Loading posts…</string>
<string name="no_saved_posts">You don\'t have any saved posts</string> <string name="no_saved_posts">You don\'t have any saved posts</string>
<string name="hottest_posts">Hottest</string>
<string name="saved_posts">Saved</string>
</resources> </resources>