Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#300-image-load
Browse files Browse the repository at this point in the history
  • Loading branch information
yys7517 committed Jan 13, 2023
2 parents 529455d + f6860c5 commit d85f9bf
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.starters.yeogida.presentation.home

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.os.Parcelable
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -30,6 +33,10 @@ class HomeFragment : Fragment() {
private lateinit var binding: FragmentHomeBinding
private val viewModel: HomeViewModel by viewModels()
private lateinit var mContext: Context
private var recyclerViewState = 0
private val recentTripAdapter = TripAdapter { tripId: Long ->
moveToTrip(tripId)
}

override fun onCreateView(
inflater: LayoutInflater,
Expand Down Expand Up @@ -79,37 +86,44 @@ class HomeFragment : Fragment() {
}
)

val recentTripAdapter = TripAdapter { tripId: Long ->
moveToTrip(tripId)
}
binding.rvRecentTrip.adapter = recentTripAdapter
YeogidaClient.homeService.getRecentTrip().customEnqueue(
onSuccess = {
it.data?.let { data -> recentTripAdapter.tripList.addAll(data.tripList) }
recentTripAdapter.notifyDataSetChanged()
}
)
initRecentTripAdapter("all")
}

val followRecentTripAdapter = TripAdapter { tripId: Long ->
moveToTrip(tripId)
}
binding.rvFollowRecentTrip.adapter = followRecentTripAdapter
YeogidaClient.homeService.getFollowRecentTrip().customEnqueue(
onSuccess = {
if (it.code == 200) {
binding.tvHomeFollowRecentTripEmpty.text = ""
it.data?.let { data -> followRecentTripAdapter.tripList.addAll(data.tripList) }
followRecentTripAdapter.notifyDataSetChanged()
}
},
onError = {
if (it.message == "No one Follow Error!") {
binding.tvHomeFollowRecentTripEmpty.text = "아직 팔로잉한 사람이 없어요\n사람들을 팔로잉 해보세요!"
} else if (it.message == "Trip NotFound Error!") {
binding.tvHomeFollowRecentTripEmpty.text = "팔로잉들이 아직 게시글을 올리지 않았어요\n더 많은 사람들을 팔로잉 해보세요!"
}
private fun initRecentTripAdapter(type: String) {
when (type) {
"all" -> {
binding.rvRecentTrip.adapter = recentTripAdapter
YeogidaClient.homeService.getRecentTrip().customEnqueue(
onSuccess = {
recentTripAdapter.tripList.clear()
it.data?.let { data -> recentTripAdapter.tripList.addAll(data.tripList) }
recentTripAdapter.notifyDataSetChanged()
}
)
}
)
"follow" -> {
binding.rvRecentTrip.adapter = recentTripAdapter
YeogidaClient.homeService.getFollowRecentTrip().customEnqueue(
onSuccess = {
if (it.code == 200) {
recentTripAdapter.tripList.clear()
binding.tvHomeFollowRecentTripEmpty.text = ""
it.data?.let { data -> recentTripAdapter.tripList.addAll(data.tripList) }
recentTripAdapter.notifyDataSetChanged()
}
},
onError = {
if (it.message == "No one Follow Error!") {
binding.tvHomeFollowRecentTripEmpty.text =
"아직 팔로잉한 사람이 없어요\n사람들을 팔로잉 해보세요!"
} else if (it.message == "Trip NotFound Error!") {
binding.tvHomeFollowRecentTripEmpty.text =
"팔로잉들이 아직 게시글을 올리지 않았어요\n더 많은 사람들을 팔로잉 해보세요!"
}
}
)
}
}
}

private fun moveToTrip(tripId: Long) {
Expand Down Expand Up @@ -170,4 +184,16 @@ class HomeFragment : Fragment() {
fun moveToMoreRecentTrip(view: View) {
startActivity(Intent(mContext, MoreRecentTripActivity::class.java))
}

fun clickRecentTripFollow(view: View) {
binding.tvRecentTrip.setTextColor(Color.parseColor("#BCBCBC"))
binding.tvFollowRecentTrip.setTextColor(Color.parseColor("#000000"))
initRecentTripAdapter("follow")
}

fun clickRecentTripAll(view: View) {
binding.tvRecentTrip.setTextColor(Color.parseColor("#000000"))
binding.tvFollowRecentTrip.setTextColor(Color.parseColor("#BCBCBC"))
initRecentTripAdapter("all")
}
}
29 changes: 9 additions & 20 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
app:layout_constraintTop_toTopOf="@+id/tv_home_title" />

<androidx.core.widget.NestedScrollView
android:id="@+id/scrollView_home"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
Expand Down Expand Up @@ -165,27 +166,13 @@
android:layout_marginTop="24dp"
android:fontFamily="@font/noto_sans_bold"
android:text="@string/home_recent_trip_title"
android:onClick="@{view::clickRecentTripAll}"
android:textColor="@color/black_blue"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@+id/tv_best_traveler_title"
app:layout_constraintTop_toBottomOf="@+id/rv_best_monthly_trip" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_recent_trip"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="24dp"
android:orientation="horizontal"
android:paddingEnd="10dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_recent_trip"
tools:listitem="@layout/item_home_trip" />

<TextView
android:id="@+id/tv_more_recent_trip"
android:layout_width="wrap_content"
Expand All @@ -205,17 +192,19 @@
android:id="@+id/tv_follow_recent_trip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginStart="12dp"
android:fontFamily="@font/noto_sans_bold"
android:text="@string/home_recent_trip_title_follow"
android:textColor="@color/black_blue"
android:textColor="@color/gray_400"
android:textSize="18sp"
android:onClick="@{view::clickRecentTripFollow}"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@+id/tv_recent_trip"
app:layout_constraintTop_toBottomOf="@+id/rv_recent_trip" />
app:layout_constraintBottom_toBottomOf="@id/tv_recent_trip"
app:layout_constraintStart_toEndOf="@+id/tv_recent_trip"
app:layout_constraintTop_toTopOf="@+id/tv_recent_trip" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_follow_recent_trip"
android:id="@+id/rv_recent_trip"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="10dp"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<string name="home_title">여기다</string>
<string name="home_best_traveler_title">Best Traveler</string>
<string name="home_best_monthly_trip_title">월간 Best 여행지</string>
<string name="home_recent_trip_title_follow">팔로잉의 최근 여행지</string>
<string name="home_recent_trip_title">방금 작성된 여행지</string>
<string name="home_recent_trip_title_follow">팔로잉의 여행지</string>
<string name="home_recent_trip_title">최신 여행지</string>
<string name="home_more_text">더보기</string>

<!-- Around Place Fragment -->
Expand Down

0 comments on commit d85f9bf

Please sign in to comment.