mirror of
https://github.com/owenlejeune/TVTime.git
synced 2025-11-18 01:30:54 -05:00
extract some strings
This commit is contained in:
@@ -2,6 +2,7 @@ package com.owenlejeune.tvtime
|
||||
|
||||
import android.app.Application
|
||||
import com.facebook.stetho.Stetho
|
||||
import com.owenlejeune.tvtime.di.modules.appModule
|
||||
import com.owenlejeune.tvtime.di.modules.networkModule
|
||||
import com.owenlejeune.tvtime.di.modules.preferencesModule
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
@@ -22,7 +23,8 @@ class TvTimeApplication: Application() {
|
||||
androidContext(this@TvTimeApplication)
|
||||
modules(
|
||||
networkModule,
|
||||
preferencesModule
|
||||
preferencesModule,
|
||||
appModule
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.owenlejeune.tvtime.di.modules
|
||||
import com.owenlejeune.tvtime.BuildConfig
|
||||
import com.owenlejeune.tvtime.api.*
|
||||
import com.owenlejeune.tvtime.preferences.AppPreferences
|
||||
import com.owenlejeune.tvtime.utils.ResourceUtils
|
||||
import org.koin.dsl.module
|
||||
|
||||
val networkModule = module {
|
||||
@@ -13,4 +14,8 @@ val networkModule = module {
|
||||
|
||||
val preferencesModule = module {
|
||||
single { AppPreferences(get()) }
|
||||
}
|
||||
|
||||
val appModule = module {
|
||||
factory { ResourceUtils(get()) }
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
package com.owenlejeune.tvtime.ui.navigation
|
||||
|
||||
import com.owenlejeune.tvtime.R
|
||||
import com.owenlejeune.tvtime.utils.ResourceUtils
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
sealed class BottomNavItem(val name: String, val icon: Int, val route: String) {
|
||||
sealed class BottomNavItem(stringRes: Int, val icon: Int, val route: String): KoinComponent {
|
||||
|
||||
private val resourceUtils: ResourceUtils by inject()
|
||||
|
||||
val name = resourceUtils.getString(stringRes)
|
||||
|
||||
companion object {
|
||||
val Items = listOf(Movies, TV, Favourites, Settings)
|
||||
@@ -18,9 +25,9 @@ sealed class BottomNavItem(val name: String, val icon: Int, val route: String) {
|
||||
}
|
||||
}
|
||||
|
||||
object Movies: BottomNavItem("Movies", R.drawable.ic_movie, "movies_route")
|
||||
object TV: BottomNavItem("TV", R.drawable.ic_tv, "tv_route")
|
||||
object Favourites: BottomNavItem("Favourites", R.drawable.ic_favorite, "favourites_route")
|
||||
object Settings: BottomNavItem("Settings", R.drawable.ic_settings, "settings_route")
|
||||
object Movies: BottomNavItem(R.string.nav_movies_title, R.drawable.ic_movie, "movies_route")
|
||||
object TV: BottomNavItem(R.string.nav_tv_title, R.drawable.ic_tv, "tv_route")
|
||||
object Favourites: BottomNavItem(R.string.nav_favourites_title, R.drawable.ic_favorite, "favourites_route")
|
||||
object Settings: BottomNavItem(R.string.nav_settings_title, R.drawable.ic_settings, "settings_route")
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
package com.owenlejeune.tvtime.ui.navigation
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.navArgument
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
import com.owenlejeune.tvtime.ui.screens.DetailView
|
||||
import com.owenlejeune.tvtime.ui.screens.DetailViewType
|
||||
import com.owenlejeune.tvtime.ui.screens.MainAppView
|
||||
@@ -21,6 +17,11 @@ import com.owenlejeune.tvtime.ui.screens.tabs.MoviesTab
|
||||
import com.owenlejeune.tvtime.ui.screens.tabs.SettingsTab
|
||||
import com.owenlejeune.tvtime.ui.screens.tabs.TvTab
|
||||
|
||||
object NavConstants {
|
||||
const val ID_KEY = "id_key"
|
||||
const val TYPE_KEY = "type_key"
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MainNavigationRoutes(navController: NavHostController, displayUnderStatusBar: MutableState<Boolean> = mutableStateOf(false)) {
|
||||
NavHost(navController = navController, startDestination = MainNavItem.MainView.route) {
|
||||
@@ -29,18 +30,18 @@ fun MainNavigationRoutes(navController: NavHostController, displayUnderStatusBar
|
||||
MainAppView(appNavController = navController)
|
||||
}
|
||||
composable(
|
||||
MainNavItem.DetailView.route.plus("/{TYPE_KEY}/{ID_KEY}"),
|
||||
MainNavItem.DetailView.route.plus("/{${NavConstants.TYPE_KEY}}/{${NavConstants.ID_KEY}}"),
|
||||
arguments = listOf(
|
||||
navArgument("ID_KEY") { type = NavType.IntType },
|
||||
navArgument("TYPE_KEY") { type = NavType.EnumType(DetailViewType::class.java) }
|
||||
navArgument(NavConstants.ID_KEY) { type = NavType.IntType },
|
||||
navArgument(NavConstants.TYPE_KEY) { type = NavType.EnumType(DetailViewType::class.java) }
|
||||
)
|
||||
) { navBackStackEntry ->
|
||||
displayUnderStatusBar.value = true
|
||||
val args = navBackStackEntry.arguments
|
||||
DetailView(
|
||||
appNavController = navController,
|
||||
itemId = args?.getInt("ID_KEY"),
|
||||
type = args?.getSerializable("TYPE_KEY") as DetailViewType
|
||||
itemId = args?.getInt(NavConstants.ID_KEY),
|
||||
type = args?.getSerializable(NavConstants.TYPE_KEY) as DetailViewType
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.owenlejeune.tvtime.utils
|
||||
|
||||
import android.content.Context
|
||||
|
||||
class ResourceUtils(private val context: Context) {
|
||||
|
||||
fun getString(stringRes: Int): String {
|
||||
return context.getString(stringRes)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,8 @@ object TmdbUtils {
|
||||
private const val BACKDROP_BASE = "https://www.themoviedb.org/t/p/original"
|
||||
private const val PERSON_BASE = "https://www.themoviedb.org/t/p/w600_and_h900_bestv2"
|
||||
|
||||
private const val DEF_REGION = "US"
|
||||
|
||||
fun getFullPosterPath(posterPath: String?): String? {
|
||||
return posterPath?.let { "https://image.tmdb.org/t/p/original${posterPath}" }
|
||||
}
|
||||
@@ -93,11 +95,10 @@ object TmdbUtils {
|
||||
return ""
|
||||
}
|
||||
|
||||
val defRegion = "US"
|
||||
val currentRegion = Locale.current.language
|
||||
val certifications = HashMap<String, String>()
|
||||
releases.releaseDates.forEach { releaseDateResult ->
|
||||
if (releaseDateResult.region == currentRegion || releaseDateResult.region == defRegion) {
|
||||
if (releaseDateResult.region == currentRegion || releaseDateResult.region == DEF_REGION) {
|
||||
val cert = releaseDateResult.releaseDates.firstOrNull { it.certification.isNotEmpty() }
|
||||
if (cert != null) {
|
||||
certifications[releaseDateResult.region] = cert.certification
|
||||
@@ -105,7 +106,7 @@ object TmdbUtils {
|
||||
}
|
||||
}
|
||||
if (certifications.isNotEmpty()) {
|
||||
return certifications[currentRegion] ?: certifications[defRegion] ?: ""
|
||||
return certifications[currentRegion] ?: certifications[DEF_REGION] ?: ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -115,16 +116,15 @@ object TmdbUtils {
|
||||
return ""
|
||||
}
|
||||
|
||||
val defRegion = "US"
|
||||
val currentRegion = Locale.current.language
|
||||
val certifications = HashMap<String, String>()
|
||||
contentRatings.results.forEach { contentRating ->
|
||||
if (contentRating.language == currentRegion || contentRating.language == defRegion) {
|
||||
if (contentRating.language == currentRegion || contentRating.language == DEF_REGION) {
|
||||
certifications[contentRating.language] = contentRating.rating
|
||||
}
|
||||
}
|
||||
if (certifications.isNotEmpty()) {
|
||||
return certifications[currentRegion] ?: certifications[defRegion] ?: ""
|
||||
return certifications[currentRegion] ?: certifications[DEF_REGION] ?: ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
<resources>
|
||||
<string name="app_name">TVTime</string>
|
||||
<string name="nav_movies_title">Movies</string>
|
||||
<string name="nav_tv_title">TV</string>
|
||||
<string name="nav_favourites_title">Favourites</string>
|
||||
<string name="nav_settings_title">Settings</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user