From 569ca7844d0d67f48790b91b3475bccff4191377 Mon Sep 17 00:00:00 2001 From: metzwijaya Date: Tue, 30 Oct 2018 20:46:53 +0700 Subject: [PATCH] - tablayout dalam fragment matches - memunculkan list match dalam tablayout tersebut - membuat team model hingga memunculkan list semua team ke dalam fragment teams --- .idea/misc.xml | 2 +- app/build.gradle | 2 +- .../footballapps/MainActivityTest.kt | 1 + app/src/main/AndroidManifest.xml | 7 +- .../footballapps/FavoriteMatchesFragment.kt | 3 +- .../wijaya_pc/footballapps/MainActivity.kt | 50 ------- .../footballapps/adapter/MatchPagerAdapter.kt | 17 +++ .../footballapps/adapter/TeamAdapter.kt | 40 ++++++ .../footballapps/api/TheSportDBApi.kt | 10 +- .../footballapps/feature/main/MainActivity.kt | 65 +++++++++ .../match/DetailMatchActivity.kt} | 15 ++- .../match/ListMatchFragment.kt} | 107 ++++++++------- .../feature/match/MatchFragment.kt | 35 +++++ .../feature/team/DetailTeamActivity.kt | 89 +++++++++++++ .../feature/team/TeamsFragment.kt | 126 ++++++++++++++++++ .../wijaya_pc/footballapps/model/Team.kt | 15 ++- ...ilPresenter.kt => DetailMatchPresenter.kt} | 6 +- .../presenter/DetailTeamPresenter.kt | 35 +++++ .../{MainPresenter.kt => MatchPresenter.kt} | 10 +- .../footballapps/presenter/TeamPresenter.kt | 36 +++++ .../footballapps/ui/DetailMatchUI.kt | 6 +- .../wijaya_pc/footballapps/ui/DetailTeamUI.kt | 88 ++++++++++++ .../wijaya_pc/footballapps/ui/TeamUI.kt | 31 +++++ .../{DetailView.kt => DetailMatchView.kt} | 2 +- .../footballapps/view/DetailTeamView.kt | 9 ++ .../view/{MainView.kt => MatchView.kt} | 2 +- .../wijaya_pc/footballapps/view/TeamView.kt | 9 ++ .../{ic_next_match.xml => ic_matches.xml} | 0 app/src/main/res/drawable/ic_workers.xml | 6 + app/src/main/res/layout/activity_main.xml | 2 +- .../main/res/layout/fragment_list_match.xml | 21 +++ app/src/main/res/layout/fragment_match.xml | 41 ++++++ .../main/res/menu/bottom_navigation_menu.xml | 18 +-- app/src/main/res/values/ids.xml | 9 ++ app/src/main/res/values/strings.xml | 15 +++ .../presenter/DetailPresenterTest.kt | 8 +- .../presenter/MainPresenterTest.kt | 8 +- 37 files changed, 799 insertions(+), 147 deletions(-) delete mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/MainActivity.kt create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/adapter/MatchPagerAdapter.kt create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/adapter/TeamAdapter.kt create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/feature/main/MainActivity.kt rename app/src/main/java/com/example/wijaya_pc/footballapps/{DetailActivity.kt => feature/match/DetailMatchActivity.kt} (93%) rename app/src/main/java/com/example/wijaya_pc/footballapps/{MatchFragment.kt => feature/match/ListMatchFragment.kt} (50%) create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/MatchFragment.kt create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/DetailTeamActivity.kt create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/TeamsFragment.kt rename app/src/main/java/com/example/wijaya_pc/footballapps/presenter/{DetailPresenter.kt => DetailMatchPresenter.kt} (96%) create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailTeamPresenter.kt rename app/src/main/java/com/example/wijaya_pc/footballapps/presenter/{MainPresenter.kt => MatchPresenter.kt} (89%) create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/presenter/TeamPresenter.kt create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailTeamUI.kt create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/ui/TeamUI.kt rename app/src/main/java/com/example/wijaya_pc/footballapps/view/{DetailView.kt => DetailMatchView.kt} (90%) create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailTeamView.kt rename app/src/main/java/com/example/wijaya_pc/footballapps/view/{MainView.kt => MatchView.kt} (92%) create mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/view/TeamView.kt rename app/src/main/res/drawable/{ic_next_match.xml => ic_matches.xml} (100%) create mode 100644 app/src/main/res/drawable/ic_workers.xml create mode 100644 app/src/main/res/layout/fragment_list_match.xml create mode 100644 app/src/main/res/layout/fragment_match.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 3386629..17426a4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -29,7 +29,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 38349af..f1b2206 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/androidTest/java/com/example/wijaya_pc/footballapps/MainActivityTest.kt b/app/src/androidTest/java/com/example/wijaya_pc/footballapps/MainActivityTest.kt index ddb92f0..298c651 100644 --- a/app/src/androidTest/java/com/example/wijaya_pc/footballapps/MainActivityTest.kt +++ b/app/src/androidTest/java/com/example/wijaya_pc/footballapps/MainActivityTest.kt @@ -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 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bcac2b8..c81235a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,7 +12,7 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> - + @@ -20,7 +20,10 @@ - + + + + diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/FavoriteMatchesFragment.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/FavoriteMatchesFragment.kt index 6012f7f..b507a79 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/FavoriteMatchesFragment.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/FavoriteMatchesFragment.kt @@ -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 @@ -33,7 +34,7 @@ class FavoriteMatchesFragment : Fragment(), AnkoComponent { super.onActivityCreated(savedInstanceState) adapter = FavoriteMatchesAdapter(favorites) { - ctx.startActivity( + ctx.startActivity( "id" to "${it.matchId}", "homeTeamId" to "${it.homeTeamId}", "awayTeamId" to "${it.awayTeamId}" diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/MainActivity.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/MainActivity.kt deleted file mode 100644 index 85ea61f..0000000 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/MainActivity.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.example.wijaya_pc.footballapps - -import android.os.Bundle -import android.support.v7.app.AppCompatActivity -import com.example.wijaya_pc.footballapps.R.id.* -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_last_match -> { - val matchFragment = MatchFragment.newInstance(0) - loadMatchFragment(matchFragment) - } - - tab_next_match -> { - val matchFragment = MatchFragment.newInstance(1) - loadMatchFragment(matchFragment) - } - - favorites -> { - loadFavoritesFragment() - } - } - true - } - bottom_navigation.selectedItemId = tab_last_match - - } - - private fun loadFavoritesFragment() { - supportFragmentManager - .beginTransaction() - .replace(R.id.main_container, FavoriteMatchesFragment(), FavoriteMatchesFragment::class.java.simpleName) - .commit() - } - - private fun loadMatchFragment(matchFragment: MatchFragment) { - supportFragmentManager - .beginTransaction() - .replace(R.id.main_container, matchFragment, MatchFragment::class.java.simpleName) - .commit() - } - -} diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/MatchPagerAdapter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/MatchPagerAdapter.kt new file mode 100644 index 0000000..dd0a366 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/MatchPagerAdapter.kt @@ -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 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/TeamAdapter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/TeamAdapter.kt new file mode 100644 index 0000000..3b744e3 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/TeamAdapter.kt @@ -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, private val listener: (Team) -> Unit) : RecyclerView.Adapter(){ + + 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) } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/api/TheSportDBApi.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/api/TheSportDBApi.kt index 71bf552..e038b5c 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/api/TheSportDBApi.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/api/TheSportDBApi.kt @@ -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 } } \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/main/MainActivity.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/main/MainActivity.kt new file mode 100644 index 0000000..7eba3b7 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/main/MainActivity.kt @@ -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() + } + +} diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/DetailActivity.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/DetailMatchActivity.kt similarity index 93% rename from app/src/main/java/com/example/wijaya_pc/footballapps/DetailActivity.kt rename to app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/DetailMatchActivity.kt index 19f312f..4eb04cf 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/DetailActivity.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/DetailMatchActivity.kt @@ -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 @@ -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 @@ -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" @@ -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 @@ -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) diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/MatchFragment.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/ListMatchFragment.kt similarity index 50% rename from app/src/main/java/com/example/wijaya_pc/footballapps/MatchFragment.kt rename to app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/ListMatchFragment.kt index 2e9df37..f9db14d 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/MatchFragment.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/ListMatchFragment.kt @@ -1,4 +1,4 @@ -package com.example.wijaya_pc.footballapps +package com.example.wijaya_pc.footballapps.feature.match import android.content.Context import android.os.Bundle @@ -6,44 +6,48 @@ import android.support.v4.app.Fragment import android.support.v4.widget.SwipeRefreshLayout 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.* -import com.example.wijaya_pc.footballapps.R.color.colorAccent +import com.example.wijaya_pc.footballapps.R +import com.example.wijaya_pc.footballapps.R.array.league import com.example.wijaya_pc.footballapps.adapter.MatchAdapter import com.example.wijaya_pc.footballapps.api.ApiRepository +import com.example.wijaya_pc.footballapps.invisible import com.example.wijaya_pc.footballapps.model.League import com.example.wijaya_pc.footballapps.model.Match -import com.example.wijaya_pc.footballapps.presenter.MainPresenter -import com.example.wijaya_pc.footballapps.view.MainView +import com.example.wijaya_pc.footballapps.presenter.MatchPresenter +import com.example.wijaya_pc.footballapps.view.MatchView +import com.example.wijaya_pc.footballapps.visible import com.google.gson.Gson import org.jetbrains.anko.* -import org.jetbrains.anko.design.tabItem -import org.jetbrains.anko.design.tabLayout import org.jetbrains.anko.recyclerview.v7.recyclerView import org.jetbrains.anko.support.v4.ctx import org.jetbrains.anko.support.v4.onRefresh import org.jetbrains.anko.support.v4.swipeRefreshLayout -class MatchFragment() : Fragment(), AnkoComponent, MainView { + +class ListMatchFragment : Fragment(), AnkoComponent, MatchView { + private lateinit var listMatch: RecyclerView private lateinit var swipeRefresh: SwipeRefreshLayout private lateinit var progressBar: ProgressBar private lateinit var spinner: Spinner - private var matches: MutableList = mutableListOf() - private var leagues: MutableList = mutableListOf() - private lateinit var presenter: MainPresenter private lateinit var matchAdapter: MatchAdapter + private lateinit var presenter: MatchPresenter + + private var matches: MutableList = mutableListOf() + + private var leagueName : String = "" + companion object { - private const val leagueID = "4328" private const val ARG_SECTION_NUMBER = "section_number" - fun newInstance(sectionNumber: Int): MatchFragment { - val fragment = MatchFragment() + fun newInstance(sectionNumber: Int): ListMatchFragment { + val fragment = ListMatchFragment() val args = Bundle() args.putInt(ARG_SECTION_NUMBER, sectionNumber) fragment.arguments = args @@ -54,13 +58,17 @@ class MatchFragment() : Fragment(), AnkoComponent, MainView { override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) - /*val spinnerItems = leagues + val request = ApiRepository() + val gson = Gson() + presenter = MatchPresenter(this, request, gson) + + val spinnerItems = resources.getStringArray(league) val spinnerAdapter = ArrayAdapter(ctx, android.R.layout.simple_spinner_dropdown_item, spinnerItems) - spinner.adapter = spinnerAdapter*/ + spinner.adapter = spinnerAdapter listMatch.layoutManager = LinearLayoutManager(ctx) matchAdapter = MatchAdapter(matches) { - ctx.startActivity( + ctx.startActivity( "id" to "${it.matchId}", "homeTeamId" to "${it.idHomeTeam}", "awayTeamId" to "${it.idAwayTeam}" @@ -68,31 +76,45 @@ class MatchFragment() : Fragment(), AnkoComponent, MainView { } listMatch.adapter = matchAdapter - val request = ApiRepository() - val gson = Gson() - presenter = MainPresenter(this, request, gson) - - presenter.getLeagueList() + spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) { + leagueName = spinner.selectedItem.toString() + if (arguments?.getInt(ARG_SECTION_NUMBER) == 0) { + when(leagueName) { + "English Premier League" -> { presenter.getLast15MatchesList("4328"); swipeRefresh.onRefresh { presenter.getLast15MatchesList("4328") } } + "English League Championship" -> { presenter.getLast15MatchesList("4329"); swipeRefresh.onRefresh { presenter.getLast15MatchesList("4329") } } + "Scottish Premier League" -> { presenter.getLast15MatchesList("4330"); swipeRefresh.onRefresh { presenter.getLast15MatchesList("4330") } } + "German Bundesliga" -> { presenter.getLast15MatchesList("4331"); swipeRefresh.onRefresh { presenter.getLast15MatchesList("4331") } } + "Italian Serie A" -> { presenter.getLast15MatchesList("4332"); swipeRefresh.onRefresh { presenter.getLast15MatchesList("4332") } } + "French Ligue 1" -> { presenter.getLast15MatchesList("4334"); swipeRefresh.onRefresh { presenter.getLast15MatchesList("4334") } } + "Spanish La Liga" -> { presenter.getLast15MatchesList("4335"); swipeRefresh.onRefresh { presenter.getLast15MatchesList("4335") } } - if (arguments?.getInt(ARG_SECTION_NUMBER) == 0) { - presenter.getLast15MatchesList(leagueID) + } + } + else + { + when(leagueName) { + "English Premier League" -> { presenter.getNext15MatchesList("4328"); swipeRefresh.onRefresh { presenter.getNext15MatchesList("4328") } } + "English League Championship" -> { presenter.getNext15MatchesList("4329"); swipeRefresh.onRefresh { presenter.getNext15MatchesList("4329") } } + "Scottish Premier League" -> { presenter.getNext15MatchesList("4330"); swipeRefresh.onRefresh { presenter.getNext15MatchesList("4330") } } + "German Bundesliga" -> { presenter.getNext15MatchesList("4331"); swipeRefresh.onRefresh { presenter.getNext15MatchesList("4331") } } + "Italian Serie A" -> { presenter.getNext15MatchesList("4332"); swipeRefresh.onRefresh { presenter.getNext15MatchesList("4332") } } + "French Ligue 1" -> { presenter.getNext15MatchesList("4334"); swipeRefresh.onRefresh { presenter.getNext15MatchesList("4334") } } + "Spanish La Liga" -> { presenter.getNext15MatchesList("4335"); swipeRefresh.onRefresh { presenter.getNext15MatchesList("4335") } } + } + } - swipeRefresh.onRefresh { - presenter.getLast15MatchesList(leagueID) } - } else { - presenter.getNext15MatchesList(leagueID) - swipeRefresh.onRefresh { - presenter.getNext15MatchesList(leagueID) - } + override fun onNothingSelected(parent: AdapterView<*>) {} } } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return createView(AnkoContext.create(ctx)) + } override fun createView(ui: AnkoContext): View = with(ui) { @@ -103,24 +125,11 @@ class MatchFragment() : Fragment(), AnkoComponent, MainView { leftPadding = dip(16) rightPadding = dip(16) - tabLayout { - id = R.id.tab_match - lparams(width = matchParent) - - tabItem { - - }.lparams(width = wrapContent, height = wrapContent) - - tabItem { - - }.lparams(width = wrapContent, height = wrapContent) - } - spinner = spinner() swipeRefresh = swipeRefreshLayout { setColorSchemeResources( - colorAccent, + R.color.colorAccent, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light @@ -160,9 +169,9 @@ class MatchFragment() : Fragment(), AnkoComponent, MainView { } override fun showLeagueList(data: List) { - leagues.clear() - leagues.addAll(data) + /*leagues.clear() + leagues.addAll(data)*/ + - // val leagueAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, leagues) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/MatchFragment.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/MatchFragment.kt new file mode 100644 index 0000000..8334591 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/MatchFragment.kt @@ -0,0 +1,35 @@ +package com.example.wijaya_pc.footballapps.feature.match + +import android.os.Bundle +import android.support.design.widget.TabLayout +import android.support.v4.app.Fragment +import android.support.v4.view.ViewPager +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.example.wijaya_pc.footballapps.R +import com.example.wijaya_pc.footballapps.adapter.MatchPagerAdapter +import org.jetbrains.anko.find + +class MatchFragment : Fragment() { + + private lateinit var viewPager : ViewPager + private lateinit var tabs : TabLayout + + private lateinit var mMatchPagerAdapter: MatchPagerAdapter + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + val rootView = inflater.inflate(R.layout.fragment_match, container, false) + + viewPager = rootView.find(R.id.viewPagerContainer) as ViewPager + tabs = rootView.find(R.id.tabs) as TabLayout + + mMatchPagerAdapter = MatchPagerAdapter(childFragmentManager) + viewPager.adapter = mMatchPagerAdapter + + viewPager.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabs)) + tabs.addOnTabSelectedListener(TabLayout.ViewPagerOnTabSelectedListener(viewPager)) + + return rootView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/DetailTeamActivity.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/DetailTeamActivity.kt new file mode 100644 index 0000000..6bda6a4 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/DetailTeamActivity.kt @@ -0,0 +1,89 @@ +package com.example.wijaya_pc.footballapps.feature.team + +import android.os.Bundle +import android.support.v4.widget.SwipeRefreshLayout +import android.support.v7.app.AppCompatActivity +import android.widget.ImageView +import android.widget.ProgressBar +import android.widget.TextView +import com.example.wijaya_pc.footballapps.R.id.* +import com.example.wijaya_pc.footballapps.api.ApiRepository +import com.example.wijaya_pc.footballapps.invisible +import com.example.wijaya_pc.footballapps.model.Team +import com.example.wijaya_pc.footballapps.presenter.DetailTeamPresenter +import com.example.wijaya_pc.footballapps.ui.DetailTeamUI +import com.example.wijaya_pc.footballapps.view.DetailTeamView +import com.example.wijaya_pc.footballapps.visible +import com.google.gson.Gson +import com.squareup.picasso.Picasso +import org.jetbrains.anko.find +import org.jetbrains.anko.setContentView +import org.jetbrains.anko.support.v4.onRefresh + +class DetailTeamActivity : AppCompatActivity(), DetailTeamView { + + private lateinit var swipeRefresh : SwipeRefreshLayout + private lateinit var progressBar : ProgressBar + + private lateinit var teamBadge: ImageView + private lateinit var teamName: TextView + private lateinit var teamFormedYear: TextView + private lateinit var teamStadium: TextView + private lateinit var teamDescription: TextView + + private lateinit var presenter: DetailTeamPresenter + private lateinit var teams: Team + private lateinit var id: String + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + DetailTeamUI().setContentView(this) + + swipeRefresh = find(swipeRefreshDetailTeam) + progressBar = find(progressBarDetailTeam) + teamBadge = find(team_badgeDetailTeam) + teamName = find(team_nameDetailTeam) + teamFormedYear = find(team_formedyearDetailTeam) + teamStadium = find(team_stadiumDetailTeam) + teamDescription = find(team_descDetailTeam) + + + val intent = intent + id = intent.getStringExtra("id") + + // nambah toolbar judul dan tombol back + supportActionBar?.title = "Team Detail" + supportActionBar?.setDisplayHomeAsUpEnabled(true) + + val request = ApiRepository() + val gson = Gson() + presenter = DetailTeamPresenter(this, request, gson) + presenter.getTeamDetail(id) + + swipeRefresh.onRefresh { + presenter.getTeamDetail(id) + } + + } + + override fun showLoading() { + progressBar.visible() + } + + override fun hideLoading() { + progressBar.invisible() + } + + override fun showTeamDetail(data: List) { + teams = Team(data[0].teamId, + data[0].teamName, + data[0].teamBadge) + + swipeRefresh.isRefreshing = false + Picasso.get().load(data[0].teamBadge).into(teamBadge) + teamName.text = data[0].teamName + teamDescription.text = data[0].teamDescription + teamFormedYear.text = data[0].teamFormedYear + teamStadium.text = data[0].teamStadium + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/TeamsFragment.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/TeamsFragment.kt new file mode 100644 index 0000000..a43063b --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/TeamsFragment.kt @@ -0,0 +1,126 @@ +package com.example.wijaya_pc.footballapps.feature.team + +import android.R +import android.content.Context +import android.os.Bundle +import android.support.v4.app.Fragment +import android.support.v4.widget.SwipeRefreshLayout +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 android.widget.* +import com.example.wijaya_pc.footballapps.R.array.league +import com.example.wijaya_pc.footballapps.R.color.colorAccent +import com.example.wijaya_pc.footballapps.adapter.TeamAdapter +import com.example.wijaya_pc.footballapps.api.ApiRepository +import com.example.wijaya_pc.footballapps.invisible +import com.example.wijaya_pc.footballapps.model.Team +import com.example.wijaya_pc.footballapps.presenter.TeamPresenter +import com.example.wijaya_pc.footballapps.view.TeamView +import com.example.wijaya_pc.footballapps.visible +import com.google.gson.Gson +import org.jetbrains.anko.* +import org.jetbrains.anko.recyclerview.v7.recyclerView +import org.jetbrains.anko.support.v4.ctx +import org.jetbrains.anko.support.v4.onRefresh +import org.jetbrains.anko.support.v4.swipeRefreshLayout + +class TeamsFragment : Fragment(), AnkoComponent, TeamView { + + private lateinit var listTeam : RecyclerView + private lateinit var progressBar : ProgressBar + private lateinit var swipeRefresh : SwipeRefreshLayout + private lateinit var spinner : Spinner + + private var teams: MutableList = mutableListOf() + private lateinit var teamPresenter: TeamPresenter + private lateinit var teamAdapter: TeamAdapter + + private lateinit var leagueName : String + + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) + + val request = ApiRepository() + val gson = Gson() + teamPresenter = TeamPresenter(this, request, gson) + + val spinnerItems = resources.getStringArray(league) + val spinnerAdapter = ArrayAdapter(ctx, R.layout.simple_spinner_dropdown_item, spinnerItems) + spinner.adapter = spinnerAdapter + + teamAdapter = TeamAdapter(teams) { + ctx.startActivity("id" to "${it.teamId}") + } + listTeam.adapter = teamAdapter + + spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) { + leagueName = spinner.selectedItem.toString() + teamPresenter.getTeamList(leagueName) + } + + override fun onNothingSelected(p0: AdapterView<*>?) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + } + + swipeRefresh.onRefresh { + teamPresenter.getTeamList(leagueName) + } + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return createView(AnkoContext.create(ctx)) + } + + override fun createView(ui: AnkoContext): View = with(ui) { + linearLayout { + lparams(width = matchParent, height = wrapContent) + orientation = LinearLayout.VERTICAL + topPadding = dip(16) + leftPadding = dip(16) + rightPadding = dip(16) + + spinner = spinner () + + swipeRefresh = swipeRefreshLayout { + setColorSchemeResources(colorAccent, + android.R.color.holo_green_light, + android.R.color.holo_orange_light, + android.R.color.holo_red_light) + + relativeLayout { + lparams(width = matchParent, height = wrapContent) + + listTeam = recyclerView { + lparams(width = matchParent, height = wrapContent) + layoutManager = LinearLayoutManager(ctx) + } + + progressBar = progressBar { + }.lparams{ + centerHorizontally() + } + } + } + } + } + + override fun showLoading() { + progressBar.visible() + } + + override fun hideLoading() { + progressBar.invisible() + } + + override fun showTeamList(data: List) { + swipeRefresh.isRefreshing = false + teams.clear() + teams.addAll(data) + teamAdapter.notifyDataSetChanged() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/model/Team.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/model/Team.kt index 748f94e..1d9c8cc 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/model/Team.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/model/Team.kt @@ -4,11 +4,20 @@ import com.google.gson.annotations.SerializedName data class Team( @SerializedName("idTeam") - var teamId: String? , + var teamId: String? = null, @SerializedName("strTeam") - var teamName: String? , + var teamName: String? = null, @SerializedName("strTeamBadge") - var teamBadge: String? + var teamBadge: String? = null, + + @SerializedName("intFormedYear") + var teamFormedYear: String? = null, + + @SerializedName("strStadium") + var teamStadium: String? = null, + + @SerializedName("strDescriptionEN") + var teamDescription: String? = null ) diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailPresenter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailMatchPresenter.kt similarity index 96% rename from app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailPresenter.kt rename to app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailMatchPresenter.kt index 80c3e4e..0569a4a 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailPresenter.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailMatchPresenter.kt @@ -10,7 +10,7 @@ import com.example.wijaya_pc.footballapps.database.database import com.example.wijaya_pc.footballapps.model.FavoriteMatches import com.example.wijaya_pc.footballapps.model.MatchResponse import com.example.wijaya_pc.footballapps.model.TeamResponse -import com.example.wijaya_pc.footballapps.view.DetailView +import com.example.wijaya_pc.footballapps.view.DetailMatchView import com.google.gson.Gson import kotlinx.coroutines.experimental.async import org.jetbrains.anko.coroutines.experimental.bg @@ -18,8 +18,8 @@ import org.jetbrains.anko.db.delete import org.jetbrains.anko.db.insert -class DetailPresenter( - private val view: DetailView, +class DetailMatchPresenter( + private val view: DetailMatchView, private val apiRepository: ApiRepository, private val gson: Gson, private val context: CoroutineContextProvider = CoroutineContextProvider() diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailTeamPresenter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailTeamPresenter.kt new file mode 100644 index 0000000..a354028 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailTeamPresenter.kt @@ -0,0 +1,35 @@ +package com.example.wijaya_pc.footballapps.presenter + +import com.example.wijaya_pc.footballapps.api.ApiRepository +import com.example.wijaya_pc.footballapps.api.TheSportDBApi +import com.example.wijaya_pc.footballapps.coroutine.CoroutineContextProvider +import com.example.wijaya_pc.footballapps.model.TeamResponse +import com.example.wijaya_pc.footballapps.view.DetailTeamView +import com.google.gson.Gson +import kotlinx.coroutines.experimental.android.UI +import kotlinx.coroutines.experimental.async +import org.jetbrains.anko.coroutines.experimental.bg + +class DetailTeamPresenter(private val view: DetailTeamView, + private val apiRepository: ApiRepository, + private val gson: Gson, + private val context: CoroutineContextProvider = CoroutineContextProvider() +) +{ + + fun getTeamDetail(teamId: String) { + view.showLoading() + + async(context.main) { + val data = bg { + gson.fromJson(apiRepository + .doRequest(TheSportDBApi.getTeamDetail(teamId)), + TeamResponse::class.java + ) + } + view.showTeamDetail(data.await().teams) + view.hideLoading() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/MainPresenter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/MatchPresenter.kt similarity index 89% rename from app/src/main/java/com/example/wijaya_pc/footballapps/presenter/MainPresenter.kt rename to app/src/main/java/com/example/wijaya_pc/footballapps/presenter/MatchPresenter.kt index 4753ab6..3867944 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/MainPresenter.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/MatchPresenter.kt @@ -1,20 +1,17 @@ package com.example.wijaya_pc.footballapps.presenter -import android.util.Log import com.example.wijaya_pc.footballapps.api.ApiRepository import com.example.wijaya_pc.footballapps.api.TheSportDBApi import com.example.wijaya_pc.footballapps.coroutine.CoroutineContextProvider import com.example.wijaya_pc.footballapps.model.LeagueResponse import com.example.wijaya_pc.footballapps.model.MatchResponse -import com.example.wijaya_pc.footballapps.view.MainView +import com.example.wijaya_pc.footballapps.view.MatchView import com.google.gson.Gson import kotlinx.coroutines.experimental.async import org.jetbrains.anko.coroutines.experimental.bg -import org.jetbrains.anko.doAsync -import org.jetbrains.anko.uiThread -class MainPresenter( - private val view: MainView, +class MatchPresenter( + private val view: MatchView, private val apiRepository: ApiRepository, private val gson: Gson, private val context: CoroutineContextProvider = CoroutineContextProvider() @@ -60,7 +57,6 @@ class MainPresenter( ) } view.showLeagueList(data.await().leagues) - Log.e("leagues", "$data") } } } \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/TeamPresenter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/TeamPresenter.kt new file mode 100644 index 0000000..527bbba --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/TeamPresenter.kt @@ -0,0 +1,36 @@ +package com.example.wijaya_pc.footballapps.presenter + +import android.util.Log +import com.example.wijaya_pc.footballapps.api.ApiRepository +import com.example.wijaya_pc.footballapps.api.TheSportDBApi +import com.example.wijaya_pc.footballapps.coroutine.CoroutineContextProvider +import com.example.wijaya_pc.footballapps.model.TeamResponse +import com.example.wijaya_pc.footballapps.view.TeamView +import com.google.gson.Gson +import kotlinx.coroutines.experimental.async +import org.jetbrains.anko.coroutines.experimental.bg +import org.jetbrains.anko.doAsync +import org.jetbrains.anko.uiThread + +class TeamPresenter(private val view: TeamView, + private val apiRepository: ApiRepository, + private val gson: Gson, + private val context: CoroutineContextProvider = CoroutineContextProvider() +) +{ + fun getTeamList(league: String?) { + view.showLoading() + + async(context.main) { + val data = bg { + gson.fromJson(apiRepository. + doRequest(TheSportDBApi.getAllTeams(league)), + TeamResponse::class.java + ) + } + view.showTeamList(data.await().teams) + view.hideLoading() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailMatchUI.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailMatchUI.kt index 5d19181..d34c540 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailMatchUI.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailMatchUI.kt @@ -5,13 +5,13 @@ import android.support.v4.content.ContextCompat import android.view.Gravity import android.view.View import android.widget.LinearLayout -import com.example.wijaya_pc.footballapps.DetailActivity +import com.example.wijaya_pc.footballapps.feature.match.DetailMatchActivity import com.example.wijaya_pc.footballapps.R import org.jetbrains.anko.* -class DetailMatchUI : AnkoComponent { +class DetailMatchUI : AnkoComponent { - override fun createView(ui: AnkoContext): View = with(ui) { + override fun createView(ui: AnkoContext): View = with(ui) { relativeLayout { lparams(width = matchParent) diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailTeamUI.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailTeamUI.kt new file mode 100644 index 0000000..efb57a1 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailTeamUI.kt @@ -0,0 +1,88 @@ +package com.example.wijaya_pc.footballapps.ui + +import android.graphics.Color +import android.support.v4.content.ContextCompat +import android.support.v4.widget.SwipeRefreshLayout +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.ProgressBar +import android.widget.TextView +import com.example.wijaya_pc.footballapps.R +import com.example.wijaya_pc.footballapps.R.color.colorAccent +import com.example.wijaya_pc.footballapps.R.color.colorPrimary +import com.example.wijaya_pc.footballapps.feature.team.DetailTeamActivity +import org.jetbrains.anko.* +import org.jetbrains.anko.support.v4.swipeRefreshLayout + +class DetailTeamUI : AnkoComponent { + override fun createView(ui: AnkoContext): View = with(ui) { + linearLayout { + lparams(width = matchParent, height = wrapContent) + orientation = LinearLayout.VERTICAL + backgroundColor = Color.WHITE + + swipeRefreshLayout { + id = R.id.swipeRefreshDetailTeam + + setColorSchemeResources(colorAccent, + android.R.color.holo_green_light, + android.R.color.holo_orange_light, + android.R.color.holo_red_light) + + scrollView { + isVerticalScrollBarEnabled = false + relativeLayout { + lparams(width = matchParent, height = wrapContent) + + linearLayout { + lparams(width = matchParent, height = wrapContent) + padding = dip(10) + orientation = LinearLayout.VERTICAL + gravity = Gravity.CENTER_HORIZONTAL + + //team badge + imageView{ + id = R.id.team_badgeDetailTeam + }.lparams(height = dip(75)) + + //team name + textView { + id = R.id.team_nameDetailTeam + this.gravity = Gravity.CENTER + textSize = 20f + textColor = ContextCompat.getColor(context, colorAccent) + }.lparams{ + topMargin = dip(5) + } + + //team formed year + textView{ + id = R.id.team_formedyearDetailTeam + this.gravity = Gravity.CENTER + } + + //team stadium + textView { + id = R.id.team_stadiumDetailTeam + this.gravity = Gravity.CENTER + textColor = ContextCompat.getColor(context, colorPrimary) + } + + //team descrption + textView{ + id = R.id.team_descDetailTeam + }.lparams{topMargin = dip(20)} + } + + progressBar { + id = R.id.progressBarDetailTeam + }.lparams{ centerHorizontally() } + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/TeamUI.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/TeamUI.kt new file mode 100644 index 0000000..bb08e70 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/TeamUI.kt @@ -0,0 +1,31 @@ +package com.example.wijaya_pc.footballapps.ui + +import android.view.View +import android.view.ViewGroup +import android.widget.LinearLayout +import com.example.wijaya_pc.footballapps.R +import org.jetbrains.anko.* + +class TeamUI : AnkoComponent { + override fun createView(ui: AnkoContext): View = with(ui){ + linearLayout { + lparams(matchParent, wrapContent) + padding = dip(16) + orientation = LinearLayout.HORIZONTAL + + imageView { + id = R.id.team_badge + }.lparams{ + height = dip(50) + width = dip(50) + } + + textView { + id = R.id.team_name + textSize = 16f + }.lparams{ + margin = dip(15) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailView.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailMatchView.kt similarity index 90% rename from app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailView.kt rename to app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailMatchView.kt index 87419aa..7f8f557 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailView.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailMatchView.kt @@ -3,7 +3,7 @@ package com.example.wijaya_pc.footballapps.view import com.example.wijaya_pc.footballapps.model.Match import com.example.wijaya_pc.footballapps.model.Team -interface DetailView { +interface DetailMatchView { fun showLoading() fun hideLoading() fun getMatch(data: Match) diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailTeamView.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailTeamView.kt new file mode 100644 index 0000000..3fcda62 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailTeamView.kt @@ -0,0 +1,9 @@ +package com.example.wijaya_pc.footballapps.view + +import com.example.wijaya_pc.footballapps.model.Team + +interface DetailTeamView { + fun showLoading() + fun hideLoading() + fun showTeamDetail(data: List) +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/view/MainView.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/view/MatchView.kt similarity index 92% rename from app/src/main/java/com/example/wijaya_pc/footballapps/view/MainView.kt rename to app/src/main/java/com/example/wijaya_pc/footballapps/view/MatchView.kt index 2e39b0b..a2de15f 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/view/MainView.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/view/MatchView.kt @@ -3,7 +3,7 @@ package com.example.wijaya_pc.footballapps.view import com.example.wijaya_pc.footballapps.model.League import com.example.wijaya_pc.footballapps.model.Match -interface MainView { +interface MatchView { fun showLoading() fun hideLoading() fun showMatchList(data: List) diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/view/TeamView.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/view/TeamView.kt new file mode 100644 index 0000000..beb9ef7 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/view/TeamView.kt @@ -0,0 +1,9 @@ +package com.example.wijaya_pc.footballapps.view + +import com.example.wijaya_pc.footballapps.model.Team + +interface TeamView { + fun showLoading() + fun hideLoading() + fun showTeamList(data: List) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_next_match.xml b/app/src/main/res/drawable/ic_matches.xml similarity index 100% rename from app/src/main/res/drawable/ic_next_match.xml rename to app/src/main/res/drawable/ic_matches.xml diff --git a/app/src/main/res/drawable/ic_workers.xml b/app/src/main/res/drawable/ic_workers.xml new file mode 100644 index 0000000..18ca27f --- /dev/null +++ b/app/src/main/res/drawable/ic_workers.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a3c92b5..860ab30 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,7 +6,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" - tools:context=".MainActivity"> + tools:context=".feature.main.MainActivity"> + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_match.xml b/app/src/main/res/layout/fragment_match.xml new file mode 100644 index 0000000..0d7adec --- /dev/null +++ b/app/src/main/res/layout/fragment_match.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/bottom_navigation_menu.xml b/app/src/main/res/menu/bottom_navigation_menu.xml index 429980b..d8537f5 100644 --- a/app/src/main/res/menu/bottom_navigation_menu.xml +++ b/app/src/main/res/menu/bottom_navigation_menu.xml @@ -2,18 +2,18 @@ - + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2da01aa..49a1841 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,5 +14,20 @@ Forward Substitutes Favorites + Teams + Matches + + + English Premier League + English League Championship + Scottish Premier League + German Bundesliga + Italian Serie A + French Ligue 1 + Spanish La Liga + + + + Hello blank fragment diff --git a/app/src/test/java/com/example/wijaya_pc/footballapps/presenter/DetailPresenterTest.kt b/app/src/test/java/com/example/wijaya_pc/footballapps/presenter/DetailPresenterTest.kt index e0dd619..1d5ca21 100644 --- a/app/src/test/java/com/example/wijaya_pc/footballapps/presenter/DetailPresenterTest.kt +++ b/app/src/test/java/com/example/wijaya_pc/footballapps/presenter/DetailPresenterTest.kt @@ -7,7 +7,7 @@ import com.example.wijaya_pc.footballapps.model.Match import com.example.wijaya_pc.footballapps.model.MatchResponse import com.example.wijaya_pc.footballapps.model.Team import com.example.wijaya_pc.footballapps.model.TeamResponse -import com.example.wijaya_pc.footballapps.view.DetailView +import com.example.wijaya_pc.footballapps.view.DetailMatchView import com.google.gson.Gson import org.junit.Before import org.junit.Test @@ -21,7 +21,7 @@ class DetailPresenterTest { @Mock private - lateinit var view: DetailView + lateinit var view: DetailMatchView @Mock private @@ -31,12 +31,12 @@ class DetailPresenterTest { private lateinit var gson: Gson - private lateinit var presenter: DetailPresenter + private lateinit var presenter: DetailMatchPresenter @Before fun setUp() { MockitoAnnotations.initMocks(this) - presenter = DetailPresenter(view, apiRepository, gson, TestContextProvider()) + presenter = DetailMatchPresenter(view, apiRepository, gson, TestContextProvider()) } @Test diff --git a/app/src/test/java/com/example/wijaya_pc/footballapps/presenter/MainPresenterTest.kt b/app/src/test/java/com/example/wijaya_pc/footballapps/presenter/MainPresenterTest.kt index 7e67341..2d2abf7 100644 --- a/app/src/test/java/com/example/wijaya_pc/footballapps/presenter/MainPresenterTest.kt +++ b/app/src/test/java/com/example/wijaya_pc/footballapps/presenter/MainPresenterTest.kt @@ -5,7 +5,7 @@ import com.example.wijaya_pc.footballapps.api.TheSportDBApi import com.example.wijaya_pc.footballapps.coroutine.TestContextProvider import com.example.wijaya_pc.footballapps.model.Match import com.example.wijaya_pc.footballapps.model.MatchResponse -import com.example.wijaya_pc.footballapps.view.MainView +import com.example.wijaya_pc.footballapps.view.MatchView import com.google.gson.Gson import org.junit.Before import org.junit.Test @@ -18,7 +18,7 @@ class MainPresenterTest { @Mock private - lateinit var view: MainView + lateinit var view: MatchView @Mock private @@ -29,12 +29,12 @@ class MainPresenterTest { lateinit var gson: Gson - private lateinit var presenter: MainPresenter + private lateinit var presenter: MatchPresenter @Before fun setUp() { MockitoAnnotations.initMocks(this) - presenter = MainPresenter(view, apiRepository, gson, TestContextProvider()) + presenter = MatchPresenter(view, apiRepository, gson, TestContextProvider()) } @Test