Skip to content

Commit

Permalink
Detail Team image club,name, stadiun,tahun, some clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
HarioBudiharjo committed Oct 25, 2018
1 parent 87a8bcc commit b8fe0d9
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,72 @@ import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.support.v4.view.ViewPager
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.bumptech.glide.Glide
import com.google.gson.Gson
import com.hariobudiharjo.footballmatchschedule.DetailTeam.OverviewTeam.OverviewFragment
import com.hariobudiharjo.footballmatchschedule.DetailTeam.PlayerTeam.PlayerTeamFragment
import com.hariobudiharjo.footballmatchschedule.Model.teamModel
import com.hariobudiharjo.footballmatchschedule.Network.ApiMatch
import com.hariobudiharjo.footballmatchschedule.R

import kotlinx.android.synthetic.main.activity_detail_team.*
import kotlinx.android.synthetic.main.content_detail_team.*

class DetailTeamActivity : AppCompatActivity() {
class DetailTeamActivity : AppCompatActivity(), DetailTeamView {

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

override fun hideLoading() {
Log.d("DEBUG Detail Team", "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
}

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

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

viewPager = findViewById(R.id.viewpager)
val idTeam = intent.getStringExtra("id")

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

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

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

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


private fun setupViewPager(viewPager: ViewPager) {
val adapter = ViewPagerAdapter(supportFragmentManager)
adapter.addFragment(OverviewFragment(), "PAST")
adapter.addFragment(PlayerTeamFragment(), "NEXT")
adapter.addFragment(OverviewFragment(), "Overview")
adapter.addFragment(PlayerTeamFragment(), "Player")
viewPager.adapter = adapter
}

internal inner class ViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager) {
private val mFragmentList = arrayListOf<Fragment>()
private val mFragmentTitleList = arrayListOf<String>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.hariobudiharjo.footballmatchschedule.DetailTeam

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

class DetailTeamPresenter(private val view: DetailTeamView,
private val apiRepository: ApiMatch,
private val gson: Gson,
private val contextPool: CoroutineContextProvider = CoroutineContextProvider()) {
private var teams: MutableList<teamModel> = mutableListOf()

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

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

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

import com.hariobudiharjo.footballmatchschedule.Model.teamModel

interface DetailTeamView {
fun showLoading()
fun hideLoading()
fun showDetail(data: MutableList<teamModel>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@ import android.view.ViewGroup

import com.hariobudiharjo.footballmatchschedule.R

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
* A simple [Fragment] subclass.
*
*/
class OverviewFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_overview, container, false)
val viewku = inflater.inflate(R.layout.fragment_overview, container, false)



return viewku
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,12 @@ import android.view.ViewGroup

import com.hariobudiharjo.footballmatchschedule.R

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
* A simple [Fragment] subclass.
*
*/
class PlayerTeamFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_player_team, container, false)
val viewku = inflater.inflate(R.layout.fragment_player_team, container, false)
return viewku
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,69 @@ package com.hariobudiharjo.footballmatchschedule.Favorite


import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.support.v4.view.ViewPager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.hariobudiharjo.footballmatchschedule.FavoriteEvent.FavoriteEventFragment
import com.hariobudiharjo.footballmatchschedule.FavoriteEvent.FavoriteTeamFragment
import com.hariobudiharjo.footballmatchschedule.NextMatch.NextMatchFragment
import com.hariobudiharjo.footballmatchschedule.PrevMatch.PrevMatchFragment

import com.hariobudiharjo.footballmatchschedule.R


class FavoriteFragment : Fragment() {

lateinit var tabLayout: TabLayout
lateinit var viewPager: ViewPager
lateinit var viewku: View

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_favorite2, container, false)
viewku = inflater.inflate(R.layout.fragment_favorite2, container, false)
viewPager = viewku.findViewById(R.id.viewpager)
setupViewPager(viewPager);

tabLayout = viewku.findViewById(R.id.tabs)
tabLayout.setupWithViewPager(viewPager)
return viewku
}

private fun setupViewPager(viewPager: ViewPager) {
val adapter = ViewPagerAdapter(fragmentManager!!)
adapter.addFragment(FavoriteEventFragment.favoriteMatchInstance(), "EVENT")
adapter.addFragment(FavoriteTeamFragment.favoriteTeamInstance(), "TEAM")
viewPager.adapter = adapter
}

companion object {
fun matchInstance(): FavoriteFragment = FavoriteFragment()
}

internal inner class ViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager) {
private val mFragmentList = arrayListOf<Fragment>()
private val mFragmentTitleList = arrayListOf<String>()

override fun getItem(position: Int): Fragment {
return mFragmentList.get(position)
}

override fun getCount(): Int {
return mFragmentList.size
}

fun addFragment(fragment: Fragment, title: String) {
mFragmentList.add(fragment)
mFragmentTitleList.add(title)
}

override fun getPageTitle(position: Int): CharSequence? {
return mFragmentTitleList.get(position)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import com.hariobudiharjo.footballmatchschedule.R
import org.jetbrains.anko.db.classParser
import org.jetbrains.anko.db.select

/**
* A simple [Fragment] subclass.
*
*/
class FavoriteEventFragment : Fragment() {


Expand Down Expand Up @@ -59,5 +55,8 @@ class FavoriteEventFragment : Fragment() {

}

companion object {
fun favoriteMatchInstance() : FavoriteEventFragment = FavoriteEventFragment()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import com.hariobudiharjo.footballmatchschedule.R
import org.jetbrains.anko.db.classParser
import org.jetbrains.anko.db.select

/**
* A simple [Fragment] subclass.
*
*/
class FavoriteTeamFragment : Fragment() {


Expand Down Expand Up @@ -59,5 +55,8 @@ class FavoriteTeamFragment : Fragment() {

}

companion object {
fun favoriteTeamInstance() : FavoriteTeamFragment = FavoriteTeamFragment()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.support.design.widget.BottomNavigationView
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentTransaction
import android.support.v7.app.AppCompatActivity
import com.hariobudiharjo.footballmatchschedule.Favorite.FavoriteFragment
import com.hariobudiharjo.footballmatchschedule.FavoriteEvent.FavoriteEventFragment
import com.hariobudiharjo.footballmatchschedule.Match.MatchFragment
import com.hariobudiharjo.footballmatchschedule.R
Expand Down Expand Up @@ -38,7 +39,7 @@ class UtamaActivity : AppCompatActivity() {
return@OnNavigationItemSelectedListener true
}
R.id.navigation_favorite -> {
currentFragment = FavoriteEventFragment()
currentFragment = FavoriteFragment()
ft = supportFragmentManager.beginTransaction()
ft.replace(R.id.fl_main, currentFragment)
ft.commit()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package com.hariobudiharjo.footballmatchschedule.Match


import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.hariobudiharjo.footballmatchschedule.R
import android.support.v4.app.FragmentPagerAdapter
import com.hariobudiharjo.footballmatchschedule.Match.MatchFragment.ViewPagerAdapter
import android.support.v4.view.ViewPager
import com.hariobudiharjo.footballmatchschedule.NextMatch.NextMatchFragment
import com.hariobudiharjo.footballmatchschedule.PrevMatch.PrevMatchFragment
import android.support.design.widget.TabLayout
import android.util.Log


class MatchFragment : Fragment() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ package com.hariobudiharjo.footballmatchschedule.Model
data class teamModel(
val idTeam: String?,
val strTeam: String?,
val strTeamBadge: String?)
val strTeamBadge: String?,
val intFormedYear: String?,
val strStadium: String?,
val strDescriptionEN: String?)
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class RVTeamAdapter(var context: Context, var matchs: List<teamModel>) : Recycle
Glide.with(itemView.context).load(data.strTeamBadge).into(iv_club)

itemView.setOnClickListener({
var intent = Intent(it.context, DetailTeamActivity::class.java)
val intent = Intent(it.context, DetailTeamActivity::class.java)
intent.putExtra("id", data.idTeam)
it.context.startActivity(intent)
})
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/res/layout/content_detail_team.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,31 @@
tools:showIn="@layout/activity_detail_team">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:id="@+id/ivClubDetailTeam"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
app:srcCompat="@drawable/arsenal" />

<TextView
android:id="@+id/tvNamaDetailTeam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Barcelona" />

<TextView
android:id="@+id/tvTahunDetailTeam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="1997" />

<TextView
android:id="@+id/tvStadiunDetailTeam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Camp Nou" />

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
Expand Down
Loading

0 comments on commit b8fe0d9

Please sign in to comment.