-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ffec3c
commit d33fcac
Showing
9 changed files
with
166 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/src/main/kotlin/jp/co/yumemi/android/code_check/presentation/Navigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package jp.co.yumemi.android.code_check.presentation | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.rememberNavController | ||
import jp.co.yumemi.android.code_check.presentation.detail.navigation.detailView | ||
import jp.co.yumemi.android.code_check.presentation.detail.navigation.navigateToDetailView | ||
import jp.co.yumemi.android.code_check.presentation.main.navigation.mainRoute | ||
import jp.co.yumemi.android.code_check.presentation.main.navigation.mainView | ||
|
||
@Composable | ||
fun Navigation() { | ||
val navController = rememberNavController() | ||
|
||
NavHost( | ||
navController = navController, | ||
startDestination = mainRoute, | ||
) { | ||
mainView { | ||
navController.navigateToDetailView(it) | ||
} | ||
|
||
detailView() | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
app/src/main/kotlin/jp/co/yumemi/android/code_check/presentation/detail/DetailView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package jp.co.yumemi.android.code_check.presentation.detail | ||
|
||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import jp.co.yumemi.android.code_check.models.Repository | ||
|
||
@Composable | ||
fun DetailView() { | ||
fun DetailView(repository: Repository) { | ||
Text(text = repository.toString()) | ||
} |
82 changes: 82 additions & 0 deletions
82
...kotlin/jp/co/yumemi/android/code_check/presentation/detail/navigation/DetailNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package jp.co.yumemi.android.code_check.presentation.detail.navigation | ||
|
||
import androidx.navigation.NavController | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.NavType | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.navArgument | ||
import jp.co.yumemi.android.code_check.models.Repository | ||
import jp.co.yumemi.android.code_check.presentation.detail.DetailView | ||
import jp.co.yumemi.android.code_check.presentation.util.Constants | ||
|
||
|
||
const val detailRoute = "detail_route" | ||
|
||
const val name = "name" | ||
const val iconUrl = "icon_url" | ||
const val language = "language" | ||
const val stars = "stars" | ||
const val watchers = "watchers" | ||
const val forks = "forks" | ||
const val issues = "issues" | ||
|
||
|
||
fun NavController.navigateToDetailView(repository: Repository) { | ||
|
||
val icon = repository.ownerIconUrl | ||
.replace("/", Constants.SLASH_ENCODED) | ||
.replace("?", Constants.QUESTION_ENCODED) | ||
val repoName = repository.name | ||
.replace("/", Constants.SLASH_ENCODED) | ||
.replace("?", Constants.QUESTION_ENCODED) | ||
this.navigateUp() | ||
this.navigate( | ||
detailRoute | ||
+ "/$name=${repoName}&$iconUrl=${icon}&$language=${repository.language}" | ||
+ "&$stars=${repository.stargazersCount}&$watchers=${repository.watchersCount}" | ||
+ "&$forks=${repository.forksCount}&$issues=${repository.openIssuesCount}" | ||
) | ||
} | ||
|
||
fun NavGraphBuilder.detailView() { | ||
composable( | ||
route = detailRoute | ||
+ "/$name={${name}}&$iconUrl={${iconUrl}}&$language={${language}}" | ||
+ "&$stars={${stars}}&$watchers={${watchers}}" | ||
+ "&$forks={${forks}}&$issues={${issues}}", | ||
|
||
arguments = listOf( | ||
navArgument(name) { type = NavType.StringType }, | ||
navArgument(iconUrl) { type = NavType.StringType }, | ||
navArgument(language) { type = NavType.StringType }, | ||
navArgument(stars) { type = NavType.LongType }, | ||
navArgument(watchers) { type = NavType.LongType }, | ||
navArgument(forks) { type = NavType.LongType }, | ||
navArgument(issues) { type = NavType.LongType }, | ||
) | ||
) { backStackEntry -> | ||
|
||
val name = backStackEntry.arguments?.getString(name) | ||
?.replace(Constants.SLASH_ENCODED, "/") | ||
?.replace(Constants.QUESTION_ENCODED, "?") ?: "" | ||
val iconUrl = backStackEntry.arguments?.getString(iconUrl) | ||
?.replace(Constants.SLASH_ENCODED, "/") | ||
?.replace(Constants.QUESTION_ENCODED, "?") ?: "" | ||
val language = backStackEntry.arguments?.getString(language) ?: "" | ||
val stars = backStackEntry.arguments?.getLong(stars) ?: 0L | ||
val watchers = backStackEntry.arguments?.getLong(watchers) ?: 0L | ||
val forks = backStackEntry.arguments?.getLong(forks) ?: 0L | ||
val issues = backStackEntry.arguments?.getLong(issues) ?: 0L | ||
val repository = Repository( | ||
name = name, | ||
ownerIconUrl = iconUrl, | ||
language = language, | ||
stargazersCount = stars, | ||
watchersCount = watchers, | ||
forksCount = forks, | ||
openIssuesCount = issues | ||
) | ||
|
||
DetailView(repository = repository) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ain/kotlin/jp/co/yumemi/android/code_check/presentation/main/navigation/MainNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package jp.co.yumemi.android.code_check.presentation.main.navigation | ||
|
||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
import jp.co.yumemi.android.code_check.models.Repository | ||
import jp.co.yumemi.android.code_check.presentation.main.MainView | ||
|
||
const val mainRoute = "main_route" | ||
|
||
fun NavGraphBuilder.mainView( | ||
onRepositoryClick: (Repository) -> Unit, | ||
) { | ||
composable(route = mainRoute) { | ||
MainView(onRepositoryClick) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/kotlin/jp/co/yumemi/android/code_check/presentation/util/Constants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package jp.co.yumemi.android.code_check.presentation.util | ||
|
||
object Constants { | ||
/** | ||
* Escape string (percent-encoding) | ||
*/ | ||
const val SLASH_ENCODED = "%2F" | ||
const val QUESTION_ENCODED = "%3F" | ||
} |