Skip to content

Commit af00991

Browse files
authored
Merge pull request #27 from harutiro/features/8
UI をブラッシュアップ
2 parents 810c210 + a94b51d commit af00991

38 files changed

+1472
-573
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
[*.{kt,kts}]
22
ktlint_standard_package-name = disabled
3+
ktlint_function_naming_ignore_when_annotated_with = Composable
4+

app/build.gradle

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
id("org.jlleitschuh.gradle.ktlint") version "12.1.2"
88
id 'com.google.dagger.hilt.android'
99
id 'jacoco'
10+
id("org.jetbrains.kotlin.plugin.compose") version "2.1.0"
1011
}
1112

1213
android {
@@ -39,6 +40,10 @@ android {
3940
buildFeatures {
4041
viewBinding true
4142
buildConfig true
43+
compose true
44+
}
45+
composeOptions {
46+
kotlinCompilerExtensionVersion '1.5.0'
4247
}
4348
}
4449

@@ -69,13 +74,29 @@ dependencies {
6974
kapt "com.google.dagger:hilt-compiler:2.55"
7075
testImplementation "org.mockito:mockito-core:5.2.0"
7176
testImplementation 'org.mockito:mockito-inline:5.2.0'
77+
implementation 'androidx.hilt:hilt-navigation-compose:1.2.0'
7278

7379

7480
// Retrofit
7581
implementation("com.squareup.retrofit2:converter-moshi:2.9.0")
7682
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
7783
implementation("com.squareup.retrofit2:retrofit:2.11.0")
7884
implementation("com.squareup.moshi:moshi-kotlin:1.14.0")
85+
86+
// jetpack compose
87+
def composeBom = platform('androidx.compose:compose-bom:2025.01.00')
88+
implementation composeBom
89+
androidTestImplementation composeBom
90+
implementation 'androidx.compose.material3:material3'
91+
implementation 'androidx.compose.foundation:foundation'
92+
implementation 'androidx.compose.ui:ui'
93+
implementation 'androidx.compose.ui:ui-tooling-preview'
94+
debugImplementation 'androidx.compose.ui:ui-tooling'
95+
implementation 'androidx.activity:activity-compose:1.10.0'
96+
implementation 'androidx.navigation:navigation-compose:2.8.5'
97+
implementation "io.coil-kt:coil-compose:2.4.0"
98+
implementation "androidx.compose.material:material-icons-extended:1.7.6"
99+
79100
}
80101

81102
kapt {
@@ -86,11 +107,6 @@ jacoco {
86107
toolVersion = "0.8.8"
87108
}
88109

89-
//tasks.withType(Test) {
90-
// useJUnitPlatform()
91-
// finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
92-
//}
93-
94110
tasks.register("jacocoTestReport", JacocoReport) {
95111
dependsOn(tasks.test)
96112

@@ -111,4 +127,4 @@ tasks.register("jacocoTestReport", JacocoReport) {
111127
"jacoco/testDebugUnitTest.exec",
112128
"outputs/code-coverage/connected/*coverage.ec"
113129
]))
114-
}
130+
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
android:fullBackupContent="@xml/backup_descriptor"
1515
android:name=".CodeCheckApplication">
1616
<activity
17-
android:name="jp.co.yumemi.android.code_check.TopActivity"
17+
android:name="jp.co.yumemi.android.code_check.MainActivity"
1818
android:exported="true">
1919
<intent-filter>
2020
<action android:name="android.intent.action.MAIN" />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright © 2021 YUMEMI Inc. All rights reserved.
3+
*/
4+
package jp.co.yumemi.android.code_check
5+
6+
import android.os.Bundle
7+
import androidx.activity.ComponentActivity
8+
import androidx.activity.compose.setContent
9+
import dagger.hilt.android.AndroidEntryPoint
10+
import jp.co.yumemi.android.code_check.core.presenter.MainScreen
11+
import jp.co.yumemi.android.code_check.core.presenter.theme.CodeCheckAppTheme
12+
13+
@AndroidEntryPoint
14+
class MainActivity : ComponentActivity() {
15+
override fun onCreate(savedInstanceState: Bundle?) {
16+
super.onCreate(savedInstanceState)
17+
setContent {
18+
CodeCheckAppTheme {
19+
MainScreen()
20+
}
21+
}
22+
}
23+
}

app/src/main/kotlin/jp/co/yumemi/android/code_check/TopActivity.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.

app/src/main/kotlin/jp/co/yumemi/android/code_check/core/entity/RepositoryItem.kt renamed to app/src/main/kotlin/jp/co/yumemi/android/code_check/core/entity/RepositoryEntity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import android.os.Parcelable
44
import kotlinx.parcelize.Parcelize
55

