- SignInActivity , SignUpActivity, HomeActivity
binding.btnSign.setOnClickListener{ startActivity(intent) } binding.btnLogin.setOnClickListener{ if (binding.etId.text.toString().equals("")||binding.etId2.text.toString().equals("")) { Toast.makeText(this, "로그인 실패", Toast.LENGTH_LONG).show() } else { Toast.makeText(this, binding.etId.text.toString() + " 님 환영합니다.", Toast.LENGTH_SHORT) .show() startActivity(intent2) } } setContentView(binding.root) } }
binding= ActivitySignUpBinding.inflate(layoutInflater) binding.btnsignup.setOnClickListener{ if (binding.etId.text.toString().equals("")||binding.etId2.text.toString().equals("")||binding.etName.text.toString().equals("")) { Toast.makeText(this, "입력되지 않은 정보가 있습니다.", Toast.LENGTH_LONG).show() } else finish() } setContentView(binding.root) }
로그인-홈 | 회원가입 |
---|---|
```
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#FF00CC" />
<corners android:radius="4dp"/>
<solid
android:color="#FFFFFF" />
</shape>
```
-
FollowerFragment , RepositoryFragment, HomeActivity
-
<androidx.recyclerview.widget.RecyclerView android:id="@+id/rv_follower" android:layout_width="match_parent" android:layout_height="match_parent" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" tools:itemCount="4" tools:listitem="@layout/item_sample_list" />
-
class FollowerFragment : Fragment() { private var _binding : FragmentFollowerBinding? = null private val binding get() = _binding ?: error("Binding이 초기화 되지 않았습니다.") // adapter 초기화 private lateinit var followerAdapter : FollowerAdapter override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { _binding = FragmentFollowerBinding.inflate(layoutInflater,container,false) initAdapter() return binding.root } override fun onDestroyView() { super.onDestroyView() _binding=null } private fun initAdapter() { //adapter 초기화 followerAdapter = FollowerAdapter() //adatper와 recyclerview 연동 binding.rvFollower.adapter = followerAdapter followerAdapter.userList.addAll( listOf( UserData("김수빈", "안드로이드"), UserData("문다빈", "안드로이드 파트장"), "UserData 데이터 삽입 내용" ) ) followerAdapter.notifyDataSetChanged() } }
-
class FollowerAdapter : RecyclerView.Adapter<FollowerAdapter.FollowerViewHolder>() { val userList = mutableListOf<UserData>() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FollowerViewHolder { val binding = ItemSampleListBinding.inflate( LayoutInflater.from(parent.context), parent,false ) return FollowerViewHolder(binding) } override fun onBindViewHolder(holder: FollowerViewHolder, position: Int) { holder.onBind(userList[position]) } override fun getItemCount(): Int = userList.size // Binding 객체를 생성자로 가지는 ViewHolder 클래스 생성 class FollowerViewHolder(private val binding: ItemSampleListBinding) : RecyclerView.ViewHolder(binding.root){ fun onBind(data : UserData){ binding.tvName.text=data.name binding.tvIntroduce.text=data.introduction } } }
📌 FollowerRecyclerView 설명
1) "팔로워 목록" 버튼 클릭시 팔로워 목록을 linearlayout으로 보여주기 2) UserData data class를 만들어 name과 introduction을 만들어줌 3) data를 활용해 followeradapter에서 " val userList = mutableListOf<UserData>() " 리스트를 만들어 데이터 삽입 4) adapter : 데이터 가져오기 , fragment : adapter와 recyclerview 연동 및 데이터 삽입 </div>
-
<androidx.recyclerview.widget.RecyclerView android:id="@+id/rv_repository" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginStart="10dp" android:layout_marginEnd="10dp" app:layoutManager="androidx.recyclerview.widget.GridLayoutManager" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:spanCount="2" tools:itemCount="4" tools:listitem="@layout/item_repository" />
-
private fun initTransactionEvent(){ val followerFragment = FollowerFragment() val repositoryFragment = RepositoryFragment() supportFragmentManager.beginTransaction().add(R.id.container_view, followerFragment).commit() binding.btnRepo.setOnClickListener { val transaction = supportFragmentManager.beginTransaction() when (position){ FOLLOWER_POSITION -> { transaction.replace(R.id.container_view,repositoryFragment) position = REPOSITORY_POSITION } } transaction.commit() } binding.btnFollower.setOnClickListener{ val transaction = supportFragmentManager.beginTransaction() when (position){ REPOSITORY_POSITION -> { transaction.replace(R.id.container_view, followerFragment) position = FOLLOWER_POSITION } } transaction.commit() } } companion object { const val FOLLOWER_POSITION = 1 const val REPOSITORY_POSITION = 2 }
-
Home화면 |
---|
-
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@color/black" android:state_pressed="false" /> <item android:color="@color/white" android:state_pressed="true"/> </selector>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_fill_gray" android:state_pressed="false" /> <item android:drawable="@drawable/button_fill_color" android:state_pressed="true"/> </selector>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/rectangle_fill_gray" android:state_focused="false"/> <item android:drawable="@drawable/rectangle_border_pink" android:state_focused="true"/> </selector>
-
-
private fun initAdapter(){ val fragmentList=listOf(HomeFollowerFragment(),HomeFollowingFragment()) homeFollowViewPagerAdapter=HomeFollowViewPagerAdapter(this) homeFollowViewPagerAdapter.fragments.addAll(fragmentList) binding.vpHomefragment.adapter=homeFollowViewPagerAdapter } private fun initTabLayout(){ val tabLabel=listOf("팔로잉","팔로워") // tablayout이랑 viepager2 연결 TabLayoutMediator(binding.homeTablayout,binding.vpHomefragment){ tab,position-> tab.text=tabLabel[position] }.attach() }
-
-
<com.example.androidsopt.NestedScrollableHost android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintTop_toBottomOf="@+id/home_tablayout" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"> <androidx.viewpager2.widget.ViewPager2 android:id="@+id/vp_homefragment" android:background="#dfdfdf" android:layout_width="match_parent" android:layout_height="match_parent" /> </com.example.androidsopt.NestedScrollableHost>
-
-
-
class FollowerViewHolder(private val binding: ItemSampleListBinding) : RecyclerView.ViewHolder(binding.root) { fun onBind(data: UserData) { binding.tvName.text = data.name binding.tvIntroduce.text = data.introduction Glide.with(binding.root) .load(data.Img) .circleCrop() .into(binding.ivProfile) } }
private fun initAdapter() { //adapter 초기화 followerAdapter = FollowerAdapter() //adatper와 recyclerview 연동 binding.rvFollower.adapter = followerAdapter val img1 ="http://image.cine21.com/resize/cine21/still/2019/0624/16_07_21__5d1076a9eca7f[W578-].JPG" val img2 ="http://image.cine21.com/resize/cine21/still/2019/0624/16_15_30__5d1078925c7c5[W578-].jpg" val img3 ="https://search.pstatic.net/common/?src=http%3A%2F%2Fshop1.phinf.naver.net%2F20210118_180%2F161094482719298FEG_JPEG%2FB01MU764R0_9.jpg&type=sc960_832" val img4 ="https://search.pstatic.net/common/?src=http%3A%2F%2Fblogfiles.naver.net%2F20160902_16%2Fdynamote_1472795070315jifGn_JPEG%2F1.jpeg&type=sc960_832" val img5 ="img url(길어서 생략)" val img6 ="img url(길어서 생략)" followerAdapter.userList.addAll( listOf( UserData(img1,"김수빈", "안드로이드"), UserData(img2,"문다빈", "안드로이드 파트장"), UserData(img3,"김현아", "기획 파트장"), UserData(img4,"이성현", "디자인 파트장"), UserData(img5,"김우영", "서버 파트장"), UserData(img6,"김의진", "웹 파트장") ) ) followerAdapter.notifyDataSetChanged() }
-
-
week3실행화면 |
---|
button selected 여부로 코드 구현했는데 실행하면 에뮬레이터에서 적용이 안됩니다요.... 어디가 틀렸는지 알수가없숩니다...알려주쎄여... 이부분만 2시간동안 째려봐써여👀
Button색상 안바뀜 |
---|
```kotlin
private fun initTransactionEvent(){
val followerFragment = FollowerFragment()
val repositoryFragment = RepositoryFragment()
childFragmentManager.beginTransaction().add(R.id.container_view, followerFragment).commit()
binding.btnFollower.isSelected = true //처음 화면 보여질 시에
binding.btnFollower.setOnClickListener{
childFragmentManager.beginTransaction()
.replace(R.id.container_view, followerFragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
binding.btnFollower.isSelected=true
binding.btnRepo.isSelected=false
}
binding.btnRepo.setOnClickListener {
childFragmentManager.beginTransaction()
.replace(R.id.container_view,repositoryFragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
binding.btnRepo.isSelected=true
binding.btnFollower.isSelected=false
}
}
```
* childFragmentManager.beginTransaction().add(R.id.container_view, followerFragment).commit() --> ProfileFragment에서 구현시에 사용.
-
interface SignUpService { @Headers("Content-Type: application/json") @POST("user/signup") fun postSignup( @Body body : RequestSignUpData ) :Call<ResponseSignUpData> }
data class RequestSignUpData( @SerializedName("email") val id : String, val name : String, val password : String )
data class ResponseSignUpData( val status : Int, val success : Boolean, val message : String, val data : Data ) { data class Data( val id: Int, val name: String, val email: String ) }
private fun initNetwork() { val requestSignupData = RequestSignUpData( id = binding.etId.text.toString(), name = binding.etName.text.toString(), password = binding.etId2.text.toString() ) val call: Call<ResponseSignUpData> = ServiceCreator.signupService.postSignup(requestSignupData) call.enqueue(object : Callback<ResponseSignUpData> { override fun onResponse( call: Call<ResponseSignUpData>, response: Response<ResponseSignUpData> ) { if (response.isSuccessful) { val data = response.body()?.data Toast.makeText(this@SignUpActivity, "${data?.email}님 회원가입이 완료되었습니다!", Toast.LENGTH_SHORT).show() } else Toast.makeText(this@SignUpActivity, "회원가입에 실패하셨습니다", Toast.LENGTH_SHORT).show() } override fun onFailure(call: Call<ResponseSignUpData>, t: Throwable) { Log.e("NetworkText", "error:$t") } }) }
-
private fun initNetwork() { val requestSignInData = RequestSignInData( id = binding.etId.text.toString(), password = binding.etId2.text.toString() ) val call: Call<ResponseSignInData> = ServiceCreator.signinService.postLogin(requestSignInData) call.enqueue(object : Callback<ResponseSignInData> { override fun onResponse( call: Call<ResponseSignInData>, response: Response<ResponseSignInData> ) { if (response.isSuccessful) { val data = response.body()?.data Toast.makeText(this@SignInActivity, "${data?.email}님 반갑습니다!", Toast.LENGTH_LONG).show() startActivity(Intent(this@SignInActivity, HomeActivity::class.java)) } else Toast.makeText(this@SignInActivity, "로그인에 실패하셨습니다", Toast.LENGTH_LONG).show() } override fun onFailure(call: Call<ResponseSignInData>, t: Throwable) { Log.e("NetworkTest", "error:$t") } }) }
week4실행화면 |
---|
-
- fragment1,2,3으로 SOPT Hub 로그인 화면 전까지 온보딩 구현
- 각 fragment 전환은 버튼을 눌러 이동
<navigation 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:id="@+id/nav_sample" app:startDestination="@id/firstFragment"> <fragment android:id="@+id/firstFragment" android:name="com.example.androidsopt.view.onBoarding.FirstFragment" android:label="fragment_first" tools:layout="@layout/fragment_first" > <action android:id="@+id/action_firstFragment_to_secondFragment" app:destination="@id/secondFragment" /> </fragment> <fragment android:id="@+id/thirdFragment" android:name="com.example.androidsopt.view.onBoarding.ThirdFragment" android:label="fragment_third" tools:layout="@layout/fragment_third" > <action android:id="@+id/action_thirdFragment_to_signInActivity" app:destination="@id/signInActivity" /> </fragment> <fragment android:id="@+id/secondFragment" android:name="com.example.androidsopt.view.onBoarding.SecondFragment" android:label="fragment_second" tools:layout="@layout/fragment_second" > <action android:id="@+id/action_secondFragment_to_thirdFragment" app:destination="@id/thirdFragment" /> </fragment> <activity android:id="@+id/signInActivity" android:name="com.example.androidsopt.view.Login.SignInActivity" android:label="activity_sign_in" tools:layout="@layout/activity_sign_in" /> </navigation>
-
object SharedPreferences { private const val STORAGE_KEY = "USER_AUTH" private const val AUTO_LOGIN = "AUTO_LOGIN" fun getAutoLogin(context: Context): Boolean { val preferences = context.getSharedPreferences("USER_AUTH",Context.MODE_PRIVATE) return preferences.getBoolean(AUTO_LOGIN, false) } fun setAutoLogin(context: Context, value :Boolean) { val preferences = context.getSharedPreferences("USER_AUTH",Context.MODE_PRIVATE) preferences.edit() .putBoolean(AUTO_LOGIN, value) .apply() }
private fun initClickEvent() { binding.tvCancel.setOnClickListener { val sp : SharedPreferences = getSharedPreferences("USER_AUTH", MODE_PRIVATE) val editor : SharedPreferences.Editor = sp.edit() editor.remove("USER_AUTH") editor.clear() editor.commit() } }
-
┣ 📂adapter ┣ 📂util ┣ 📂network : 서버통신관련 ┣ 📂data ┣ 📂view ┣ 📂Home ┣ 📂Profile ┣ 📂Login ┣ 📂Camera ┗ 📂onBoarding
week7 온보딩 | 자동로그인 | 자동로그인 알림 | 자동로그인 해제 |
---|---|---|---|