From 59988f890d200bd3c1c8dc4da145b2b0cd3fb3b2 Mon Sep 17 00:00:00 2001 From: b1urrrr Date: Sat, 6 May 2023 15:13:45 +0900 Subject: [PATCH 01/16] =?UTF-8?q?[FEAT/#8]=20Gallery=20ViewPager=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/gallery/GalleryFragment.kt | 22 ++++++++++ .../presentation/main/gallery/ImageAdapter.kt | 40 +++++++++++++++++++ app/src/main/res/layout/fragment_gallery.xml | 9 ++--- .../main/res/layout/item_gallery_image.xml | 27 +++++++++++++ 4 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/org/android/go/sopt/presentation/main/gallery/ImageAdapter.kt create mode 100644 app/src/main/res/layout/item_gallery_image.xml diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt b/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt index cebfbb3..f547124 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt @@ -7,8 +7,30 @@ import org.android.go.sopt.databinding.FragmentGalleryBinding import org.android.go.sopt.util.binding.BindingFragment class GalleryFragment : BindingFragment(R.layout.fragment_gallery) { + private var imageAdapter: ImageAdapter? = null + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + + initImageAdapter() + } + + private fun initImageAdapter() { + imageAdapter = ImageAdapter() + binding.vpGallery.adapter = imageAdapter + imageAdapter?.submitList( + listOf( + R.drawable.img_main_profile, + R.drawable.img_main_profile, + R.drawable.img_main_profile, + ), + ) + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + imageAdapter = null } companion object { diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/gallery/ImageAdapter.kt b/app/src/main/java/org/android/go/sopt/presentation/main/gallery/ImageAdapter.kt new file mode 100644 index 0000000..76d43b1 --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/presentation/main/gallery/ImageAdapter.kt @@ -0,0 +1,40 @@ +package org.android.go.sopt.presentation.main.gallery + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.annotation.DrawableRes +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView +import org.android.go.sopt.databinding.ItemGalleryImageBinding +import org.android.go.sopt.util.DiffCallback + +class ImageAdapter : ListAdapter(diffUtil) { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + return ImageViewHolder( + ItemGalleryImageBinding.inflate( + LayoutInflater.from(parent.context), + parent, + false, + ), + ) + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + if (holder is ImageViewHolder) holder.setImage(getItem(position)) + } + + class ImageViewHolder(private val binding: ItemGalleryImageBinding) : + RecyclerView.ViewHolder(binding.root) { + fun setImage(@DrawableRes index: Int) { + // TODO : 이미지 연결 + } + } + + companion object { + private val diffUtil = DiffCallback( + onItemsTheSame = { old, new -> old == new }, + onContentsTheSame = { old, new -> old == new }, + ) + } +} diff --git a/app/src/main/res/layout/fragment_gallery.xml b/app/src/main/res/layout/fragment_gallery.xml index 6a50998..fb913b9 100644 --- a/app/src/main/res/layout/fragment_gallery.xml +++ b/app/src/main/res/layout/fragment_gallery.xml @@ -13,13 +13,12 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + + + + + + + + + + + \ No newline at end of file From fe37b7aaaaa2b8267d62d9d4a2928d8dd41e7eaa Mon Sep 17 00:00:00 2001 From: b1urrrr Date: Sat, 6 May 2023 16:33:20 +0900 Subject: [PATCH 02/16] =?UTF-8?q?[ADD/#8]=20post=20sign=20up=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=ED=86=B5=EC=8B=A0=20=ED=95=A8=EC=88=98=20=EC=84=A4?= =?UTF-8?q?=EA=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 10 +++++ .../remote/request/RequestPostSignUpDto.kt | 11 +++++ .../remote/response/ResponsePostSignUpDto.kt | 9 ++++ .../entity/remote/wrapper/BaseResponse.kt | 12 ++++++ .../data/repository/AuthRepositoryImpl.kt | 9 ++++ .../go/sopt/data/service/AuthService.kt | 14 +++++++ .../go/sopt/data/source/AuthDataSource.kt | 16 +++++++ .../org/android/go/sopt/di/RetrofitModule.kt | 42 +++++++++++++++++++ .../sopt/domain/repository/AuthRepository.kt | 4 ++ 9 files changed, 127 insertions(+) create mode 100644 app/src/main/java/org/android/go/sopt/data/entity/remote/request/RequestPostSignUpDto.kt create mode 100644 app/src/main/java/org/android/go/sopt/data/entity/remote/response/ResponsePostSignUpDto.kt create mode 100644 app/src/main/java/org/android/go/sopt/data/entity/remote/wrapper/BaseResponse.kt create mode 100644 app/src/main/java/org/android/go/sopt/data/service/AuthService.kt create mode 100644 app/src/main/java/org/android/go/sopt/data/source/AuthDataSource.kt create mode 100644 app/src/main/java/org/android/go/sopt/di/RetrofitModule.kt diff --git a/app/build.gradle b/app/build.gradle index b04dc4c..b04f5ca 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,6 +8,9 @@ plugins { id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.10' } +Properties properties = new Properties() +properties.load(project.rootProject.file('local.properties').newDataInputStream()) + android { namespace 'org.android.go.sopt' compileSdk 33 @@ -20,6 +23,8 @@ android { versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + buildConfigField "String", "BASE_URL", properties['base.url'] } buildTypes { @@ -81,6 +86,11 @@ dependencies { implementation "com.google.code.gson:gson:2.10.1" implementation "com.squareup.retrofit2:retrofit:2.9.0" + // okhttp + implementation "com.squareup.okhttp3:okhttp" + implementation "com.squareup.okhttp3:okhttp-bom:4.10.0" + implementation "com.squareup.okhttp3:logging-interceptor" + // coil implementation "io.coil-kt:coil:2.3.0" diff --git a/app/src/main/java/org/android/go/sopt/data/entity/remote/request/RequestPostSignUpDto.kt b/app/src/main/java/org/android/go/sopt/data/entity/remote/request/RequestPostSignUpDto.kt new file mode 100644 index 0000000..c2fa148 --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/data/entity/remote/request/RequestPostSignUpDto.kt @@ -0,0 +1,11 @@ +package org.android.go.sopt.data.entity.remote.request + +import kotlinx.serialization.Serializable + +@Serializable +data class RequestPostSignUpDto( + val id: String, + val password: String, + val name: String, + val skill: String, +) diff --git a/app/src/main/java/org/android/go/sopt/data/entity/remote/response/ResponsePostSignUpDto.kt b/app/src/main/java/org/android/go/sopt/data/entity/remote/response/ResponsePostSignUpDto.kt new file mode 100644 index 0000000..e66e4ac --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/data/entity/remote/response/ResponsePostSignUpDto.kt @@ -0,0 +1,9 @@ +package org.android.go.sopt.data.entity.remote.response + +import kotlinx.serialization.Serializable + +@Serializable +data class ResponsePostSignUpDto( + val name: String, + val skill: String, +) diff --git a/app/src/main/java/org/android/go/sopt/data/entity/remote/wrapper/BaseResponse.kt b/app/src/main/java/org/android/go/sopt/data/entity/remote/wrapper/BaseResponse.kt new file mode 100644 index 0000000..5d7a197 --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/data/entity/remote/wrapper/BaseResponse.kt @@ -0,0 +1,12 @@ +package org.android.go.sopt.data.entity.remote.wrapper + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class BaseResponse( + val status: Int, + val message: String, + @SerialName("data") + val data: T, +) diff --git a/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt b/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt index c25b041..16990e1 100644 --- a/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt +++ b/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt @@ -1,13 +1,22 @@ package org.android.go.sopt.data.repository +import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto +import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto +import org.android.go.sopt.data.source.AuthDataSource import org.android.go.sopt.data.source.LocalPrefDataSource import org.android.go.sopt.domain.model.User import org.android.go.sopt.domain.repository.AuthRepository import javax.inject.Inject class AuthRepositoryImpl @Inject constructor( + private val authDataSource: AuthDataSource, private val localPrefDataSource: LocalPrefDataSource, ) : AuthRepository { + override suspend fun postSignup(requestPostSignUpDto: RequestPostSignUpDto): Result = + runCatching { + authDataSource.postSignup(requestPostSignUpDto).data + } + override fun setAutoLogin(isAutoLogin: Boolean) { localPrefDataSource.isAutoLogin = isAutoLogin } diff --git a/app/src/main/java/org/android/go/sopt/data/service/AuthService.kt b/app/src/main/java/org/android/go/sopt/data/service/AuthService.kt new file mode 100644 index 0000000..68197f8 --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/data/service/AuthService.kt @@ -0,0 +1,14 @@ +package org.android.go.sopt.data.service + +import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto +import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto +import org.android.go.sopt.data.entity.remote.wrapper.BaseResponse +import retrofit2.http.Body +import retrofit2.http.POST + +interface AuthService { + @POST("sign-up") + suspend fun postSignUp( + @Body requestPostSignUpDto: RequestPostSignUpDto, + ): BaseResponse +} diff --git a/app/src/main/java/org/android/go/sopt/data/source/AuthDataSource.kt b/app/src/main/java/org/android/go/sopt/data/source/AuthDataSource.kt new file mode 100644 index 0000000..3afabdf --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/data/source/AuthDataSource.kt @@ -0,0 +1,16 @@ +package org.android.go.sopt.data.source + +import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto +import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto +import org.android.go.sopt.data.entity.remote.wrapper.BaseResponse +import org.android.go.sopt.data.service.AuthService +import javax.inject.Inject + +class AuthDataSource @Inject constructor( + private val authService: AuthService, +) { + suspend fun postSignup( + requestPostSignUpDto: RequestPostSignUpDto, + ): BaseResponse = + authService.postSignUp(requestPostSignUpDto) +} diff --git a/app/src/main/java/org/android/go/sopt/di/RetrofitModule.kt b/app/src/main/java/org/android/go/sopt/di/RetrofitModule.kt new file mode 100644 index 0000000..8707df3 --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/di/RetrofitModule.kt @@ -0,0 +1,42 @@ +package org.android.go.sopt.di + +import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import kotlinx.serialization.json.Json +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import org.android.go.sopt.BuildConfig.BASE_URL +import retrofit2.Retrofit +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object RetrofitModule { + private const val APPLICATION_JSON = "application/json" + + @Provides + @Singleton + fun providesOkHttpClient(): OkHttpClient = + OkHttpClient.Builder() + .addInterceptor( + HttpLoggingInterceptor().apply { + level = HttpLoggingInterceptor.Level.BODY + }, + ) + .build() + + @Provides + @Singleton + fun providesRetrofit( + client: OkHttpClient, + ): Retrofit = + Retrofit.Builder() + .baseUrl(BASE_URL) + .addConverterFactory(Json.asConverterFactory(APPLICATION_JSON.toMediaType())) + .client(client) + .build() +} diff --git a/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt b/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt index b8b043c..efc1edf 100644 --- a/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt +++ b/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt @@ -1,8 +1,12 @@ package org.android.go.sopt.domain.repository +import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto +import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto import org.android.go.sopt.domain.model.User interface AuthRepository { + suspend fun postSignup(requestPostSignUpDto: RequestPostSignUpDto): Result + fun setAutoLogin(isAutoLogin: Boolean) fun getAutoLogin(): Boolean From 4b7768aabd7cf3a7da045e4c5c2e55750aa09dcf Mon Sep 17 00:00:00 2001 From: b1urrrr Date: Sat, 6 May 2023 17:47:55 +0900 Subject: [PATCH 03/16] =?UTF-8?q?[FEAT/#8]=20sign=20up=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=ED=86=B5=EC=8B=A0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../remote/request/RequestPostSignUpDto.kt | 5 ++ .../remote/response/ResponsePostSignUpDto.kt | 3 + .../entity/remote/wrapper/BaseResponse.kt | 2 + .../org/android/go/sopt/di/ServiceModule.kt | 18 +++++ .../org/android/go/sopt/domain/model/User.kt | 2 +- .../sopt/presentation/login/LoginActivity.kt | 4 +- .../sopt/presentation/login/LoginViewModel.kt | 10 +-- .../main/gallery/GalleryFragment.kt | 1 + .../presentation/main/home/HomeFragment.kt | 4 +- .../presentation/main/home/HomeViewModel.kt | 10 +-- .../presentation/signup/SignupActivity.kt | 7 +- .../presentation/signup/SignupViewModel.kt | 78 ++++++++++++++----- .../java/org/android/go/sopt/util/UiState.kt | 7 -- .../go/sopt/util/state/LocalUiState.kt | 6 ++ .../go/sopt/util/state/RemoteUiState.kt | 7 ++ app/src/main/res/layout/activity_signup.xml | 12 +-- app/src/main/res/values/strings.xml | 1 + 17 files changed, 128 insertions(+), 49 deletions(-) create mode 100644 app/src/main/java/org/android/go/sopt/di/ServiceModule.kt delete mode 100644 app/src/main/java/org/android/go/sopt/util/UiState.kt create mode 100644 app/src/main/java/org/android/go/sopt/util/state/LocalUiState.kt create mode 100644 app/src/main/java/org/android/go/sopt/util/state/RemoteUiState.kt diff --git a/app/src/main/java/org/android/go/sopt/data/entity/remote/request/RequestPostSignUpDto.kt b/app/src/main/java/org/android/go/sopt/data/entity/remote/request/RequestPostSignUpDto.kt index c2fa148..49511d8 100644 --- a/app/src/main/java/org/android/go/sopt/data/entity/remote/request/RequestPostSignUpDto.kt +++ b/app/src/main/java/org/android/go/sopt/data/entity/remote/request/RequestPostSignUpDto.kt @@ -1,11 +1,16 @@ package org.android.go.sopt.data.entity.remote.request +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class RequestPostSignUpDto( + @SerialName("id") val id: String, + @SerialName("password") val password: String, + @SerialName("name") val name: String, + @SerialName("skill") val skill: String, ) diff --git a/app/src/main/java/org/android/go/sopt/data/entity/remote/response/ResponsePostSignUpDto.kt b/app/src/main/java/org/android/go/sopt/data/entity/remote/response/ResponsePostSignUpDto.kt index e66e4ac..52c3fdf 100644 --- a/app/src/main/java/org/android/go/sopt/data/entity/remote/response/ResponsePostSignUpDto.kt +++ b/app/src/main/java/org/android/go/sopt/data/entity/remote/response/ResponsePostSignUpDto.kt @@ -1,9 +1,12 @@ package org.android.go.sopt.data.entity.remote.response +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class ResponsePostSignUpDto( + @SerialName("name") val name: String, + @SerialName("skill") val skill: String, ) diff --git a/app/src/main/java/org/android/go/sopt/data/entity/remote/wrapper/BaseResponse.kt b/app/src/main/java/org/android/go/sopt/data/entity/remote/wrapper/BaseResponse.kt index 5d7a197..caab5ce 100644 --- a/app/src/main/java/org/android/go/sopt/data/entity/remote/wrapper/BaseResponse.kt +++ b/app/src/main/java/org/android/go/sopt/data/entity/remote/wrapper/BaseResponse.kt @@ -5,7 +5,9 @@ import kotlinx.serialization.Serializable @Serializable data class BaseResponse( + @SerialName("status") val status: Int, + @SerialName("message") val message: String, @SerialName("data") val data: T, diff --git a/app/src/main/java/org/android/go/sopt/di/ServiceModule.kt b/app/src/main/java/org/android/go/sopt/di/ServiceModule.kt new file mode 100644 index 0000000..7153202 --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/di/ServiceModule.kt @@ -0,0 +1,18 @@ +package org.android.go.sopt.di + +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import org.android.go.sopt.data.service.AuthService +import retrofit2.Retrofit +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object ServiceModule { + @Provides + @Singleton + fun providesAuthService(retrofit: Retrofit): AuthService = + retrofit.create(AuthService::class.java) +} diff --git a/app/src/main/java/org/android/go/sopt/domain/model/User.kt b/app/src/main/java/org/android/go/sopt/domain/model/User.kt index 6fc5a11..c970f4e 100644 --- a/app/src/main/java/org/android/go/sopt/domain/model/User.kt +++ b/app/src/main/java/org/android/go/sopt/domain/model/User.kt @@ -9,7 +9,7 @@ import org.android.go.sopt.util.type.MBTI.NONE data class User( val id: String = "", val pwd: String = "", - val name: String? = "", + val name: String? = "익명", val specialty: String? = "", val mbti: MBTI? = NONE, ) : Parcelable diff --git a/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt b/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt index 3a2d67d..9afe8bf 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt @@ -12,8 +12,8 @@ import org.android.go.sopt.databinding.ActivityLoginBinding import org.android.go.sopt.domain.model.User import org.android.go.sopt.presentation.main.MainActivity import org.android.go.sopt.presentation.signup.SignupActivity -import org.android.go.sopt.util.UiState.Failure -import org.android.go.sopt.util.UiState.Success +import org.android.go.sopt.util.state.LocalUiState.Failure +import org.android.go.sopt.util.state.LocalUiState.Success import org.android.go.sopt.util.binding.BindingActivity import org.android.go.sopt.util.extension.getCompatibleParcelableExtra import org.android.go.sopt.util.extension.setOnSingleClickListener diff --git a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt index d3bf1cd..49b4a65 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt @@ -6,9 +6,9 @@ import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel import org.android.go.sopt.domain.model.User import org.android.go.sopt.domain.repository.AuthRepository -import org.android.go.sopt.util.UiState -import org.android.go.sopt.util.UiState.Failure -import org.android.go.sopt.util.UiState.Success +import org.android.go.sopt.util.state.LocalUiState +import org.android.go.sopt.util.state.LocalUiState.Failure +import org.android.go.sopt.util.state.LocalUiState.Success import javax.inject.Inject @HiltViewModel @@ -17,8 +17,8 @@ class LoginViewModel @Inject constructor( ) : ViewModel() { var signedUpUser = User() - private val _loginState = MutableLiveData() - val loginState: LiveData + private val _loginState = MutableLiveData() + val loginState: LiveData get() = _loginState val id = MutableLiveData("") diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt b/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt index f547124..fe7cc9e 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt @@ -6,6 +6,7 @@ import org.android.go.sopt.R import org.android.go.sopt.databinding.FragmentGalleryBinding import org.android.go.sopt.util.binding.BindingFragment + class GalleryFragment : BindingFragment(R.layout.fragment_gallery) { private var imageAdapter: ImageAdapter? = null diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt b/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt index 7b3bc62..647f93b 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt @@ -7,8 +7,8 @@ import androidx.recyclerview.widget.ConcatAdapter import dagger.hilt.android.AndroidEntryPoint import org.android.go.sopt.R import org.android.go.sopt.databinding.FragmentHomeBinding -import org.android.go.sopt.util.UiState.Failure -import org.android.go.sopt.util.UiState.Success +import org.android.go.sopt.util.state.LocalUiState.Failure +import org.android.go.sopt.util.state.LocalUiState.Success import org.android.go.sopt.util.binding.BindingFragment import org.android.go.sopt.util.extension.showSnackbar diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeViewModel.kt index 20f2dbc..b841ff1 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeViewModel.kt @@ -8,9 +8,9 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import org.android.go.sopt.domain.model.Repo import org.android.go.sopt.domain.repository.RepoRepository -import org.android.go.sopt.util.UiState -import org.android.go.sopt.util.UiState.Failure -import org.android.go.sopt.util.UiState.Success +import org.android.go.sopt.util.state.LocalUiState +import org.android.go.sopt.util.state.LocalUiState.Failure +import org.android.go.sopt.util.state.LocalUiState.Success import timber.log.Timber import javax.inject.Inject @@ -22,8 +22,8 @@ class HomeViewModel @Inject constructor( val repoList: LiveData> get() = _repoList - private val _getRepoListState = MutableLiveData() - val getRepoListState: LiveData + private val _getRepoListState = MutableLiveData() + val getRepoListState: LiveData get() = _getRepoListState init { diff --git a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt index 9a2c076..7b5d4d0 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt @@ -11,10 +11,11 @@ import org.android.go.sopt.databinding.ActivitySignupBinding import org.android.go.sopt.presentation.login.LoginActivity import org.android.go.sopt.presentation.signup.SignupViewModel.Companion.CODE_INVALID_ID import org.android.go.sopt.presentation.signup.SignupViewModel.Companion.CODE_INVALID_PWD -import org.android.go.sopt.util.UiState.Failure -import org.android.go.sopt.util.UiState.Success import org.android.go.sopt.util.binding.BindingActivity import org.android.go.sopt.util.extension.showSnackbar +import org.android.go.sopt.util.state.RemoteUiState.Error +import org.android.go.sopt.util.state.RemoteUiState.Failure +import org.android.go.sopt.util.state.RemoteUiState.Success @AndroidEntryPoint class SignupActivity : BindingActivity(R.layout.activity_signup) { @@ -44,6 +45,8 @@ class SignupActivity : BindingActivity(R.layout.activity_ ) } } + + is Error -> showSnackbar(binding.root, getString(R.string.server_error_msg)) } } } diff --git a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt index 31b8735..74b509c 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt @@ -3,29 +3,50 @@ package org.android.go.sopt.presentation.signup import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto import org.android.go.sopt.domain.model.User import org.android.go.sopt.domain.repository.AuthRepository -import org.android.go.sopt.util.UiState -import org.android.go.sopt.util.UiState.Failure -import org.android.go.sopt.util.UiState.Success import org.android.go.sopt.util.safeValueOf +import org.android.go.sopt.util.state.RemoteUiState +import org.android.go.sopt.util.state.RemoteUiState.Error +import org.android.go.sopt.util.state.RemoteUiState.Failure +import org.android.go.sopt.util.state.RemoteUiState.Success +import org.android.go.sopt.util.type.MBTI import org.android.go.sopt.util.type.MBTI.NONE +import retrofit2.HttpException +import timber.log.Timber import javax.inject.Inject @HiltViewModel class SignupViewModel @Inject constructor( private val authRepository: AuthRepository, ) : ViewModel() { - private val _signupState = MutableLiveData() - val signupState: LiveData + private val _signupState = MutableLiveData() + val signupState: LiveData get() = _signupState - val id = MutableLiveData("") - val pwd = MutableLiveData("") - val name = MutableLiveData("") - val specialty = MutableLiveData("") - val mbti = MutableLiveData("") + val _id = MutableLiveData("") + val id: String + get() = requireNotNull(_id.value).trim() + + val _pwd = MutableLiveData("") + val pwd: String + get() = requireNotNull(_pwd.value).trim() + + val _name = MutableLiveData("") + val name: String + get() = _name.value?.trim() ?: "" + + val _specialty = MutableLiveData("") + val specialty: String + get() = _specialty.value?.trim() ?: "" + + val _mbti = MutableLiveData("") + val mbti: MBTI? + get() = safeValueOf(_mbti.value?.trim()?.uppercase(), NONE) private fun isValidId(id: String?) = !id.isNullOrBlank() && id.length in MIN_ID_LENGTH..MAX_ID_LENGTH @@ -34,25 +55,44 @@ class SignupViewModel @Inject constructor( !pwd.isNullOrBlank() && pwd.length in MIN_PWD_LENGTH..MAX_PWD_LENGTH fun signup() { - if (!isValidId(id.value)) { + if (!isValidId(_id.value)) { _signupState.value = Failure(CODE_INVALID_ID) return } - if (!isValidPwd(pwd.value)) { + if (!isValidPwd(_pwd.value)) { _signupState.value = Failure(CODE_INVALID_PWD) return } - authRepository.setSignedUpUser(getUser()) - _signupState.value = Success + + val requestPostSignUpDto = RequestPostSignUpDto( + id = id, + password = pwd, + name = name, + skill = specialty, + ) + viewModelScope.launch { + authRepository.postSignup(requestPostSignUpDto) + .onSuccess { response -> + authRepository.setSignedUpUser(getUser()) + _signupState.value = Success + Timber.d("$response") + } + .onFailure { t -> + if (t is HttpException) { + Timber.e("${t.code()} : ${t.message()}") + _signupState.value = Error + } + } + } } fun getUser(): User { return User( - requireNotNull(id.value).trim(), - requireNotNull(pwd.value).trim(), - name.value?.trim(), - specialty.value?.trim(), - safeValueOf(mbti.value?.trim()?.uppercase(), NONE), + id = id, + pwd = pwd, + name = name, + specialty = specialty, + mbti = mbti, ) } diff --git a/app/src/main/java/org/android/go/sopt/util/UiState.kt b/app/src/main/java/org/android/go/sopt/util/UiState.kt deleted file mode 100644 index 1713014..0000000 --- a/app/src/main/java/org/android/go/sopt/util/UiState.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.android.go.sopt.util - -sealed class UiState { - object Success : UiState() - data class Failure(val code: Int?) : UiState() -// object Error : UiState() -} diff --git a/app/src/main/java/org/android/go/sopt/util/state/LocalUiState.kt b/app/src/main/java/org/android/go/sopt/util/state/LocalUiState.kt new file mode 100644 index 0000000..0e362ab --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/util/state/LocalUiState.kt @@ -0,0 +1,6 @@ +package org.android.go.sopt.util.state + +sealed class LocalUiState { + object Success : LocalUiState() + data class Failure(val code: Int?) : LocalUiState() +} diff --git a/app/src/main/java/org/android/go/sopt/util/state/RemoteUiState.kt b/app/src/main/java/org/android/go/sopt/util/state/RemoteUiState.kt new file mode 100644 index 0000000..f670fcd --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/util/state/RemoteUiState.kt @@ -0,0 +1,7 @@ +package org.android.go.sopt.util.state + +sealed class RemoteUiState { + object Success : RemoteUiState() + data class Failure(val code: Int?) : RemoteUiState() + object Error : RemoteUiState() +} diff --git a/app/src/main/res/layout/activity_signup.xml b/app/src/main/res/layout/activity_signup.xml index 670e2d3..71b6e19 100644 --- a/app/src/main/res/layout/activity_signup.xml +++ b/app/src/main/res/layout/activity_signup.xml @@ -38,7 +38,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/login_id_label" - android:textAppearance="?attr/textAppearanceHeadlineSmall" + android:textAppearance="?textAppearanceHeadlineSmall" android:textColor="?colorOnBackground" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -53,7 +53,7 @@ android:inputType="text" android:maxLength="@{vm.MAX_ID_LENGTH}" android:paddingVertical="16dp" - android:text="@={vm.id}" + android:text="@={vm._id}" android:textAppearance="@style/TextAppearance.GoSopt.BodyLarge" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -80,7 +80,7 @@ android:inputType="textPassword" android:maxLength="@{vm.MAX_PWD_LENGTH}" android:paddingVertical="16dp" - android:text="@={vm.pwd}" + android:text="@={vm._pwd}" android:textAppearance="@style/TextAppearance.GoSopt.BodyLarge" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -106,7 +106,7 @@ android:imeOptions="actionNext" android:inputType="text|textPersonName" android:paddingVertical="16dp" - android:text="@={vm.name}" + android:text="@={vm._name}" android:textAppearance="@style/TextAppearance.GoSopt.BodyLarge" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -132,7 +132,7 @@ android:imeOptions="actionNext" android:inputType="text" android:paddingVertical="16dp" - android:text="@={vm.specialty}" + android:text="@={vm._specialty}" android:textAppearance="@style/TextAppearance.GoSopt.BodyLarge" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -158,7 +158,7 @@ android:imeOptions="actionDone" android:inputType="textCapCharacters" android:paddingVertical="16dp" - android:text="@={vm.mbti}" + android:text="@={vm._mbti}" android:textAppearance="@style/TextAppearance.GoSopt.BodyLarge" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1cbd580..f4caee5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -5,6 +5,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 잘못된 입력입니다. + 서버를 불러올 수 없습니다. Binding not initialized to reference the view. Unknown View Type : %d From d3c31159dbb00177bbaabc554127d1127988e72a Mon Sep 17 00:00:00 2001 From: b1urrrr Date: Fri, 12 May 2023 19:29:40 +0900 Subject: [PATCH 04/16] =?UTF-8?q?[MOVE/#8]=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/entity/{ => local}/MockRepoDto.kt | 22 ++++++++++++++++++- .../model => data/entity/local}/User.kt | 2 +- .../{ => response}/wrapper/BaseResponse.kt | 4 ++-- .../data/repository/AuthRepositoryImpl.kt | 20 ++++++++--------- .../data/repository/RepoRepositoryImpl.kt | 2 +- .../go/sopt/data/service/AuthService.kt | 2 +- .../data/source/{ => local}/RepoDataSource.kt | 4 ++-- .../SharedPrefDataSource.kt} | 10 ++++----- .../source/{ => remote}/AuthDataSource.kt | 4 ++-- .../sopt/domain/repository/AuthRepository.kt | 4 ++-- .../sopt/presentation/login/LoginActivity.kt | 2 +- .../sopt/presentation/login/LoginViewModel.kt | 2 +- .../main/gallery/GalleryFragment.kt | 1 - .../presentation/main/home/HomeFragment.kt | 4 ++-- .../main/profile/ProfileViewModel.kt | 2 +- .../presentation/signup/SignupViewModel.kt | 2 +- 16 files changed, 52 insertions(+), 35 deletions(-) rename app/src/main/java/org/android/go/sopt/data/entity/{ => local}/MockRepoDto.kt (90%) rename app/src/main/java/org/android/go/sopt/{domain/model => data/entity/local}/User.kt (88%) rename app/src/main/java/org/android/go/sopt/data/entity/remote/{ => response}/wrapper/BaseResponse.kt (73%) rename app/src/main/java/org/android/go/sopt/data/source/{ => local}/RepoDataSource.kt (84%) rename app/src/main/java/org/android/go/sopt/data/source/{LocalPrefDataSource.kt => local/SharedPrefDataSource.kt} (83%) rename app/src/main/java/org/android/go/sopt/data/source/{ => remote}/AuthDataSource.kt (80%) diff --git a/app/src/main/java/org/android/go/sopt/data/entity/MockRepoDto.kt b/app/src/main/java/org/android/go/sopt/data/entity/local/MockRepoDto.kt similarity index 90% rename from app/src/main/java/org/android/go/sopt/data/entity/MockRepoDto.kt rename to app/src/main/java/org/android/go/sopt/data/entity/local/MockRepoDto.kt index 6d6ffc3..82431b8 100644 --- a/app/src/main/java/org/android/go/sopt/data/entity/MockRepoDto.kt +++ b/app/src/main/java/org/android/go/sopt/data/entity/local/MockRepoDto.kt @@ -1,4 +1,4 @@ -package org.android.go.sopt.data.entity +package org.android.go.sopt.data.entity.local import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -10,6 +10,7 @@ data class MockRepoDto( val allowForking: Boolean, @SerialName("archive_url") val archiveUrl: String, + @SerialName("archived") val archived: Boolean, @SerialName("assignees_url") val assigneesUrl: String, @@ -37,13 +38,17 @@ data class MockRepoDto( val defaultBranch: String, @SerialName("deployments_url") val deploymentsUrl: String, + @SerialName("description") val description: String, + @SerialName("disabled") val disabled: Boolean, @SerialName("downloads_url") val downloadsUrl: String, @SerialName("events_url") val eventsUrl: String, + @SerialName("fork") val fork: Boolean, + @SerialName("forks") val forks: Int, @SerialName("forks_count") val forksCount: Int, @@ -71,11 +76,13 @@ data class MockRepoDto( val hasProjects: Boolean, @SerialName("has_wiki") val hasWiki: Boolean, + @SerialName("homepage") val homepage: String, @SerialName("hooks_url") val hooksUrl: String, @SerialName("html_url") val htmlUrl: String, + @SerialName("id") val id: Int, @SerialName("is_template") val isTemplate: Boolean, @@ -89,9 +96,11 @@ data class MockRepoDto( val keysUrl: String, @SerialName("labels_url") val labelsUrl: String, + @SerialName("language") val language: String?, @SerialName("languages_url") val languagesUrl: String, + @SerialName("license") val license: String?, @SerialName("merges_url") val mergesUrl: String, @@ -99,6 +108,7 @@ data class MockRepoDto( val milestonesUrl: String, @SerialName("mirror_url") val mirrorUrl: String?, + @SerialName("name") val name: String, @SerialName("node_id") val nodeId: String, @@ -108,6 +118,7 @@ data class MockRepoDto( val openIssues: Int, @SerialName("open_issues_count") val openIssuesCount: Int, + @SerialName("owner") val owner: Owner, @SerialName("private") val isPrivate: Boolean, @@ -117,6 +128,7 @@ data class MockRepoDto( val pushedAt: String, @SerialName("releases_url") val releasesUrl: String, + @SerialName("size") val size: Int, @SerialName("ssh_url") val sshUrl: String, @@ -136,13 +148,17 @@ data class MockRepoDto( val tagsUrl: String, @SerialName("teams_url") val teamsUrl: String, + @SerialName("topics") val topics: List, @SerialName("trees_url") val treesUrl: String, @SerialName("updated_at") val updatedAt: String, + @SerialName("url") val url: String, + @SerialName("visibility") val visibility: String, + @SerialName("watchers") val watchers: Int, @SerialName("watchers_count") val watchersCount: Int, @@ -165,7 +181,9 @@ data class MockRepoDto( val gravatarId: String, @SerialName("html_url") val htmlUrl: String, + @SerialName("id") val id: Int, + @SerialName("login") val login: String, @SerialName("node_id") val nodeId: String, @@ -181,7 +199,9 @@ data class MockRepoDto( val starredUrl: String, @SerialName("subscriptions_url") val subscriptionsUrl: String, + @SerialName("type") val type: String, + @SerialName("url") val url: String, ) diff --git a/app/src/main/java/org/android/go/sopt/domain/model/User.kt b/app/src/main/java/org/android/go/sopt/data/entity/local/User.kt similarity index 88% rename from app/src/main/java/org/android/go/sopt/domain/model/User.kt rename to app/src/main/java/org/android/go/sopt/data/entity/local/User.kt index c970f4e..d648e0e 100644 --- a/app/src/main/java/org/android/go/sopt/domain/model/User.kt +++ b/app/src/main/java/org/android/go/sopt/data/entity/local/User.kt @@ -1,4 +1,4 @@ -package org.android.go.sopt.domain.model +package org.android.go.sopt.data.entity.local import android.os.Parcelable import kotlinx.parcelize.Parcelize diff --git a/app/src/main/java/org/android/go/sopt/data/entity/remote/wrapper/BaseResponse.kt b/app/src/main/java/org/android/go/sopt/data/entity/remote/response/wrapper/BaseResponse.kt similarity index 73% rename from app/src/main/java/org/android/go/sopt/data/entity/remote/wrapper/BaseResponse.kt rename to app/src/main/java/org/android/go/sopt/data/entity/remote/response/wrapper/BaseResponse.kt index caab5ce..0a2ac9f 100644 --- a/app/src/main/java/org/android/go/sopt/data/entity/remote/wrapper/BaseResponse.kt +++ b/app/src/main/java/org/android/go/sopt/data/entity/remote/response/wrapper/BaseResponse.kt @@ -1,4 +1,4 @@ -package org.android.go.sopt.data.entity.remote.wrapper +package org.android.go.sopt.data.entity.remote.response.wrapper import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -10,5 +10,5 @@ data class BaseResponse( @SerialName("message") val message: String, @SerialName("data") - val data: T, + val data: T? = null, ) diff --git a/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt b/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt index 16990e1..75d0eaf 100644 --- a/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt +++ b/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt @@ -2,34 +2,34 @@ package org.android.go.sopt.data.repository import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto -import org.android.go.sopt.data.source.AuthDataSource -import org.android.go.sopt.data.source.LocalPrefDataSource -import org.android.go.sopt.domain.model.User +import org.android.go.sopt.data.source.local.SharedPrefDataSource +import org.android.go.sopt.data.source.remote.AuthDataSource +import org.android.go.sopt.data.entity.local.User import org.android.go.sopt.domain.repository.AuthRepository import javax.inject.Inject class AuthRepositoryImpl @Inject constructor( private val authDataSource: AuthDataSource, - private val localPrefDataSource: LocalPrefDataSource, + private val sharedPrefDataSource: SharedPrefDataSource, ) : AuthRepository { - override suspend fun postSignup(requestPostSignUpDto: RequestPostSignUpDto): Result = + override suspend fun postSignup(requestPostSignUpDto: RequestPostSignUpDto): Result = runCatching { authDataSource.postSignup(requestPostSignUpDto).data } override fun setAutoLogin(isAutoLogin: Boolean) { - localPrefDataSource.isAutoLogin = isAutoLogin + sharedPrefDataSource.isAutoLogin = isAutoLogin } - override fun getAutoLogin(): Boolean = localPrefDataSource.isAutoLogin + override fun getAutoLogin(): Boolean = sharedPrefDataSource.isAutoLogin override fun setSignedUpUser(user: User) { - localPrefDataSource.signedUpUser = user + sharedPrefDataSource.signedUpUser = user } - override fun getSignedUpUser(): User? = localPrefDataSource.signedUpUser + override fun getSignedUpUser(): User? = sharedPrefDataSource.signedUpUser override fun clearLocalPref() { - localPrefDataSource.clearLocalPref() + sharedPrefDataSource.clearLocalPref() } } diff --git a/app/src/main/java/org/android/go/sopt/data/repository/RepoRepositoryImpl.kt b/app/src/main/java/org/android/go/sopt/data/repository/RepoRepositoryImpl.kt index 733d6e1..25cf5d4 100644 --- a/app/src/main/java/org/android/go/sopt/data/repository/RepoRepositoryImpl.kt +++ b/app/src/main/java/org/android/go/sopt/data/repository/RepoRepositoryImpl.kt @@ -1,6 +1,6 @@ package org.android.go.sopt.data.repository -import org.android.go.sopt.data.source.RepoDataSource +import org.android.go.sopt.data.source.local.RepoDataSource import org.android.go.sopt.domain.model.Repo import org.android.go.sopt.domain.repository.RepoRepository import javax.inject.Inject diff --git a/app/src/main/java/org/android/go/sopt/data/service/AuthService.kt b/app/src/main/java/org/android/go/sopt/data/service/AuthService.kt index 68197f8..9dd01c1 100644 --- a/app/src/main/java/org/android/go/sopt/data/service/AuthService.kt +++ b/app/src/main/java/org/android/go/sopt/data/service/AuthService.kt @@ -2,7 +2,7 @@ package org.android.go.sopt.data.service import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto -import org.android.go.sopt.data.entity.remote.wrapper.BaseResponse +import org.android.go.sopt.data.entity.remote.response.wrapper.BaseResponse import retrofit2.http.Body import retrofit2.http.POST diff --git a/app/src/main/java/org/android/go/sopt/data/source/RepoDataSource.kt b/app/src/main/java/org/android/go/sopt/data/source/local/RepoDataSource.kt similarity index 84% rename from app/src/main/java/org/android/go/sopt/data/source/RepoDataSource.kt rename to app/src/main/java/org/android/go/sopt/data/source/local/RepoDataSource.kt index 0da411f..377c9dd 100644 --- a/app/src/main/java/org/android/go/sopt/data/source/RepoDataSource.kt +++ b/app/src/main/java/org/android/go/sopt/data/source/local/RepoDataSource.kt @@ -1,8 +1,8 @@ -package org.android.go.sopt.data.source +package org.android.go.sopt.data.source.local import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json -import org.android.go.sopt.data.entity.MockRepoDto +import org.android.go.sopt.data.entity.local.MockRepoDto import org.android.go.sopt.util.AssetLoader import javax.inject.Inject diff --git a/app/src/main/java/org/android/go/sopt/data/source/LocalPrefDataSource.kt b/app/src/main/java/org/android/go/sopt/data/source/local/SharedPrefDataSource.kt similarity index 83% rename from app/src/main/java/org/android/go/sopt/data/source/LocalPrefDataSource.kt rename to app/src/main/java/org/android/go/sopt/data/source/local/SharedPrefDataSource.kt index def0dc7..ef5fdf0 100644 --- a/app/src/main/java/org/android/go/sopt/data/source/LocalPrefDataSource.kt +++ b/app/src/main/java/org/android/go/sopt/data/source/local/SharedPrefDataSource.kt @@ -1,15 +1,15 @@ -package org.android.go.sopt.data.source +package org.android.go.sopt.data.source.local import android.content.SharedPreferences import androidx.core.content.edit import com.google.gson.Gson import com.google.gson.GsonBuilder -import org.android.go.sopt.domain.model.User +import org.android.go.sopt.data.entity.local.User import javax.inject.Inject import javax.inject.Singleton @Singleton -class LocalPrefDataSource @Inject constructor( +class SharedPrefDataSource @Inject constructor( private val prefs: SharedPreferences, ) { var isAutoLogin: Boolean @@ -30,9 +30,7 @@ class LocalPrefDataSource @Inject constructor( } } - fun clearLocalPref() { - prefs.edit { clear() } - } + fun clearLocalPref() = prefs.edit { clear() } companion object { const val PREF_IS_AUTO_LOGIN = "IS_AUTO_LOGIN" diff --git a/app/src/main/java/org/android/go/sopt/data/source/AuthDataSource.kt b/app/src/main/java/org/android/go/sopt/data/source/remote/AuthDataSource.kt similarity index 80% rename from app/src/main/java/org/android/go/sopt/data/source/AuthDataSource.kt rename to app/src/main/java/org/android/go/sopt/data/source/remote/AuthDataSource.kt index 3afabdf..0c448a9 100644 --- a/app/src/main/java/org/android/go/sopt/data/source/AuthDataSource.kt +++ b/app/src/main/java/org/android/go/sopt/data/source/remote/AuthDataSource.kt @@ -1,8 +1,8 @@ -package org.android.go.sopt.data.source +package org.android.go.sopt.data.source.remote import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto -import org.android.go.sopt.data.entity.remote.wrapper.BaseResponse +import org.android.go.sopt.data.entity.remote.response.wrapper.BaseResponse import org.android.go.sopt.data.service.AuthService import javax.inject.Inject diff --git a/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt b/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt index efc1edf..69082ea 100644 --- a/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt +++ b/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt @@ -2,10 +2,10 @@ package org.android.go.sopt.domain.repository import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto -import org.android.go.sopt.domain.model.User +import org.android.go.sopt.data.entity.local.User interface AuthRepository { - suspend fun postSignup(requestPostSignUpDto: RequestPostSignUpDto): Result + suspend fun postSignup(requestPostSignUpDto: RequestPostSignUpDto): Result fun setAutoLogin(isAutoLogin: Boolean) diff --git a/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt b/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt index 903d411..ad7ae88 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt @@ -9,7 +9,7 @@ import androidx.activity.viewModels import dagger.hilt.android.AndroidEntryPoint import org.android.go.sopt.R import org.android.go.sopt.databinding.ActivityLoginBinding -import org.android.go.sopt.domain.model.User +import org.android.go.sopt.data.entity.local.User import org.android.go.sopt.presentation.main.MainActivity import org.android.go.sopt.presentation.signup.SignupActivity import org.android.go.sopt.util.state.LocalUiState.Failure diff --git a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt index 49b4a65..1453c78 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt @@ -4,7 +4,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel -import org.android.go.sopt.domain.model.User +import org.android.go.sopt.data.entity.local.User import org.android.go.sopt.domain.repository.AuthRepository import org.android.go.sopt.util.state.LocalUiState import org.android.go.sopt.util.state.LocalUiState.Failure diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt b/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt index fe7cc9e..70936b4 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt @@ -30,7 +30,6 @@ class GalleryFragment : BindingFragment(R.layout.fragmen override fun onDestroyView() { super.onDestroyView() - _binding = null imageAdapter = null } diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt b/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt index d00592d..03d50f4 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt @@ -7,10 +7,10 @@ import androidx.recyclerview.widget.ConcatAdapter import dagger.hilt.android.AndroidEntryPoint import org.android.go.sopt.R import org.android.go.sopt.databinding.FragmentHomeBinding -import org.android.go.sopt.util.state.LocalUiState.Failure -import org.android.go.sopt.util.state.LocalUiState.Success import org.android.go.sopt.util.binding.BindingFragment import org.android.go.sopt.util.extension.showSnackbar +import org.android.go.sopt.util.state.LocalUiState.Failure +import org.android.go.sopt.util.state.LocalUiState.Success @AndroidEntryPoint class HomeFragment : BindingFragment(R.layout.fragment_home) { diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileViewModel.kt index 43314dc..eb55d05 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileViewModel.kt @@ -3,7 +3,7 @@ package org.android.go.sopt.presentation.main.profile import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel -import org.android.go.sopt.domain.model.User +import org.android.go.sopt.data.entity.local.User import org.android.go.sopt.domain.repository.AuthRepository import javax.inject.Inject diff --git a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt index 74b509c..5fee5c3 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt @@ -7,7 +7,7 @@ import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto -import org.android.go.sopt.domain.model.User +import org.android.go.sopt.data.entity.local.User import org.android.go.sopt.domain.repository.AuthRepository import org.android.go.sopt.util.safeValueOf import org.android.go.sopt.util.state.RemoteUiState From 2e8e9e5b6d5a4588eb26a451705e52afda26c028 Mon Sep 17 00:00:00 2001 From: b1urrrr Date: Fri, 12 May 2023 19:32:04 +0900 Subject: [PATCH 05/16] =?UTF-8?q?[ADD/#8]=20placeholder,=20error,=20fallba?= =?UTF-8?q?ck=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/android/go/sopt/util/binding/BindingAdapter.kt | 5 ++++- app/src/main/res/drawable/ic_image_not_supported.xml | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_image_not_supported.xml diff --git a/app/src/main/java/org/android/go/sopt/util/binding/BindingAdapter.kt b/app/src/main/java/org/android/go/sopt/util/binding/BindingAdapter.kt index 99653e6..a4096a1 100644 --- a/app/src/main/java/org/android/go/sopt/util/binding/BindingAdapter.kt +++ b/app/src/main/java/org/android/go/sopt/util/binding/BindingAdapter.kt @@ -4,13 +4,16 @@ import android.widget.ImageView import androidx.databinding.BindingAdapter import coil.load import coil.transform.RoundedCornersTransformation +import org.android.go.sopt.R object BindingAdapter { @JvmStatic @BindingAdapter("setRoundedCornersImage") fun ImageView.setRoundedCornersImage(img: String?) { load(img) { - // TODO: placeholder & load error 이미지 추가 + placeholder(R.mipmap.ic_go_sopt) + error(R.drawable.ic_image_not_supported) + fallback(R.drawable.ic_image_not_supported) transformations(RoundedCornersTransformation(50f)) } } diff --git a/app/src/main/res/drawable/ic_image_not_supported.xml b/app/src/main/res/drawable/ic_image_not_supported.xml new file mode 100644 index 0000000..d5a32e1 --- /dev/null +++ b/app/src/main/res/drawable/ic_image_not_supported.xml @@ -0,0 +1,5 @@ + + + From e7d9d642ceffa67bcdc4af8736b42d0221924103 Mon Sep 17 00:00:00 2001 From: b1urrrr Date: Fri, 12 May 2023 19:50:25 +0900 Subject: [PATCH 06/16] =?UTF-8?q?[ADD/#8]=20follower=20=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=20=EB=A9=94=EB=89=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../go/sopt/presentation/main/MainActivity.kt | 2 ++ .../main/follower/FollowerFragment.kt | 13 +++++++++ .../main/res/drawable/ic_main_follower.xml | 5 ++++ app/src/main/res/layout/fragment_follower.xml | 29 +++++++++++++++++++ app/src/main/res/menu/menu_main.xml | 4 +++ app/src/main/res/values/strings.xml | 4 +++ 6 files changed, 57 insertions(+) create mode 100644 app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerFragment.kt create mode 100644 app/src/main/res/drawable/ic_main_follower.xml create mode 100644 app/src/main/res/layout/fragment_follower.xml diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt b/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt index 7e79d74..27d1c6a 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt @@ -7,6 +7,7 @@ import androidx.fragment.app.replace import dagger.hilt.android.AndroidEntryPoint import org.android.go.sopt.R import org.android.go.sopt.databinding.ActivityMainBinding +import org.android.go.sopt.presentation.main.follower.FollowerFragment import org.android.go.sopt.presentation.main.gallery.GalleryFragment import org.android.go.sopt.presentation.main.home.HomeFragment import org.android.go.sopt.presentation.main.profile.ProfileFragment @@ -30,6 +31,7 @@ class MainActivity : BindingActivity(R.layout.activity_main R.id.menu_home -> navigateTo() R.id.menu_gallery -> navigateTo() R.id.menu_search -> navigateTo() + R.id.menu_follower -> navigateTo() R.id.menu_profile -> navigateTo() } true diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerFragment.kt b/app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerFragment.kt new file mode 100644 index 0000000..3fa5066 --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerFragment.kt @@ -0,0 +1,13 @@ +package org.android.go.sopt.presentation.main.follower + +import org.android.go.sopt.R +import org.android.go.sopt.databinding.FragmentFollowerBinding +import org.android.go.sopt.util.binding.BindingFragment + +class FollowerFragment : BindingFragment(R.layout.fragment_follower) { + + companion object { + @JvmStatic + fun newInstance() = FollowerFragment() + } +} diff --git a/app/src/main/res/drawable/ic_main_follower.xml b/app/src/main/res/drawable/ic_main_follower.xml new file mode 100644 index 0000000..a3ccd71 --- /dev/null +++ b/app/src/main/res/drawable/ic_main_follower.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/fragment_follower.xml b/app/src/main/res/layout/fragment_follower.xml new file mode 100644 index 0000000..6e0ea78 --- /dev/null +++ b/app/src/main/res/layout/fragment_follower.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 1cc7666..c032ffa 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -12,6 +12,10 @@ android:id="@+id/menu_search" android:icon="@drawable/ic_main_search" android:title="@string/main_search" /> + 갤러리 검색 + 팔로워 프로필 @@ -48,6 +49,9 @@ SEARCH FRAGMENT + + FOLLOWER FRAGMENT + 이름 : %s 특기 : %s From a532abbb07bb83335aee868273309bf692fc0f51 Mon Sep 17 00:00:00 2001 From: b1urrrr Date: Fri, 12 May 2023 20:53:24 +0900 Subject: [PATCH 07/16] =?UTF-8?q?[ADD/#8]=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=84=9C=EB=B2=84=20=ED=86=B5=EC=8B=A0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repository/AuthRepositoryImpl.kt | 2 +- .../data/source/local/SharedPrefDataSource.kt | 2 +- .../entity/local => domain/model}/User.kt | 8 ++-- .../sopt/domain/repository/AuthRepository.kt | 2 +- .../sopt/presentation/login/LoginActivity.kt | 2 +- .../sopt/presentation/login/LoginViewModel.kt | 2 +- .../main/profile/ProfileViewModel.kt | 2 +- .../presentation/signup/SignupActivity.kt | 20 +++++++- .../presentation/signup/SignupViewModel.kt | 48 ++++++++++++------- .../java/org/android/go/sopt/util/EnumUtil.kt | 2 +- app/src/main/res/values/strings.xml | 4 +- 11 files changed, 64 insertions(+), 30 deletions(-) rename app/src/main/java/org/android/go/sopt/{data/entity/local => domain/model}/User.kt (63%) diff --git a/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt b/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt index 75d0eaf..b0524d0 100644 --- a/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt +++ b/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt @@ -4,7 +4,7 @@ import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto import org.android.go.sopt.data.source.local.SharedPrefDataSource import org.android.go.sopt.data.source.remote.AuthDataSource -import org.android.go.sopt.data.entity.local.User +import org.android.go.sopt.domain.model.User import org.android.go.sopt.domain.repository.AuthRepository import javax.inject.Inject diff --git a/app/src/main/java/org/android/go/sopt/data/source/local/SharedPrefDataSource.kt b/app/src/main/java/org/android/go/sopt/data/source/local/SharedPrefDataSource.kt index ef5fdf0..a189381 100644 --- a/app/src/main/java/org/android/go/sopt/data/source/local/SharedPrefDataSource.kt +++ b/app/src/main/java/org/android/go/sopt/data/source/local/SharedPrefDataSource.kt @@ -4,7 +4,7 @@ import android.content.SharedPreferences import androidx.core.content.edit import com.google.gson.Gson import com.google.gson.GsonBuilder -import org.android.go.sopt.data.entity.local.User +import org.android.go.sopt.domain.model.User import javax.inject.Inject import javax.inject.Singleton diff --git a/app/src/main/java/org/android/go/sopt/data/entity/local/User.kt b/app/src/main/java/org/android/go/sopt/domain/model/User.kt similarity index 63% rename from app/src/main/java/org/android/go/sopt/data/entity/local/User.kt rename to app/src/main/java/org/android/go/sopt/domain/model/User.kt index d648e0e..cac352a 100644 --- a/app/src/main/java/org/android/go/sopt/data/entity/local/User.kt +++ b/app/src/main/java/org/android/go/sopt/domain/model/User.kt @@ -1,4 +1,4 @@ -package org.android.go.sopt.data.entity.local +package org.android.go.sopt.domain.model import android.os.Parcelable import kotlinx.parcelize.Parcelize @@ -9,7 +9,7 @@ import org.android.go.sopt.util.type.MBTI.NONE data class User( val id: String = "", val pwd: String = "", - val name: String? = "익명", - val specialty: String? = "", - val mbti: MBTI? = NONE, + val name: String = "익명", + val specialty: String = "", + val mbti: MBTI = NONE, ) : Parcelable diff --git a/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt b/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt index 69082ea..f19542b 100644 --- a/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt +++ b/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt @@ -2,7 +2,7 @@ package org.android.go.sopt.domain.repository import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto -import org.android.go.sopt.data.entity.local.User +import org.android.go.sopt.domain.model.User interface AuthRepository { suspend fun postSignup(requestPostSignUpDto: RequestPostSignUpDto): Result diff --git a/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt b/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt index ad7ae88..903d411 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt @@ -9,7 +9,7 @@ import androidx.activity.viewModels import dagger.hilt.android.AndroidEntryPoint import org.android.go.sopt.R import org.android.go.sopt.databinding.ActivityLoginBinding -import org.android.go.sopt.data.entity.local.User +import org.android.go.sopt.domain.model.User import org.android.go.sopt.presentation.main.MainActivity import org.android.go.sopt.presentation.signup.SignupActivity import org.android.go.sopt.util.state.LocalUiState.Failure diff --git a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt index 1453c78..49b4a65 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt @@ -4,7 +4,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel -import org.android.go.sopt.data.entity.local.User +import org.android.go.sopt.domain.model.User import org.android.go.sopt.domain.repository.AuthRepository import org.android.go.sopt.util.state.LocalUiState import org.android.go.sopt.util.state.LocalUiState.Failure diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileViewModel.kt index eb55d05..43314dc 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileViewModel.kt @@ -3,7 +3,7 @@ package org.android.go.sopt.presentation.main.profile import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel -import org.android.go.sopt.data.entity.local.User +import org.android.go.sopt.domain.model.User import org.android.go.sopt.domain.repository.AuthRepository import javax.inject.Inject diff --git a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt index c962b21..afc7b3b 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt @@ -9,7 +9,10 @@ import dagger.hilt.android.AndroidEntryPoint import org.android.go.sopt.R import org.android.go.sopt.databinding.ActivitySignupBinding import org.android.go.sopt.presentation.login.LoginActivity +import org.android.go.sopt.presentation.signup.SignupViewModel.Companion.CODE_DUPLICATED_INFO import org.android.go.sopt.presentation.signup.SignupViewModel.Companion.CODE_INVALID_ID +import org.android.go.sopt.presentation.signup.SignupViewModel.Companion.CODE_INVALID_INPUT +import org.android.go.sopt.presentation.signup.SignupViewModel.Companion.CODE_INVALID_NAME import org.android.go.sopt.presentation.signup.SignupViewModel.Companion.CODE_INVALID_PWD import org.android.go.sopt.util.binding.BindingActivity import org.android.go.sopt.util.extension.showSnackbar @@ -43,10 +46,25 @@ class SignupActivity : BindingActivity(R.layout.activity_ binding.root, getString(R.string.signup_invalid_pwd_msg), ) + + CODE_INVALID_NAME -> showSnackbar( + binding.root, + getString(R.string.signup_invalid_name_msg), + ) + + CODE_INVALID_INPUT -> showSnackbar( + binding.root, + getString(R.string.wrong_input_msg), + ) + + CODE_DUPLICATED_INFO -> showSnackbar( + binding.root, + getString(R.string.signup_duplicated_info_msg), + ) } } - is Error -> showSnackbar(binding.root, getString(R.string.server_error_msg)) + is Error -> showSnackbar(binding.root, getString(R.string.unknown_error_msg)) } } } diff --git a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt index 5fee5c3..e6c9b45 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt @@ -7,7 +7,7 @@ import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto -import org.android.go.sopt.data.entity.local.User +import org.android.go.sopt.domain.model.User import org.android.go.sopt.domain.repository.AuthRepository import org.android.go.sopt.util.safeValueOf import org.android.go.sopt.util.state.RemoteUiState @@ -29,58 +29,69 @@ class SignupViewModel @Inject constructor( get() = _signupState val _id = MutableLiveData("") - val id: String - get() = requireNotNull(_id.value).trim() + private val id: String + get() = _id.value?.trim() ?: "" val _pwd = MutableLiveData("") - val pwd: String - get() = requireNotNull(_pwd.value).trim() + private val pwd: String + get() = _pwd.value?.trim() ?: "" val _name = MutableLiveData("") - val name: String + private val name: String get() = _name.value?.trim() ?: "" val _specialty = MutableLiveData("") - val specialty: String + private val specialty: String get() = _specialty.value?.trim() ?: "" val _mbti = MutableLiveData("") - val mbti: MBTI? + private val mbti: MBTI get() = safeValueOf(_mbti.value?.trim()?.uppercase(), NONE) - private fun isValidId(id: String?) = - !id.isNullOrBlank() && id.length in MIN_ID_LENGTH..MAX_ID_LENGTH + private fun isValidId() = id.isNotBlank() && id.length in MIN_ID_LENGTH..MAX_ID_LENGTH - private fun isValidPwd(pwd: String?) = - !pwd.isNullOrBlank() && pwd.length in MIN_PWD_LENGTH..MAX_PWD_LENGTH + private fun isValidPwd() = pwd.isNotBlank() && pwd.length in MIN_PWD_LENGTH..MAX_PWD_LENGTH + + private fun isValidName() = name.isNotBlank() fun signup() { - if (!isValidId(_id.value)) { + if (!isValidId()) { _signupState.value = Failure(CODE_INVALID_ID) return } - if (!isValidPwd(_pwd.value)) { + + if (!isValidPwd()) { _signupState.value = Failure(CODE_INVALID_PWD) return } + if (!isValidName()) { + _signupState.value = Failure(CODE_INVALID_NAME) + return + } + val requestPostSignUpDto = RequestPostSignUpDto( id = id, password = pwd, name = name, skill = specialty, ) + viewModelScope.launch { authRepository.postSignup(requestPostSignUpDto) .onSuccess { response -> authRepository.setSignedUpUser(getUser()) _signupState.value = Success - Timber.d("$response") + Timber.d("POST SIGNUP SUCCESS : $response") } .onFailure { t -> if (t is HttpException) { - Timber.e("${t.code()} : ${t.message()}") - _signupState.value = Error + when (t.code()) { + CODE_INVALID_INPUT -> _signupState.value = Failure(CODE_INVALID_INPUT) + CODE_DUPLICATED_INFO -> _signupState.value = Failure(CODE_DUPLICATED_INFO) + else -> _signupState.value = Error + } + Timber.e("POST SIGNUP FAIL ${t.code()} : ${t.message()}") } } } @@ -104,5 +115,8 @@ class SignupViewModel @Inject constructor( const val CODE_INVALID_ID = 100 const val CODE_INVALID_PWD = 101 + const val CODE_INVALID_NAME = 102 + const val CODE_INVALID_INPUT = 400 + const val CODE_DUPLICATED_INFO = 409 } } diff --git a/app/src/main/java/org/android/go/sopt/util/EnumUtil.kt b/app/src/main/java/org/android/go/sopt/util/EnumUtil.kt index e9fbffc..c2ada6b 100644 --- a/app/src/main/java/org/android/go/sopt/util/EnumUtil.kt +++ b/app/src/main/java/org/android/go/sopt/util/EnumUtil.kt @@ -1,6 +1,6 @@ package org.android.go.sopt.util -inline fun > safeValueOf(type: String?, default: T?): T? { +inline fun > safeValueOf(type: String?, default: T): T { return try { java.lang.Enum.valueOf(T::class.java, type ?: return default) } catch (e: IllegalArgumentException) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f715b64..df1ec23 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -5,7 +5,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 잘못된 입력입니다. - 서버를 불러올 수 없습니다. + 알 수 없는 오류가 발생했습니다. Binding not initialized to reference the view. Unknown View Type : %d @@ -30,6 +30,8 @@ 이름을 입력하세요. 잘못된 아이디입니다. 잘못된 비밀번호입니다. + 잘못된 이름입니다. + 이미 가입된 정보입니다. From a1e8550686610b05355aa4812c7a0252b1a71db0 Mon Sep 17 00:00:00 2001 From: b1urrrr Date: Fri, 12 May 2023 21:04:35 +0900 Subject: [PATCH 08/16] =?UTF-8?q?[MOD/#8]=20MBTI=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/android/go/sopt/domain/model/User.kt | 3 --- .../sopt/presentation/login/LoginActivity.kt | 13 +++------- .../sopt/presentation/login/LoginViewModel.kt | 15 ++++------- .../presentation/signup/SignupActivity.kt | 2 -- .../presentation/signup/SignupViewModel.kt | 19 -------------- .../org/android/go/sopt/util/type/MBTI.kt | 5 ---- app/src/main/res/layout/activity_signup.xml | 26 ------------------- 7 files changed, 8 insertions(+), 75 deletions(-) delete mode 100644 app/src/main/java/org/android/go/sopt/util/type/MBTI.kt diff --git a/app/src/main/java/org/android/go/sopt/domain/model/User.kt b/app/src/main/java/org/android/go/sopt/domain/model/User.kt index cac352a..6fa189b 100644 --- a/app/src/main/java/org/android/go/sopt/domain/model/User.kt +++ b/app/src/main/java/org/android/go/sopt/domain/model/User.kt @@ -2,8 +2,6 @@ package org.android.go.sopt.domain.model import android.os.Parcelable import kotlinx.parcelize.Parcelize -import org.android.go.sopt.util.type.MBTI -import org.android.go.sopt.util.type.MBTI.NONE @Parcelize data class User( @@ -11,5 +9,4 @@ data class User( val pwd: String = "", val name: String = "익명", val specialty: String = "", - val mbti: MBTI = NONE, ) : Parcelable diff --git a/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt b/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt index 903d411..5f09c22 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt @@ -2,23 +2,20 @@ package org.android.go.sopt.presentation.login import android.app.Activity import android.content.Intent -import android.content.Intent.EXTRA_USER import android.os.Bundle import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import dagger.hilt.android.AndroidEntryPoint import org.android.go.sopt.R import org.android.go.sopt.databinding.ActivityLoginBinding -import org.android.go.sopt.domain.model.User import org.android.go.sopt.presentation.main.MainActivity import org.android.go.sopt.presentation.signup.SignupActivity -import org.android.go.sopt.util.state.LocalUiState.Failure -import org.android.go.sopt.util.state.LocalUiState.Success import org.android.go.sopt.util.binding.BindingActivity -import org.android.go.sopt.util.extension.getCompatibleParcelableExtra import org.android.go.sopt.util.extension.setOnSingleClickListener import org.android.go.sopt.util.extension.showSnackbar import org.android.go.sopt.util.extension.showToast +import org.android.go.sopt.util.state.LocalUiState.Failure +import org.android.go.sopt.util.state.LocalUiState.Success @AndroidEntryPoint class LoginActivity : BindingActivity(R.layout.activity_login) { @@ -36,11 +33,7 @@ class LoginActivity : BindingActivity(R.layout.activity_lo val signupResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> if (result.resultCode == Activity.RESULT_OK) { - val resultData = result.data ?: return@registerForActivityResult - resultData.getCompatibleParcelableExtra(EXTRA_USER)?.let { user -> - viewModel.setSavedUser(user) - showSnackbar(binding.root, getString(R.string.login_signup_success_msg)) - } + showSnackbar(binding.root, getString(R.string.login_signup_success_msg)) } } diff --git a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt index 49b4a65..7f77ed1 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt @@ -4,7 +4,6 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel -import org.android.go.sopt.domain.model.User import org.android.go.sopt.domain.repository.AuthRepository import org.android.go.sopt.util.state.LocalUiState import org.android.go.sopt.util.state.LocalUiState.Failure @@ -15,8 +14,6 @@ import javax.inject.Inject class LoginViewModel @Inject constructor( private val authRepository: AuthRepository, ) : ViewModel() { - var signedUpUser = User() - private val _loginState = MutableLiveData() val loginState: LiveData get() = _loginState @@ -29,21 +26,19 @@ class LoginViewModel @Inject constructor( } private fun setupAutoLogin() { - if (authRepository.getAutoLogin() && authRepository.getSignedUpUser() != null) _loginState.value = Success - } - - fun setSavedUser(savedUser: User) { - this.signedUpUser = savedUser + if (authRepository.getAutoLogin() && authRepository.getSignedUpUser() != null) { + _loginState.value = Success + } } - private fun isValidInput() = - !id.value.isNullOrBlank() && id.value == signedUpUser.id && !pwd.value.isNullOrBlank() && pwd.value == signedUpUser.pwd + private fun isValidInput() = !id.value.isNullOrBlank() && !pwd.value.isNullOrBlank() fun login() { if (!isValidInput()) { _loginState.value = Failure(null) return } + // TODO : 로그인 정보 저장 authRepository.setAutoLogin(true) _loginState.value = Success } diff --git a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt index afc7b3b..c1efe8f 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupActivity.kt @@ -2,7 +2,6 @@ package org.android.go.sopt.presentation.signup import android.app.Activity import android.content.Intent -import android.content.Intent.EXTRA_USER import android.os.Bundle import androidx.activity.viewModels import dagger.hilt.android.AndroidEntryPoint @@ -71,7 +70,6 @@ class SignupActivity : BindingActivity(R.layout.activity_ private fun navigateToLoginScreen() { Intent(this, LoginActivity::class.java).apply { - this.putExtra(EXTRA_USER, viewModel.getUser()) setResult(Activity.RESULT_OK, this) if (!isFinishing) finish() } diff --git a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt index e6c9b45..9bbb909 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt @@ -7,15 +7,11 @@ import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto -import org.android.go.sopt.domain.model.User import org.android.go.sopt.domain.repository.AuthRepository -import org.android.go.sopt.util.safeValueOf import org.android.go.sopt.util.state.RemoteUiState import org.android.go.sopt.util.state.RemoteUiState.Error import org.android.go.sopt.util.state.RemoteUiState.Failure import org.android.go.sopt.util.state.RemoteUiState.Success -import org.android.go.sopt.util.type.MBTI -import org.android.go.sopt.util.type.MBTI.NONE import retrofit2.HttpException import timber.log.Timber import javax.inject.Inject @@ -44,10 +40,6 @@ class SignupViewModel @Inject constructor( private val specialty: String get() = _specialty.value?.trim() ?: "" - val _mbti = MutableLiveData("") - private val mbti: MBTI - get() = safeValueOf(_mbti.value?.trim()?.uppercase(), NONE) - private fun isValidId() = id.isNotBlank() && id.length in MIN_ID_LENGTH..MAX_ID_LENGTH private fun isValidPwd() = pwd.isNotBlank() && pwd.length in MIN_PWD_LENGTH..MAX_PWD_LENGTH @@ -80,7 +72,6 @@ class SignupViewModel @Inject constructor( viewModelScope.launch { authRepository.postSignup(requestPostSignUpDto) .onSuccess { response -> - authRepository.setSignedUpUser(getUser()) _signupState.value = Success Timber.d("POST SIGNUP SUCCESS : $response") } @@ -97,16 +88,6 @@ class SignupViewModel @Inject constructor( } } - fun getUser(): User { - return User( - id = id, - pwd = pwd, - name = name, - specialty = specialty, - mbti = mbti, - ) - } - companion object { const val MIN_ID_LENGTH = 6 const val MAX_ID_LENGTH = 10 diff --git a/app/src/main/java/org/android/go/sopt/util/type/MBTI.kt b/app/src/main/java/org/android/go/sopt/util/type/MBTI.kt deleted file mode 100644 index 27b175d..0000000 --- a/app/src/main/java/org/android/go/sopt/util/type/MBTI.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.android.go.sopt.util.type - -enum class MBTI { - NONE, ISTJ, ISFJ, INFJ, INTJ, ISTP, ISFP, INFP, INTP, ESTP, ESFP, ENFP, ENTP, ESTJ, ESFJ, ENFJ, ENTJ -} diff --git a/app/src/main/res/layout/activity_signup.xml b/app/src/main/res/layout/activity_signup.xml index 71b6e19..7e299f4 100644 --- a/app/src/main/res/layout/activity_signup.xml +++ b/app/src/main/res/layout/activity_signup.xml @@ -137,32 +137,6 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tv_signup_specialty_label" /> - - - - From 95b1324cbae693cf09c96e29d5f22388fc4121d8 Mon Sep 17 00:00:00 2001 From: b1urrrr Date: Fri, 12 May 2023 21:12:04 +0900 Subject: [PATCH 09/16] =?UTF-8?q?[DEL/#8]=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=95=84=EC=9B=83=EC=97=90=EC=84=9C=20mbti?= =?UTF-8?q?=20=ED=85=8D=EC=8A=A4=ED=8A=B8=EB=B7=B0=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/fragment_profile.xml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 39b57d3..8e737a3 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -53,19 +53,6 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tv_profile_name" /> - -