-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add screens for implementing sign up
- Loading branch information
Showing
13 changed files
with
408 additions
and
8 deletions.
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: 0 additions & 5 deletions
5
...rc/main/java/net/pengcook/android/presentation/core/listener/BottomButtonClickListener.kt
This file was deleted.
Oops, something went wrong.
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 | ||
} |
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() | ||
} |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
package net.pengcook.android.presentation.signup | ||
|
||
import java.io.File | ||
|
||
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 = "" | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...id/app/src/main/java/net/pengcook/android/presentation/signup/SignUpFormChangeListener.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,19 @@ | ||
package net.pengcook.android.presentation.signup | ||
|
||
import java.io.File | ||
|
||
interface SignUpFormEventListener { | ||
fun onProfileImageChange(image: File) | ||
|
||
fun onUsernameChange(username: String) | ||
|
||
fun onNicknameChange(nickname: String) | ||
|
||
fun onYearOfBirthChange(year: Int) | ||
|
||
fun onMonthOfBirthChange(month: Int) | ||
|
||
fun onDayOfBirthChange(day: Int) | ||
|
||
fun onCountryChange(country: String) | ||
} |
120 changes: 120 additions & 0 deletions
120
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,120 @@ | ||
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 onDestroy() { | ||
super.onDestroy() | ||
_binding = null | ||
} | ||
|
||
private fun setUpCountrySpinner() { | ||
val countryAdapter = | ||
ArrayAdapter( | ||
requireContext(), | ||
android.R.layout.simple_spinner_item, | ||
List(100) { "country$it" }, | ||
) | ||
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 + 1820).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 { | ||
var usernameContent: MutableLiveData<String> = MutableLiveData("") | ||
var nicknameContent: MutableLiveData<String> = MutableLiveData("") | ||
var year: MutableLiveData<String> = MutableLiveData("") | ||
var month: MutableLiveData<String> = MutableLiveData("") | ||
var day: MutableLiveData<String> = MutableLiveData("") | ||
var 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) | ||
} | ||
} |
Oops, something went wrong.