-
Notifications
You must be signed in to change notification settings - Fork 0
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
✨ implement screens for sign up #85
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c6235b7
:lipstick: add style settings for implementing signup
kmkim2689 e12892a
:lipstick: add layout components for implementing sign up
kmkim2689 15a10fe
:sparkles: add screens for implementing sign up
kmkim2689 156b6ae
:rotating_light: fix kt lint error
kmkim2689 02de6c8
:recycle: add string values for sign up to string.xml
kmkim2689 d7e823f
:recycle: change MutableLiveData properties from var to val
kmkim2689 67f2484
:recycle: nullify binding object on onDestroyView callback
kmkim2689 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...rc/main/java/net/pengcook/android/presentation/core/listener/AppbarActionEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.pengcook.android.presentation.core.listener | ||
|
||
interface AppbarActionEventListener { | ||
fun onNavigateBack() | ||
} |
17 changes: 17 additions & 0 deletions
17
android/app/src/main/java/net/pengcook/android/presentation/core/util/Event.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package net.pengcook.android.presentation.core.util | ||
|
||
open class Event<out T>(private val content: T) { | ||
var hasBeenHandled = false | ||
private set | ||
|
||
fun getContentIfNotHandled(): T? { | ||
return if (hasBeenHandled) { | ||
null | ||
} else { | ||
hasBeenHandled = true | ||
content | ||
} | ||
} | ||
|
||
fun peekContent(): T = content | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...d/app/src/main/java/net/pengcook/android/presentation/signup/BottomButtonClickListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.pengcook.android.presentation.signup | ||
|
||
interface BottomButtonClickListener { | ||
fun onConfirm() | ||
} |
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/net/pengcook/android/presentation/signup/SignUpEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package net.pengcook.android.presentation.signup | ||
|
||
sealed interface SignUpEvent { | ||
class NavigateToMain( | ||
val accessToken: String, | ||
val refreshToken: String, | ||
) : SignUpEvent | ||
|
||
data object Error : SignUpEvent | ||
|
||
data object NavigateBack : SignUpEvent | ||
} |
21 changes: 21 additions & 0 deletions
21
android/app/src/main/java/net/pengcook/android/presentation/signup/SignUpForm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.pengcook.android.presentation.signup | ||
|
||
import java.io.File | ||
|
||
data class SignUpForm( | ||
val profileImage: File? = null, | ||
val username: String = INITIAL_VALUE, | ||
val nickname: String = INITIAL_VALUE, | ||
val yearOfBirthday: Int = INITIAL_YEAR, | ||
val monthOfBirthday: Int = INITIAL_MONTH, | ||
val dayOfBirthday: Int = INITIAL_DAY, | ||
val country: String = INITIAL_COUNTRY, | ||
) { | ||
companion object { | ||
private const val INITIAL_VALUE = "" | ||
private const val INITIAL_YEAR = 2024 | ||
private const val INITIAL_MONTH = 1 | ||
private const val INITIAL_DAY = 1 | ||
private const val INITIAL_COUNTRY = "" | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
android/app/src/main/java/net/pengcook/android/presentation/signup/SignUpFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package net.pengcook.android.presentation.signup | ||
|
||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ArrayAdapter | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import androidx.navigation.fragment.findNavController | ||
import net.pengcook.android.R | ||
import net.pengcook.android.databinding.FragmentSignUpBinding | ||
|
||
class SignUpFragment : Fragment() { | ||
private var _binding: FragmentSignUpBinding? = null | ||
private val binding: FragmentSignUpBinding | ||
get() = _binding!! | ||
private val viewModel: SignUpViewModel by viewModels() | ||
private val launcher = | ||
registerForActivityResult<String, Uri>(ActivityResultContracts.GetContent()) { uri -> | ||
try { | ||
viewModel.changeProfileImage(uri) | ||
} catch (e: RuntimeException) { | ||
} | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View { | ||
_binding = FragmentSignUpBinding.inflate(inflater) | ||
binding.viewModel = viewModel | ||
binding.lifecycleOwner = this | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated( | ||
view: View, | ||
savedInstanceState: Bundle?, | ||
) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setUpBirthDateSpinner() | ||
setUpCountrySpinner() | ||
setUpClickListener() | ||
observeViewModel() | ||
} | ||
|
||
private fun setUpClickListener() { | ||
binding.ivProfileImage.setOnClickListener { | ||
launcher.launch("image/*") | ||
} | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
|
||
private fun setUpCountrySpinner() { | ||
val countryAdapter = | ||
ArrayAdapter( | ||
requireContext(), | ||
android.R.layout.simple_spinner_item, | ||
List(100) { "country$it" }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 여기는 국가를 샘플로 담은 것 같은데, 향후 국가리스트를 서버에서 받을지, 인메모리로 저장해둘지 공유해주시면 좋을것 같아요 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 사안은 서버와 협의해봐야 할 것 같네요! |
||
) | ||
countryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) | ||
binding.formCountry.spFormContent.spDefault.adapter = countryAdapter | ||
} | ||
|
||
private fun setUpBirthDateSpinner() { | ||
val yearAdapter = | ||
ArrayAdapter( | ||
requireContext(), | ||
android.R.layout.simple_spinner_item, | ||
List(100) { (it + 1920).toString() }, | ||
) | ||
yearAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) | ||
binding.formBirthDate.spFormContent1.spDefault.adapter = yearAdapter | ||
|
||
val monthAdapter = | ||
ArrayAdapter( | ||
requireContext(), | ||
android.R.layout.simple_spinner_item, | ||
List(12) { (it + 1).toString() }, | ||
) | ||
monthAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) | ||
binding.formBirthDate.spFormContent2.spDefault.adapter = monthAdapter | ||
|
||
val dayAdapter = | ||
ArrayAdapter( | ||
requireContext(), | ||
android.R.layout.simple_spinner_item, | ||
List(31) { (it + 1).toString() }, | ||
) | ||
dayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) | ||
binding.formBirthDate.spFormContent3.spDefault.adapter = dayAdapter | ||
} | ||
|
||
private fun observeViewModel() { | ||
viewModel.signUpEvent.observe(viewLifecycleOwner) { event -> | ||
val signUpEvent = event.getContentIfNotHandled() ?: return@observe | ||
when (signUpEvent) { | ||
is SignUpEvent.NavigateToMain -> { | ||
findNavController().navigate(R.id.action_signUpFragment_to_homeFragment) | ||
} | ||
is SignUpEvent.Error -> { | ||
} | ||
is SignUpEvent.NavigateBack -> { | ||
findNavController().navigate(R.id.action_signUpFragment_to_onboardingFragment) | ||
} | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/net/pengcook/android/presentation/signup/SignUpUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.pengcook.android.presentation.signup | ||
|
||
import android.net.Uri | ||
|
||
data class SignUpUiState( | ||
val isLoading: Boolean = false, | ||
val profileImage: Uri? = null, | ||
val fulfilled: Boolean = false, | ||
) |
39 changes: 39 additions & 0 deletions
39
android/app/src/main/java/net/pengcook/android/presentation/signup/SignUpViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.pengcook.android.presentation.signup | ||
|
||
import android.net.Uri | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import net.pengcook.android.presentation.core.util.Event | ||
|
||
class SignUpViewModel : | ||
ViewModel(), | ||
BottomButtonClickListener { | ||
val usernameContent: MutableLiveData<String> = MutableLiveData() | ||
val nicknameContent: MutableLiveData<String> = MutableLiveData() | ||
val year: MutableLiveData<String> = MutableLiveData() | ||
val month: MutableLiveData<String> = MutableLiveData() | ||
val day: MutableLiveData<String> = MutableLiveData() | ||
val country: MutableLiveData<String> = MutableLiveData() | ||
private var _imageUri: MutableLiveData<Uri> = MutableLiveData() | ||
val imageUri: LiveData<Uri> | ||
get() = _imageUri | ||
|
||
private var _signUpUiState: MutableLiveData<SignUpUiState> = MutableLiveData(SignUpUiState()) | ||
val signUpUiState: LiveData<SignUpUiState> | ||
get() = _signUpUiState | ||
|
||
private var _signUpEvent: MutableLiveData<Event<SignUpEvent>> = MutableLiveData() | ||
val signUpEvent: LiveData<Event<SignUpEvent>> | ||
get() = _signUpEvent | ||
|
||
fun changeProfileImage(uri: Uri) { | ||
_imageUri.value = uri | ||
} | ||
|
||
override fun onConfirm() { | ||
_signUpUiState.value = signUpUiState.value?.copy(isLoading = true) | ||
_signUpEvent.value = Event(SignUpEvent.NavigateToMain("", "")) | ||
_signUpUiState.value = signUpUiState.value?.copy(isLoading = false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
<solid android:color="@android:color/transparent"/> | ||
<corners android:radius="16dp"/> | ||
<stroke android:color="@color/gray" android:width="1dp" /> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp"> | ||
|
||
<path android:fillColor="@android:color/white" android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/> | ||
|
||
</vector> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
binding nullable 처리에 이어 destroy때 null로 해주는거 좋네요. 명시적으로 destroy 되는 느낌이 있어 좋아보이는데, 궁금한점은 nullable 처리해뒀기 때문에 GC가 일정 시간 지나면 알아서 destroy 하지 않는지 궁금합니다. 제가 몰라서 혹시 아시면 알려주시면 감사하겠습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구글에서 해당 방식으로 fragment를 사용하도록 제시하는데, 가장 큰 이유는 fragment의 생명주기의 특성 상 메모리 누수가 발생할 수 있기 때문이라고 볼 수 있습니다.
https://www.reddit.com/r/android_devs/comments/orbdas/is_it_required_or_good_practice_to_set_the/
https://woowacourse.slack.com/archives/C06DZU72A79/p1714702344693229?thread_ts=1714700634.545369&cid=C06DZU72A79