Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.dagger.hilt.android'
id 'com.google.devtools.ksp'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}

android {
Expand Down Expand Up @@ -30,14 +33,52 @@ android {
kotlinOptions {
jvmTarget = '17'
}
buildFeatures{
viewBinding = true
buildConfig = true
}
ksp {
arg("dagger.hilt.disableModulesHaveInstallInCheck", "true")
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.15.0'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.core:core-ktx:1.16.0'
implementation 'androidx.appcompat:appcompat:1.7.1'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'

implementation 'androidx.activity:activity-ktx:1.10.1'
implementation 'androidx.fragment:fragment-ktx:1.8.8'

implementation "com.google.dagger:hilt-android:2.56.2"
implementation 'androidx.navigation:navigation-fragment-ktx:2.8.6'
ksp "com.google.dagger:hilt-compiler:2.56.2"

implementation("com.google.android.material:material:1.12.0")

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")

implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")

implementation("com.google.code.gson:gson:2.8.5")

implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation 'com.squareup.okhttp3:okhttp:4.12.0'

testImplementation("junit:junit:4.13.2")
testImplementation 'androidx.arch.core:core-testing:2.2.0'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0'
testImplementation 'org.mockito:mockito-core:5.12.0'
testImplementation 'org.mockito.kotlin:mockito-kotlin:5.2.1'
testImplementation 'org.mockito:mockito-inline:5.2.0'
testImplementation 'net.bytebuddy:byte-buddy:1.14.15'
androidTestImplementation 'org.mockito:mockito-android:5.12.0'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name=".presentation.WizardApp"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -13,7 +16,7 @@
android:theme="@style/Theme.BasicArchitecture"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".presentation.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.otus.basicarchitecture.data

import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.Header
import retrofit2.http.Headers
import retrofit2.http.POST
import ru.otus.basicarchitecture.data.dto.AddressRequestDto
import ru.otus.basicarchitecture.data.dto.AddressResponseDto

interface AddressApiService {

@Headers("Content-Type: application/json")
@POST("suggest/address")
suspend fun suggestAddress(
@Header("Authorization") token: String,
@Body request: AddressRequestDto,
): Response<AddressResponseDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ru.otus.basicarchitecture.data

import android.util.Log
import ru.otus.basicarchitecture.BuildConfig
import ru.otus.basicarchitecture.data.mapper.AddressMapper
import ru.otus.basicarchitecture.data.dto.AddressRequestDto
import ru.otus.basicarchitecture.domain.AddressRepository
import ru.otus.basicarchitecture.domain.UserAddress
import javax.inject.Inject

class AddressRepositoryImpl @Inject constructor(
private val addressApiService: AddressApiService
) : AddressRepository {

override suspend fun suggestAddress(query: String): List<UserAddress> {
val token = "Token ${BuildConfig.dadata_api_key}"
val response = addressApiService.suggestAddress(token, AddressRequestDto(query))
if (!response.isSuccessful){
val errorResponse = response.errorBody()?.string()
Log.e("API Error", "Error response: $errorResponse")
}
val listAddressDataDto = response.body()?.suggestions?.map { suggestion ->
suggestion.data.copy(fullAddress = suggestion.unrestricted_value)
}
val mapper = AddressMapper()
val listUserAddress = listAddressDataDto?.map {
mapper.mapDtoToEntity(it)
}
return listUserAddress ?: listOf()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.otus.basicarchitecture.data.dto

data class AddressDataDto(
val country: String?,
val city: String?,
val street: String?,
val house: String?,
val block: String?,
val fullAddress: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.otus.basicarchitecture.data.dto

data class AddressRequestDto(
val query: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.otus.basicarchitecture.data.dto

data class AddressResponseDto(
val suggestions: List<AddressSuggestionDto>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.otus.basicarchitecture.data.dto

data class AddressSuggestionDto(
val value: String,
val unrestricted_value: String,
val data: AddressDataDto
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.otus.basicarchitecture.data.mapper

import ru.otus.basicarchitecture.data.dto.AddressDataDto
import ru.otus.basicarchitecture.domain.UserAddress

class AddressMapper {

fun mapDtoToEntity(dto: AddressDataDto) = UserAddress(
fullAddress = dto.fullAddress ?: "",
country = dto.country ?: "",
city = dto.city ?: "",
street = dto.street ?: "",
house = dto.house ?: "",
block = dto.block ?: ""
)

}
49 changes: 49 additions & 0 deletions app/src/main/java/ru/otus/basicarchitecture/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ru.otus.basicarchitecture.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import ru.otus.basicarchitecture.data.AddressApiService
import ru.otus.basicarchitecture.data.AddressRepositoryImpl
import ru.otus.basicarchitecture.domain.AddressRepository
import ru.otus.basicarchitecture.domain.AddressSuggestUseCase
import ru.otus.basicarchitecture.presentation.WizardCache
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object AppModule {
@Provides
@Singleton
fun userInfo() = WizardCache()

@Provides
@Singleton
fun provideRetrofit(): Retrofit {
return Retrofit.Builder()
.baseUrl("https://suggestions.dadata.ru/suggestions/api/4_1/rs/")
.addConverterFactory(GsonConverterFactory.create())
.build()
}

@Provides
@Singleton
fun provideDaDataService(retrofit: Retrofit): AddressApiService {
return retrofit.create(AddressApiService::class.java)
}

@Provides
@Singleton
fun provideAddressRepository(impl: AddressRepositoryImpl): AddressRepository {
return impl
}

@Provides
@Singleton
fun provideAddressSuggestUseCase(repository: AddressRepository): AddressSuggestUseCase {
return AddressSuggestUseCase(repository)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.otus.basicarchitecture.domain

interface AddressRepository {
suspend fun suggestAddress(query: String): List<UserAddress>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ru.otus.basicarchitecture.domain

class AddressSuggestUseCase(private val addressRepository: AddressRepository) {

suspend operator fun invoke(query: String): List<UserAddress> {
return addressRepository.suggestAddress(query)
}
}
17 changes: 17 additions & 0 deletions app/src/main/java/ru/otus/basicarchitecture/domain/User.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.otus.basicarchitecture.domain


data class UserName(
var name: String,
var surname: String,
var birthday: String
)

data class UserAddress(
var country: String,
var city: String,
var street: String,
var house: String,
var block: String,
var fullAddress: String
)
Loading