-
Notifications
You must be signed in to change notification settings - Fork 7
homework #47
base: main
Are you sure you want to change the base?
homework #47
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
package com.example.mymusicplayer.data.purchase | ||
package com.example.app.data.purchase | ||
|
||
import android.content.Context | ||
import com.android.billingclient.api.* | ||
import com.example.app.data.purchase.GooglePlayProductMapper | ||
import com.example.app.domain.purchase.ProductEntity | ||
import com.example.app.domain.purchase.PurchaseStateInteractor | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
|
@@ -17,7 +16,7 @@ class PurchaseStateInteractorGooglePlay( | |
} | ||
|
||
val _isPremium = MutableStateFlow(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. либо делай private, либо это одна и та же переменная There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. К переменной isPremium нельзя обратиться There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ну а зачем две isPremium тогда? |
||
override val isPremium: StateFlow<Boolean> = _isPremium | ||
override var isPremium: StateFlow<Boolean> = _isPremium | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Оставляй val. |
||
|
||
private val purchasesUpdatedListener = | ||
PurchasesUpdatedListener { billingResult, purchases -> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
package com.example.app.presentation.view.albumsrecycler | ||
|
||
import android.content.res.Resources | ||
import android.graphics.Outline | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.ViewOutlineProvider | ||
import android.widget.ImageView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import coil.load | ||
|
||
import com.example.app.domain.AlbumModel | ||
import com.example.app.view.R | ||
|
||
class AlbumsAdapter(data: List<AlbumModel>) : RecyclerView.Adapter<AlbumsViewHolder>() { | ||
|
||
var data: List<AlbumModel> = data | ||
set(value) { | ||
field = value | ||
} | ||
class AlbumsAdapter(var data: List<AlbumModel>) : RecyclerView.Adapter<AlbumsViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AlbumsViewHolder { | ||
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_album, parent, false) | ||
|
@@ -26,17 +23,20 @@ class AlbumsAdapter(data: List<AlbumModel>) : RecyclerView.Adapter<AlbumsViewHol | |
|
||
override fun onBindViewHolder(holder: AlbumsViewHolder, position: Int) { | ||
val item = data[position] | ||
holder.imageAlbum.load(item.image) | ||
holder.textAlbum.text = item.name | ||
|
||
holder.imageAlbum.clipToOutline = true | ||
holder.imageAlbum.outlineProvider = object : ViewOutlineProvider() { | ||
holder.imageAlbum.apply { | ||
load(item.image) | ||
outlineProvider = object : ViewOutlineProvider() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. дублирование кода -переноси в общие функции. |
||
override fun getOutline(p0: View, p1: Outline) { | ||
p1.setRoundRect(0, 0, p0.width, p0.height, 10.0F) | ||
p1.setRoundRect(0, 0, p0.width, p0.height, dpToPx(10)) | ||
} | ||
} | ||
} | ||
|
||
} | ||
private fun dpToPx(dp: Int): Float = dp * Resources.getSystem().displayMetrics.density | ||
|
||
override fun getItemCount(): Int { | ||
return data.size | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.example.app.presentation.view.tracksrecycler | ||
|
||
import android.content.res.Resources | ||
import android.graphics.Outline | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
|
@@ -10,38 +11,40 @@ import coil.load | |
import com.example.app.domain.TrackModel | ||
import com.example.app.view.R | ||
|
||
class TracksAdapter(data: List<TrackModel>, private val onItemClick: (View, TrackModel) -> Boolean) : RecyclerView.Adapter<TracksViewHolder>() { | ||
|
||
var data: List<TrackModel> = data | ||
set(value) { | ||
field = value | ||
} | ||
class TracksAdapter( | ||
var data: List<TrackModel>, | ||
private val onItemClick: (View, TrackModel) -> Boolean | ||
) : RecyclerView.Adapter<TracksViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TracksViewHolder { | ||
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_track, parent, false) | ||
|
||
return TracksViewHolder(view) | ||
} | ||
|
||
private fun dpToPx(dp: Int): Float = dp * Resources.getSystem().displayMetrics.density | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Во все классы будешь копировать? |
||
|
||
override fun onBindViewHolder(holder: TracksViewHolder, position: Int) { | ||
val item = data[position] | ||
holder.imageTrack.load(item.image.replace("{w}", "200").replace("{h}", "200")) | ||
holder.titleTrack.text = item.title | ||
holder.textTrack.text = item.artist | ||
|
||
holder.imageTrack.clipToOutline = true | ||
holder.imageTrack.outlineProvider = object: ViewOutlineProvider() { | ||
override fun getOutline(p0: View, p1: Outline) { | ||
p1.setRoundRect(0, 0, p0.width, p0.height, 8.0F) | ||
holder.imageTrack.apply { | ||
load(item.image.replace("{w}", "200").replace("{h}", "200")) | ||
clipToOutline = true | ||
outlineProvider = object : ViewOutlineProvider() { | ||
override fun getOutline(p0: View, p1: Outline) { | ||
p1.setRoundRect(0, 0, p0.width, p0.height, dpToPx(10)) | ||
} | ||
} | ||
} | ||
|
||
holder.itemView.setOnLongClickListener{ | ||
holder.titleTrack.text = item.title | ||
holder.textTrack.text = item.artist | ||
holder.itemView.setOnLongClickListener { | ||
onItemClick(it, item) | ||
return@setOnLongClickListener true | ||
} | ||
} | ||
|
||
|
||
override fun getItemCount(): Int { | ||
return data.size | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Используй koin + Dependency Inversion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут у меня не работает через koin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сделай, чтобы работало. https://insert-koin.io/docs/reference/koin-android/workmanager/