Skip to content

Commit

Permalink
Detail Player,Player team list,overview team,model Player
Browse files Browse the repository at this point in the history
  • Loading branch information
HarioBudiharjo committed Oct 26, 2018
1 parent b8fe0d9 commit c8692c2
Show file tree
Hide file tree
Showing 16 changed files with 380 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,65 @@
package com.hariobudiharjo.footballmatchschedule.DetailPlayer

import android.app.ProgressDialog
import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v7.app.AppCompatActivity;
import android.util.Log
import com.bumptech.glide.Glide
import com.google.gson.Gson
import com.hariobudiharjo.footballmatchschedule.Model.playerModel
import com.hariobudiharjo.footballmatchschedule.Network.ApiMatch
import com.hariobudiharjo.footballmatchschedule.R

import kotlinx.android.synthetic.main.activity_detail_player.*
import kotlinx.android.synthetic.main.content_detail_player.*

class DetailPlayerActivity : AppCompatActivity() {
class DetailPlayerActivity : AppCompatActivity(), DetailPlayerView {

private var matchs: MutableList<playerModel> = mutableListOf()
lateinit var progress: ProgressDialog
lateinit var presenter: DetailPlayerPresenter

override fun showLoading() {
progress.show()
}

override fun hideLoading() {
progress.dismiss()
}

override fun showDetail(data: MutableList<playerModel>) {
Log.d("DEBUGDETAIL", data.toString())
Glide.with(this@DetailPlayerActivity).load(data[0].strFanart1).into(ivFanart)
tvWeight.text = data[0].strWeight
tvHeight.text = data[0].strHeight
tvPosition.text = data[0].strPosition
tvDescription.text = data[0].strDescriptionEN

}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_detail_player)
setSupportActionBar(toolbar)

getSupportActionBar()!!.setDisplayHomeAsUpEnabled(true)

toolbar.setNavigationOnClickListener {
onBackPressed()
}


val idplayer = intent.getStringExtra("id")
val request = ApiMatch()
val gson = Gson()

progress = ProgressDialog(this)
progress.setTitle("Loading")
progress.setMessage("Wait while loading...")
progress.setCancelable(false)

presenter = DetailPlayerPresenter(this, request, gson)
presenter.getPlayerList(idplayer)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.hariobudiharjo.footballmatchschedule.DetailPlayer

import android.util.Log
import com.google.gson.Gson
import com.hariobudiharjo.footballmatchschedule.Model.playerDetailResponse
import com.hariobudiharjo.footballmatchschedule.Model.playerModel
import com.hariobudiharjo.footballmatchschedule.Model.playerResponse
import com.hariobudiharjo.footballmatchschedule.Network.ApiMatch
import com.hariobudiharjo.footballmatchschedule.Util.CoroutineContextProvider
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread

class DetailPlayerPresenter(private val view: DetailPlayerView,
private val apiRepository: ApiMatch,
private val gson: Gson,
private val contextPool: CoroutineContextProvider = CoroutineContextProvider()) {
private var matchs: MutableList<playerModel> = mutableListOf()

fun getPlayerList(idPlayer: String) {

Log.d("DEBUGDETAIL", "MASUK PAK EKO")
view.showLoading()
doAsync {
val data = gson.fromJson(apiRepository
.doRequest("https://www.thesportsdb.com/api/v1/json/1/lookupplayer.php?id=$idPlayer"),
playerDetailResponse::class.java)
matchs.clear()
matchs.addAll(data.players)
Log.d("DEBUG", matchs.toString())

uiThread {
view.showDetail(matchs)
view.hideLoading()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hariobudiharjo.footballmatchschedule.DetailPlayer

import com.hariobudiharjo.footballmatchschedule.Model.playerModel

interface DetailPlayerView {
fun showLoading()
fun hideLoading()
fun showDetail(data: MutableList<playerModel>)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hariobudiharjo.footballmatchschedule.DetailTeam

import android.app.ProgressDialog
import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
Expand All @@ -22,28 +23,28 @@ import kotlinx.android.synthetic.main.content_detail_team.*
class DetailTeamActivity : AppCompatActivity(), DetailTeamView {

override fun showLoading() {
Log.d("DEBUG Detail Team", "SHOW")
progress.show()
}

override fun hideLoading() {
Log.d("DEBUG Detail Team", "DISMISS")
progress.dismiss()
}

override fun showDetail(data: MutableList<teamModel>) {
teams.addAll(data)
Log.d("DEBUG Detail Team", teams.toString())


Glide.with(this@DetailTeamActivity).load(teams[0].strTeamBadge).into(ivClubDetailTeam)
tvNamaDetailTeam.text = teams[0].strTeam
tvTahunDetailTeam.text = teams[0].intFormedYear
tvStadiunDetailTeam.text = teams[0].strStadium
setupViewPager(viewPager, teams[0].strDescriptionEN.toString(), teams[0].idTeam.toString());
}

lateinit var tabLayout: TabLayout
lateinit var viewPager: ViewPager
private var teams: MutableList<teamModel> = mutableListOf()
lateinit var presenter: DetailTeamPresenter
lateinit var progress: ProgressDialog

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -53,23 +54,49 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView {
val idTeam = intent.getStringExtra("id")

viewPager = findViewById(R.id.viewpager)
setupViewPager(viewPager);

tabLayout = findViewById(R.id.tabs)
tabLayout.setupWithViewPager(viewPager)

val request = ApiMatch()
val gson = Gson()

progress = ProgressDialog(this)
progress.setTitle("Loading")
progress.setMessage("Wait while loading...")
progress.setCancelable(false)

presenter = DetailTeamPresenter(this, request, gson)
presenter.getTeamDetail(idTeam)

getSupportActionBar()!!.setDisplayHomeAsUpEnabled(true)

toolbar.setNavigationOnClickListener {
onBackPressed()
}
}


private fun setupViewPager(viewPager: ViewPager) {
private fun setupViewPager(viewPager: ViewPager, overView: String, idTeam: String) {

val bundleOverView = Bundle()
bundleOverView.putString("overview", overView)

val bundleTeam = Bundle()
bundleTeam.putString("idteam", idTeam)

val adapter = ViewPagerAdapter(supportFragmentManager)
adapter.addFragment(OverviewFragment(), "Overview")
adapter.addFragment(PlayerTeamFragment(), "Player")
// adapter.addFragment(OverviewFragment(), "Overview")
// adapter.addFragment(PlayerTeamFragment(), "Player")

val overviewFragment = OverviewFragment()
val playerTeamFragment = PlayerTeamFragment()

overviewFragment.arguments = bundleOverView
playerTeamFragment.arguments = bundleTeam

adapter.addFragment(overviewFragment, "Overview")
adapter.addFragment(playerTeamFragment, "Player")
viewPager.adapter = adapter
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.hariobudiharjo.footballmatchschedule.DetailTeam.OverviewTeam

import android.os.Bundle
import android.support.v4.app.Fragment
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView

import com.hariobudiharjo.footballmatchschedule.R

Expand All @@ -15,7 +17,12 @@ class OverviewFragment : Fragment() {
savedInstanceState: Bundle?): View? {
val viewku = inflater.inflate(R.layout.fragment_overview, container, false)


val strtext = arguments!!.getString("overview")
val tvOverview = viewku.findViewById<TextView>(R.id.tvOverview)
tvOverview.text = strtext


Log.d("OVERVIEW", strtext)

return viewku
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,69 @@
package com.hariobudiharjo.footballmatchschedule.DetailTeam.PlayerTeam


import android.app.ProgressDialog
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.google.gson.Gson
import com.hariobudiharjo.footballmatchschedule.Model.playerModel
import com.hariobudiharjo.footballmatchschedule.Network.ApiMatch

import com.hariobudiharjo.footballmatchschedule.R

class PlayerTeamFragment : Fragment() {
class PlayerTeamFragment : Fragment(), PlayerTeamView {

private var matchs: MutableList<playerModel> = mutableListOf()
lateinit var adapter: RVPlayerAdapter
lateinit var progress: ProgressDialog
lateinit var presenter: PlayerTeamPresenter
override fun showLoading() {
progress.show()
}

override fun hideLoading() {
progress.dismiss()
}

override fun showDetail(data: MutableList<playerModel>) {
matchs.addAll(data)
adapter.notifyDataSetChanged()
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {

// https://www.thesportsdb.com/api/v1/json/1/lookup_all_players.php?id=133604
val viewku = inflater.inflate(R.layout.fragment_player_team, container, false)


val _recyclerView: RecyclerView = viewku.findViewById(R.id.rv_player)
_recyclerView.layoutManager = LinearLayoutManager(context, LinearLayout.VERTICAL, false)

val idteam = arguments!!.getString("idteam")
Log.d("IDTEAM", idteam)

val request = ApiMatch()
val gson = Gson()

progress = ProgressDialog(context)
progress.setTitle("Loading")
progress.setMessage("Wait while loading...")
progress.setCancelable(false)

presenter = PlayerTeamPresenter(this, request, gson)
presenter.getPlayerList(idteam)


adapter = RVPlayerAdapter(context!!, matchs)
_recyclerView.adapter = adapter

return viewku
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.hariobudiharjo.footballmatchschedule.DetailTeam.PlayerTeam

import android.util.Log
import com.google.gson.Gson
import com.hariobudiharjo.footballmatchschedule.Model.playerModel
import com.hariobudiharjo.footballmatchschedule.Model.playerResponse
import com.hariobudiharjo.footballmatchschedule.Network.ApiMatch
import com.hariobudiharjo.footballmatchschedule.Util.CoroutineContextProvider
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread

class PlayerTeamPresenter(private val view: PlayerTeamView,
private val apiRepository: ApiMatch,
private val gson: Gson,
private val contextPool: CoroutineContextProvider = CoroutineContextProvider()) {
private var matchs: MutableList<playerModel> = mutableListOf()

fun getPlayerList(idTeam: String) {
view.showLoading()
doAsync {
val data = gson.fromJson(apiRepository
.doRequest("https://www.thesportsdb.com/api/v1/json/1/lookup_all_players.php?id=$idTeam"),
playerResponse::class.java)
matchs.clear()
matchs.addAll(data.player)
Log.d("DEBUG", matchs.toString())

uiThread {
view.showDetail(matchs)
view.hideLoading()
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hariobudiharjo.footballmatchschedule.DetailTeam.PlayerTeam

import com.hariobudiharjo.footballmatchschedule.Model.playerModel
import com.hariobudiharjo.footballmatchschedule.Model.teamModel

interface PlayerTeamView {
fun showLoading()
fun hideLoading()
fun showDetail(data: MutableList<playerModel>)
}
Loading

0 comments on commit c8692c2

Please sign in to comment.