Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 회원가입 #48

Merged
merged 1 commit into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ android {
viewBinding {
enabled = true
}
sourceSets {
main {
assets {
srcDirs 'src\\main\\assets'
}
}
}
}

dependencies {
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


<application
Expand All @@ -23,7 +21,8 @@
android:supportsRtl="true"
android:theme="@style/Theme.Ttoklip"
android:usesCleartextTraffic="true"
tools:targetApi="31">
tools:targetApi="31"
android:requestLegacyExternalStorage="true">

<meta-data
android:name="com.naver.maps.map.CLIENT_ID"
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/com/umc/ttoklip/data/api/SignupApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.umc.ttoklip.data.api
import com.umc.ttoklip.data.model.ResponseBody
import com.umc.ttoklip.data.model.signup.SignupResponse
import com.umc.ttoklip.data.model.signup.SignupRequest
import com.umc.ttoklip.data.model.signup.TermResponse
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.Response
Expand All @@ -23,9 +24,19 @@ interface SignupApi {
@Multipart
@POST("/api/v1/privacy/insert")
suspend fun savePrivacy(
@Part profileImage: MultipartBody.Part,
@Part profileImage: MultipartBody.Part?,
@Part categories:List<MultipartBody.Part>,
@PartMap params:MutableMap<String,RequestBody>
)
:Response<ResponseBody<SignupResponse>>

@GET("/api/v1/term")
suspend fun getTerm(
@Query("page")page:Int
):Response<ResponseBody<TermResponse>>

// @POST("/api/v1/privacy/insert")
// suspend fun savePrivacy(
// @Body userInfo:SignupRequest
// ):Response<ResponseBody<SignupResponse>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.umc.ttoklip.data.model.signup

data class TermDetailResponse (
val termId:Int,
val title:String,
val content:String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.umc.ttoklip.data.model.signup

data class TermResponse (
val terms:ArrayList<TermDetailResponse>,
val totalPage:Int,
val totalElements:Int,
val isFirst:Boolean,
val isLast:Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ interface SignupRepository {
info:MutableMap<String, RequestBody>
,cate:List<MultipartBody.Part>)
: NetworkResult<SignupResponse>
// suspend fun savePrivacy(userInfo:SignupRequest)
// : NetworkResult<SignupResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ class SignupRepositoryImpl @Inject constructor(
override suspend fun savePrivacy(photo:MultipartBody.Part,info:MutableMap<String, RequestBody>,cate:List<MultipartBody.Part>): NetworkResult<SignupResponse> {
return handleApi({api.savePrivacy(photo,cate,info)}) {response: ResponseBody<SignupResponse> ->response.result}
}

// override suspend fun savePrivacy(userInfo:SignupRequest): NetworkResult<SignupResponse> {
// return handleApi({api.savePrivacy(userInfo)}) {response: ResponseBody<SignupResponse> ->response.result}
// }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.umc.ttoklip.presentation.intro

import android.graphics.BitmapFactory
import android.graphics.Typeface
import android.os.Bundle
import android.text.Spannable
Expand All @@ -9,6 +10,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.umc.ttoklip.R
import com.umc.ttoklip.databinding.FragmentIntroBinding

class IntroFragment(val position:Int): Fragment() {
Expand All @@ -24,13 +26,18 @@ class IntroFragment(val position:Int): Fragment() {
0->{val spannable=SpannableStringBuilder("어려움과 도움을 함께\n독립생활의 꿀팁공유")
spannable.setSpan(StyleSpan(Typeface.BOLD),11,22, Spannable.SPAN_EXCLUSIVE_INCLUSIVE)
binding.itemIntroTitleTv.text=spannable
/**인앱화면 연결 필요**/}
binding.itemIntroAppimageIv.setImageBitmap(
BitmapFactory.decodeStream(resources.openRawResource(R.raw.intro_image_1st)))}
1->{val spannable=SpannableStringBuilder("자취에 도움되는\n최신뉴스를 한눈에")
spannable.setSpan(StyleSpan(Typeface.BOLD),8,13, Spannable.SPAN_EXCLUSIVE_INCLUSIVE)
binding.itemIntroTitleTv.text=spannable}
binding.itemIntroTitleTv.text=spannable
binding.itemIntroAppimageIv.setImageBitmap(
BitmapFactory.decodeStream(resources.openRawResource(R.raw.intro_image_2nd)))}
else->{val spannable=SpannableStringBuilder("혼자서는 비싸,\n동네친구들과 함께")
spannable.setSpan(StyleSpan(Typeface.BOLD),15,18, Spannable.SPAN_EXCLUSIVE_INCLUSIVE)
binding.itemIntroTitleTv.text=spannable}
binding.itemIntroTitleTv.text=spannable
binding.itemIntroAppimageIv.setImageBitmap(
BitmapFactory.decodeStream(resources.openRawResource(R.raw.intro_image_3rd)))}
}

return binding.root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>(R.layout.activity_login
Log.i("카카오로그인", "카카오톡으로 로그인 성공")
val loginRequest = LoginRequest("${token.accessToken}", "kakao")
//임시 토큰확인용
// Log.i("KAKAO-LOGIN","${token.accessToken}")
Log.i("KAKAO-LOGIN","${token.accessToken}")
viewModel.postLogin(loginRequest)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DirectLocationActivity :
response: Response<KakaoResponse.ResultSearchKeyword>
) {
kakao.value = response.body()
Log.i("kakao", "${kakao.value!!.documents[0].address_name}")
Log.i("KAKAO SEARCH", "${kakao.value!!.documents[0].address_name}")
}

override fun onFailure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import com.umc.ttoklip.data.model.KakaoResponse
import com.umc.ttoklip.databinding.ItemAddressBinding

class DirectLocationRVAdapter(private val addressList:List<KakaoResponse.Place>):RecyclerView.Adapter<DirectLocationRVAdapter.ViewHolder>() {
inner class ViewHolder(val binding:ItemAddressBinding):RecyclerView.ViewHolder(binding.root){
fun bind(place:KakaoResponse.Place){
binding.itemAddressTitleTv.text=place.place_name
binding.itemAddressDetailTv.text=place.address_name
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding:ItemAddressBinding=ItemAddressBinding.inflate(LayoutInflater.from(parent.context),parent,false)
Expand All @@ -24,4 +18,11 @@ class DirectLocationRVAdapter(private val addressList:List<KakaoResponse.Place>)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(addressList[position])
}

inner class ViewHolder(val binding:ItemAddressBinding):RecyclerView.ViewHolder(binding.root){
fun bind(place:KakaoResponse.Place){
binding.itemAddressTitleTv.text=place.place_name
binding.itemAddressDetailTv.text=place.address_name
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package com.umc.ttoklip.presentation.signup

import android.app.Application
import android.content.res.AssetManager
import android.net.Uri
import android.provider.MediaStore
import android.util.Log
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.umc.ttoklip.R
import com.umc.ttoklip.TtoklipApplication
import com.umc.ttoklip.data.model.signup.SignupRequest
import com.umc.ttoklip.data.repository.signup.SignupRepositoryImpl
import com.umc.ttoklip.module.onError
import com.umc.ttoklip.module.onFail
import com.umc.ttoklip.module.onSuccess
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.job
import kotlinx.coroutines.launch
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
Expand All @@ -22,13 +29,14 @@ import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.ResponseBody
import java.io.File
import java.io.InputStream
import javax.inject.Inject
import javax.inject.Singleton

@HiltViewModel
class SignupViewModel @Inject constructor(
private val signupRepository: SignupRepositoryImpl
) : ViewModel() {
private val signupRepository: SignupRepositoryImpl, application: Application
) : AndroidViewModel(application) {

private val _nickcheckbtn=MutableStateFlow<Boolean>(false)
val nickcheckbtn:StateFlow<Boolean>
Expand Down Expand Up @@ -111,10 +119,18 @@ class SignupViewModel @Inject constructor(

fun savePrivacy() {
viewModelScope.launch {
val file = File(profileImage.value)
val requestBody = file.asRequestBody("image/jpeg".toMediaTypeOrNull())
val fileToUpload =
MultipartBody.Part.createFormData("profileImage", file.name+".jpg", requestBody)
var fileToUpload:MultipartBody.Part
if(profileImage.value.isEmpty()){
fileToUpload=MultipartBody.Part.createFormData("profileImage","defaultImage",
RequestBody.create(
"image/*".toMediaTypeOrNull(),
getApplication<TtoklipApplication>().resources.openRawResource(
R.raw.profile_image_default).readBytes()))
}else{
val file = File(profileImage.value)
val requestBody = file.asRequestBody("image/*".toMediaTypeOrNull())
fileToUpload = MultipartBody.Part.createFormData("profileImage", file.name, requestBody)
}

val cate=ArrayList<MultipartBody.Part>()
for (c in categories.value) {
Expand All @@ -127,13 +143,19 @@ class SignupViewModel @Inject constructor(
requestMap["independentYear"] = independenctYear.value.toString().toRequestBody("text/plain".toMediaTypeOrNull())
requestMap["independentMonth"] = independenctMonth.value.toString().toRequestBody("text/plain".toMediaTypeOrNull())
signupRepository.savePrivacy(fileToUpload, requestMap,cate)

// signupRepository.savePrivacy(SignupRequest(
// street,nickname.value,categories.value,profileImage.value,independenctYear.value,independenctMonth.value
// ))
.onSuccess {
Log.i("USERSAVE", "성공")
}.onFail {
Log.d("USERSAVE", "실패")
}.onError {
Log.d("USERSAVE ERROR", it.toString())
}

}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.umc.ttoklip.presentation.signup.fragments

class DirectLocationViewModel {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Signup3Fragment : BaseFragment<FragmentSignup3Binding>(R.layout.fragment_s
var locationAgree: Boolean = false

override fun initObserver() {

}

override fun initView() {
Expand Down
Loading