Skip to content

Commit

Permalink
fix/#5: 마이페이지 데이터 미전달 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeeum committed Apr 14, 2024
1 parent f6a8a70 commit b379d72
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
23 changes: 15 additions & 8 deletions app/src/main/java/com/sopt/now/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LoginActivity : AppCompatActivity() {
}
}
binding.btnLogin.setOnClickListener {
sendData(id,pw,nick)
moveToMain(id,pw,nick)
}
}
private fun moveToSignUp(){
Expand All @@ -62,16 +62,23 @@ class LoginActivity : AppCompatActivity() {
Toast.makeText(this,message,Toast.LENGTH_SHORT).show()
return loginBool
}
private fun sendData(id:String,pw:String,nick:String){
private fun moveToMain(id:String,pw:String,nick:String){
if (isLoginAvailable(id, pw)) {
val intent = Intent(this, MainActivity::class.java)
val mypagefragment = MyPageFragment()
val bundle = Bundle()
bundle.putString("id",id)
bundle.putString("pw",pw)
bundle.putString("nick",nick)
mypagefragment.arguments = bundle
saveUserInfo(id,pw,nick)
startActivity(intent)
}
}
private fun saveUserInfo(id:String,pw:String,nick:String) {
if (isLoginAvailable(id, pw)) {
val sharedPreferences = getSharedPreferences("userInfo", MODE_PRIVATE)
val editor = sharedPreferences.edit()

editor
.putString("userId", id)
.putString("userPw", pw)
.putString("userNick", nick)
.apply()
}
}
}
16 changes: 6 additions & 10 deletions app/src/main/java/com/sopt/now/MyPageFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sopt.now

import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
Expand All @@ -10,13 +12,6 @@ import com.sopt.now.databinding.FragmentMyPageBinding
class MyPageFragment : Fragment() {
private lateinit var binding: FragmentMyPageBinding

private var param1: String? = null
private var param2: String? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -26,8 +21,9 @@ class MyPageFragment : Fragment() {
return binding.root
}
private fun getUserInfo() {
binding.tvMainNick.text = arguments?.getString("nick")
binding.tvMainId.text = arguments?.getString("id")
binding.tvMainPw.text = arguments?.getString("pw")
val userInfo = activity?.getSharedPreferences("userInfo",Context.MODE_PRIVATE)
binding.tvMainNick.text = userInfo?.getString("userNick","")
binding.tvMainId.text = userInfo?.getString("userId","")
binding.tvMainPw.text = userInfo?.getString("userPw","")
}
}

0 comments on commit b379d72

Please sign in to comment.