Skip to content

Commit 9f74e74

Browse files
Sangwook123lsakee
authored andcommitted
[mod] #187 setting view
1 parent 619d75f commit 9f74e74

File tree

3 files changed

+192
-37
lines changed

3 files changed

+192
-37
lines changed

feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsFragment.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ import androidx.fragment.app.Fragment
1212
import androidx.fragment.app.viewModels
1313
import androidx.lifecycle.flowWithLifecycle
1414
import androidx.navigation.fragment.findNavController
15+
import coil.load
16+
import coil.transform.CircleCropTransformation
1517
import dagger.hilt.android.AndroidEntryPoint
1618
import designsystem.components.dialog.LinkMindDialog
1719
import kotlinx.coroutines.flow.launchIn
1820
import kotlinx.coroutines.flow.onEach
1921
import org.sopt.common.intentprovider.IntentProvider
2022
import org.sopt.common.intentprovider.LOGIN
2123
import org.sopt.datastore.datastore.SecurityDataStore
24+
import org.sopt.model.user.MyPageData
2225
import org.sopt.model.user.SettingPageData
2326
import org.sopt.mypage.R
2427
import org.sopt.mypage.databinding.FragmentSettingsBinding
@@ -122,6 +125,16 @@ class SettingsFragment : Fragment() {
122125
}
123126
}.launchIn(viewLifeCycleScope)
124127

128+
viewModel.getUserMyPage()
129+
viewModel.myPageState.flowWithLifecycle(viewLifeCycle).onEach { state ->
130+
when (state) {
131+
is UiState.Success -> {
132+
initMyPageData(state.data)
133+
}
134+
else -> {}
135+
}
136+
}.launchIn(viewLifeCycleScope)
137+
125138
onClickToggle()
126139
onClickLogoutBtn()
127140
onClickCloseBtn()
@@ -201,6 +214,19 @@ class SettingsFragment : Fragment() {
201214
}
202215
}
203216

