forked from Yandex-Practicum/practicum-android-diploma
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from ElchinGasymov/iteration_1_review
Iteration 1 review
- Loading branch information
Showing
94 changed files
with
1,205 additions
and
46 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
11 changes: 11 additions & 0 deletions
11
app/src/main/java/ru/practicum/android/diploma/data/db/AppDatabase.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,11 @@ | ||
package ru.practicum.android.diploma.data.db | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
|
||
@Database( | ||
version = 1, | ||
entities = [VacancyEntity::class] | ||
) | ||
abstract class AppDatabase : RoomDatabase() | ||
|
11 changes: 11 additions & 0 deletions
11
app/src/main/java/ru/practicum/android/diploma/data/db/VacancyEntity.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,11 @@ | ||
package ru.practicum.android.diploma.data.db | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "vacancy_table") | ||
data class VacancyEntity( | ||
@PrimaryKey(autoGenerate = true) | ||
val vacancyId: Int | ||
) | ||
|
7 changes: 7 additions & 0 deletions
7
app/src/main/java/ru/practicum/android/diploma/data/db/dao/VacancyDao.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,7 @@ | ||
package ru.practicum.android.diploma.data.db.dao | ||
|
||
import androidx.room.Dao | ||
|
||
@Dao | ||
interface VacancyDao | ||
|
10 changes: 10 additions & 0 deletions
10
app/src/main/java/ru/practicum/android/diploma/data/dto/Responce.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,10 @@ | ||
package ru.practicum.android.diploma.data.dto | ||
|
||
const val RESULT_CODE_NO_INTERNET = -1 | ||
const val RESULT_CODE_SUCCESS = 200 | ||
const val RESULT_CODE_BAD_REQUEST = 400 | ||
const val RESULT_CODE_SERVER_ERROR = 500 | ||
|
||
class Responce { | ||
var resultCode = 0 | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/ru/practicum/android/diploma/data/dto/SearchRequest.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,5 @@ | ||
package ru.practicum.android.diploma.data.dto | ||
|
||
data class SearchRequest( | ||
val options: Map<String, String> | ||
) |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/ru/practicum/android/diploma/data/dto/VacancyRequest.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,5 @@ | ||
package ru.practicum.android.diploma.data.dto | ||
|
||
data class VacancyRequest( | ||
val id: Int | ||
) |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/ru/practicum/android/diploma/data/network/HHApiService.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,21 @@ | ||
package ru.practicum.android.diploma.data.network | ||
|
||
import retrofit2.http.GET | ||
import retrofit2.http.Headers | ||
import retrofit2.http.Path | ||
import retrofit2.http.QueryMap | ||
import ru.practicum.android.diploma.BuildConfig | ||
import ru.practicum.android.diploma.data.dto.Responce | ||
|
||
const val USER_AGENT_AUTHORIZATION = "Authorization: Bearer ${BuildConfig.HH_ACCESS_TOKEN}" | ||
const val USER_AGENT_APP_NAME = "HH-User-Agent: CareerHub ([email protected])" | ||
|
||
interface HHApiService { | ||
@Headers(USER_AGENT_AUTHORIZATION, USER_AGENT_APP_NAME) | ||
@GET("vacancies/{vacancy_id}") | ||
suspend fun getVacancy(@Path("vacancy_id") id: Int): Responce | ||
|
||
@Headers(USER_AGENT_AUTHORIZATION, USER_AGENT_APP_NAME) | ||
@GET("vacancies") | ||
suspend fun searchVacancies(@QueryMap options: Map<String, String>): Responce | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/ru/practicum/android/diploma/data/network/NetworkClient.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,7 @@ | ||
package ru.practicum.android.diploma.data.network | ||
|
||
import ru.practicum.android.diploma.data.dto.Responce | ||
|
||
interface NetworkClient { | ||
suspend fun doRequest(dto: Any): Responce | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/ru/practicum/android/diploma/data/network/RetrofitNetworkClient.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,54 @@ | ||
package ru.practicum.android.diploma.data.network | ||
|
||
import android.content.Context | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import retrofit2.HttpException | ||
import ru.practicum.android.diploma.data.dto.RESULT_CODE_BAD_REQUEST | ||
import ru.practicum.android.diploma.data.dto.RESULT_CODE_NO_INTERNET | ||
import ru.practicum.android.diploma.data.dto.RESULT_CODE_SERVER_ERROR | ||
import ru.practicum.android.diploma.data.dto.RESULT_CODE_SUCCESS | ||
import ru.practicum.android.diploma.data.dto.Responce | ||
import ru.practicum.android.diploma.data.dto.SearchRequest | ||
import ru.practicum.android.diploma.data.dto.VacancyRequest | ||
import ru.practicum.android.diploma.util.isInternetAvailable | ||
|
||
class RetrofitNetworkClient( | ||
private val hhApiService: HHApiService, | ||
private val context: Context | ||
) : NetworkClient { | ||
|
||
override suspend fun doRequest(dto: Any): Responce { | ||
if (!isInternetAvailable(context)) { | ||
return Responce().apply { resultCode = RESULT_CODE_NO_INTERNET } | ||
} | ||
return getResponce(dto = dto) | ||
} | ||
|
||
private suspend fun getResponce(dto: Any): Responce { | ||
return withContext(Dispatchers.IO) { | ||
try { | ||
when (dto) { | ||
is VacancyRequest -> { | ||
val response = hhApiService.getVacancy(dto.id) | ||
response.apply { resultCode = RESULT_CODE_SUCCESS } | ||
} | ||
|
||
is SearchRequest -> { | ||
val response = hhApiService.searchVacancies(options = dto.options) | ||
response.apply { resultCode = RESULT_CODE_SUCCESS } | ||
} | ||
|
||
else -> { | ||
Responce().apply { resultCode = RESULT_CODE_BAD_REQUEST } | ||
} | ||
} | ||
|
||
} catch (e: HttpException) { | ||
println("RetrofitClient error code: ${e.code()} message: ${e.message}") | ||
Responce().apply { resultCode = RESULT_CODE_SERVER_ERROR } | ||
} | ||
} | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/ru/practicum/android/diploma/di/DataModule.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,35 @@ | ||
package ru.practicum.android.diploma.di | ||
|
||
import androidx.room.Room | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.dsl.module | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import ru.practicum.android.diploma.data.db.AppDatabase | ||
import ru.practicum.android.diploma.data.network.HHApiService | ||
import ru.practicum.android.diploma.data.network.NetworkClient | ||
import ru.practicum.android.diploma.data.network.RetrofitNetworkClient | ||
|
||
const val BASE_URL = "https://api.hh.ru/" | ||
val dataModule = module { | ||
single<NetworkClient> { | ||
RetrofitNetworkClient( | ||
hhApiService = get(), | ||
context = androidContext() | ||
) | ||
} | ||
|
||
single<HHApiService> { | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
.create(HHApiService::class.java) | ||
} | ||
single { | ||
Room.databaseBuilder(androidContext(), AppDatabase::class.java, "database.db") | ||
.fallbackToDestructiveMigration() | ||
.build() | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/ru/practicum/android/diploma/di/InteractorModule.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,7 @@ | ||
package ru.practicum.android.diploma.di | ||
|
||
import org.koin.dsl.module | ||
|
||
val interactorModule = module { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/ru/practicum/android/diploma/di/RepositoryModule.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,7 @@ | ||
package ru.practicum.android.diploma.di | ||
|
||
import org.koin.dsl.module | ||
|
||
val repositoryModule = module { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/ru/practicum/android/diploma/di/ViewModelModule.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,7 @@ | ||
package ru.practicum.android.diploma.di | ||
|
||
import org.koin.dsl.module | ||
|
||
val viewModelModule = module { | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/ru/practicum/android/diploma/ui/fragments/FavouritesFragment.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,24 @@ | ||
package ru.practicum.android.diploma.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import by.kirich1409.viewbindingdelegate.CreateMethod | ||
import by.kirich1409.viewbindingdelegate.viewBinding | ||
import ru.practicum.android.diploma.databinding.FragmentFavouritesBinding | ||
|
||
class FavouritesFragment : Fragment() { | ||
|
||
private val binding: FragmentFavouritesBinding by viewBinding(CreateMethod.INFLATE) | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return binding.root | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/ru/practicum/android/diploma/ui/fragments/FilterFragment.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,34 @@ | ||
package ru.practicum.android.diploma.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.fragment.findNavController | ||
import by.kirich1409.viewbindingdelegate.CreateMethod | ||
import by.kirich1409.viewbindingdelegate.viewBinding | ||
import ru.practicum.android.diploma.R | ||
import ru.practicum.android.diploma.databinding.FragmentFilterBinding | ||
|
||
class FilterFragment : Fragment() { | ||
|
||
private val binding: FragmentFilterBinding by viewBinding(CreateMethod.INFLATE) | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
binding.buttonBackToSearchFromFilter.setOnClickListener { | ||
findNavController().navigate(R.id.mainFragment) | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/ru/practicum/android/diploma/ui/fragments/SearchFragment.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,38 @@ | ||
package ru.practicum.android.diploma.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.fragment.findNavController | ||
import by.kirich1409.viewbindingdelegate.CreateMethod | ||
import by.kirich1409.viewbindingdelegate.viewBinding | ||
import ru.practicum.android.diploma.R | ||
import ru.practicum.android.diploma.databinding.FragmentSearchBinding | ||
|
||
class SearchFragment : Fragment() { | ||
|
||
private val binding: FragmentSearchBinding by viewBinding(CreateMethod.INFLATE) | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
binding.buttonToFilter.setOnClickListener { | ||
findNavController().navigate(R.id.action_searchFragment_to_filterFragment) | ||
} | ||
|
||
binding.buttonToVacancy.setOnClickListener { | ||
findNavController().navigate(R.id.action_searchFragment_to_vacancyFragment) | ||
} | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/ru/practicum/android/diploma/ui/fragments/TeamFragment.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,24 @@ | ||
package ru.practicum.android.diploma.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import by.kirich1409.viewbindingdelegate.CreateMethod | ||
import by.kirich1409.viewbindingdelegate.viewBinding | ||
import ru.practicum.android.diploma.databinding.FragmentTeamBinding | ||
|
||
class TeamFragment : Fragment() { | ||
|
||
private val binding: FragmentTeamBinding by viewBinding(CreateMethod.INFLATE) | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return binding.root | ||
} | ||
|
||
} |
Oops, something went wrong.