-
Notifications
You must be signed in to change notification settings - Fork 0
[Fix] 네트워크 없을 때 앱이 종료되도록 설계된 것을 dialog만 띄우도록 수정 #422
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
40 changes: 0 additions & 40 deletions
40
app/src/main/java/com/eatssu/android/presentation/error/ServerErrorActivity.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
38 changes: 25 additions & 13 deletions
38
app/src/main/java/com/eatssu/android/presentation/util/ActivityUtil.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -1,39 +1,51 @@ | ||
| package com.eatssu.android.presentation.util | ||
|
|
||
| import android.app.Activity | ||
| import android.app.AlertDialog | ||
| import android.content.Intent | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.lifecycle.lifecycleScope | ||
| import com.eatssu.android.R | ||
| import com.eatssu.android.presentation.base.NetworkErrorEventBus | ||
| import com.eatssu.android.presentation.error.ServerErrorActivity | ||
| import kotlinx.coroutines.launch | ||
|
|
||
| inline fun <reified T : Activity> AppCompatActivity.startActivity(block: Intent.() -> Unit = {}) { | ||
| startActivity(Intent(this, T::class.java).apply(block)) | ||
| } | ||
|
|
||
| /** | ||
| * NetworkErrorEventBus를 구독하여 네트워크 에러 발생 시 ServerErrorActivity로 이동합니다. | ||
| * NetworkErrorEventBus를 구독하여 네트워크 에러 발생 시 다이얼로그를 표시합니다. | ||
| * 액티비티를 종료하지 않아 진행 중인 요청이 취소되지 않습니다. | ||
| */ | ||
| fun AppCompatActivity.observeNetworkError( | ||
| errorTitle: String? = null, | ||
| errorMessage: String? = null | ||
| ) { | ||
| var networkErrorDialog: AlertDialog? = null | ||
|
|
||
| lifecycleScope.launch { | ||
| NetworkErrorEventBus.networkError.collect { | ||
| val intent = Intent(this@observeNetworkError, ServerErrorActivity::class.java).apply { | ||
| putExtra( | ||
| ServerErrorActivity.EXTRA_TITLE, | ||
| errorTitle ?: getString(R.string.server_error_title) | ||
| ) | ||
| putExtra( | ||
| ServerErrorActivity.EXTRA_MESSAGE, | ||
| errorMessage ?: getString(R.string.server_error_message) | ||
| ) | ||
| if (networkErrorDialog?.isShowing == true) { | ||
| return@collect | ||
| } | ||
| startActivity(intent) | ||
| finish() | ||
|
|
||
| val title = errorTitle ?: getString(R.string.server_error_title) | ||
| val message = errorMessage ?: getString(R.string.server_error_message) | ||
|
|
||
| networkErrorDialog = AlertDialog.Builder(this@observeNetworkError) | ||
| .setTitle(title) | ||
| .setMessage(message) | ||
| .setPositiveButton(getString(R.string.confirm)) { dialog, _ -> | ||
| dialog.dismiss() | ||
| } | ||
| .setCancelable(true) | ||
| .create() | ||
| .also { dialog -> | ||
| dialog.setOnDismissListener { | ||
| networkErrorDialog = null | ||
| } | ||
| dialog.show() | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이부분이 슬랙에서 의견주신 다이얼로그 -> 토스트, 사용 문구 변경 맞죵? 요 부분만 반영되면 될 것 같네요!
그리고 추가적으로 해당 PR은 모두 문제 없는 것 같은데
브랜치 이동해서 observeNetworkError 확장함수 호출부를 봤는데요
사진처럼 각각 observeEvent(), observeTokenExpiration()함수 내부에 있는게 제가 보기엔 조금 부자연스러워보여서요!
혹시 해당 함수 호출부 액티비티 두곳 모두에서 onCreate()함수 내부에서 바로 호출해서 뎁스를 줄이는 거는 어떻게 생각하시나용?