mirror of
https://github.com/imcarlost/Friendlists.git
synced 2026-04-10 10:56:54 -04:00
create module and implement it
This commit is contained in:
@@ -3,7 +3,7 @@ package com.hako.albumlist.domain.usecase
|
||||
import com.hako.albumlist.domain.datasource.AlbumlistRemoteApi
|
||||
import com.hako.albumlist.model.AlbumViewable
|
||||
import com.hako.albumlist.model.toAlbumEntity
|
||||
import com.hako.albumlist.model.toUserViewable
|
||||
import com.hako.albumlist.model.toAlbumViewable
|
||||
import com.hako.base.domain.database.dao.AlbumDao
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
@@ -28,13 +28,13 @@ class GetAlbum(private val dao: AlbumDao) : KoinComponent {
|
||||
api.getAlbums(userId)
|
||||
.doOnSuccess {
|
||||
dao.saveAll(it.map { album -> album.toAlbumEntity() })
|
||||
onSuccess(dao.getAlbums(userId).map { album -> album.toUserViewable() })
|
||||
onSuccess(dao.getAlbums(userId).map { album -> album.toAlbumViewable() })
|
||||
}
|
||||
.doOnSubscribe { onLoading() }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe({}, { onError(it) })
|
||||
} else {
|
||||
onSuccess(dbAlbum.map { it.toUserViewable() })
|
||||
onSuccess(dbAlbum.map { it.toAlbumViewable() })
|
||||
}
|
||||
}
|
||||
.subscribe()
|
||||
|
||||
@@ -20,5 +20,5 @@ data class AlbumViewable(
|
||||
|
||||
fun Album.toAlbumEntity() = AlbumEntity(this.id, this.userId, this.title)
|
||||
|
||||
fun AlbumEntity.toUserViewable() = AlbumViewable(this.id, this.userId, this.title)
|
||||
fun AlbumEntity.toAlbumViewable() = AlbumViewable(this.id, this.userId, this.title)
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ class AlbumlistViewmodel : ViewModel(), KoinComponent {
|
||||
val data = MutableLiveData<Either<Throwable, List<AlbumViewable>>>()
|
||||
val requestStatus = MutableLiveData<RequestStatus>()
|
||||
|
||||
private val getUsers: GetAlbum = get()
|
||||
private val getAlbum: GetAlbum = get()
|
||||
|
||||
fun fetchAlbums(userId: Int) {
|
||||
getUsers.execute(
|
||||
getAlbum.execute(
|
||||
userId,
|
||||
onSuccess = {
|
||||
requestStatus.postValue(Ready)
|
||||
|
||||
@@ -20,7 +20,7 @@ class AlbumlistAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
var onItemClick: (AlbumViewable) -> Unit = { }
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder =
|
||||
UserViewHolder(
|
||||
AlbumViewHolder(
|
||||
LayoutInflater
|
||||
.from(parent.context)
|
||||
.inflate(R.layout.item_album_card, parent, false),
|
||||
@@ -37,12 +37,12 @@ class AlbumlistAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
||||
override fun onBindViewHolder(viewholder: RecyclerView.ViewHolder, position: Int) =
|
||||
when (viewholder) {
|
||||
is UserViewHolder -> viewholder.bind(items[position])
|
||||
is AlbumViewHolder -> viewholder.bind(items[position])
|
||||
else -> throw NoWhenBranchMatchedException("Undefined viewholder")
|
||||
}
|
||||
}
|
||||
|
||||
class UserViewHolder(private val view: View,
|
||||
class AlbumViewHolder(private val view: View,
|
||||
private val onItemClick: (AlbumViewable) -> Unit) :
|
||||
RecyclerView.ViewHolder(view) {
|
||||
|
||||
|
||||
@@ -14,12 +14,15 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_album_card_album_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:ellipsize="end"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Album name" />
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
android:id="@+id/albumlistFragment"
|
||||
android:name="com.hako.albumlist.feature.AlbumlistFragment"
|
||||
tools:layout="@layout/fragment_albumlist"
|
||||
android:label="AlbumListFragment" />
|
||||
android:label="AlbumlistFragment" />
|
||||
|
||||
</navigation>
|
||||
Reference in New Issue
Block a user