Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Правки после первого ревью #34

Merged
merged 1 commit into from
Aug 6, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const val RESULT_CODE_SUCCESS = 200
const val RESULT_CODE_BAD_REQUEST = 400
const val RESULT_CODE_SERVER_ERROR = 500

class Responce {
class Response {
var resultCode = 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ 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
import ru.practicum.android.diploma.data.dto.Response

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
suspend fun getVacancy(@Path("vacancy_id") id: Int): Response

@Headers(USER_AGENT_AUTHORIZATION, USER_AGENT_APP_NAME)
@GET("vacancies")
suspend fun searchVacancies(@QueryMap options: Map<String, String>): Responce
suspend fun searchVacancies(@QueryMap options: Map<String, String>): Response
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ru.practicum.android.diploma.data.network

import ru.practicum.android.diploma.data.dto.Responce
import ru.practicum.android.diploma.data.dto.Response

interface NetworkClient {
suspend fun doRequest(dto: Any): Responce
suspend fun doRequest(dto: Any): Response
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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.Response
import ru.practicum.android.diploma.data.dto.SearchRequest
import ru.practicum.android.diploma.data.dto.VacancyRequest
import ru.practicum.android.diploma.util.isInternetAvailable
Expand All @@ -18,14 +18,14 @@ class RetrofitNetworkClient(
private val context: Context
) : NetworkClient {

override suspend fun doRequest(dto: Any): Responce {
override suspend fun doRequest(dto: Any): Response {
if (!isInternetAvailable(context)) {
return Responce().apply { resultCode = RESULT_CODE_NO_INTERNET }
return Response().apply { resultCode = RESULT_CODE_NO_INTERNET }
}
return getResponce(dto = dto)
}

private suspend fun getResponce(dto: Any): Responce {
private suspend fun getResponce(dto: Any): Response {
return withContext(Dispatchers.IO) {
try {
when (dto) {
Expand All @@ -40,13 +40,13 @@ class RetrofitNetworkClient(
}

else -> {
Responce().apply { resultCode = RESULT_CODE_BAD_REQUEST }
Response().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 }
Response().apply { resultCode = RESULT_CODE_SERVER_ERROR }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,10 @@ class RootActivity : AppCompatActivity() {

navController.addOnDestinationChangedListener { _, destination, _ ->
when (destination.id) {
R.id.mainFragment -> {
R.id.mainFragment, R.id.favoriteFragment, R.id.teamFragment ->
binding.bottomNavigationView.isVisible = true
}

R.id.favoriteFragment -> {
binding.bottomNavigationView.isVisible = true
}

R.id.teamFragment -> {
binding.bottomNavigationView.isVisible = true
}

else -> {
binding.bottomNavigationView.isVisible = false
}
else -> binding.bottomNavigationView.isVisible = false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@ package ru.practicum.android.diploma.util

import android.view.View
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import ru.practicum.android.diploma.util.DebounceExtension.Companion.HALF_SECOND

class DebounceExtension(
private val delayMillis: Long,
private val action: () -> Unit
private val action: () -> Unit,
private val scope: CoroutineScope
) {
companion object {
const val HALF_SECOND = 500L
}

private var debounceJob: Job? = null

fun debounce() {
debounceJob?.cancel()
debounceJob = CoroutineScope(Dispatchers.Main).launch {
debounceJob = scope.launch {
delay(delayMillis)
action.invoke()
}
}
}

fun View.setDebouncedClickListener(
scope: CoroutineScope,
delayMillis: Long = HALF_SECOND,
onClick: () -> Unit
) {
var debounceJob: Job? = null
setOnClickListener {
debounceJob?.cancel()
debounceJob = CoroutineScope(Dispatchers.Main).launch {
debounceJob = scope.launch {
delay(delayMillis)
onClick()
}
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ koin-android = { module = "io.insert-koin:koin-android", version.ref = "koinAndr
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinxCoroutinesAndroid" }
navigation-fragment-ktx = { module = "androidx.navigation:navigation-fragment-ktx", version.ref = "navigationFragmentKtx" }
navigation-ui-ktx = { module = "androidx.navigation:navigation-ui-ktx", version.ref = "navigationFragmentKtx" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit-v290 = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofitVersion" }
room-compiler = { module = "androidx.room:room-compiler", version.ref = "roomCompiler" }
room-ktx = { module = "androidx.room:room-ktx", version.ref = "roomCompiler" }
Expand Down
Loading