This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package egorikem.mybet.presentation.view.adapters | |
import android.os.Bundle | |
import android.support.v4.app.Fragment | |
import android.support.v7.widget.LinearLayoutManager | |
import android.support.v7.widget.RecyclerView | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import butterknife.BindView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseHolder { | |
val inflater = LayoutInflater.from(parent.context) | |
val itemView: View | |
val dataHolder: BaseHolder = when(viewType) { | |
Type.NORMAL.value -> { | |
itemView = inflater.inflate(normalCellLayout, parent, false) | |
NormalGoodHolder(itemView, callback) | |
} | |
Type.SALE.value -> { | |
itemView = inflater.inflate(saleCellLayout, parent, false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun getItemViewType(position: Int): Int { | |
if(getItemAtPosition(position).saleAmount > 0) { | |
return Type.SALE.value | |
} | |
return Type.NORMAL.value | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SaleGoodHolder(itemView: View, callback: Callback) : BaseHolder(itemView, callback) { | |
@BindView(R.id.sale_item_name) | |
lateinit var name: TextView | |
@BindView(R.id.sale_item_sale_amount) | |
lateinit var saleAmount: TextView | |
@BindView(R.id.sale_item_price) | |
lateinit var price: TextView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GoodsAdapter (dataSet: MutableList<Good>, val callback: Callback) : AbstractArrayAdapter<Good, GoodsAdapter.BaseHolder>(dataSet) { | |
interface Callback { | |
fun onNormalGoodClick(data: Good) | |
fun onSaleGoodClick(data: Good) | |
} | |
enum class Type(val value: Int) { | |
NORMAL(1), | |
SALE(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Good( | |
val name: String, | |
val saleAmount: Int, | |
val price: Int | |
) { | |
/** | |
* Method to get current price with sale | |
*/ | |
fun calculatePrice(): Int { | |
return price - price*saleAmount/100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseHolder(itemView: View, protected var callback: Callback) : RecyclerView.ViewHolder(itemView) { | |
protected var unbinder: Unbinder? = null | |
protected lateinit var data: Good | |
abstract fun bindData(data: Good) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.support.v7.widget.RecyclerView | |
import java.util.* | |
abstract class AbstractArrayAdapter<ITEM, VH : RecyclerView.ViewHolder>(dataSet: MutableList<ITEM>?) : RecyclerView.Adapter<VH>() { | |
//region Data | |
private val dataSet: MutableList<ITEM> | |
//endregion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gravity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gravity |