Skip to content

Commit

Permalink
- tablayout dalam fragment matches
Browse files Browse the repository at this point in the history
- memunculkan list match dalam tablayout tersebut
- membuat team model hingga memunculkan list semua team ke dalam fragment teams
  • Loading branch information
andremw96 committed Oct 30, 2018
1 parent ee26b7a commit 569ca78
Show file tree
Hide file tree
Showing 37 changed files with 799 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.wijaya_pc.eplmatchschedule"
applicationId "com.example.wijaya_pc.footballapps"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import android.support.v7.widget.RecyclerView
import com.example.wijaya_pc.footballapps.R.id.*
import com.example.wijaya_pc.footballapps.feature.main.MainActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name="com.example.wijaya_pc.footballapps.MainActivity">
<activity android:name="com.example.wijaya_pc.footballapps.feature.main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<activity android:name="com.example.wijaya_pc.footballapps.DetailActivity">
<activity android:name="com.example.wijaya_pc.footballapps.feature.match.DetailMatchActivity">
</activity>

<activity android:name="com.example.wijaya_pc.footballapps.feature.team.DetailTeamActivity">
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.view.ViewGroup
import com.example.wijaya_pc.footballapps.R.color.colorAccent
import com.example.wijaya_pc.footballapps.adapter.FavoriteMatchesAdapter
import com.example.wijaya_pc.footballapps.database.database
import com.example.wijaya_pc.footballapps.feature.match.DetailMatchActivity
import com.example.wijaya_pc.footballapps.model.FavoriteMatches
import org.jetbrains.anko.*
import org.jetbrains.anko.db.classParser
Expand All @@ -33,7 +34,7 @@ class FavoriteMatchesFragment : Fragment(), AnkoComponent<Context> {
super.onActivityCreated(savedInstanceState)

adapter = FavoriteMatchesAdapter(favorites) {
ctx.startActivity<DetailActivity>(
ctx.startActivity<DetailMatchActivity>(
"id" to "${it.matchId}",
"homeTeamId" to "${it.homeTeamId}",
"awayTeamId" to "${it.awayTeamId}"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.wijaya_pc.footballapps.adapter

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import com.example.wijaya_pc.footballapps.feature.match.ListMatchFragment

class MatchPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {

override fun getItem(position: Int): Fragment {
return ListMatchFragment.newInstance(position)
}

override fun getCount(): Int {
return 2
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.wijaya_pc.footballapps.adapter

import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.example.wijaya_pc.footballapps.R.id.team_badge
import com.example.wijaya_pc.footballapps.R.id.team_name
import com.example.wijaya_pc.footballapps.model.Team
import com.example.wijaya_pc.footballapps.ui.TeamUI
import com.squareup.picasso.Picasso
import org.jetbrains.anko.AnkoContext
import org.jetbrains.anko.find
import org.jetbrains.anko.sdk25.coroutines.onClick

class TeamAdapter(private val teams: List<Team>, private val listener: (Team) -> Unit) : RecyclerView.Adapter<TeamViewHolder>(){

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TeamViewHolder {
return TeamViewHolder(TeamUI().createView(AnkoContext.create(parent.context, parent)))
}

override fun getItemCount(): Int = teams.size

override fun onBindViewHolder(holder: TeamViewHolder, position: Int) {
holder.bindItem(teams[position], listener)
}
}

class TeamViewHolder(view: View) : RecyclerView.ViewHolder(view) {

private val teamBadge : ImageView = view.find(team_badge)
private val teamName : TextView = view.find(team_name)

fun bindItem(teams: Team, listener: (Team) -> Unit) {
Picasso.get().load(teams.teamBadge).into(teamBadge)
teamName.text = teams.teamName
itemView.onClick { listener(teams) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ object TheSportDBApi {
}

fun getLeague() : String {
return BuildConfig.BASE_URL + "api/v1/json/${BuildConfig.TSDB_API_KEY}" + "/all_leagues.php?"
return BuildConfig.BASE_URL + "api/v1/json/${BuildConfig.TSDB_API_KEY}" + "/all_leagues.php?s=Soccer"
}

fun getAllTeams(leagueName: String?) : String {
return BuildConfig.BASE_URL + "api/v1/json/${BuildConfig.TSDB_API_KEY}" + "/search_all_teams.php?l=" + leagueName
}

fun getTeamDetail(teamId: String?): String {
return BuildConfig.BASE_URL + "api/v1/json/${BuildConfig.TSDB_API_KEY}" + "/lookupteam.php?id=" + teamId
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.example.wijaya_pc.footballapps.feature.main

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.example.wijaya_pc.footballapps.FavoriteMatchesFragment
import com.example.wijaya_pc.footballapps.feature.match.MatchFragment
import com.example.wijaya_pc.footballapps.R
import com.example.wijaya_pc.footballapps.R.id.*
import com.example.wijaya_pc.footballapps.feature.team.TeamsFragment
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

bottom_navigation.setOnNavigationItemSelectedListener { item ->
when (item.itemId) {
tab_matches -> {
loadMatchFragment()
}

tab_teams -> {
loadTeamsFragment()
}

favorites -> {
loadFavoritesFragment()
}
}
true
}
bottom_navigation.selectedItemId = tab_matches

}

private fun loadTeamsFragment() {
supportFragmentManager
.beginTransaction()
.replace(
R.id.main_container,
TeamsFragment(), TeamsFragment::class.java.simpleName)
.commit()
}

private fun loadFavoritesFragment() {
supportFragmentManager
.beginTransaction()
.replace(
R.id.main_container,
FavoriteMatchesFragment(), FavoriteMatchesFragment::class.java.simpleName)
.commit()
}

private fun loadMatchFragment() {
supportFragmentManager
.beginTransaction()
.replace(
R.id.main_container,
MatchFragment(), MatchFragment::class.java.simpleName)
.commit()
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.wijaya_pc.footballapps
package com.example.wijaya_pc.footballapps.feature.match

import android.os.Bundle
import android.support.v4.content.ContextCompat
Expand All @@ -15,12 +15,15 @@ import com.example.wijaya_pc.footballapps.R.id.*
import com.example.wijaya_pc.footballapps.R.menu.detail_menu
import com.example.wijaya_pc.footballapps.api.ApiRepository
import com.example.wijaya_pc.footballapps.database.database
import com.example.wijaya_pc.footballapps.dateToSimpleString
import com.example.wijaya_pc.footballapps.invisible
import com.example.wijaya_pc.footballapps.model.FavoriteMatches
import com.example.wijaya_pc.footballapps.model.Match
import com.example.wijaya_pc.footballapps.model.Team
import com.example.wijaya_pc.footballapps.presenter.DetailPresenter
import com.example.wijaya_pc.footballapps.presenter.DetailMatchPresenter
import com.example.wijaya_pc.footballapps.ui.DetailMatchUI
import com.example.wijaya_pc.footballapps.view.DetailView
import com.example.wijaya_pc.footballapps.view.DetailMatchView
import com.example.wijaya_pc.footballapps.visible
import com.google.gson.Gson
import com.squareup.picasso.Picasso
import org.jetbrains.anko.ctx
Expand All @@ -31,7 +34,7 @@ import org.jetbrains.anko.find
import org.jetbrains.anko.setContentView


class DetailActivity : AppCompatActivity(), DetailView {
class DetailMatchActivity : AppCompatActivity(), DetailMatchView {

companion object {
const val dataParcel = "data_parcel"
Expand All @@ -41,7 +44,7 @@ class DetailActivity : AppCompatActivity(), DetailView {
private lateinit var detailView: ScrollView
private lateinit var progressBar: ProgressBar

private lateinit var detailPresenter: DetailPresenter
private lateinit var detailPresenter: DetailMatchPresenter
private var menuItem: Menu? = null
private var isFavorite: Boolean = false

Expand Down Expand Up @@ -69,7 +72,7 @@ class DetailActivity : AppCompatActivity(), DetailView {

val request = ApiRepository()
val gson = Gson()
detailPresenter = DetailPresenter(this, request, gson)
detailPresenter = DetailMatchPresenter(this, request, gson)

detailPresenter.getMatchDetail(matchID)

Expand Down
Loading

0 comments on commit 569ca78

Please sign in to comment.