Skip to content

Commit

Permalink
Feat: 로그아웃 시 로그인에서 모달 띄우기
Browse files Browse the repository at this point in the history
  • Loading branch information
dkyuuum committed Feb 16, 2024
1 parent dd4f5da commit 50602cb
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 13 deletions.
24 changes: 24 additions & 0 deletions app/src/main/java/umc/com/mobile/project/ui/login/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package umc.com.mobile.project.ui.login

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.view.KeyEvent
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import umc.com.mobile.project.MainActivity
import umc.com.mobile.project.R
import umc.com.mobile.project.databinding.ActivityLoginBinding
import umc.com.mobile.project.ui.login.viewmodel.LoginViewModel
import kotlin.coroutines.coroutineContext
Expand Down Expand Up @@ -56,6 +59,27 @@ class LoginActivity : AppCompatActivity() {
}
false
}

// 이전 화면에서 로그아웃을 통해 돌아온 경우 다이얼로그 표시
val isLoggedOut = intent.getBooleanExtra("logged_out", false)
if (isLoggedOut) {
showLogoutDialog()
}
}

private fun showLogoutDialog() {
var dialogBuilder =
AlertDialog.Builder(this, R.style.CustomAlertDialogTheme)

val customView = layoutInflater.inflate(R.layout.custom_dialog_logout_home, null)
dialogBuilder.setView(customView)

val dialog = dialogBuilder.create()
dialog.show()

Handler().postDelayed({
dialog.dismiss()
}, 2000)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
Expand Down Expand Up @@ -35,7 +36,8 @@ class SettingFragment : Fragment() {

viewModel.userInfoResponse.observe(viewLifecycleOwner, Observer {
binding.tvAccountIdContent.text = it?.result?.id.toString()
binding.tvAccountMajorContent.text = "1트랙: ${it?.result?.track1} / 트랙: ${it?.result?.track2}"
binding.tvAccountMajorContent.text =
"1트랙: ${it?.result?.track1} / 트랙: ${it?.result?.track2}"
})

return binding.root
Expand All @@ -52,25 +54,29 @@ class SettingFragment : Fragment() {
}

binding.tvEtcLogout.setOnClickListener {
var dialog = AlertDialog.Builder(requireContext())
dialog.setTitle("로그아웃을 하시겠습니까?")
dialog.setMessage("서비스를 이용해주셔서 감사합니다.")
var dialogBuilder =
AlertDialog.Builder(requireContext(), R.style.CustomAlertDialogTheme)

fun toast() {
Toast.makeText(requireContext(), "로그아웃 되었습니다.", Toast.LENGTH_SHORT).show()
val customView = layoutInflater.inflate(R.layout.custom_dialog_logout, null)
dialogBuilder.setView(customView)
val alertDialog = dialogBuilder.create()

alertDialog.show()

customView.findViewById<Button>(R.id.button_positive).setOnClickListener {
// Toast.makeText(requireContext(), "로그아웃 되었습니다.", Toast.LENGTH_SHORT).show()
val intent = Intent(requireContext(), LoginActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
intent.putExtra("logged_out", true)
startActivity(intent)
requireActivity().finish()
}
var dialogLister = DialogInterface.OnClickListener { p0, p1 ->
when (p1) {
DialogInterface.BUTTON_POSITIVE -> toast()
}

customView.findViewById<Button>(R.id.button_negative).setOnClickListener {
alertDialog.dismiss()
}
dialog.setPositiveButton("YES", dialogLister)
dialog.setNegativeButton("NO", null)
dialog.show()

}

}
}
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/bg_dialog_black_47.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="#78000000" /> <!-- 검정색의 투명도를 나타내는 78(47) + 검정색 값 -->
</shape>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/custom_dialog_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="#FFFFFF" />
</shape>
48 changes: 48 additions & 0 deletions app/src/main/res/layout/custom_dialog_logout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_solid_white_radius_20"
android:orientation="vertical">

<TextView
android:id="@+id/textView_message"
style="@style/SemiBoldFont.16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="21dp"
android:text="포어그래드에서\n로그아웃 하시겠습니까?"
android:textColor="@android:color/black" />

<!-- 버튼들 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button_positive"
style="@style/SemiBoldFont.16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="9dp"
android:background="@drawable/bg_solid_white_radius_20"
android:stateListAnimator="@null"
android:padding="15dp"
android:text="로그아웃"
android:textColor="@color/skyBlue" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button_negative"
style="@style/SemiBoldFont.16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_solid_white_radius_20"
android:stateListAnimator="@null"
android:padding="15dp"
android:text="닫기"
android:textColor="@color/black" />
</LinearLayout>
</LinearLayout>
26 changes: 26 additions & 0 deletions app/src/main/res/layout/custom_dialog_logout_home.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_dialog_black_47"
android:orientation="vertical">

<TextView
android:id="@+id/textView_message"
style="@style/SemiBoldFont.16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="38dp"
android:layout_marginEnd="38dp"
android:gravity="center"
android:padding="21dp"
android:text="로그아웃 되었습니다."
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@
<style name="FullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowFullscreen">true</item>
</style>

<!-- 커스텀 다이얼로그 -->
<style name="CustomAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:background">@drawable/custom_dialog_background</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
</resources>

0 comments on commit 50602cb

Please sign in to comment.