Skip to content

Commit

Permalink
feat: use DialogUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
HI-JIN2 committed May 14, 2024
1 parent b7ec754 commit a9a2558
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 50 deletions.
90 changes: 42 additions & 48 deletions app/src/main/java/com/eatssu/android/ui/mypage/MyPageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.eatssu.android.BuildConfig
Expand All @@ -19,8 +18,9 @@ import com.eatssu.android.ui.mypage.inquire.InquireActivity
import com.eatssu.android.ui.mypage.myreview.MyReviewListActivity
import com.eatssu.android.ui.mypage.terms.WebViewActivity
import com.eatssu.android.ui.mypage.usernamechange.UserNameChangeActivity
import com.eatssu.android.util.extension.showToast
import com.eatssu.android.util.extension.startActivity
import com.eatssu.android.util.DialogUtil
import com.eatssu.android.util.showToast
import com.eatssu.android.util.startActivity
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -116,7 +116,6 @@ class MyPageActivity : BaseActivity<ActivityMyPageBinding>(ActivityMyPageBinding
}

private fun initViewModel() { //Todo ๋ฆฌํŒฉํ† ๋งํ•˜๊ธฐ

firebaseRemoteConfigRepository = FirebaseRemoteConfigRepository()

versionViewModel = ViewModelProvider(
Expand All @@ -129,61 +128,56 @@ class MyPageActivity : BaseActivity<ActivityMyPageBinding>(ActivityMyPageBinding

private fun showLogoutDialog() {

// ๋‹ค์ด์–ผ๋กœ๊ทธ๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด Builder ํด๋ž˜์Šค ์ƒ์„ฑ์ž๋ฅผ ์ด์šฉํ•ด ์ค๋‹ˆ๋‹ค.
val builder = AlertDialog.Builder(this)
builder.setTitle("๋กœ๊ทธ์•„์›ƒ")
.setMessage("๋กœ๊ทธ์•„์›ƒ ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?")
.setPositiveButton(
"๋กœ๊ทธ์•„์›ƒ"
) { _, _ ->
//๋กœ๊ทธ์•„์›ƒ
myPageViewModel.loginOut()

lifecycleScope.launch {
myPageViewModel.uiState.collectLatest {
if (it.isLoginOuted) {
showToast(it.toastMessage)
startActivity<LoginActivity>()
finishAffinity()
}

DialogUtil.createDialogWithCancelButton(
"๋กœ๊ทธ์•„์›ƒ",
this@MyPageActivity,
"๋กœ๊ทธ์•„์›ƒ ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?",
"์ทจ์†Œ",
"๋กœ๊ทธ์•„์›ƒ"
) { _, _ ->
// ActivityCompat.finishAffinity(this)
// exitProcess(0)
//๋กœ๊ทธ์•„์›ƒ
myPageViewModel.loginOut()

lifecycleScope.launch {
myPageViewModel.uiState.collectLatest {
if (it.isLoginOuted) {
showToast(it.toastMessage)
startActivity<LoginActivity>()
finishAffinity()
}

}
}
.setNegativeButton("์ทจ์†Œ") { _, _ ->
}
// ๋‹ค์ด์–ผ๋กœ๊ทธ๋ฅผ ๋„์›Œ์ฃผ๊ธฐ
builder.show()
}
}

private fun showSignoutDialog() {

// ๋‹ค์ด์–ผ๋กœ๊ทธ๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด Builder ํด๋ž˜์Šค ์ƒ์„ฑ์ž๋ฅผ ์ด์šฉํ•ด ์ค๋‹ˆ๋‹ค.
val builder = AlertDialog.Builder(this)
builder.setTitle("ํƒˆํ‡ดํ•˜๊ธฐ")
.setMessage("ํƒˆํ‡ด ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?")
.setPositiveButton(
"ํƒˆํ‡ดํ•˜๊ธฐ"
) { _, _ ->
//ํƒˆํ‡ด์ฒ˜๋ฆฌ
myPageViewModel.signOut()

lifecycleScope.launch {
myPageViewModel.uiState.collectLatest {
if (it.isSignOuted) {
showToast(it.toastMessage)
startActivity<LoginActivity>()
finishAffinity()
}
private fun showSignoutDialog() {
DialogUtil.createDialogWithCancelButton(
"ํƒˆํ‡ดํ•˜๊ธฐ",
this@MyPageActivity,
"ํƒˆํ‡ด ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?",
"์ทจ์†Œ",
"ํƒˆํ‡ดํ•˜๊ธฐ"
) { _, _ ->
// ActivityCompat.finishAffinity(this)
// exitProcess(0)
myPageViewModel.signOut()

lifecycleScope.launch {
myPageViewModel.uiState.collectLatest {
if (it.isSignOuted) {
showToast(it.toastMessage)
startActivity<LoginActivity>()
finishAffinity()
}

}
}
}
.setNegativeButton("์ทจ์†Œ") { _, _ ->
}
// ๋‹ค์ด์–ผ๋กœ๊ทธ๋ฅผ ๋„์›Œ์ฃผ๊ธฐ
builder.show()
}


private fun moveToPlayStore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ class MyReviewDialogActivity : AppCompatActivity() {
}

private fun showReviewDeleteDialog() {
DialogUtil.createDialog(
"๋ฆฌ๋ทฐ ์‚ญ์ œ", "์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๋ฅผ ์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?", this@MyReviewDialogActivity,
DialogUtil.createDialogWithCancelButton(
"๋ฆฌ๋ทฐ ์‚ญ์ œ",
this@MyReviewDialogActivity,
"์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๋ฅผ ์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?",
"์ทจ์†Œ",
"์‚ญ์ œ"
) { _, _ ->
// ActivityCompat.finishAffinity(this)
// exitProcess(0)
viewModel.postData(reviewId)
finish()
}
Expand Down
133 changes: 133 additions & 0 deletions app/src/main/java/com/eatssu/android/util/DialogUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.eatssu.android.util

import android.app.AlertDialog
import android.content.Context
import android.content.DialogInterface

object DialogUtil {

// fun createDialog(positiveMessage: String,
// message: String,
// context: Context,
// listener: DialogInterface.OnClickListener? = null
// ) {
// var builder: AlertDialog.Builder = AlertDialog.Builder(context)
// builder.setMessage(message)
// builder.setPositiveButton(positiveMessage, listener) { dialogInterface, i ->
// dialogInterface.dismiss()
// }
// builder.create().show()
// }


fun createDialogWithTitleAndMessage(
title: String,
message: String,
context: Context,
listener: DialogInterface.OnClickListener? = null,
) {
var builder: AlertDialog.Builder = AlertDialog.Builder(context)
builder.setTitle(title)
builder.setMessage(message)
builder.setPositiveButton("ํ™•์ธ", listener)
builder.create().show()
}


fun createDialogWithMessage(message: String, context: Context) {
var builder: AlertDialog.Builder = AlertDialog.Builder(context)
builder.setMessage(message)
builder.setPositiveButton("ํ™•์ธ") { dialogInterface, i ->
dialogInterface.dismiss()
}
builder.create().show()
}

// fun createDialogWithTitleAndMessage(
// title: String,
// message: String,
// context: Context,
// listener: DialogInterface.OnClickListener? = null,
// ) {
// var builder: AlertDialog.Builder = AlertDialog.Builder(context)
// builder.setTitle(title)
// builder.setMessage(message)
// builder.setPositiveButton("ํ™•์ธ", listener)
// builder.create().show()
// }

fun createDialogWithCancelButton(
title: String,
context: Context,
message: String? = null,
cancelText: String,
confirmText: String,
positiveButtonListener: DialogInterface.OnClickListener? = null,
negativeButtonListener: DialogInterface.OnClickListener? = null,
) {
var builder: AlertDialog.Builder = AlertDialog.Builder(context)
builder.setTitle(title)
builder.setCancelable(true)
if (message != null) builder.setMessage(message)
builder.setNegativeButton(cancelText, negativeButtonListener)
builder.setPositiveButton(confirmText, positiveButtonListener)
builder.create().show()
}

fun createDialogWithCancelButtonAndMessage(
title: String,
message: String,
context: Context,
cancelText: String,
confirmText: String,
listener: DialogInterface.OnClickListener? = null,
) {
var builder: AlertDialog.Builder = AlertDialog.Builder(context)
builder.setTitle(title)
builder.setMessage(message)
builder.setCancelable(true)
builder.setNegativeButton(
cancelText,
DialogInterface.OnClickListener { dialogInterface, i ->
dialogInterface.cancel()
},
)
builder.setPositiveButton(confirmText, listener)
builder.create().show()
}

// fun createDialogWithEditText(
// context: Context,
// title: String,
// callback: (String) -> Unit,
// editText: EditText? = null,
// ) {
// val builder = AlertDialog.Builder(context)
// builder.setTitle(title)
// editText?.let {
// val container = FrameLayout(context)
// val params = FrameLayout.LayoutParams(
// ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.WRAP_CONTENT,
// )
//// params.leftMargin = context.resources.getDimensionPixelSize(R.dimen.dialog_margin)
//// params.rightMargin = context.resources.getDimensionPixelSize(R.dimen.dialog_margin)
// it.layoutParams = params
// container.addView(it)
// builder.setView(container)
// }
// builder.setPositiveButton(
// "ํ™•์ธ",
// ) { dialog, which ->
// dialog.dismiss()
// editText?.let {
// val strText = editText.text.toString()
// callback.invoke(strText)
// }
// }
// builder.setNegativeButton(
// "์ทจ์†Œ",
// ) { dialog, which -> dialog.cancel() }
// builder.show()
// }
}

0 comments on commit a9a2558

Please sign in to comment.