217+
private fun initMyPageData(data: MyPageData) {
218+
val myPage = data
219+
if (myPage != null) {
220+
with(binding) {
221+
tvUserName.text = myPage.nickname
222+
tvMyTotalLinkNum.text = myPage.allReadToast.toString()
223+
tvReadLinkThisWeekNum.text = myPage.thisWeekendRead.toString()
224+
tvSaveLinkThisWeekNum.text = myPage.thisWeekendSaved.toString()
225+
ivProfile.load(data.profile) { transformations(CircleCropTransformation()) }
226+
}
227+
}
228+
}
229+
204230
companion object {
205231
const val URL_1ON1 = "https://open.kakao.com/o/sfN9Fr4f"
206232
const val URL_RULE = "https://www.notion.so/db429c114629431f8301a969ed028e37"

feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsViewModel.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import kotlinx.coroutines.flow.StateFlow
99
import kotlinx.coroutines.flow.asStateFlow
1010
import kotlinx.coroutines.launch
1111
import org.sopt.auth.repository.AuthRepository
12+
import org.sopt.model.user.MyPageData
1213
import org.sopt.model.user.SettingPageData
1314
import org.sopt.ui.view.UiState
15+
import org.sopt.user.usecase.GetUserMyPageUseCase
1416
import org.sopt.user.usecase.GetUserSettingUseCase
1517
import org.sopt.user.usecase.PatchPushUseCase
1618
import javax.inject.Inject
@@ -19,6 +21,7 @@ import javax.inject.Inject
1921
class SettingsViewModel @Inject constructor(
2022
private val getUserSettingUseCase: GetUserSettingUseCase,
2123
private val patchPushUseCase: PatchPushUseCase,
24+
private val getUserMyPageUseCase: GetUserMyPageUseCase,
2225
private val authRepository: AuthRepository,
2326
) : ViewModel() {
2427
private val _logoutState = MutableStateFlow<UiState<Unit>>(UiState.Empty)
@@ -30,6 +33,16 @@ class SettingsViewModel @Inject constructor(
3033
private val _settingState = MutableStateFlow<UiState<SettingPageData>>(UiState.Empty)
3134
val settingState: StateFlow<UiState<SettingPageData>> = _settingState.asStateFlow()
3235

36+
private val _myPageState = MutableStateFlow<UiState<MyPageData>>(UiState.Empty)
37+
val myPageState: StateFlow<UiState<MyPageData>> = _myPageState.asStateFlow()
38+
fun getUserMyPage() = viewModelScope.launch {
39+
getUserMyPageUseCase.invoke().onSuccess { data ->
40+
_myPageState.emit(UiState.Success(data))
41+
}.onFailure { error ->
42+
_myPageState.emit(UiState.Failure(error.toString()))
43+
}
44+
}
45+
3346
val pushIsAllowed = MutableStateFlow(true)
3447

3548
fun getUserInfo() = viewModelScope.launch {

feature/mypage/src/main/res/layout/fragment_settings.xml

Lines changed: 153 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,77 +53,193 @@
5353
app:layout_constraintTop_toTopOf="parent" />
5454
</androidx.constraintlayout.widget.ConstraintLayout>
5555

56-
<FrameLayout
57-
android:id="@+id/fl_settings_alert_off"
56+
<androidx.constraintlayout.widget.ConstraintLayout
57+
android:id="@+id/cl_mypage_now_link"
5858
android:layout_width="match_parent"
5959
android:layout_height="wrap_content"
60+
android:layout_marginHorizontal="20dp"
6061
app:layout_constraintEnd_toEndOf="parent"
6162
app:layout_constraintStart_toStartOf="parent"
6263
app:layout_constraintTop_toBottomOf="@id/cl_settings_title">
6364

64-
<TextView
65-
android:id="@+id/tv_settings_alert_off"
66-
android:layout_width="match_parent"
67-
android:layout_height="wrap_content"
68-
android:layout_gravity="center"
69-
android:layout_marginHorizontal="20dp"
70-
android:layout_marginVertical="12dp"
71-
android:background="@drawable/shape_neutrals050_fill_12_rect"
72-
android:gravity="center"
73-
android:padding="12dp"
74-
android:text="@string/settings_alert_off"
75-
android:textAppearance="@style/Typography.suit.bold_12"
76-
android:textColor="@color/neutrals400" />
77-
</FrameLayout>
78-
79-
80-
<androidx.constraintlayout.widget.ConstraintLayout
81-
android:id="@+id/cl_user_info"
82-
android:layout_width="match_parent"
83-
android:layout_height="wrap_content"
84-
app:layout_constraintTop_toBottomOf="@id/fl_settings_alert_off">
65+
<ImageView
66+
android:id="@+id/iv_profile"
67+
android:layout_width="48dp"
68+
android:layout_height="48dp"
69+
android:layout_marginTop="1dp"
70+
android:scaleType="centerCrop"
71+
app:layout_constraintStart_toStartOf="parent"
72+
app:layout_constraintTop_toTopOf="parent"
73+
tools:src="@drawable/img_mypage_profile" />
8574

8675
<TextView
8776
android:id="@+id/tv_user_name"
8877
android:layout_width="wrap_content"
8978
android:layout_height="wrap_content"
90-
android:layout_marginStart="20dp"
91-
android:layout_marginTop="22dp"
79+
android:layout_marginStart="12dp"
80+
android:layout_marginBottom="2dp"
9281
android:textAppearance="@style/Typography.suit.bold_18"
9382
android:textColor="@color/neutrals900"
94-
app:layout_constraintBaseline_toBaselineOf="@id/tv_user_name_nim"
95-
app:layout_constraintBottom_toBottomOf="parent"
96-
app:layout_constraintStart_toStartOf="parent"
97-
app:layout_constraintTop_toTopOf="parent"
98-
tools:text="홍길동" />
83+
app:layout_constraintBottom_toTopOf="@id/tv_now_link"
84+
app:layout_constraintStart_toEndOf="@id/iv_profile"
85+
tools:text="@string/mypage_name_ex" />
9986

10087
<TextView
10188
android:id="@+id/tv_user_name_nim"
10289
android:layout_width="wrap_content"
10390
android:layout_height="wrap_content"
104-
android:layout_marginTop="22dp"
105-
android:layout_marginBottom="22dp"
106-
android:text="@string/user_nim"
91+
android:layout_marginBottom="2dp"
92+
android:text="@string/mypage_nim"
10793
android:textAppearance="@style/Typography.suit.regular_18"
10894
android:textColor="@color/neutrals900"
109-
app:layout_constraintBottom_toBottomOf="parent"
95+
app:layout_constraintBaseline_toBaselineOf="@id/tv_user_name"
11096
app:layout_constraintStart_toEndOf="@id/tv_user_name"
11197
app:layout_constraintTop_toTopOf="parent" />
11298

99+
<TextView
100+
android:id="@+id/tv_now_link"
101+
android:layout_width="wrap_content"
102+
android:layout_height="wrap_content"
103+
android:layout_marginStart="12dp"
104+
android:layout_marginTop="26dp"
105+
android:text="@string/mypage_link_number_now"
106+
android:textAppearance="@style/Typography.suit.regular_18"
107+
android:textColor="@color/neutrals900"
108+
app:layout_constraintStart_toEndOf="@id/iv_profile"
109+
app:layout_constraintTop_toTopOf="parent" />
110+
111+
<TextView
112+
android:id="@+id/tv_my_total_link_num"
113+
android:layout_width="wrap_content"
114+
android:layout_height="wrap_content"
115+
android:layout_marginEnd="3dp"
116+
android:text="@string/search_clip_amount_n"
117+
android:textAppearance="@style/Typography.suit.bold_28"
118+
android:textColor="@color/primary"
119+
app:layout_constraintBaseline_toBaselineOf="@id/tv_my_total_link"
120+
app:layout_constraintEnd_toStartOf="@id/tv_my_total_link" />
121+
122+
<TextView
123+
android:id="@+id/tv_my_total_link"
124+
android:layout_width="wrap_content"
125+
android:layout_height="wrap_content"
126+
android:text="@string/mypage_number"
127+
android:textAppearance="@style/Typography.suit.regular_18"
128+
android:textColor="@color/neutrals900"
129+
app:layout_constraintBottom_toBottomOf="parent"
130+
app:layout_constraintEnd_toEndOf="parent" />
131+
113132
</androidx.constraintlayout.widget.ConstraintLayout>
114133

134+
115135
<View
116-
android:id="@+id/v_settings_1"
136+
android:id="@+id/bg_link_record"
137+
android:layout_width="0dp"
138+
android:layout_height="83dp"
139+
android:layout_marginStart="20dp"
140+
android:layout_marginTop="18dp"
141+
android:layout_marginEnd="20dp"
142+
android:layout_marginBottom="24dp"
143+
android:background="@drawable/shape_neutrals050_line_12_rect"
144+
app:layout_constraintEnd_toEndOf="parent"
145+
app:layout_constraintStart_toStartOf="parent"
146+
app:layout_constraintTop_toBottomOf="@+id/cl_mypage_now_link" />
147+
148+
<TextView
149+
android:id="@+id/tv_read_link_this_week"
150+
android:layout_width="wrap_content"
151+
android:layout_height="wrap_content"
152+
android:layout_marginStart="14dp"
153+
android:layout_marginTop="14dp"
154+
android:text="@string/mypage_this_week_read_link"
155+
android:textAppearance="@style/Typography.suit.regular_14"
156+
android:textColor="@color/neutrals400"
157+
app:layout_constraintStart_toStartOf="@+id/bg_link_record"
158+
app:layout_constraintTop_toTopOf="@+id/bg_link_record" />
159+
160+
<TextView
161+
android:id="@+id/tv_read_link_this_week_num"
162+
android:layout_width="wrap_content"
163+
android:layout_height="wrap_content"
164+
android:layout_marginEnd="14dp"
165+
android:layout_marginBottom="14dp"
166+
tools:text="@string/mypage_nn"
167+
android:textAppearance="@style/Typography.suit.bold_24"
168+
android:textColor="@color/neutrals900"
169+
app:layout_constraintBottom_toBottomOf="@id/bg_link_record"
170+
app:layout_constraintEnd_toStartOf="@id/v_mypage_line" />
171+
172+
<TextView
173+
android:id="@+id/tv_save_link_this_week"
174+
android:layout_width="wrap_content"
175+
android:layout_height="wrap_content"
176+
android:layout_marginStart="14dp"
177+
android:layout_marginTop="14dp"
178+
android:text="@string/mypage_this_week_save_link"
179+
android:textAppearance="@style/Typography.suit.regular_14"
180+
android:textColor="@color/neutrals400"
181+
app:layout_constraintStart_toEndOf="@+id/v_mypage_line"
182+
app:layout_constraintTop_toTopOf="@+id/bg_link_record" />
183+
184+
<TextView
185+
android:id="@+id/tv_save_link_this_week_num"
186+
android:layout_width="wrap_content"
187+
android:layout_height="wrap_content"
188+
android:layout_marginEnd="14dp"
189+
android:layout_marginBottom="14dp"
190+
tools:text="@string/mypage_nn"
191+
android:textAppearance="@style/Typography.suit.bold_24"
192+
android:textColor="@color/neutrals900"
193+
app:layout_constraintBottom_toBottomOf="@id/bg_link_record"
194+
app:layout_constraintEnd_toEndOf="@id/bg_link_record" />
195+
196+
<View
197+
android:id="@+id/v_mypage_line"
198+
android:layout_width="1dp"
199+
android:layout_height="0dp"
200+
android:background="@color/neutrals100"
201+
app:layout_constraintBottom_toBottomOf="@+id/bg_link_record"
202+
app:layout_constraintEnd_toEndOf="parent"
203+
app:layout_constraintStart_toStartOf="parent"
204+
app:layout_constraintTop_toTopOf="@+id/bg_link_record" />
205+
206+
<View
207+
android:id="@+id/v_settings_0"
117208
android:layout_width="match_parent"
118209
android:layout_height="4dp"
210+
android:layout_marginTop="24dp"
119211
android:background="@color/neutrals050"
120-
app:layout_constraintTop_toBottomOf="@id/cl_user_info" />
212+
app:layout_constraintTop_toBottomOf="@id/v_mypage_line" />
213+
214+
<FrameLayout
215+
android:id="@+id/fl_settings_alert_off"
216+
android:layout_width="match_parent"
217+
android:layout_height="wrap_content"
218+
android:layout_marginTop="12dp"
219+
app:layout_constraintEnd_toEndOf="parent"
220+
app:layout_constraintStart_toStartOf="parent"
221+
app:layout_constraintTop_toBottomOf="@id/v_settings_0">
222+
223+
<TextView
224+
android:id="@+id/tv_settings_alert_off"
225+
android:layout_width="match_parent"
226+
android:layout_height="wrap_content"
227+
android:layout_gravity="center"
228+
android:layout_marginHorizontal="20dp"
229+
android:layout_marginVertical="6dp"
230+
android:background="@drawable/shape_neutrals050_fill_12_rect"
231+
android:gravity="center"
232+
android:padding="12dp"
233+
android:text="@string/settings_alert_off"
234+
android:textAppearance="@style/Typography.suit.bold_12"
235+
android:textColor="@color/neutrals400" />
236+
</FrameLayout>
121237

122238
<androidx.constraintlayout.widget.ConstraintLayout
123239
android:id="@+id/cl_settings_list"
124240
android:layout_width="match_parent"
125241
android:layout_height="wrap_content"
126-
app:layout_constraintTop_toTopOf="@id/v_settings_1">
242+
app:layout_constraintTop_toBottomOf="@id/fl_settings_alert_off">
127243

128244
<androidx.constraintlayout.widget.ConstraintLayout
129245
android:id="@+id/cl_setting_1"

0 commit comments

Comments
 (0)