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
<layout... > | |
<data> | |
<variable | |
name="viewModel" | |
type="com.azaless.cheerball.viewmodels.TeamDetailViewModel" /> | |
</data> | |
... | |
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 TeamDetailViewModel(private val cheerBallDataRepository: CheerBallDataRepository, | |
private val teamId: Int) : ViewModel() { | |
private val players = MutableLiveData<List<Player>>() | |
private val compositeDisposable: CompositeDisposable = CompositeDisposable() | |
val adapter = MutableLiveData<PlayerListAdapter>() | |
val layoutManager = MutableLiveData<RecyclerView.LayoutManager>() | |
fun getPlayers(): LiveData<List<Player>> { | |
return players |
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
<?xml version="1.0" encoding="utf-8"?> | |
<layout | |
xmlns:android="http://schemas.android.com/apk/res/android" > | |
<data> | |
<variable | |
name="player" | |
type="com.azaless.cheerball.view.model.Player" /> | |
</data> |
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 PlayerListAdapter : DataBindingAdapter<List<Player>, PlayerListAdapter.ViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val layoutInflater = LayoutInflater.from(parent.context) | |
val binding = DataBindingUtil.inflate<ListItemPlayerBinding>(layoutInflater, R.layout.list_item_player, parent, false) | |
return ViewHolder(binding) | |
} | |
override fun getItemCount() = values?.size ?: 0 |
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
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.v7.widget.CardView | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal"> |
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 GroupBallItemAdapter : RecyclerView.Adapter<GroupBallItemAdapter.ViewHolder>(){ | |
var values: List<GroupDetail> = listOf() | |
set(items) { | |
field = items | |
notifyDataSetChanged() | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
return ViewHolder(LayoutInflater.from(parent.context) | |
.inflate(R.layout.list_item_team_small, 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
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.v7.widget.CardView | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<LinearLayout |
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
var values: List<GroupDetail> = listOf() | |
set(items) { | |
field = items | |
notifyDataSetChanged() | |
} | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
with(holder) { | |
value.keys.filterIndexed { index, _ -> index == position } | |
.firstOrNull()?.let { key -> |
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 TeamDetailViewModel(private val cheerBallDataRepository: CheerBallDataRepository, | |
private val teamId: Int) : ViewModel() { | |
private val flagURL = MutableLiveData<String>() | |
private val team = MutableLiveData<Team>() | |
private val players = MutableLiveData<List<Player>>() | |
private val compositeDisposable: CompositeDisposable = CompositeDisposable() | |
val teamName = MutableLiveData<String>() | |
val adapter = MutableLiveData<PlayerListAdapter>() | |
val layoutManager = MutableLiveData<RecyclerView.LayoutManager>() |
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 onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
// factory คือ การสร้าง model โดยมีการโยนค่าอื่นๆเข้าไป | |
val factory = InjectorUtils.provideTeamViewModelFactory(context!!, teamId, teamName) | |
teamDetailViewModel = ViewModelProviders.of(this, factory).get(TeamDetailViewModel::class.java) | |
viewDataBinding.viewModel = teamDetailViewModel | |
teamDetailViewModel.adapter.value = PlayerListAdapter() |