Skip to content

Commit cc4bbe6

Browse files
authored
Merge pull request #8 from CGreenP/dev
feat: Enhance documentation and code clarity
2 parents 8404b63 + 5db0331 commit cc4bbe6

23 files changed

+229
-26
lines changed

app/src/main/java/com/example/techexactly/MainActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ import androidx.navigation.compose.rememberNavController
1313
import com.example.techexactly.ui.theme.TechExactlyTheme
1414
import com.example.techexactly.view.navigation.SetupNavGraph
1515

16+
/**
17+
* The main activity of the TechExactly application.
18+
*
19+
* This activity serves as the entry point for the application. It handles the following:
20+
* - Sets up the splash screen with a custom exit animation.
21+
* - Enables edge-to-edge display for a more immersive experience.
22+
* - Sets the content of the activity to a Compose-based UI, including:
23+
* - A navigation controller to manage screen transitions.
24+
* - A navigation graph to define the app's structure.
25+
* - The application's theme.
26+
*/
1627
class MainActivity : ComponentActivity() {
1728
override fun onCreate(savedInstanceState: Bundle?) {
1829
super.onCreate(savedInstanceState)

app/src/main/java/com/example/techexactly/TechExactlyApplication.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import org.koin.android.ext.koin.androidLogger
77
import org.koin.core.context.startKoin
88
import org.koin.core.logger.Level
99

10+
/**
11+
* The main application class for the TechExactly application. This class
12+
* initializes Koin, the dependency injection framework, during the application's
13+
* `onCreate` lifecycle event.
14+
*/
1015
class TechExactlyApplication : Application() {
1116
override fun onCreate() {
1217
super.onCreate()

app/src/main/java/com/example/techexactly/di/AppModule.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import com.example.techexactly.viewmodel.MainViewModel
77
import org.koin.core.module.dsl.viewModelOf
88
import org.koin.dsl.module
99

10+
/**
11+
* Koin module defining dependencies related to the application's core functionalities.
12+
* It includes:
13+
* - Retrofit instance for network communication.
14+
* - User API interface implementation.
15+
* - UserRepository instance for accessing user data.
16+
* - MainViewModel instance for managing the main screen's data and logic.
17+
*/
1018
val appModule = module {
1119
single { provideRetrofit() }
1220
single { provideUserApi(get()) }

app/src/main/java/com/example/techexactly/model/dataclass/User.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ package com.example.techexactly.model.dataclass
22

33
import kotlinx.serialization.Serializable
44

5+
/**
6+
* Represents a user with their personal and professional information.
7+
*
8+
* @property id The unique identifier of the user.
9+
* @property name The full name of the user.
10+
* @property username The username or alias of the user.
11+
* @property email The email address of the user.
12+
* @property address The address details of the user, including street, city, etc.
13+
* @property phone The phone number of the user.
14+
* @property website The website associated with the user.
15+
* @property company The company details of the user, including name and other information.
16+
*/
517
@Serializable
618
data class User(
719
val id: Long,

app/src/main/java/com/example/techexactly/model/network/RetrofitInstance.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,39 @@ import retrofit2.converter.gson.GsonConverterFactory
88

99
private const val BASE_URL = "https://jsonplaceholder.typicode.com/"
1010

11+
/**
12+
* Provides a configured Retrofit instance for making network requests.
13+
*
14+
* This function sets up a Retrofit client with the following features:
15+
* - **Base URL:** Uses the [BASE_URL] constant as the base URL for all requests. Ensure this constant is defined in your project.
16+
* - **OkHttpClient:** Uses an OkHttpClient to handle the network communication, configured with:
17+
* - **Logging Interceptor:** An [HttpLoggingInterceptor] that logs the request and response bodies at the `BODY` level, aiding in debugging. **Note:** This should be removed or adjusted for production builds.
18+
* - **Gson Converter Factory:** Uses a [GsonConverterFactory] to serialize and deserialize JSON responses using the Gson library. The Gson instance is configured to be lenient, allowing for some flexibility in the expected JSON structure.
19+
*
20+
* @return A configured [Retrofit] instance ready for creating API interfaces.
21+
*/
1122
fun provideRetrofit(): Retrofit {
1223
val loggingInterceptor = HttpLoggingInterceptor().apply {
1324
level = HttpLoggingInterceptor.Level.BODY
1425
}
1526
val okHttpClient = OkHttpClient.Builder().addInterceptor(loggingInterceptor).build()
1627
val gson = GsonBuilder().setLenient().create()
1728

18-
return Retrofit.Builder()
19-
.baseUrl(BASE_URL)
20-
.client(okHttpClient)
21-
.addConverterFactory(GsonConverterFactory.create(gson))
22-
.build()
29+
return Retrofit.Builder().baseUrl(BASE_URL).client(okHttpClient)
30+
.addConverterFactory(GsonConverterFactory.create(gson)).build()
2331
}
2432

33+
/**
34+
* Provides an instance of the [UserApi] interface.
35+
*
36+
* This function uses a pre-configured [Retrofit] instance to create an implementation of the [UserApi] interface,
37+
* which is used to interact with the user-related endpoints of the API. This abstraction allows for easier testing
38+
* and decoupling of the network layer from the rest of the application.
39+
*
40+
* @param retrofit A configured [Retrofit] instance. This instance should already be configured with the base URL,
41+
* converter factories (e.g., GsonConverterFactory), and any necessary interceptors (e.g., for authentication).
42+
* @return An instance of [UserApi] that can be used to make API calls related to users.
43+
*/
2544
fun provideUserApi(retrofit: Retrofit): UserApi {
2645
return retrofit.create(UserApi::class.java)
2746
}

app/src/main/java/com/example/techexactly/model/network/UserApi.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import com.example.techexactly.model.dataclass.User
44
import retrofit2.Response
55
import retrofit2.http.GET
66

7+
/**
8+
* Defines the API endpoints for interacting with user data.
9+
*/
710
interface UserApi {
811
@GET("/users")
912
suspend fun getUsers(): Response<List<User>>

app/src/main/java/com/example/techexactly/model/repository/UserRepository.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import kotlinx.coroutines.flow.Flow
77
import kotlinx.coroutines.flow.flow
88
import kotlinx.coroutines.flow.flowOn
99

10+
/**
11+
* Repository class responsible for managing user data.
12+
* It interacts with the [UserApi] to fetch user information from a remote source.
13+
*
14+
* @property userApi The API interface used to communicate with the user data source.
15+
*/
1016
class UserRepository(private val userApi: UserApi) {
1117
fun getUsers(): Flow<Result<List<User>>> = flow {
1218
try {

app/src/main/java/com/example/techexactly/view/home/HomeScreen.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import com.example.techexactly.model.dataclass.User
1818
import com.example.techexactly.viewmodel.MainViewModel
1919
import org.koin.androidx.compose.koinViewModel
2020

21+
/**
22+
* The main screen of the application, displaying a list of users and a search bar.
23+
*
24+
* @param onUserClicked Callback function invoked when a user item in the list is clicked. It takes a [User] object as a parameter representing the clicked user.
25+
* @param mainViewModel The [MainViewModel] instance used to manage the data and state for the screen, defaults to an instance retrieved from Koin.
26+
*/
2127
@OptIn(ExperimentalMaterial3Api::class)
2228
@Composable
2329
fun HomeScreen(

app/src/main/java/com/example/techexactly/view/home/HomeScreenContent.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ import com.example.techexactly.model.dataclass.User
2626
import com.example.techexactly.viewmodel.MainViewModel
2727
import com.example.techexactly.viewmodel.UiState
2828

29+
/**
30+
* Displays the content of the Home Screen, handling different UI states (Loading, Success, Error).
31+
*
32+
* @param onUserClicked Callback function triggered when a user in the list is clicked. It receives the clicked [User] as a parameter.
33+
* @param mainViewModel The [MainViewModel] instance providing the current UI state.
34+
*/
2935
@Composable
3036
fun HomeScreenContent(
3137
onUserClicked: (User) -> Unit, mainViewModel: MainViewModel

app/src/main/java/com/example/techexactly/view/home/HomeScreenTopBar.kt

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ import androidx.compose.ui.tooling.preview.Preview
3535
import androidx.compose.ui.unit.dp
3636
import com.example.techexactly.R
3737

38+
/**
39+
* Composable function for the top app bar of the Home Screen.
40+
*
41+
* This composable displays a centered top app bar with the app logo, title, subtitle, and a search bar.
42+
* The search bar can be toggled via a search icon button, and it filters the displayed content based on user input.
43+
*
44+
* @param title The main title to display in the top bar.
45+
* @param subtitle The subtitle to display below the main title.
46+
* @param scrollBehavior The scroll behavior for the top app bar, handling scrolling effects.
47+
* @param searchQuery The current search query string. Defaults to an empty string.
48+
* @param onSearchQueryChanged Callback function invoked when the search query changes. It receives the new query string as a parameter.
49+
*/
3850
@OptIn(ExperimentalMaterial3Api::class)
3951
@Composable
4052
fun HomeScreenTopBar(
@@ -76,16 +88,17 @@ fun HomeScreenTopBar(
7688
}
7789
}
7890
}, navigationIcon = {
79-
Image(
80-
modifier = Modifier.padding(start = 8.dp).size(24.dp),
81-
painter = painterResource(id = R.drawable.app_logo),
82-
contentDescription = null,
83-
colorFilter = ColorFilter.tint(
84-
MaterialTheme.colorScheme.onSurface
85-
)
91+
Image(
92+
modifier = Modifier
93+
.padding(start = 8.dp)
94+
.size(24.dp),
95+
painter = painterResource(id = R.drawable.app_logo),
96+
contentDescription = null,
97+
colorFilter = ColorFilter.tint(
98+
MaterialTheme.colorScheme.onSurface
8699
)
87-
},
88-
scrollBehavior = scrollBehavior
100+
)
101+
}, scrollBehavior = scrollBehavior
89102
)
90103
AnimatedVisibility(visible = showSearchBar) {
91104
DockedSearchBar(

0 commit comments

Comments
 (0)