-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] 네트워크 연결 상태 확인 (로딩,에러 뷰)
- Loading branch information
Showing
37 changed files
with
533 additions
and
148 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
2 changes: 1 addition & 1 deletion
2
...data/datasource/remote/AuthInterceptor.kt → ...rce/remote/intercepter/AuthInterceptor.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
31 changes: 31 additions & 0 deletions
31
app/src/main/java/sopt/motivoo/data/datasource/remote/intercepter/ErrorInterceptor.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,31 @@ | ||
package sopt.motivoo.data.datasource.remote.intercepter | ||
|
||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import sopt.motivoo.data.datasource.remote.listener.NetworkErrorListener | ||
import javax.inject.Inject | ||
|
||
class ErrorInterceptor @Inject constructor( | ||
private val networkErrorListener: NetworkErrorListener, | ||
) : Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
val request = chain.request() | ||
var response = chain.proceed(chain.request()) | ||
|
||
when (response.code) { | ||
|
||
in SERVER_ERROR_START..SERVER_ERROR_END -> { | ||
networkErrorListener.onApiCallFailed() | ||
|
||
response.close() | ||
response = chain.proceed(request) | ||
} | ||
} | ||
return response | ||
} | ||
|
||
companion object { | ||
private const val SERVER_ERROR_START = 500 | ||
private const val SERVER_ERROR_END = 599 | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/sopt/motivoo/data/datasource/remote/listener/NetworkErrorListener.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 sopt.motivoo.data.datasource.remote.listener | ||
|
||
interface NetworkErrorListener { | ||
fun onApiCallFailed() | ||
fun setOnApiCallFailedCallback(callback: () -> Unit) | ||
fun clearOnApiCallFailedCallback() | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/sopt/motivoo/data/datasource/remote/listener/NetworkErrorListenerImpl.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,19 @@ | ||
package sopt.motivoo.data.datasource.remote.listener | ||
|
||
import javax.inject.Inject | ||
|
||
class NetworkErrorListenerImpl @Inject constructor() : NetworkErrorListener { | ||
private var onApiCallFailedCallback: (() -> Unit)? = null | ||
|
||
override fun onApiCallFailed() { | ||
onApiCallFailedCallback?.invoke() | ||
} | ||
|
||
override fun setOnApiCallFailedCallback(callback: () -> Unit) { | ||
onApiCallFailedCallback = callback | ||
} | ||
|
||
override fun clearOnApiCallFailedCallback() { | ||
onApiCallFailedCallback = null | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/sopt/motivoo/data/repository/NetworkRepositoryImpl.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 sopt.motivoo.data.repository | ||
|
||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import sopt.motivoo.domain.repository.NetworkRepository | ||
import sopt.motivoo.util.NetworkState | ||
import javax.inject.Inject | ||
|
||
class NetworkRepositoryImpl @Inject constructor( | ||
networkState: NetworkState | ||
) : NetworkRepository { | ||
|
||
override val networkStateFlow = networkState.networkState | ||
|
||
private val _isLoading = MutableSharedFlow<Boolean>(replay = 1) | ||
override val isLoading get() = _isLoading.asSharedFlow() | ||
|
||
override suspend fun setLoading(isLoading: Boolean) { | ||
_isLoading.emit(isLoading) | ||
} | ||
} |
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,15 @@ | ||
package sopt.motivoo.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ActivityComponent | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
|
||
@Module | ||
@InstallIn(ActivityComponent::class) | ||
object CoroutineModule { | ||
@Provides | ||
fun provideMainDispatcher(): CoroutineDispatcher = Dispatchers.Main | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package sopt.motivoo.di | ||
|
||
import android.content.Context | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import sopt.motivoo.util.NetworkState | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object NetworkModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideNetworkState(@ApplicationContext context: Context): NetworkState { | ||
return NetworkState(context) | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
app/src/main/java/sopt/motivoo/domain/repository/NetworkRepository.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 sopt.motivoo.domain.repository | ||
|
||
import kotlinx.coroutines.flow.SharedFlow | ||
|
||
interface NetworkRepository { | ||
|
||
val networkStateFlow: SharedFlow<Boolean> | ||
val isLoading: SharedFlow<Boolean> | ||
suspend fun setLoading(isLoading: Boolean) | ||
} |
8 changes: 0 additions & 8 deletions
8
app/src/main/java/sopt/motivoo/presentation/LoadingFragment.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.