Skip to content

Commit

Permalink
Merge branch 'feature/1-login_signup_ui' of https://github.com/EarthG…
Browse files Browse the repository at this point in the history
…ardener/EarthGardener-Android into feature/13-User_View_Logic
  • Loading branch information
OliviaYJH committed Feb 4, 2022
2 parents 5541516 + 405099d commit 543c257
Show file tree
Hide file tree
Showing 15 changed files with 721 additions and 4 deletions.
15 changes: 13 additions & 2 deletions EarthGardener/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@
android:supportsRtl="true"
android:theme="@style/Theme.EarthGardener.Splash">
<activity
android:name=".presentation.post.PostFormActivity"
android:name=".presentation.user.signup.SignUpActivity"
android:theme="@style/Theme.EarthGardener"
android:windowSoftInputMode="adjustResize"
android:exported="false" />
<activity
android:name=".presentation.MainActivity"
android:name=".presentation.user.login.LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".presentation.post.PostFormActivity"
android:exported="false" />
<activity
android:name=".presentation.MainActivity"
android:theme="@style/Theme.EarthGardener"
android:exported="false">
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()

setContentView(binding.root)

initViews()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package team.gdsc.earthgardener.presentation.user.login

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import android.os.Bundle
import android.widget.Toast
import team.gdsc.earthgardener.R
import team.gdsc.earthgardener.databinding.ActivityLoginBinding
import team.gdsc.earthgardener.presentation.MainActivity
import team.gdsc.earthgardener.presentation.base.BaseActivity
import team.gdsc.earthgardener.presentation.user.signup.SignUpActivity

class LoginActivity : BaseActivity<ActivityLoginBinding>(R.layout.activity_login) {

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
btnLoginEvent()
navigateToSignUp()
}

private fun btnLoginEvent(){
binding.btnLogin.setOnClickListener {
val email = binding.etLoginEmail.text.toString()
val pw = binding.etLoginPw.text.toString()
// Post Login

navigateToMain()
}
}

private fun navigateToSignUp(){
binding.tvLoginSignUp.setOnClickListener {
startActivity(Intent(this, SignUpActivity::class.java))
}
}

private fun navigateToMain(){
startActivity(Intent(this, MainActivity::class.java))
finish()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package team.gdsc.earthgardener.presentation.user.signup

import android.os.Bundle
import androidx.fragment.app.Fragment
import team.gdsc.earthgardener.R
import team.gdsc.earthgardener.databinding.ActivitySignUpBinding
import team.gdsc.earthgardener.presentation.base.BaseActivity
import team.gdsc.earthgardener.presentation.user.signup.emailpw.EmailPwFragment

class SignUpActivity : BaseActivity<ActivitySignUpBinding>(R.layout.activity_sign_up) {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setSignUpFragment()
}

private fun setSignUpFragment(){
supportFragmentManager.beginTransaction()
.add(R.id.frame_sign_up, EmailPwFragment())
.commit()
}

fun nextSignUpFragment(fa: Fragment){
supportFragmentManager.beginTransaction()
.replace(R.id.frame_sign_up, fa)
.commit()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package team.gdsc.earthgardener.presentation.user.signup.emailpw

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import team.gdsc.earthgardener.R
import team.gdsc.earthgardener.databinding.FragmentEmailPwBinding
import team.gdsc.earthgardener.presentation.base.BaseFragment
import team.gdsc.earthgardener.presentation.user.signup.nickname.NickNameFragment
import team.gdsc.earthgardener.presentation.user.signup.SignUpActivity
import java.util.regex.Pattern

class EmailPwFragment : BaseFragment<FragmentEmailPwBinding>(R.layout.fragment_email_pw) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
checkEmailPattern()
checkEmailWatcher()
getCodeEvent()
checkCode()
etPasswordWatcher()
btnNextEvent()
}

private fun checkEmailPattern(): Boolean{
val email = binding.etSignUpEmail.text.toString().trim()
val emailValidation = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"
val p = Pattern.matches(emailValidation, email)
return if(p){
binding.etSignUpEmail.setTextColor(ContextCompat.getColor(context!!, R.color.text_black))
true
}else{
binding.etSignUpEmail.setTextColor(ContextCompat.getColor(context!!, R.color.accent_pink))
false
}
}

private fun checkEmailWatcher(){
binding.etSignUpEmail.addTextChangedListener(object: TextWatcher{
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

}

override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

}

override fun afterTextChanged(p0: Editable?) {
checkEmailPattern()
}

})
}

