Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Mod functioning #7

Open
wants to merge 6 commits into
base: develop/view
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ android {
}

dependencies {
implementation 'com.jakewharton.timber:timber:5.0.1'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
// ViewModel 생성함수를 편하게 사용하고 싶다면?
implementation "androidx.fragment:fragment-ktx:1.5.3"
Expand Down
21 changes: 11 additions & 10 deletions app/src/main/java/org/sopt/sample/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
package org.sopt.sample

import org.sopt.sample.adapter.rvAdapter
import org.sopt.sample.databinding.FragmentHomeBinding
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.android.material.snackbar.Snackbar
import org.sopt.sample.adapter.rvAdapter
import org.sopt.sample.base.BindingFragment
import org.sopt.sample.databinding.FragmentSearchBinding
import org.sopt.sample.remote.*
import org.sopt.sample.databinding.FragmentHomeBinding
import org.sopt.sample.remote.ResponseUserDTO
import org.sopt.sample.remote.UserServicePool
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import timber.log.Timber

class HomeFragment: BindingFragment<FragmentHomeBinding>(R.layout.fragment_home) {
private var _binding : FragmentHomeBinding? = null
class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home) {
private var _binding: FragmentHomeBinding? = null
get() = requireNotNull(_binding)
private val userService = UserServicePool.userService

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if(BuildConfig.DEBUG){
Timber.plant(Timber.DebugTree())
}
val adapter = rvAdapter(requireContext())
binding.rvRepos.adapter = adapter
userService.user().enqueue(object : Callback<ResponseUserDTO> {
override fun onResponse(
call: Call<ResponseUserDTO>,
response: Response<ResponseUserDTO>
) {
Log.d("유저 정보", "${response.body()}")
if (response.isSuccessful) {
response.body()?.let {
Timber.d("${response.body()}")
adapter.setRepoList(it.data)
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/sopt/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.fragment.app.FragmentContainerView
import com.google.android.material.bottomnavigation.BottomNavigationView
import org.sopt.sample.base.BindingActivity
import org.sopt.sample.databinding.ActivityMainBinding
import timber.log.Timber

class MainActivity :BindingActivity<ActivityMainBinding>(R.layout.activity_main){
private val frame: FragmentContainerView by lazy { // activity_main의 화면 부분
Expand Down
22 changes: 18 additions & 4 deletions app/src/main/java/org/sopt/sample/SignInActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.sopt.sample

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.activity.viewModels
import org.sopt.sample.base.BindingActivity
import org.sopt.sample.databinding.ActivitySignInBinding
Expand All @@ -13,19 +14,32 @@ class SignInActivity: BindingActivity<ActivitySignInBinding>(R.layout.activity_s
super.onCreate(savedInstanceState)
binding.viewModel = viewModel
binding.lifecycleOwner = this
// 버튼 클릭 이벤트

addListeners()
addObservers()
}
private fun addListeners(){
binding.loginBtn.setOnClickListener {
viewModel.login(
binding.editTextId.text.toString(),
binding.editTextPw.text.toString()
)
}

viewModel.loginResult.observe(this) {
startActivity(Intent(this, MainActivity::class.java))
}
binding.registerBtn.setOnClickListener(){
startActivity(Intent(this,SignUpActivity::class.java))
}
}

private fun addObservers() {
viewModel.loginResult.observe(this) {
Toast.makeText(this, getString(R.string.sign_in_success_toast_msg), Toast.LENGTH_LONG).show()
moveToMain()
}
}

private fun moveToMain() {
startActivity(Intent(this, MainActivity::class.java))
finish()
}
Comment on lines +34 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수화 좋습니다 :)

}
39 changes: 22 additions & 17 deletions app/src/main/java/org/sopt/sample/SignUpActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.Toast
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import org.sopt.sample.base.BindingActivity
Expand All @@ -15,21 +16,30 @@ import java.util.regex.Pattern

class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_sign_up) {
private val viewModel by viewModels<SignupViewModel>()
var validEmail = false
var validPw = false
val EmailPattern = "^(?=.*[A-Za-z])(?=.*[0-9])[A-Za-z[0-9]]{6,10}$"
val pattern1 = Pattern.compile(EmailPattern)
val PwPattern = "^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[$@$!%*#?&.])[A-Za-z[0-9]$@$!%*#?&.]{6,12}$"
val pattern2 = Pattern.compile(PwPattern)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.viewModel = viewModel
binding.lifecycleOwner = this

// 버튼 클릭 이벤트
var validEmail = false
var validPw = false
val EmailPattern = "^(?=.*[A-Za-z])(?=.*[0-9])[A-Za-z[0-9]]{6,10}$"
val pattern1 = Pattern.compile(EmailPattern)
val PwPattern = "^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[$@$!%*#?&.])[A-Za-z[0-9]$@$!%*#?&.]{6,12}$"
val pattern2 = Pattern.compile(PwPattern)


addListeners()
addObservers()
}

private fun addListeners(){
binding.finishBtn.setOnClickListener {
viewModel.signup(
binding.editTextEmail.text.toString(),
binding.editTextPw.text.toString(),
binding.editTextName.text.toString()
)
}
binding.editTextEmail.addTextChangedListener(object : TextWatcher {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
// 입력난에 변화가 있을 시 조치
Expand All @@ -55,7 +65,9 @@ class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_
// 입력하기 전에 조치
}
})
}

private fun addObservers() {
viewModel.inputEmail.observe(this) {
val matcher1 = pattern1.matcher(it)
if(matcher1.find() == true) {
Expand Down Expand Up @@ -90,16 +102,9 @@ class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_
binding.finishBtn.isEnabled = true
}

binding.finishBtn.setOnClickListener {
viewModel.signup(
binding.editTextEmail.text.toString(),
binding.editTextPw.text.toString(),
binding.editTextName.text.toString()
)
}

viewModel.signupResult.observe(this) {
startActivity(Intent(this,SignInActivity::class.java))
Toast.makeText(this,getString(R.string.sign_up_success_toast_msg), Toast.LENGTH_LONG).show()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RepoViewHolder(
): RecyclerView.ViewHolder(binding.root){
fun onBind(data: ResponseUserDTO.Data){
binding.imgGithub.load(data.avatar)
binding.txtGithubName.setText(data.first_name)
binding.txtGithubName.setText(data.firstName)
binding.txtGithubAuthor.setText(data.email)
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/sopt/sample/login/LoginViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.sample.login

import android.util.Log
import android.widget.Toast
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
Expand All @@ -9,7 +10,7 @@ import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class LoginViewModel: ViewModel() {
class LoginViewModel : ViewModel() {
private val _loginResult: MutableLiveData<ResponseLoginDTO> = MutableLiveData()
val loginResult: LiveData<ResponseLoginDTO>
get() = _loginResult
Expand All @@ -22,7 +23,6 @@ class LoginViewModel: ViewModel() {
call: Call<ResponseLoginDTO>,
response: Response<ResponseLoginDTO>
) {
Log.d("로그인 성공", "${response.body()}")
_loginResult.value = response.body()
}

Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/org/sopt/sample/remote/ResponseUserDTO.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.sopt.sample.remote

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseUserDTO(
val page: Int,
val per_page: Int,
val total: Int,
val total_pages: Int,
@SerialName("total_pages")
val totalPages: Int,
val data: List<Data>,
val support: Support,

Expand All @@ -16,8 +18,10 @@ data class ResponseUserDTO(
data class Data(
val id: Int,
val email: String,
val first_name: String,
val last_name: String,
@SerialName("first_name")
val firstName: String,
@SerialName("last_name")
val lastName: String,
val avatar: String,
)

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/org/sopt/sample/signup/SignupViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ class SignupViewModel: ViewModel() {
response: Response<ResponseSignupDTO>
) {
_signupResult.value = response.body()
Log.d("회원가입 성공", "${response.body()}")
}

override fun onFailure(call: Call<ResponseSignupDTO>, t: Throwable) {
TODO("Not yet implemented")

}
})

Expand Down
14 changes: 7 additions & 7 deletions app/src/main/res/layout/activity_sign_in.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:text="Welcome to SOPT"
android:text="@string/sign_in_title"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -35,7 +35,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="32dp"
android:text="ID"
android:text="@string/sign_id_label"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_title" />
Expand All @@ -46,7 +46,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginTop="20dp"
android:hint="아이디를 입력하세요"
android:hint="@string/sign_id_hint"
app:layout_constraintTop_toBottomOf="@+id/txt_id_title"
tools:layout_editor_absoluteX="40dp" />

Expand All @@ -56,7 +56,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="32dp"
android:text="비밀번호"
android:text="@string/sign_pw_label"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText_id" />
Expand All @@ -67,7 +67,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginTop="20dp"
android:hint="비밀번호를 입력하세요"
android:hint="@string/sign_pw_hint"
android:inputType="textPassword"
app:layout_constraintTop_toBottomOf="@+id/txt_password_title" />

Expand All @@ -77,7 +77,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginTop="30dp"
android:text="LOGIN"
android:text="@string/sign_in"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText_pw" />
Expand All @@ -87,7 +87,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:text="SIGNUP"
android:text="@string/sign_up"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginBtn" />
Expand Down
Loading