Skip to content

Commit

Permalink
Merge pull request #302 from SuhasDissa/navigation
Browse files Browse the repository at this point in the history
Use Destination class to store navigation routes
  • Loading branch information
Bnyro authored Jul 27, 2023
2 parents 67eab52 + 2e92d37 commit 8085e90
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
20 changes: 20 additions & 0 deletions app/src/debug/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2023 Bnyro
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<resources>
<string name="app_name" translatable="false">Translate You Debug</string>
</resources>
25 changes: 25 additions & 0 deletions app/src/main/java/com/bnyro/translate/ui/nav/Destination.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2023 Bnyro
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.bnyro.translate.ui.nav

sealed class Destination(val route: String) {
object Translate : Destination("translate")
object History : Destination("history")
object Settings : Destination("settings")
object About : Destination("about")
}
10 changes: 5 additions & 5 deletions app/src/main/java/com/bnyro/translate/ui/nav/NavigationHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ fun NavigationHost(
navController: NavHostController,
translationModel: TranslationModel
) {
NavHost(navController = navController, "translate") {
composable("translate") {
NavHost(navController = navController, Destination.Translate.route) {
composable(Destination.Translate.route) {
TranslationPage(navController, translationModel)
}
composable("history") {
composable(Destination.History.route) {
HistoryScreen(navController, translationModel)
}
composable("settings") {
composable(Destination.Settings.route) {
SettingsScreen(navController)
}
composable("about") {
composable(Destination.About.route) {
AboutPage(navController)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import com.bnyro.translate.R
import com.bnyro.translate.obj.MenuItemData
import com.bnyro.translate.ui.components.LanguageSelector
import com.bnyro.translate.ui.models.TranslationModel
import com.bnyro.translate.ui.nav.Destination
import com.bnyro.translate.ui.views.TopBar
import com.bnyro.translate.ui.views.TranslationComponent

Expand Down Expand Up @@ -77,23 +78,23 @@ fun TranslationPage(
),
icon = Icons.Default.Menu
) {
navHostController.navigate("settings")
navHostController.navigate(Destination.Settings.route)
},
MenuItemData(
text = stringResource(
id = R.string.history
),
icon = Icons.Default.History
) {
navHostController.navigate("history")
navHostController.navigate(Destination.History.route)
},
MenuItemData(
text = stringResource(
id = R.string.about
),
icon = Icons.Default.Info
) {
navHostController.navigate("about")
navHostController.navigate(Destination.About.route)
}
)
)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/bnyro/translate/ui/views/HistoryRow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import androidx.navigation.NavController
import com.bnyro.translate.R
import com.bnyro.translate.db.obj.HistoryItem
import com.bnyro.translate.ui.models.TranslationModel
import com.bnyro.translate.ui.nav.Destination
import com.bnyro.translate.util.Preferences

@OptIn(ExperimentalMaterial3Api::class)
Expand All @@ -63,7 +64,7 @@ fun HistoryRow(
showDialog = false
translationModel.insertedText = historyItem.insertedText
translationModel.translateNow()
navController.navigate("translate")
navController.navigate(Destination.Translate.route)
}

val compactHistory = Preferences.get(
Expand Down

0 comments on commit 8085e90

Please sign in to comment.