Skip to content

Commit

Permalink
feat: GitHub のリポジトリへのリンクを追加 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
kokoichi206 committed Dec 4, 2022
1 parent 98dfa33 commit a688ad3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MockGitHubRepositoryImpl : GitHubRepository {
return listOf(
Repository(
name = "actions-marketplace-validations/kokoichi206_action-URL-watcher",
repoUrl = "https://github.com/actions-marketplace-validations/kokoichi206_action-URL-watcher",
ownerIconUrl = "https://avatars.githubusercontent.com/u/112583732?v=4",
language = "Kotlin",
stargazersCount = 1,
Expand All @@ -37,6 +38,7 @@ class MockGitHubRepositoryImpl : GitHubRepository {
),
Repository(
name = "kokoichi206/kokoichi206",
repoUrl = "https://github.com/kokoichi206/kokoichi206",
ownerIconUrl = "https://avatars.githubusercontent.com/u/52474650?v=4",
language = "Shell",
stargazersCount = 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class Repository(
val name: String,
val repoUrl: String,
val ownerIconUrl: String,
val language: String,
val stargazersCount: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package jp.co.yumemi.android.code_check.presentation.detail

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Divider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -98,6 +103,26 @@ fun DetailView(repository: Repository) {
iconId = R.drawable.issue,
)
Divider(color = Colors.Divider)

val uriHandler = LocalUriHandler.current

Spacer(modifier = Modifier.height(16.dp))
Box(
modifier = Modifier
.fillMaxWidth(),
contentAlignment = Alignment.CenterEnd
) {
Image(
modifier = Modifier
.size(50.dp)
.clip(CircleShape)
.clickable {
uriHandler.openUri(repository.repoUrl)
},
painter = painterResource(id = R.drawable.github),
contentDescription = "github icon",
)
}
}
}
}
Expand All @@ -109,6 +134,7 @@ fun DetailView(repository: Repository) {
fun DetailViewPreview() {
val repository = Repository(
name = "kokoichi206/kokoichi206",
repoUrl = "",
ownerIconUrl = "https://avatars.githubusercontent.com/u/52474650?v=4",
language = "Go",
stargazersCount = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import jp.co.yumemi.android.code_check.presentation.util.Constants
const val detailRoute = "detail_route"

const val name = "name"
const val repoUrl = "repoUrl"
const val iconUrl = "icon_url"
const val language = "language"
const val stars = "stars"
Expand All @@ -26,13 +27,16 @@ fun NavController.navigateToDetailView(repository: Repository) {
val icon = repository.ownerIconUrl
.replace("/", Constants.SLASH_ENCODED)
.replace("?", Constants.QUESTION_ENCODED)
val url = repository.repoUrl
.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}"
+ "/$name=${repoName}&$repoUrl=${url}&$iconUrl=${icon}&$language=${repository.language}"
+ "&$stars=${repository.stargazersCount}&$watchers=${repository.watchersCount}"
+ "&$forks=${repository.forksCount}&$issues=${repository.openIssuesCount}"
)
Expand All @@ -41,12 +45,13 @@ fun NavController.navigateToDetailView(repository: Repository) {
fun NavGraphBuilder.detailView() {
composable(
route = detailRoute
+ "/$name={${name}}&$iconUrl={${iconUrl}}&$language={${language}}"
+ "/$name={${name}}&$repoUrl={${repoUrl}}&$iconUrl={${iconUrl}}&$language={${language}}"
+ "&$stars={${stars}}&$watchers={${watchers}}"
+ "&$forks={${forks}}&$issues={${issues}}",

arguments = listOf(
navArgument(name) { type = NavType.StringType },
navArgument(repoUrl) { type = NavType.StringType },
navArgument(iconUrl) { type = NavType.StringType },
navArgument(language) { type = NavType.StringType },
navArgument(stars) { type = NavType.LongType },
Expand All @@ -59,6 +64,9 @@ fun NavGraphBuilder.detailView() {
val name = backStackEntry.arguments?.getString(name)
?.replace(Constants.SLASH_ENCODED, "/")
?.replace(Constants.QUESTION_ENCODED, "?") ?: ""
val repoUrl = backStackEntry.arguments?.getString(repoUrl)
?.replace(Constants.SLASH_ENCODED, "/")
?.replace(Constants.QUESTION_ENCODED, "?") ?: ""
val iconUrl = backStackEntry.arguments?.getString(iconUrl)
?.replace(Constants.SLASH_ENCODED, "/")
?.replace(Constants.QUESTION_ENCODED, "?") ?: ""
Expand All @@ -69,6 +77,7 @@ fun NavGraphBuilder.detailView() {
val issues = backStackEntry.arguments?.getLong(issues) ?: 0L
val repository = Repository(
name = name,
repoUrl = repoUrl,
ownerIconUrl = iconUrl,
language = language,
stargazersCount = stars,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fun OneRepository(
fun OneRepositoryPreview() {
val repository = Repository(
name = "kokoichi206/kokoichi206",
repoUrl = "",
ownerIconUrl = "",
language = "Kotlin",
stargazersCount = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.json.JSONObject
*/
fun JSONObject.toRepository(): Repository {
val name = optString("full_name")
val repoUrl = optString("html_url")
val ownerIconUrl = optJSONObject("owner")?.optString("avatar_url") ?: "empty_url"
val language = optString("language")
val stargazersCount = optLong("stargazers_count")
Expand All @@ -20,6 +21,7 @@ fun JSONObject.toRepository(): Repository {

return Repository(
name = name,
repoUrl = repoUrl,
ownerIconUrl = ownerIconUrl,
language = language,
stargazersCount = stargazersCount,
Expand Down
Binary file added app/src/main/res/drawable/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a688ad3

Please sign in to comment.