parent
1f36d8ef25
commit
772005910c
|
@ -30,6 +30,7 @@ interface SeriesApi {
|
|||
@Path("id") seriesId: Long,
|
||||
@Query("page") page: Int,
|
||||
@Query("size") size: Int,
|
||||
@Query("sortType") sortType: SeriesListAllViewModel.SeriesSortType,
|
||||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<GetSeriesContentListResponse>>
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class SeriesListAllViewModel(private val repository: SeriesRepository) : BaseVie
|
|||
|
||||
enum class SeriesSortType {
|
||||
@SerializedName("NEWEST") NEWEST,
|
||||
@SerializedName("POPULAR") POPULAR
|
||||
@SerializedName("OLDEST") OLDEST
|
||||
}
|
||||
|
||||
private val _toastLiveData = MutableLiveData<String?>()
|
||||
|
|
|
@ -24,11 +24,13 @@ class SeriesRepository(private val api: SeriesApi) {
|
|||
seriesId: Long,
|
||||
page: Int,
|
||||
size: Int,
|
||||
sortType: SeriesListAllViewModel.SeriesSortType,
|
||||
token: String
|
||||
) = api.getSeriesContentList(
|
||||
seriesId = seriesId,
|
||||
page = page - 1,
|
||||
size = size,
|
||||
sortType = sortType,
|
||||
authHeader = token
|
||||
)
|
||||
|
||||
|
|
|
@ -2,11 +2,15 @@ package kr.co.vividnext.sodalive.audio_content.series.content
|
|||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.audio_content.detail.AudioContentDetailActivity
|
||||
import kr.co.vividnext.sodalive.audio_content.series.SeriesListAllViewModel
|
||||
import kr.co.vividnext.sodalive.base.BaseActivity
|
||||
import kr.co.vividnext.sodalive.common.Constants
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
|
@ -86,6 +90,14 @@ class SeriesContentAllActivity : BaseActivity<ActivitySeriesContentAllBinding>(
|
|||
})
|
||||
|
||||
binding.rvSeriesContentAll.adapter = adapter
|
||||
|
||||
binding.tvSortNewest.setOnClickListener {
|
||||
viewModel.changeSort(SeriesListAllViewModel.SeriesSortType.NEWEST)
|
||||
}
|
||||
|
||||
binding.tvSortOldest.setOnClickListener {
|
||||
viewModel.changeSort(SeriesListAllViewModel.SeriesSortType.OLDEST)
|
||||
}
|
||||
}
|
||||
|
||||
fun bindData() {
|
||||
|
@ -104,5 +116,42 @@ class SeriesContentAllActivity : BaseActivity<ActivitySeriesContentAllBinding>(
|
|||
viewModel.seriesContentListLiveData.observe(this) {
|
||||
adapter.addItems(it)
|
||||
}
|
||||
|
||||
viewModel.sortLiveData.observe(this) {
|
||||
deselectSort()
|
||||
selectSort(
|
||||
when (it) {
|
||||
SeriesListAllViewModel.SeriesSortType.OLDEST -> {
|
||||
binding.tvSortOldest
|
||||
}
|
||||
|
||||
else -> {
|
||||
binding.tvSortNewest
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun deselectSort() {
|
||||
val color = ContextCompat.getColor(
|
||||
applicationContext,
|
||||
R.color.color_88e2e2e2
|
||||
)
|
||||
|
||||
binding.tvSortNewest.setTextColor(color)
|
||||
binding.tvSortOldest.setTextColor(color)
|
||||
}
|
||||
|
||||
private fun selectSort(view: TextView) {
|
||||
view.setTextColor(
|
||||
ContextCompat.getColor(
|
||||
applicationContext,
|
||||
R.color.color_e2e2e2
|
||||
)
|
||||
)
|
||||
|
||||
adapter.clear()
|
||||
viewModel.getSeriesContentList()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
|
|||
import com.orhanobut.logger.Logger
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import kr.co.vividnext.sodalive.audio_content.series.SeriesListAllViewModel
|
||||
import kr.co.vividnext.sodalive.audio_content.series.SeriesRepository
|
||||
import kr.co.vividnext.sodalive.audio_content.series.detail.GetSeriesContentListItem
|
||||
import kr.co.vividnext.sodalive.base.BaseViewModel
|
||||
|
@ -23,6 +24,10 @@ class SeriesContentAllViewModel(private val repository: SeriesRepository) : Base
|
|||
val seriesContentListLiveData: LiveData<List<GetSeriesContentListItem>>
|
||||
get() = _seriesContentListLiveData
|
||||
|
||||
private var _sortLiveData = MutableLiveData(SeriesListAllViewModel.SeriesSortType.NEWEST)
|
||||
val sortLiveData: LiveData<SeriesListAllViewModel.SeriesSortType>
|
||||
get() = _sortLiveData
|
||||
|
||||
var seriesId = 0L
|
||||
|
||||
var page = 1
|
||||
|
@ -38,6 +43,7 @@ class SeriesContentAllViewModel(private val repository: SeriesRepository) : Base
|
|||
seriesId = seriesId,
|
||||
page = page,
|
||||
size = pageSize,
|
||||
sortType = _sortLiveData.value!!,
|
||||
token = "Bearer ${SharedPreferenceManager.token}"
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
@ -70,4 +76,12 @@ class SeriesContentAllViewModel(private val repository: SeriesRepository) : Base
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun changeSort(sortType: SeriesListAllViewModel.SeriesSortType) {
|
||||
if (_sortLiveData.value != sortType) {
|
||||
page = 1
|
||||
isLast = false
|
||||
_sortLiveData.value = sortType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,41 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_sort"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/color_161616"
|
||||
android:gravity="end"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="20dp"
|
||||
android:paddingVertical="13.3dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/toolbar">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_sort_newest"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/gmarket_sans_medium"
|
||||
android:gravity="center"
|
||||
android:text="최신순"
|
||||
android:textColor="@color/color_88e2e2e2"
|
||||
android:textSize="13.3sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_sort_oldest"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="13.3dp"
|
||||
android:fontFamily="@font/gmarket_sans_medium"
|
||||
android:gravity="center"
|
||||
android:text="등록순"
|
||||
android:textColor="@color/color_88e2e2e2"
|
||||
android:textSize="13.3sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_series_content_all"
|
||||
android:layout_width="0dp"
|
||||
|
@ -19,5 +54,5 @@
|
|||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/ll_sort" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
Loading…
Reference in New Issue