Skip to content

Commit

Permalink
#11 / [MOD] binding Activity 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchbreeze committed May 30, 2023
1 parent fdec19f commit 9a8d333
Show file tree
Hide file tree
Showing 6 changed files with 299 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,26 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.inputmethod.InputMethodManager
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatDelegate
import org.android.go.sopt.R
import org.android.go.sopt.databinding.ActivityLoginBinding
import org.android.go.sopt.presentation.main.MainActivity
import org.android.go.sopt.util.base.BindingActivity
import org.android.go.sopt.util.extension.makeSnackBar
import org.android.go.sopt.util.extension.makeToast
import timber.log.Timber

class LoginActivity : AppCompatActivity() {
private lateinit var binding: ActivityLoginBinding
class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_login) {
private lateinit var sharedPreferences: SharedPreferences
private lateinit var editor: SharedPreferences.Editor

private val viewModel by viewModels<LoginViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityLoginBinding.inflate(layoutInflater)
setContentView(binding.root)

// 야간모드 무시
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@ package org.android.go.sopt.presentation.auth
import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.inputmethod.InputMethodManager
import androidx.activity.viewModels
import androidx.core.widget.doAfterTextChanged
import org.android.go.sopt.R
import org.android.go.sopt.databinding.ActivitySignUpBinding
import org.android.go.sopt.util.KeyboardVisibilityUtils
import org.android.go.sopt.util.base.BindingActivity
import org.android.go.sopt.util.extension.makeSnackBar
import timber.log.Timber

class SignUpActivity : AppCompatActivity() {
private lateinit var binding: ActivitySignUpBinding
class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_sign_up) {
private lateinit var keyboardVisibilityUtils: KeyboardVisibilityUtils

private val viewModel by viewModels<SignUpViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySignUpBinding.inflate(layoutInflater)
setContentView(binding.root)

// 텍스트 입력을 감지해서 조건 만족 시 버튼 활성화
Expand All @@ -45,7 +43,7 @@ class SignUpActivity : AppCompatActivity() {
}

// 뷰모델 observer 설정
viewModel.signUpResult.observe(this) {signUpResult ->
viewModel.signUpResult.observe(this) { signUpResult ->
binding.root.makeSnackBar(getString(R.string.snackbar_signup_success))
if (!isFinishing) {
val intent = Intent(binding.root.context, LoginActivity::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.android.go.sopt.presentation.main

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import androidx.fragment.app.Fragment
Expand All @@ -12,9 +11,10 @@ import org.android.go.sopt.databinding.ActivityMainBinding
import org.android.go.sopt.presentation.follower.FollowerFragment
import org.android.go.sopt.presentation.playlist.ListFragment
import org.android.go.sopt.presentation.search.SearchFragment
import org.android.go.sopt.util.base.BindingActivity

class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main) {

class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var listFragment: ListFragment
private lateinit var albumFragment: AlbumFragment
private lateinit var searchFragment: SearchFragment
Expand All @@ -23,7 +23,6 @@ class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

// 시작 Fragment 설정
Expand All @@ -44,6 +43,7 @@ class MainActivity : AppCompatActivity() {
?: supportFragmentManager.beginTransaction().add(R.id.fcv_main, listFragment).commit()
}

// 바텀 네비게이션 누를 때마다 새로운 프래그먼트 객체가 생성되지 않도록 설정
private fun changeFragmentByBnv() {
binding.bnvMain.setOnItemSelectedListener { item ->
when (item.itemId) {
Expand Down Expand Up @@ -84,7 +84,7 @@ class MainActivity : AppCompatActivity() {
}
}

private fun scrollToTopForReselectedItem(item : MenuItem) {
private fun scrollToTopForReselectedItem(item: MenuItem) {
if (item.itemId == R.id.menu_playlist) {
when (val currentFragment = supportFragmentManager.findFragmentById(R.id.fcv_main)) {
is ListFragment -> {
Expand Down
186 changes: 97 additions & 89 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
@@ -1,100 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.auth.LoginActivity">
xmlns:tools="http://schemas.android.com/tools">

<TextView
android:id="@+id/tv_login_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="50dp"
android:text="@string/tv_login_title"
android:textColor="@color/black"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<data>

<TextView
android:id="@+id/tv_login_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:padding="2dp"
android:text="@string/tv_login_id_title"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@id/tv_login_title"
app:layout_constraintTop_toBottomOf="@+id/tv_login_title" />
</data>

<EditText
android:id="@+id/et_login_id"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="5dp"
android:autofillHints="username"
android:hint="@string/et_login_id_hint"
android:imeOptions="actionNext"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_login_id" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.auth.LoginActivity">

<TextView
android:id="@+id/tv_login_pw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:padding="2dp"
android:text="@string/tv_login_pw_title"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@id/et_login_id"
app:layout_constraintTop_toBottomOf="@+id/et_login_id" />
<TextView
android:id="@+id/tv_login_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="50dp"
android:text="@string/tv_login_title"
android:textColor="@color/black"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/et_login_pw"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="5dp"
android:autofillHints="password"
android:hint="@string/et_login_pw_hint"
android:imeOptions="actionDone"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_login_pw" />
<TextView
android:id="@+id/tv_login_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:padding="2dp"
android:text="@string/tv_login_id_title"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@id/tv_login_title"
app:layout_constraintTop_toBottomOf="@+id/tv_login_title" />

<Button
android:id="@+id/btn_login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:padding="24dp"
android:text="@string/btn_login_login"
android:textSize="15sp"
app:layout_constraintBottom_toTopOf="@+id/btn_sign_up"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="@+id/et_login_id"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="5dp"
android:autofillHints="username"
android:hint="@string/et_login_id_hint"
android:imeOptions="actionNext"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_login_id" />

<Button
android:id="@+id/btn_sign_up"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginHorizontal="30dp"
android:text="@string/btn_login_sign_up"
android:textSize="15sp"
android:layout_marginBottom="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/tv_login_pw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:padding="2dp"
android:text="@string/tv_login_pw_title"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@id/et_login_id"
app:layout_constraintTop_toBottomOf="@+id/et_login_id" />

<EditText
android:id="@+id/et_login_pw"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="5dp"
android:autofillHints="password"
android:hint="@string/et_login_pw_hint"
android:imeOptions="actionDone"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_login_pw" />

</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/btn_login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:padding="24dp"
android:text="@string/btn_login_login"
android:textSize="15sp"
app:layout_constraintBottom_toTopOf="@+id/btn_sign_up"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/btn_sign_up"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginHorizontal="30dp"
android:layout_marginBottom="10dp"
android:text="@string/btn_login_sign_up"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

</layout>
62 changes: 35 additions & 27 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.main.MainActivity">
xmlns:tools="http://schemas.android.com/tools">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fcv_main"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/bnv_main"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout="@layout/fragment_list" />
<data>

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bnv_main"
android:layout_width="0dp"
android:layout_height="56dp"
android:background="?attr/colorSurface"
app:itemIconTint="@drawable/bnv_selector_color"
app:itemRippleColor="@color/light_blue_200"
app:itemTextColor="@drawable/bnv_selector_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/menu" />
</data>

</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.main.MainActivity">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fcv_main"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/bnv_main"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout="@layout/fragment_list" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bnv_main"
android:layout_width="0dp"
android:layout_height="56dp"
android:background="?attr/colorSurface"
app:itemIconTint="@drawable/bnv_selector_color"
app:itemRippleColor="@color/light_blue_200"
app:itemTextColor="@drawable/bnv_selector_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/menu" />

</androidx.constraintlayout.widget.ConstraintLayout>

</layout>
Loading

0 comments on commit 9a8d333

Please sign in to comment.