66
@Parcelize
7-
data class RepositoryItem(
7+
data class RepositoryEntity(
8+
val id: Int,
89
val name: String,
910
val ownerIconUrl: String,
1011
val language: String,
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package jp.co.yumemi.android.code_check.core.presenter
2+
3+
import androidx.compose.foundation.layout.padding
4+
import androidx.compose.material.icons.Icons
5+
import androidx.compose.material.icons.automirrored.outlined.ArrowBack
6+
import androidx.compose.material.icons.outlined.ArrowBack
7+
import androidx.compose.material3.ExperimentalMaterial3Api
8+
import androidx.compose.material3.Icon
9+
import androidx.compose.material3.IconButton
10+
import androidx.compose.material3.MaterialTheme
11+
import androidx.compose.material3.Scaffold
12+
import androidx.compose.material3.Snackbar
13+
import androidx.compose.material3.SnackbarHost
14+
import androidx.compose.material3.SnackbarHostState
15+
import androidx.compose.material3.Text
16+
import androidx.compose.material3.TopAppBar
17+
import androidx.compose.material3.TopAppBarDefaults
18+
import androidx.compose.runtime.Composable
19+
import androidx.compose.runtime.getValue
20+
import androidx.compose.runtime.mutableStateOf
21+
import androidx.compose.runtime.remember
22+
import androidx.compose.runtime.rememberCoroutineScope
23+
import androidx.compose.runtime.setValue
24+
import androidx.compose.ui.Modifier
25+
import androidx.compose.ui.platform.LocalContext
26+
import androidx.compose.ui.text.font.FontWeight
27+
import androidx.navigation.compose.currentBackStackEntryAsState
28+
import androidx.navigation.compose.rememberNavController
29+
import jp.co.yumemi.android.code_check.R
30+
import jp.co.yumemi.android.code_check.core.presenter.router.BottomNavigationBarRoute
31+
import jp.co.yumemi.android.code_check.core.presenter.router.MainRouter
32+
import jp.co.yumemi.android.code_check.core.presenter.widget.EmptyCompose
33+
import kotlinx.coroutines.launch
34+
35+
@OptIn(ExperimentalMaterial3Api::class)
36+
@Composable
37+
fun MainScreen() {
38+
val context = LocalContext.current
39+
val appName = context.getString(R.string.app_name)
40+
41+
val navController = rememberNavController()
42+
val navBackStackEntry by navController.currentBackStackEntryAsState()
43+
var topBarTitle by remember {
44+
mutableStateOf(appName)
45+
}
46+
47+
val hostState = remember { SnackbarHostState() }
48+
var isErrorMessage by remember { mutableStateOf(false) }
49+
val scope = rememberCoroutineScope()
50+
51+
val navigationIcon: @Composable () -> Unit =
52+
if (navBackStackEntry?.destination?.route != BottomNavigationBarRoute.SEARCH.route) {
53+
{
54+
IconButton(onClick = {
55+
navController.popBackStack()
56+
}) {
57+
Icon(
58+
imageVector = Icons.AutoMirrored.Outlined.ArrowBack,
59+
contentDescription = "Back",
60+
)
61+
}
62+
}
63+
} else {
64+
{
65+
EmptyCompose()
66+
}
67+
}
68+
69+
Scaffold(
70+
topBar = {
71+
TopAppBar(
72+
title = {
73+
Text(
74+
text = topBarTitle,
75+
fontWeight = FontWeight.Bold,
76+
)
77+
},
78+
colors =
79+
TopAppBarDefaults.topAppBarColors(
80+
containerColor = MaterialTheme.colorScheme.primaryContainer,
81+
titleContentColor = MaterialTheme.colorScheme.primary,
82+
),
83+
navigationIcon = navigationIcon,
84+
)
85+
},
86+
snackbarHost = { CustomSnackbarHost(hostState = hostState, isErrorMessage = isErrorMessage) },
87+
) { innerPadding ->
88+
MainRouter(
89+
toDetailScreen = { id ->
90+
navController.navigate("${BottomNavigationBarRoute.DETAIL.route}/$id")
91+
},
92+
toBackScreen = {
93+
navController.popBackStack()
94+
},
95+
changeTopBarTitle = {
96+
topBarTitle = it
97+
},
98+
showSnackbar = { message, isError ->
99+
scope.launch {
100+
isErrorMessage = isError
101+
hostState.showSnackbar(message)
102+
}
103+
},
104+
navController = navController,
105+
modifier =
106+
Modifier
107+
.padding(innerPadding),
108+
)
109+
}
110+
}
111+
112+
@Composable
113+
fun CustomSnackbarHost(
114+
hostState: SnackbarHostState,
115+
isErrorMessage: Boolean,
116+
) {
117+
SnackbarHost(
118+
hostState = hostState,
119+
) { snackbarData ->
120+
Snackbar(
121+
snackbarData = snackbarData,
122+
containerColor = if (isErrorMessage) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primaryContainer,
123+
contentColor = if (isErrorMessage) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer,
124+
)
125+
}
126+
}

app/src/main/kotlin/jp/co/yumemi/android/code_check/core/presenter/detail/RepositoryDetailFragment.kt

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)