Skip to content

Commit

Permalink
[FEAT/#3] ProfileFragment 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Apr 21, 2023
1 parent d66d66e commit 27573b4
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.android.go.sopt.presentation.main

import android.os.Bundle
import androidx.activity.viewModels
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import androidx.fragment.app.replace
Expand All @@ -16,11 +15,8 @@ import org.android.go.sopt.util.binding.BindingActivity

@AndroidEntryPoint
class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main) {
private val viewModel by viewModels<MainViewModel>()

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

initNavigationBar()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
package org.android.go.sopt.presentation.main.profile

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import dagger.hilt.android.AndroidEntryPoint
import org.android.go.sopt.R
import org.android.go.sopt.databinding.FragmentProfileBinding
import org.android.go.sopt.presentation.login.LoginActivity
import org.android.go.sopt.util.binding.BindingFragment
import org.android.go.sopt.util.extension.setOnSingleClickListener
import org.android.go.sopt.util.extension.showToast

@AndroidEntryPoint
class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragment_profile) {
private val viewModel by viewModels<ProfileViewModel>()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel

initLogoutAndLeaveBtnClickListener()
}

private fun initLogoutAndLeaveBtnClickListener() {
binding.btnProfileLogoutAndLeave.setOnSingleClickListener {
viewModel.clearLocalPref()
requireContext().showToast(getString(R.string.profile_logout_and_leave_msg))
Intent(activity, LoginActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(this)
}
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.android.go.sopt.presentation.main
package org.android.go.sopt.presentation.main.profile

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
Expand All @@ -8,17 +8,18 @@ import org.android.go.sopt.domain.repository.AuthRepository
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor(
class ProfileViewModel @Inject constructor(
private val authRepository: AuthRepository,
) : ViewModel() {
// TODO : 프로필 보여주는 Fragment ViewModel 으로 로직 옮기기
val signedUpUser = MutableLiveData<User>()

init {
signedUpUser.value = getSignedUpUser()
getSignedUpUser()
}

private fun getSignedUpUser(): User = authRepository.getSignedUpUser() ?: User()
private fun getSignedUpUser() {
signedUpUser.value = authRepository.getSignedUpUser() ?: User()
}

fun clearLocalPref() {
authRepository.clearLocalPref()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import coil.transform.RoundedCornersTransformation

object BindingAdapter {
@JvmStatic
@BindingAdapter("setCircleImage")
fun ImageView.setCircleImage(img: String?) {
@BindingAdapter("setRoundedCornersImage")
fun ImageView.setRoundedCornersImage(img: String?) {
load(img) {
// TODO : placeholder & load error 이미지 추가
// TODO: placeholder & load error 이미지 추가
transformations(RoundedCornersTransformation(50f))
}
}
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@

<data>

<variable
name="vm"
type="org.android.go.sopt.presentation.main.MainViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_main"
android:id="@+id/layout_profile"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down
80 changes: 70 additions & 10 deletions app/src/main/res/layout/fragment_profile.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<layout>
<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"
tools:context=".presentation.main.profile.ProfileFragment">

<data></data>
<data>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<variable
name="vm"
type="org.android.go.sopt.presentation.main.profile.ProfileViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.main.profile.ProfileFragment">
android:layout_height="match_parent">

<ImageView
android:id="@+id/iv_profile_profile"
android:layout_width="100dp"
android:layout_height="0dp"
android:layout_marginTop="100dp"
android:contentDescription="@string/profile_img_description"
android:src="@drawable/img_main_profile"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
android:id="@+id/tv_profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@{@string/profile_name(vm.signedUpUser.name)}"
android:textColor="@color/black"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_profile_profile" />

<TextView
android:id="@+id/tv_profile_specialty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@{@string/profile_specialty(vm.signedUpUser.specialty)}"
android:textColor="@color/black"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_profile_name" />

<TextView
android:id="@+id/tv_profile_mbti"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@{@string/profile_mbti(vm.signedUpUser.mbti)}"
android:textColor="@color/black"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_profile_specialty" />

<Button
android:id="@+id/btn_profile_logout_and_leave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginBottom="40dp"
android:paddingVertical="16dp"
android:text="@string/profile_logout_and_leave_btn"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/item_home_repo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

<ImageView
android:id="@+id/iv_repo_profile"
setCircleImage="@{data.image}"
setRoundedCornersImage="@{data.image}"
android:layout_width="0dp"
android:layout_height="100dp"
android:contentDescription="@{@string/home_repo_img_description(data.name)}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<!-- Base application theme. -->
<style name="Theme.GOSOPTAndroid" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorPrimary">@color/coral_600</item>
<item name="colorPrimaryVariant">@color/coral_500</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
Expand Down
16 changes: 9 additions & 7 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@
<string name="main_search">검색</string>
<string name="main_profile">프로필</string>

<!-- main / profile -->
<string name="main_name">이름 : %s</string>
<string name="main_specialty">특기 : %s</string>
<string name="main_mbti">MBTI : %s</string>
<string name="main_logout_and_leave_btn">LOG OUT &amp; LEAVE</string>
<string name="main_logout_and_leave_msg">회원 정보가 삭제되었습니다.</string>
<!-- profile -->
<string name="profile_name">이름 : %s</string>
<string name="profile_specialty">특기 : %s</string>
<string name="profile_mbti">MBTI : %s</string>
<string name="profile_logout_and_leave_btn">LOG OUT &amp; LEAVE</string>
<string name="profile_logout_and_leave_msg">회원 정보가 삭제되었습니다.</string>
<string name="profile_img_description">프로필 이미지</string>

<!-- home -->
<string name="home_get_repo_list_fail_msg">리포지토리 목록 불러오기에 실패했습니다.</string>

<!-- home : repo item -->
<string name="home_repo_img_description">리포지토리 %s 이미지</string>
<!-- home : repo header -->
<string name="home_repo_header_title">Repository List</string>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<!-- Base application theme. -->
<style name="Theme.GOSOPTAndroid" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/coral_500</item>
<item name="colorPrimaryVariant">@color/coral_600</item>
<item name="colorPrimary">@color/coral_600</item>
<item name="colorPrimaryVariant">@color/coral_500</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
Expand Down

0 comments on commit 27573b4

Please sign in to comment.