-
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.
refactor: dialog -> dialogFragment로 변경
- Loading branch information
Showing
12 changed files
with
209 additions
and
141 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
android/app/src/main/java/app/priceguard/ui/ConfirmDialogFragment.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,47 @@ | ||
package app.priceguard.ui | ||
|
||
import android.app.Dialog | ||
import android.os.Bundle | ||
import androidx.fragment.app.DialogFragment | ||
import app.priceguard.R | ||
import app.priceguard.ui.data.DialogConfirmAction | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
|
||
class ConfirmDialogFragment : DialogFragment() { | ||
|
||
private lateinit var title: String | ||
private lateinit var message: String | ||
private lateinit var action: DialogConfirmAction | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
title = arguments?.getString("title") ?: "" | ||
message = arguments?.getString("message") ?: "" | ||
|
||
val actionString = arguments?.getString("actionString") | ||
actionString?.let { actionString -> | ||
action = DialogConfirmAction.valueOf(actionString) | ||
}?.run { | ||
DialogConfirmAction.NOTHING | ||
} | ||
|
||
return MaterialAlertDialogBuilder( | ||
requireActivity(), | ||
R.style.ThemeOverlay_App_MaterialAlertDialog | ||
).apply { | ||
setTitle(title) | ||
setMessage(message) | ||
setPositiveButton(getString(R.string.confirm)) { _, _ -> | ||
when (action) { | ||
DialogConfirmAction.FINISH -> requireActivity().finish() | ||
DialogConfirmAction.NOTHING -> {} | ||
} | ||
dismiss() | ||
} | ||
}.create() | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
dialog?.setCancelable(false) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
android/app/src/main/java/app/priceguard/ui/ErrorDialogFragment.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,45 @@ | ||
package app.priceguard.ui | ||
|
||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.fragment.app.DialogFragment | ||
import app.priceguard.R | ||
import app.priceguard.data.repository.token.TokenRepository | ||
import app.priceguard.ui.login.LoginActivity | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
class ErrorDialogFragment : DialogFragment() { | ||
|
||
@Inject | ||
lateinit var tokenRepository: TokenRepository | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
return MaterialAlertDialogBuilder( | ||
requireActivity(), | ||
R.style.ThemeOverlay_App_MaterialAlertDialog | ||
).apply { | ||
setTitle(getString(R.string.permission_denied_title)) | ||
setMessage(getString(R.string.permission_denied_message)) | ||
setPositiveButton(getString(R.string.confirm)) { _, _ -> goBackToLoginActivity(tokenRepository) } | ||
}.create() | ||
} | ||
|
||
override fun onDismiss(dialog: DialogInterface) { | ||
super.onDismiss(dialog) | ||
goBackToLoginActivity(tokenRepository) | ||
} | ||
|
||
private fun goBackToLoginActivity(tokenRepository: TokenRepository) { | ||
CoroutineScope(Dispatchers.IO).launch { tokenRepository.clearTokens() } | ||
val intent = Intent(requireActivity(), LoginActivity::class.java) | ||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK | ||
startActivity(intent) | ||
requireActivity().finish() | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
android/app/src/main/java/app/priceguard/ui/data/DialogConfirmAction.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,6 @@ | ||
package app.priceguard.ui.data | ||
|
||
enum class DialogConfirmAction { | ||
NOTHING, | ||
FINISH | ||
} |
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
Oops, something went wrong.