diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0df362a..d02799b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,9 +12,9 @@ (R.layout.fragment_home) { override fun FragmentHomeBinding.onCreateView(){ binding.homeUserHiTv.text = getString(R.string.home_user_hi).format(InfraApplication.prefs.getString("userNickName", "null")) + Glide.with(requireActivity()) + .load(InfraApplication.prefs.getString("userProfileImg", "null")) + .circleCrop() + .error(R.drawable.user_photo) + .into(binding.homeUserPhotoIv) } override fun FragmentHomeBinding.onViewCreated() { diff --git a/app/src/main/java/com/example/infraandroid/id/model/ResponseLoginData.kt b/app/src/main/java/com/example/infraandroid/id/model/ResponseLoginData.kt index e8ec0c7..1b6b7d8 100644 --- a/app/src/main/java/com/example/infraandroid/id/model/ResponseLoginData.kt +++ b/app/src/main/java/com/example/infraandroid/id/model/ResponseLoginData.kt @@ -18,6 +18,8 @@ data class ResponseLoginData( @SerializedName("user_nickname") val userNickName : String, @SerializedName("jwtRefreshIdx") - val refreshToken : Int + val refreshToken : Int, + @SerializedName("user_prPhoto") + val userProfileImg : String ) } diff --git a/app/src/main/java/com/example/infraandroid/id/view/LoginFragment.kt b/app/src/main/java/com/example/infraandroid/id/view/LoginFragment.kt index 522810c..1f2c8c6 100644 --- a/app/src/main/java/com/example/infraandroid/id/view/LoginFragment.kt +++ b/app/src/main/java/com/example/infraandroid/id/view/LoginFragment.kt @@ -90,6 +90,7 @@ class LoginFragment : BaseFragment(R.layout.fragment_login InfraApplication.prefs.setString("refreshToken", response.body()?.result?.refreshToken.toString()) InfraApplication.prefs.setString("userId", response.body()?.result?.userId.toString()) InfraApplication.prefs.setString("userNickName", response.body()?.result?.userNickName.toString()) + InfraApplication.prefs.setString("userProfileImg", response.body()?.result?.userProfileImg.toString()) InfraApplication.prefs.setUserId(response.body()?.result?.userId.toString()) InfraApplication.prefs.setUserPW(inputPw) Toast.makeText(requireActivity(),"요청에 성공하셨습니다.", Toast.LENGTH_SHORT).show() diff --git a/app/src/main/java/com/example/infraandroid/myinfo/MyInfoFragment.kt b/app/src/main/java/com/example/infraandroid/myinfo/MyInfoFragment.kt index d7afbaa..9485afb 100644 --- a/app/src/main/java/com/example/infraandroid/myinfo/MyInfoFragment.kt +++ b/app/src/main/java/com/example/infraandroid/myinfo/MyInfoFragment.kt @@ -1,13 +1,16 @@ package com.example.infraandroid.myinfo import android.content.Intent +import android.net.Uri import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Toast import androidx.fragment.app.Fragment import androidx.navigation.findNavController import androidx.navigation.fragment.findNavController +import com.bumptech.glide.Glide import com.example.infraandroid.util.InfraApplication import com.example.infraandroid.R import com.example.infraandroid.databinding.FragmentMyInfoBinding @@ -34,6 +37,15 @@ class MyInfoFragment : Fragment() { mBinding = binding mBinding?.myInfoUserNameTv?.text = getString(R.string.my_info_name).format(InfraApplication.prefs.getString("userNickName","null")) + + mBinding?.myInfoUserProfileIv?.let { + Glide.with(requireActivity()) + .load(InfraApplication.prefs.getString("userProfileImg", "null")) + .circleCrop() + .error(R.drawable.user_photo) + .into(it) + } + return mBinding?.root } @@ -75,6 +87,17 @@ class MyInfoFragment : Fragment() { val intent = Intent(this.context, OssLicensesMenuActivity::class.java) startActivity(intent) } + + mBinding!!.csLinearLayout.setOnClickListener { + Toast.makeText(requireActivity(), "인프라 고객센터 이메일\n" + + "official.infra.app@gmail.com", Toast.LENGTH_LONG).show() + } + + mBinding!!.serviceLinearLayout.setOnClickListener { + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://chrome-fortnight-803.notion.site/41f70ebd4eed4b40928815e7e1796466")) + startActivity(intent) + } + } override fun onDestroyView() { diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectViewModel.kt b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectViewModel.kt index 21c8c79..b3df099 100644 --- a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectViewModel.kt +++ b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectViewModel.kt @@ -49,6 +49,17 @@ class MyProjectViewModel : ViewModel() { private val _currentDay = MutableLiveData() val currentDay: LiveData = _currentDay + private val _currentProjectPhotoStatus = MutableLiveData(null) + val currentProjectPhotoStatus: LiveData = _currentProjectPhotoStatus + + fun deleteProjectPhoto(){ + _currentProjectPhotoStatus.value = "삭제" + } + + fun updateProjectPhoto(){ + _currentProjectPhotoStatus.value = "등록" + } + fun updateObservingProjectNum(projectNum: Int?){ _currentObservingProjectNum.value = projectNum!! } diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaModifyPageFragment.kt b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaModifyPageFragment.kt index feadf19..d1d11d0 100644 --- a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaModifyPageFragment.kt +++ b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaModifyPageFragment.kt @@ -300,6 +300,7 @@ class MyIdeaModifyPageFragment : BaseFragment = ServiceCreator.myProjectService @@ -401,6 +406,7 @@ class MyIdeaModifyPageFragment : BaseFragment + @Multipart @PATCH("/user/profile/info/{id}") - fun ModifyMyInfo( + fun modifyMyInfo( @Header("X-ACCESS-TOKEN") jwt: String, - @Path("id") userId : String - ): Call - + @Path("id") userId : String, + @Part("user_nickname") userNickName : RequestBody, + @Part("user_prPhoto") userProfileStatus : RequestBody, + @Part images: MultipartBody.Part? + ): Call } \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/model/RequestModifyMyInfoData.kt b/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/model/ResponseModifyMyInfoData.kt similarity index 80% rename from app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/model/RequestModifyMyInfoData.kt rename to app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/model/ResponseModifyMyInfoData.kt index e729c71..a5ebf60 100644 --- a/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/model/RequestModifyMyInfoData.kt +++ b/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/model/ResponseModifyMyInfoData.kt @@ -1,6 +1,6 @@ package com.example.infraandroid.myinfo.myinfomodify.model -data class RequestModifyMyInfoData( +data class ResponseModifyMyInfoData( val isSuccess: Boolean, val code: Int, val message: String, diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/view/MyInfoModifyFragment.kt b/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/view/MyInfoModifyFragment.kt index fd3161f..0826bcf 100644 --- a/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/view/MyInfoModifyFragment.kt +++ b/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/view/MyInfoModifyFragment.kt @@ -1,12 +1,9 @@ package com.example.infraandroid.myinfo.myinfomodify.view -import android.os.Bundle +import android.content.ContentValues.TAG import android.text.Editable import android.text.TextWatcher import android.util.Log -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup import android.widget.EditText import android.widget.ImageView import android.widget.TextView @@ -14,130 +11,181 @@ import android.widget.Toast import androidx.appcompat.widget.AppCompatButton import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.isVisible -import androidx.fragment.app.Fragment +import androidx.lifecycle.ViewModelProvider import androidx.navigation.findNavController +import com.bumptech.glide.Glide import com.example.infraandroid.R import com.example.infraandroid.databinding.FragmentMyInfoModifyBinding -import com.example.infraandroid.id.viewmodel.SignUpViewModel -import com.example.infraandroid.myinfo.myinfomodify.model.RequestModifyMyInfoData +import com.example.infraandroid.myinfo.myideamanage.model.MyProjectViewModel import com.example.infraandroid.myinfo.myinfomodify.model.RequestNicknameCheckData +import com.example.infraandroid.myinfo.myinfomodify.model.ResponseModifyMyInfoData import com.example.infraandroid.myinfo.myinfomodify.model.ResponseNicknameCheckData import com.example.infraandroid.myinfo.myinfomodify.model.ResponseViewMyInfoData +import com.example.infraandroid.myinfo.myinfomodify.viewmodel.MyInfoViewModel import com.example.infraandroid.util.BaseFragment import com.example.infraandroid.util.InfraApplication import com.example.infraandroid.util.ServiceCreator +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.MultipartBody +import okhttp3.RequestBody.Companion.asRequestBody +import okhttp3.RequestBody.Companion.toRequestBody import retrofit2.Call import retrofit2.Callback import retrofit2.Response +import java.io.File //내 정보 > 내 정보 .kt class MyInfoModifyFragment : BaseFragment(R.layout.fragment_my_info_modify) { /*private var mBinding : FragmentMyInfoModifyBinding? = null*/ + private lateinit var viewModel : MyInfoViewModel private var isChecked = false + private var profileImgStatus : String = "등록" private var userNickname : String ?= null private var userPrPhoto : String ?= null + private var fileToUpload : MultipartBody.Part? = null override fun FragmentMyInfoModifyBinding.onCreateView() { + binding.inputNicknameEditText.text = InfraApplication.prefs.getString("userNickName", "null") + activity?.run{ + viewModel = ViewModelProvider(this, ViewModelProvider.NewInstanceFactory()) + .get(MyInfoViewModel::class.java) + } + + if(viewModel.currentImgBitmap.value==null){ + Glide.with(this@MyInfoModifyFragment) + .load(InfraApplication.prefs.getString("userProfileImg", "null")) + .circleCrop() + .error(R.drawable.user_photo) + .into(binding.myInfoModifyUserProfileIv) + } + else{ + Glide.with(this@MyInfoModifyFragment) + .load(viewModel.currentImgBitmap.value) + .circleCrop() + .error(R.drawable.user_photo) + .into(binding.myInfoModifyUserProfileIv) + } } override fun FragmentMyInfoModifyBinding.onViewCreated() { - val inputNicknameEditText = binding.inputNicknameEditText as EditText - val myInfoModifyBackButton = binding.myInfoModifyBackButton as ImageView - val myInfoModifyUserProfileLayout = binding.myInfoModifyUserProfileLayout as ConstraintLayout - val overlapCheckButton = binding.overlapCheckButton as AppCompatButton + val myInfoModifyBackButton = binding.myInfoModifyBackButton + val myInfoModifyUserProfileLayout = binding.myInfoModifyUserProfileLayout +// val overlapCheckButton = binding.overlapCheckButton as AppCompatButton val modifyCompletedButton = binding.modifyCompletedButton as TextView - val doNotUseThisNicknameTextView = binding.doNotUseThisNicknameTextView as TextView - val canUserIcon = binding.canUseIconImageView +// val doNotUseThisNicknameTextView = binding.doNotUseThisNicknameTextView as TextView +// val canUserIcon = binding.canUseIconImageView //내 정보 보기 서버 연결 - val viewcall: Call = ServiceCreator.myinfoService - .viewMyInfo(InfraApplication.prefs.getString("jwt","null"), - InfraApplication.prefs.getString("userId","null")) - - viewcall.enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response - ) { - if(response.isSuccessful){ - when(response.body()?.code){ - 1000 -> { - binding.myInfoModify = response.body()?.result - //userNickname = response.body()?.result?.user_nickname - - //userPrPhoto = response.body()?.result?.user_prPhoto +// val viewcall: Call = ServiceCreator.myinfoService +// .viewMyInfo(InfraApplication.prefs.getString("jwt","null"), +// InfraApplication.prefs.getString("userId","null")) +// +// viewcall.enqueue(object : Callback { +// override fun onResponse( +// call: Call, +// response: Response +// ) { +// if(response.isSuccessful){ +// when(response.body()?.code){ +// 1000 -> { +// binding.inputNicknameEditText.setText(response.body()?.result?.user_nickname) +// +// Glide.with(this@MyInfoModifyFragment) +// .load(response.body()?.result?.user_prPhoto) +// .circleCrop() +// .error(R.drawable.user_photo) +// .into(binding.myInfoModifyUserProfileIv) +// } +// } +// } +// +// } +// +// override fun onFailure(call: Call, t: Throwable) { +// Log.d("TAG","Failed : $t") +// } +// +// } ) - } - } - } - - } - - override fun onFailure(call: Call, t: Throwable) { - Log.d("TAG","Failed : $t") + //닉네임 중복 서버 연결 +// overlapCheckButton.setOnClickListener { +// val requestNicknameCheckData = RequestNicknameCheckData( +// userNickname = inputNicknameEditText.text.toString(), +// ) +// +// val checkcall: Call = ServiceCreator.nicknameDoubleCheckService +// .doublecheck(requestNicknameCheckData) +// checkcall.enqueue(object : Callback{ +// override fun onResponse( +// call: Call, +// response: Response +// ) { +// if(response.isSuccessful){ +// val data = response.body()?.code +// if(data==1000) { +// isChecked = true +// doNotUseThisNicknameTextView.isVisible = false +// canUserIcon.isVisible = true +// inputNicknameEditText.setBackgroundResource(R.drawable.can_use_this_id_background) +// } +// if(data==3104){ +// doNotUseThisNicknameTextView.isVisible = true +// canUserIcon.isVisible = false +// inputNicknameEditText.setBackgroundResource(R.drawable.double_check_id_background) +// } +// } +// } +// +// override fun onFailure(call: Call, t: Throwable) { +// +// } +// +// }) +// +// } + + + binding.modifyCompletedButton.setOnClickListener { + fileToUpload = if (viewModel.currentImg.value != null){ + val file = File(viewModel.currentImg.value) + val requestBody = file.asRequestBody("image/jpeg".toMediaTypeOrNull()) + MultipartBody.Part.createFormData("images", file.name, requestBody) + } else{ + null } - } ) - - //닉네임 중복 서버 연결 - overlapCheckButton.setOnClickListener { - val requestNicknameCheckData = RequestNicknameCheckData( - userNickname = inputNicknameEditText.text.toString(), - ) - - val checkcall: Call = ServiceCreator.nicknameDoubleCheckService - .doublecheck(requestNicknameCheckData) - checkcall.enqueue(object : Callback{ + //내 정보 수정 서버 연결 + val modifycall: Call = ServiceCreator.myinfoService + .modifyMyInfo(InfraApplication.prefs.getString("jwt", "null"), InfraApplication.prefs.getString("userId", "null"), + InfraApplication.prefs.getString("userNickName", "null").toRequestBody("text/plain".toMediaTypeOrNull()), viewModel.currentProfileImgStatus.value.toString().toRequestBody("text/plain".toMediaTypeOrNull()), + fileToUpload) + modifycall.enqueue(object : Callback { override fun onResponse( - call: Call, - response: Response + call: Call, + response: Response ) { if(response.isSuccessful){ - val data = response.body()?.code - if(data==1000) { - isChecked = true - doNotUseThisNicknameTextView.isVisible = false - canUserIcon.isVisible = true - inputNicknameEditText.setBackgroundResource(R.drawable.can_use_this_id_background) - } - if(data==3104){ - doNotUseThisNicknameTextView.isVisible = true - canUserIcon.isVisible = false - inputNicknameEditText.setBackgroundResource(R.drawable.double_check_id_background) + when(response.body()?.code){ + 1000->{ + Log.d(TAG, "onResponse: 성공") + } + else->{ + Log.d(TAG, "onResponse: 실패${response.body()?.code}") + } } } } - override fun onFailure(call: Call, t: Throwable) { - + override fun onFailure(call: Call, t: Throwable) { + Log.d("TAG","Failed : $t") } }) + it.findNavController().navigate(R.id.action_my_info_modify_fragment_to_my_info_fragment) } - //내 정보 수정 서버 연결 - val modifycall: Call = ServiceCreator.myinfoService - .ModifyMyInfo("jwt","userId") - modifycall.enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response - ) { - if(response.isSuccessful){ - when(response.body()?.code){ - - } - } - } - - override fun onFailure(call: Call, t: Throwable) { - Log.d("TAG","Failed : $t") - } - - }) - //프로필 사진 추가 바텀싵 val bottomSheetDialogFragment = MyInfoPhotoMoreMenuBottomSheetFragment() myInfoModifyUserProfileLayout.setOnClickListener { @@ -149,61 +197,55 @@ class MyInfoModifyFragment : BaseFragment(R.layout. it.findNavController().navigate(R.id.action_my_info_modify_fragment_to_my_info_fragment) } - // 수정완료 버튼 눌렀을때 - modifyCompletedButton.setOnClickListener { - //값 저장해서 넘겨주는 내용의 코드 - it.findNavController().navigate(R.id.action_my_info_modify_fragment_to_my_info_fragment) - } - - //닉네임 중복 버튼 활성화 설정 - inputNicknameEditText.addTextChangedListener(object: TextWatcher{ - override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { - overlapCheckButton.isEnabled = false - } - - override fun afterTextChanged(p0: Editable?) { - /*inputNicknameEditText.length() < 12 && inputNicknameEditText.length()>0*/ - if (inputNicknameEditText.length() < 12) { - overlapCheckButton.isEnabled = true - } else { - //Toast.makeText(requireActivity(), "12자 이하로 입력해주세요.", Toast.LENGTH_SHORT).show() - } - } - - override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { - //얘네는 나중에 수정 필요 - if (inputNicknameEditText.length() < 12) { - overlapCheckButton.isEnabled = true - } else { - Toast.makeText(requireActivity(), "12자 이하로 입력해주세요.", Toast.LENGTH_SHORT).show() - } - } - }) +// //닉네임 중복 버튼 활성화 설정 +// inputNicknameEditText.addTextChangedListener(object: TextWatcher{ +// override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { +// overlapCheckButton.isEnabled = false +// } +// +// override fun afterTextChanged(p0: Editable?) { +// /*inputNicknameEditText.length() < 12 && inputNicknameEditText.length()>0*/ +// if (inputNicknameEditText.length() < 12) { +// overlapCheckButton.isEnabled = true +// } else { +// //Toast.makeText(requireActivity(), "12자 이하로 입력해주세요.", Toast.LENGTH_SHORT).show() +// } +// } +// +// override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { +// //얘네는 나중에 수정 필요 +// if (inputNicknameEditText.length() < 12) { +// overlapCheckButton.isEnabled = true +// } else { +// Toast.makeText(requireActivity(), "12자 이하로 입력해주세요.", Toast.LENGTH_SHORT).show() +// } +// } +// }) //수정 완료 버튼 활성화 설정 - inputNicknameEditText.addTextChangedListener(object: TextWatcher{ - override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { - modifyCompletedButton.isEnabled = false - } - - override fun afterTextChanged(p0: Editable?) { - /*inputNicknameEditText.length() < 12 && inputNicknameEditText.length()>0*/ - if (inputNicknameEditText.length() < 12 && isChecked) { - modifyCompletedButton.isEnabled = true - } else { - Toast.makeText(requireActivity(), "12자 이하로 입력해주세요.", Toast.LENGTH_SHORT).show() - } - } - - override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { - //얘네는 나중에 수정 필요 - if (inputNicknameEditText.length() < 12 && isChecked) { - modifyCompletedButton.isEnabled = true - } else { - Toast.makeText(requireActivity(), "12자 이하로 입력해주세요.", Toast.LENGTH_SHORT).show() - } - } - }) +// inputNicknameEditText.addTextChangedListener(object: TextWatcher{ +// override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { +// modifyCompletedButton.isEnabled = false +// } +// +// override fun afterTextChanged(p0: Editable?) { +// /*inputNicknameEditText.length() < 12 && inputNicknameEditText.length()>0*/ +// if (inputNicknameEditText.length() < 12 && isChecked) { +// modifyCompletedButton.isEnabled = true +// } else { +// Toast.makeText(requireActivity(), "12자 이하로 입력해주세요.", Toast.LENGTH_SHORT).show() +// } +// } +// +// override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { +// //얘네는 나중에 수정 필요 +// if (inputNicknameEditText.length() < 12 && isChecked) { +// modifyCompletedButton.isEnabled = true +// } else { +// Toast.makeText(requireActivity(), "12자 이하로 입력해주세요.", Toast.LENGTH_SHORT).show() +// } +// } +// }) } diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/view/MyInfoPhotoMoreMenuBottomSheetFragment.kt b/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/view/MyInfoPhotoMoreMenuBottomSheetFragment.kt index 1d466f2..80f6d3a 100644 --- a/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/view/MyInfoPhotoMoreMenuBottomSheetFragment.kt +++ b/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/view/MyInfoPhotoMoreMenuBottomSheetFragment.kt @@ -1,16 +1,162 @@ package com.example.infraandroid.myinfo.myinfomodify.view +import android.Manifest +import android.annotation.SuppressLint +import android.app.Activity import android.app.Dialog +import android.content.Intent +import android.content.pm.PackageManager +import android.database.Cursor +import android.graphics.Bitmap +import android.graphics.ImageDecoder +import android.net.Uri +import android.os.Build +import android.os.Bundle +import android.provider.MediaStore +import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup +import android.widget.Toast +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat +import androidx.core.view.isGone +import androidx.core.view.isVisible +import androidx.lifecycle.ViewModelProvider +import androidx.navigation.fragment.findNavController +import com.bumptech.glide.Glide import com.example.infraandroid.R +import com.example.infraandroid.databinding.MyProjectMoreMenuBinding +import com.example.infraandroid.databinding.PhotoMoreMenuBinding +import com.example.infraandroid.myinfo.myideamanage.view.WarningDeleteDialog +import com.example.infraandroid.myinfo.myinfomodify.viewmodel.MyInfoViewModel import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import okhttp3.MultipartBody +import java.io.IOException //작성자 : 이은진 //작성일 : 2022.02.04 //내 정보 > 내 정보 > 프로필에 있는 + 버튼 클릭시 나오는 bottomsheet class MyInfoPhotoMoreMenuBottomSheetFragment : BottomSheetDialogFragment() { - override fun setupDialog(dialog: Dialog, style: Int) { - val contentView = View.inflate(context, R.layout.photo_more_menu, null) - dialog?.setContentView(contentView) + private lateinit var viewModel : MyInfoViewModel + private var mBinding : PhotoMoreMenuBinding? = null + private val OPEN_GALLERY = 100 + val PERMISSIONS_REQUEST_CODE = 101 + var REQUIRED_PERMISSIONS = arrayOf( Manifest.permission.READ_EXTERNAL_STORAGE) + private var mediaPath : String ?= null + private var fileToUpload : MultipartBody.Part? = null + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val binding = PhotoMoreMenuBinding.inflate(inflater, container, false) + mBinding = binding + + activity?.run{ + viewModel = ViewModelProvider(this, ViewModelProvider.NewInstanceFactory()) + .get(MyInfoViewModel::class.java) + } + + return mBinding?.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + // 앨범에서 선택 눌렀을 때 + mBinding?.findAlbumConstraintLayout?.setOnClickListener{ + requestPermission() + } + + // 프로필 사진 삭제 눌렀을 때 + mBinding?.deleteProfileConstraintLayout?.setOnClickListener { + viewModel.deleteImg() + Toast.makeText(requireContext(), "사진이 삭제되었습니다", Toast.LENGTH_SHORT).show() + dismiss() + } + } + + private fun openGallery() { + val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) + startActivityForResult(intent, OPEN_GALLERY) + } + + + private fun requestPermission(){ + var permissionCheck = ContextCompat.checkSelfPermission(requireActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) + if(permissionCheck != PackageManager.PERMISSION_GRANTED){ + //설명이 필요한지 + if(ActivityCompat.shouldShowRequestPermissionRationale(requireActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)){ + //설명 필요 (사용자가 요청을 거부한 적이 있음) + ActivityCompat.requestPermissions(requireActivity(), REQUIRED_PERMISSIONS, PERMISSIONS_REQUEST_CODE ) + }else{ + //설명 필요하지 않음 + ActivityCompat.requestPermissions(requireActivity(), REQUIRED_PERMISSIONS, PERMISSIONS_REQUEST_CODE ) + } + }else{ + //권한 허용하여 갤러리로 이동 + openGallery() + } + } + + override fun onRequestPermissionsResult( + requestCode: Int, permissions: Array, grantResults: IntArray + ) { + when(requestCode){ + PERMISSIONS_REQUEST_CODE -> { + if(grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED){ + openGallery() + }else{ + //권한 거부됨 + } + return + } + } + } + + @SuppressLint("Range") + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + + if(requestCode == OPEN_GALLERY && resultCode == Activity.RESULT_OK && data!=null){ + val selectedImage = data.data + val photoUri = data.data + try { + photoUri?.let { + var bitmap : Bitmap?= null + bitmap = if(Build.VERSION.SDK_INT < 28) { + MediaStore.Images.Media.getBitmap( + requireActivity().contentResolver, + photoUri + ) + } else { + val source = ImageDecoder.createSource(requireActivity().contentResolver, photoUri) + ImageDecoder.decodeBitmap(source) + //imageView.setImageBitmap(bitmap) + } + viewModel.updateImgBitmap(bitmap) + } + } + catch (e: IOException) { + e.printStackTrace() + } + + val cursor: Cursor = requireActivity().contentResolver.query( + Uri.parse(selectedImage.toString()), + null, + null, + null, + null + )!! + cursor.moveToFirst() + mediaPath = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA)) + viewModel.updateImg(mediaPath) + dismiss() + } + else{ + Toast.makeText(requireActivity(), "이미지 업로드 실패", Toast.LENGTH_SHORT).show() + dismiss() + } } } \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/viewmodel/MyInfoViewModel.kt b/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/viewmodel/MyInfoViewModel.kt new file mode 100644 index 0000000..5afd33b --- /dev/null +++ b/app/src/main/java/com/example/infraandroid/myinfo/myinfomodify/viewmodel/MyInfoViewModel.kt @@ -0,0 +1,31 @@ +package com.example.infraandroid.myinfo.myinfomodify.viewmodel + +import android.graphics.Bitmap +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel + +class MyInfoViewModel : ViewModel() { + private val _currentImg = MutableLiveData() + val currentImg: LiveData = _currentImg + + fun updateImg(mediaPath: String?){ + _currentImg.value = mediaPath + _currentProfileImgStatus.value = "등록" + } + + private val _currentProfileImgStatus = MutableLiveData("등록") + val currentProfileImgStatus: LiveData = _currentProfileImgStatus + + fun deleteImg(){ + _currentImg.value = null + _currentProfileImgStatus.value = "삭제" + } + + private val _currentImgBitmap = MutableLiveData(null) + val currentImgBitmap: LiveData = _currentImgBitmap + + fun updateImgBitmap(bitmap: Bitmap?){ + _currentImgBitmap.value = bitmap + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/util/SplashFragment.kt b/app/src/main/java/com/example/infraandroid/util/SplashFragment.kt index 8cbecb0..39e63b6 100644 --- a/app/src/main/java/com/example/infraandroid/util/SplashFragment.kt +++ b/app/src/main/java/com/example/infraandroid/util/SplashFragment.kt @@ -38,16 +38,14 @@ class SplashFragment : BaseFragment(R.layout.fragment_spl InfraApplication.prefs.setString("refreshToken", response.body()?.result?.refreshToken.toString()) InfraApplication.prefs.setString("userId", response.body()?.result?.userId.toString()) InfraApplication.prefs.setString("userNickName", response.body()?.result?.userNickName.toString()) + InfraApplication.prefs.setString("userProfileImg", response.body()?.result?.userProfileImg.toString()) Toast.makeText(requireActivity(),"요청에 성공하셨습니다.", Toast.LENGTH_SHORT).show() // 로그인 버튼을 누르면 home_fragment로 이동 findNavController().navigate(R.id.action_splashFragment_to_home_fragment) } - 2001 -> { - Toast.makeText(requireActivity(),"id가 비어있습니다.", Toast.LENGTH_SHORT).show()} - 3014 -> { - Toast.makeText(requireActivity(),"없는 아이디거나 비밀번호가 틀렸습니다.", Toast.LENGTH_SHORT).show()} - 4000 -> { - Toast.makeText(requireActivity(),"데이터베이스 연결에 실패하였습니다.", Toast.LENGTH_SHORT).show()} + else -> { + findNavController().navigate(R.id.action_splashFragment_to_login_fragment) + } } } else{ diff --git a/app/src/main/res/drawable/ic_app_icon_background.xml b/app/src/main/res/drawable/ic_app_icon_background.xml new file mode 100644 index 0000000..ca3826a --- /dev/null +++ b/app/src/main/res/drawable/ic_app_icon_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml index 07d5da9..ca3826a 100644 --- a/app/src/main/res/drawable/ic_launcher_background.xml +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -1,170 +1,74 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + xmlns:android="http://schemas.android.com/apk/res/android"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index ccb79fa..10fb951 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -263,16 +263,6 @@ app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="30dp" /> - @@ -483,6 +484,7 @@ android:layout_marginStart="28dp"/> diff --git a/app/src/main/res/layout/fragment_my_info_modify.xml b/app/src/main/res/layout/fragment_my_info_modify.xml index 278bf97..fd72edc 100644 --- a/app/src/main/res/layout/fragment_my_info_modify.xml +++ b/app/src/main/res/layout/fragment_my_info_modify.xml @@ -57,7 +57,6 @@ android:id="@+id/my_info_modify_user_profile_iv" android:layout_width="91dp" android:layout_height="91dp" - loadCircleImg="@{myInfoModify.user_prPhoto}" android:src="@drawable/user_photo" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/> @@ -87,9 +86,10 @@ android:layout_marginTop="8dp" android:layout_marginStart="16dp" android:translationZ="90dp"/> - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:paddingVertical="4dp"/> diff --git a/app/src/main/res/layout/fragment_user_guide.xml b/app/src/main/res/layout/fragment_user_guide.xml index 5388861..166f6a9 100644 --- a/app/src/main/res/layout/fragment_user_guide.xml +++ b/app/src/main/res/layout/fragment_user_guide.xml @@ -106,7 +106,7 @@ android:textColor="@color/black" android:includeFontPadding="false" android:visibility="gone" - android:text="수 하는 품에 같은 피부가 능히 있으랴? 창공에 고동을 청춘의 할지라도 듣는다. 얼마나 새 동산에는 없으면, 끓는다. 가진 장식하는 이것이야말로 불어 끓는 가치를 사막이다. 과실이 날카로우나 영원히 따뜻한 장식하는 이상은 유소년에게서 오아이스도 보라. 있음으로써 무한한 노래하며 꽃이 물방아 그들에게 착목한는 때문이다. 방지하는 거선의 무엇을 꽃이 크고 힘있다. 때까지 대중을 영락과 살 만물은 약동하다. 이상은 피가 온갖 낙원을 우는 끓는 풀이 위하여서. 청춘에서만 인생의 할지니, 만물은 미묘한 이 투명하되 그리하였는가? 이는 가슴에 실로 물방아 뜨거운지라, 없으면, 그러므로 트고, 쓸쓸하랴?" + android:text="홈 화면에서 상단에 '세상을 놀라게 할 아이디어가 있으신가요?'의 프로젝트 생성을 클릭 또는 하단의 목록 카테고리를 클릭 하시면 프로젝트를 등록할 수 있습니다. 프로젝트 등록에서 프로젝트 제목, 분야, 내용 등 다양한 프로젝트를 등록 할 수 있습니다. 인프라의 홈화면에서 아이디어를 프로젝트로 구현할 수 있습니다." /> + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_app_icon_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_app_icon_round.xml new file mode 100644 index 0000000..6cb34a2 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_app_icon_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_main.xml similarity index 100% rename from app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml rename to app/src/main/res/mipmap-anydpi-v26/ic_main.xml diff --git a/app/src/main/res/mipmap-hdpi/ic_app_icon.png b/app/src/main/res/mipmap-hdpi/ic_app_icon.png new file mode 100644 index 0000000..abeb7cd Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_app_icon.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_app_icon_foreground.png b/app/src/main/res/mipmap-hdpi/ic_app_icon_foreground.png new file mode 100644 index 0000000..fd7462f Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_app_icon_foreground.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_app_icon_round.png b/app/src/main/res/mipmap-hdpi/ic_app_icon_round.png new file mode 100644 index 0000000..e7c0a21 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_app_icon_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_app_icon.png b/app/src/main/res/mipmap-mdpi/ic_app_icon.png new file mode 100644 index 0000000..287d5fb Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_app_icon.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_app_icon_foreground.png b/app/src/main/res/mipmap-mdpi/ic_app_icon_foreground.png new file mode 100644 index 0000000..cf045d2 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_app_icon_foreground.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_app_icon_round.png b/app/src/main/res/mipmap-mdpi/ic_app_icon_round.png new file mode 100644 index 0000000..2db17d4 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_app_icon_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_main.webp similarity index 100% rename from app/src/main/res/mipmap-mdpi/ic_launcher.webp rename to app/src/main/res/mipmap-mdpi/ic_main.webp diff --git a/app/src/main/res/mipmap-xhdpi/ic_app_icon.png b/app/src/main/res/mipmap-xhdpi/ic_app_icon.png new file mode 100644 index 0000000..dd2d005 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_app_icon.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_app_icon_foreground.png b/app/src/main/res/mipmap-xhdpi/ic_app_icon_foreground.png new file mode 100644 index 0000000..fc14b10 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_app_icon_foreground.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_app_icon_round.png b/app/src/main/res/mipmap-xhdpi/ic_app_icon_round.png new file mode 100644 index 0000000..8ed6874 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_app_icon_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_main.webp similarity index 100% rename from app/src/main/res/mipmap-xhdpi/ic_launcher.webp rename to app/src/main/res/mipmap-xhdpi/ic_main.webp diff --git a/app/src/main/res/mipmap-xxhdpi/ic_app_icon.png b/app/src/main/res/mipmap-xxhdpi/ic_app_icon.png new file mode 100644 index 0000000..33a29a3 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_app_icon.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_app_icon_foreground.png b/app/src/main/res/mipmap-xxhdpi/ic_app_icon_foreground.png new file mode 100644 index 0000000..afb3eab Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_app_icon_foreground.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_app_icon_round.png b/app/src/main/res/mipmap-xxhdpi/ic_app_icon_round.png new file mode 100644 index 0000000..df88e5f Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_app_icon_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_main.webp similarity index 100% rename from app/src/main/res/mipmap-xxhdpi/ic_launcher.webp rename to app/src/main/res/mipmap-xxhdpi/ic_main.webp diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_app_icon.png b/app/src/main/res/mipmap-xxxhdpi/ic_app_icon.png new file mode 100644 index 0000000..1853d28 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_app_icon.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_app_icon_foreground.png b/app/src/main/res/mipmap-xxxhdpi/ic_app_icon_foreground.png new file mode 100644 index 0000000..864c1ac Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_app_icon_foreground.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_app_icon_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_app_icon_round.png new file mode 100644 index 0000000..836194c Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_app_icon_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_main.webp similarity index 100% rename from app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp rename to app/src/main/res/mipmap-xxxhdpi/ic_main.webp