private fun getCodeEvent(){
binding.tvGetCode.setOnClickListener {
if(checkEmailPattern()){
// Get Code from email


binding.tvCode.isVisible = true
binding.linearEmailCode.isVisible = true
}
}
}

private fun checkCode(){
binding.tvCheckCode.setOnClickListener {
// check if code is right
}
}

private fun etPasswordWatcher(){
binding.etSignupPw.addTextChangedListener(object: TextWatcher{
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

}

override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
btnNextActive()
}

override fun afterTextChanged(p0: Editable?) {

}

})
}

private fun btnNextActive(){
val signUpActivity = activity as SignUpActivity

if(binding.etSignupPw.text.isNotEmpty() ){ // 이메일 인증 코드 맞는지 여부 조건도 넣기
signUpActivity.binding.btnNext.setBackgroundResource(R.drawable.rectangle_primary_green_radius_30)
signUpActivity.binding.btnNext.isEnabled = true
}else{
signUpActivity.binding.btnNext.setBackgroundResource(R.drawable.rectangle_light_gray_radius_30)
signUpActivity.binding.btnNext.isEnabled = false
}
}

private fun btnNextEvent(){
val signUpActivity = activity as SignUpActivity
signUpActivity.binding.btnNext.setOnClickListener {
signUpActivity.binding.btnNext.text = getString(R.string.finish)
signUpActivity.binding.btnNext.setBackgroundResource(R.drawable.rectangle_light_gray_radius_30)
signUpActivity.binding.btnNext.isEnabled = false
signUpActivity.nextSignUpFragment(NickNameFragment())
}
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package team.gdsc.earthgardener.presentation.user.signup.nickname

import android.app.Activity
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okio.BufferedSink
import team.gdsc.earthgardener.R
import team.gdsc.earthgardener.databinding.FragmentNickNameBinding
import team.gdsc.earthgardener.presentation.base.BaseFragment
import team.gdsc.earthgardener.presentation.user.signup.SignUpActivity
import java.lang.Exception

class NickNameFragment : BaseFragment<FragmentNickNameBinding>(R.layout.fragment_nick_name) {

private val OPEN_GALLERY = 1

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
openGallery()
btnFinishActive()
btnFinishEvent()
}

private fun openGallery(){
binding.ivSignupUser.setOnClickListener {
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "image/*"
startActivityForResult(intent, OPEN_GALLERY)
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(resultCode == Activity.RESULT_OK){
if(requestCode == OPEN_GALLERY){
val currentImageUrl: Uri? = data?.data
try{
val bitmap = MediaStore.Images.Media.getBitmap(activity?.contentResolver, currentImageUrl)
binding.ivSignupUser.setImageBitmap(bitmap)
changeToMultipart(bitmap)
}catch (e: Exception){
e.printStackTrace()
}
}
}
}

private fun changeToMultipart(bitmap: Bitmap){
val bitmapRequestBody = BitmapRequestBody(bitmap)
val bitmapMultipartBody: MultipartBody.Part =
MultipartBody.Part.createFormData("image", ".jpeg", bitmapRequestBody)

// Post bitmapMultipartBody
}

inner class BitmapRequestBody(private val bitmap: Bitmap): RequestBody(){
override fun contentType(): MediaType = "image/jpeg".toMediaType()

override fun writeTo(sink: BufferedSink) {
bitmap.compress(Bitmap.CompressFormat.JPEG, 99, sink.outputStream())
}

}

private fun btnFinishActive(){
binding.etSignUpNickname.addTextChangedListener(object: TextWatcher{
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

}

override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
val signUpActivity = activity as SignUpActivity
if(binding.etSignUpNickname.text.isNotEmpty()){
signUpActivity.binding.btnNext.setBackgroundResource(R.drawable.rectangle_primary_green_radius_30)
signUpActivity.binding.btnNext.isEnabled = true
}else{
signUpActivity.binding.btnNext.setBackgroundResource(R.drawable.rectangle_light_gray_radius_30)
signUpActivity.binding.btnNext.isEnabled = false
}
}

override fun afterTextChanged(p0: Editable?) {

}

})
}

private fun btnFinishEvent(){
// Post SignUp


val signUpActivity = activity as SignUpActivity
signUpActivity.binding.btnNext.setOnClickListener {
signUpActivity.finish()
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@color/any_light_gray"/>
<corners
android:radius="30dp"/>

</shape>
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">
<stroke
android:color="@color/any_light_gray"
android:width="1dp"/>
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@color/primary_green"/>
<corners
android:radius="30dp"/>
</shape>
Loading

0 comments on commit 543c257

Please sign in to comment.