From 4a04aa70502bd7aa3df8edb7246204c7164fe73a Mon Sep 17 00:00:00 2001 From: metzwijaya Date: Sat, 3 Nov 2018 00:26:05 +0700 Subject: [PATCH] - unit testing - instrument testing --- app/build.gradle | 1 + .../footballapps/InstrumentationTest.kt | 462 ++++++++++++++++++ .../footballapps/MainActivityTest.kt | 198 -------- .../example/wijaya_pc/footballapps/Utils.kt | 22 +- .../adapter/FavoriteMatchesAdapter.kt | 5 +- .../adapter/FavoriteTeamsAdapter.kt | 7 +- .../footballapps/adapter/MatchAdapter.kt | 36 +- .../footballapps/adapter/PlayerAdapter.kt | 9 +- .../adapter/SearchMatchAdapter.kt | 2 - .../footballapps/adapter/TeamAdapter.kt | 7 +- .../footballapps/api/TheSportDBApi.kt | 2 +- .../feature/favorite/FavoriteFragment.kt | 6 +- .../feature/favorite/ListFavoriteFragment.kt | 20 +- .../feature/match/DetailMatchActivity.kt | 3 +- .../feature/match/ListMatchFragment.kt | 140 +++++- .../feature/match/MatchFragment.kt | 8 +- .../feature/match/SearchMatchActivity.kt | 11 +- .../feature/player/DetailPlayerActivity.kt | 14 +- .../feature/player/PlayersFragment.kt | 18 +- .../feature/team/DetailTeamActivity.kt | 24 +- .../feature/team/SearchTeamActivity.kt | 23 +- .../feature/team/TeamsFragment.kt | 38 +- .../footballapps/model/FavoriteTeams.kt | 10 +- .../wijaya_pc/footballapps/model/League.kt | 6 +- .../wijaya_pc/footballapps/model/Match.kt | 46 +- .../wijaya_pc/footballapps/model/Player.kt | 18 +- .../presenter/DetailPlayerPresenter.kt | 13 +- .../presenter/DetailTeamPresenter.kt | 37 +- .../footballapps/presenter/PlayerPresenter.kt | 12 +- .../presenter/SearchMatchPresenter.kt | 1 - .../footballapps/presenter/TeamPresenter.kt | 19 +- .../footballapps/ui/DetailMatchUI.kt | 2 +- .../footballapps/ui/DetailPlayerUI.kt | 2 - .../wijaya_pc/footballapps/ui/DetailTeamUI.kt | 20 +- .../wijaya_pc/footballapps/ui/MatchUI.kt | 1 - .../wijaya_pc/footballapps/ui/PlayerUI.kt | 4 +- .../wijaya_pc/footballapps/ui/SearchUI.kt | 6 +- .../wijaya_pc/footballapps/ui/TeamUI.kt | 6 +- app/src/main/res/drawable/ic_last_match.xml | 5 - app/src/main/res/layout/activity_main.xml | 3 +- app/src/main/res/layout/fragment_favorite.xml | 3 - .../main/res/layout/fragment_list_match.xml | 21 - app/src/main/res/layout/fragment_match.xml | 5 +- app/src/main/res/values/ids.xml | 26 +- app/src/main/res/values/strings.xml | 1 - app/src/main/res/values/styles.xml | 1 - .../wijaya_pc/footballapps/UtilsKtTest.kt | 37 +- ...terTest.kt => DetailMatchPresenterTest.kt} | 5 +- .../presenter/DetailPlayerPresenterTest.kt | 69 +++ .../presenter/DetailTeamPresenterTest.kt | 64 +++ ...PresenterTest.kt => MatchPresenterTest.kt} | 2 +- .../presenter/PlayerPresenterTest.kt | 60 +++ .../presenter/SearchMatchPresenterTest.kt | 59 +++ .../presenter/SearchTeamPresenterTest.kt | 58 +++ .../presenter/TeamPresenterTest.kt | 58 +++ 55 files changed, 1233 insertions(+), 503 deletions(-) create mode 100644 app/src/androidTest/java/com/example/wijaya_pc/footballapps/InstrumentationTest.kt delete mode 100644 app/src/androidTest/java/com/example/wijaya_pc/footballapps/MainActivityTest.kt delete mode 100644 app/src/main/java/com/example/wijaya_pc/footballapps/adapter/SearchMatchAdapter.kt delete mode 100644 app/src/main/res/drawable/ic_last_match.xml delete mode 100644 app/src/main/res/layout/fragment_list_match.xml rename app/src/test/java/com/example/wijaya_pc/footballapps/presenter/{DetailPresenterTest.kt => DetailMatchPresenterTest.kt} (97%) create mode 100644 app/src/test/java/com/example/wijaya_pc/footballapps/presenter/DetailPlayerPresenterTest.kt create mode 100644 app/src/test/java/com/example/wijaya_pc/footballapps/presenter/DetailTeamPresenterTest.kt rename app/src/test/java/com/example/wijaya_pc/footballapps/presenter/{MainPresenterTest.kt => MatchPresenterTest.kt} (98%) create mode 100644 app/src/test/java/com/example/wijaya_pc/footballapps/presenter/PlayerPresenterTest.kt create mode 100644 app/src/test/java/com/example/wijaya_pc/footballapps/presenter/SearchMatchPresenterTest.kt create mode 100644 app/src/test/java/com/example/wijaya_pc/footballapps/presenter/SearchTeamPresenterTest.kt create mode 100644 app/src/test/java/com/example/wijaya_pc/footballapps/presenter/TeamPresenterTest.kt diff --git a/app/build.gradle b/app/build.gradle index f1b2206..6e9e11c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,6 +44,7 @@ dependencies { implementation 'com.android.support:support-v4:28.0.0' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.22.0' + testImplementation 'org.robolectric:robolectric:3.0' androidTestImplementation 'com.android.support.test:rules:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' diff --git a/app/src/androidTest/java/com/example/wijaya_pc/footballapps/InstrumentationTest.kt b/app/src/androidTest/java/com/example/wijaya_pc/footballapps/InstrumentationTest.kt new file mode 100644 index 0000000..7c46fa0 --- /dev/null +++ b/app/src/androidTest/java/com/example/wijaya_pc/footballapps/InstrumentationTest.kt @@ -0,0 +1,462 @@ +package com.example.wijaya_pc.footballapps + +import android.support.test.espresso.Espresso.onView +import android.support.test.espresso.Espresso.pressBack +import android.support.test.espresso.UiController +import android.support.test.espresso.ViewAction +import android.support.test.espresso.action.ViewActions.click +import android.support.test.espresso.assertion.ViewAssertions.matches +import android.support.test.espresso.contrib.RecyclerViewActions +import android.support.test.espresso.matcher.ViewMatchers +import android.support.test.espresso.matcher.ViewMatchers.* +import android.support.test.rule.ActivityTestRule +import android.support.test.runner.AndroidJUnit4 +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.SearchView +import android.view.View +import android.widget.ImageButton +import com.example.wijaya_pc.footballapps.R.id.* +import com.example.wijaya_pc.footballapps.feature.main.MainActivity +import org.hamcrest.CoreMatchers.`is` +import org.hamcrest.CoreMatchers.allOf +import org.hamcrest.Matcher +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + + +@RunWith(AndroidJUnit4::class) +class MainActivityTest { + @Rule + @JvmField + var activityRule = ActivityTestRule(MainActivity::class.java) + + @Test + fun testRecyclerViewLastMatch() { + Thread.sleep(2000) + + onView(allOf(withTagValue(`is`("Last_Match" as Any)), withId(listMatch))).check(matches(isDisplayed())) + + onView( + allOf( + withTagValue(`is`("Last_Match" as Any)), + withId(listMatch) + ) + ).perform(RecyclerViewActions.scrollToPosition(14)) + Thread.sleep(2000) + onView( + allOf( + withTagValue(`is`("Last_Match" as Any)), + withId(listMatch) + ) + ).perform(RecyclerViewActions.scrollToPosition(1)) + Thread.sleep(2000) + onView( + allOf( + withTagValue(`is`("Last_Match" as Any)), + withId(listMatch) + ) + ).perform(RecyclerViewActions.actionOnItemAtPosition(1, click())) + } + + @Test + fun testRecyclerViewNextMatch() { + Thread.sleep(2000) + + onView(withId(tabs)).check(matches(isDisplayed())) + + onView(withContentDescription("Next Match")).check(matches(isDisplayed())) + onView(withContentDescription("Next Match")).perform(click()) + + onView(allOf(withTagValue(`is`("Next_Match" as Any)), withId(listMatch))).check(matches(isDisplayed())) + + onView( + allOf( + withTagValue(`is`("Next_Match" as Any)), + withId(listMatch) + ) + ).perform(RecyclerViewActions.scrollToPosition(3)) + Thread.sleep(2000) + onView( + allOf( + withTagValue(`is`("Next_Match" as Any)), + withId(listMatch) + ) + ).perform(RecyclerViewActions.scrollToPosition(7)) + Thread.sleep(2000) + onView( + allOf( + withTagValue(`is`("Next_Match" as Any)), + withId(listMatch) + ) + ).perform(RecyclerViewActions.actionOnItemAtPosition(7, click())) + } + + @Test + fun testRecyclerViewFavMatch() { + Thread.sleep(2000) + + onView(withId(R.id.bottom_navigation)).check(matches(isDisplayed())) + onView(withId(R.id.favorites)).perform(click()) + + onView(allOf(withTagValue(`is`("fav_match" as Any)), withId(listFav))).check(matches(isDisplayed())) + + onView( + allOf( + withTagValue(`is`("fav_match" as Any)), + withId(listFav) + ) + ).perform(RecyclerViewActions.scrollToPosition(14)) + Thread.sleep(2000) + onView( + allOf( + withTagValue(`is`("fav_match" as Any)), + withId(listFav) + ) + ).perform(RecyclerViewActions.scrollToPosition(1)) + Thread.sleep(2000) + onView( + allOf( + withTagValue(`is`("fav_match" as Any)), + withId(listFav) + ) + ).perform(RecyclerViewActions.actionOnItemAtPosition(1, click())) + } + + @Test + fun testRecyclerViewFavTeam() { + Thread.sleep(2000) + + onView(withId(R.id.bottom_navigation)).check(matches(isDisplayed())) + onView(withId(R.id.favorites)).perform(click()) + + onView(withId(tabsFavorite)).check(matches(isDisplayed())) + + onView(withContentDescription("Team")).check(matches(isDisplayed())) + onView(withContentDescription("Team")).perform(click()) + + onView(allOf(withTagValue(`is`("fav_team" as Any)), withId(listFav))).check(matches(isDisplayed())) + Thread.sleep(2000) + + onView( + allOf( + withTagValue(`is`("fav_team" as Any)), + withId(listFav) + ) + ).perform(RecyclerViewActions.scrollToPosition(5)) + Thread.sleep(2000) + onView( + allOf( + withTagValue(`is`("fav_team" as Any)), + withId(listFav) + ) + ).perform(RecyclerViewActions.scrollToPosition(0)) + Thread.sleep(2000) + onView( + allOf( + withTagValue(`is`("fav_team" as Any)), + withId(listFav) + ) + ).perform(RecyclerViewActions.actionOnItemAtPosition(0, click())) + } + + @Test + fun testRecyclerViewTeam() { + Thread.sleep(2000) + + onView(withId(R.id.bottom_navigation)).check(matches(isDisplayed())) + onView(withId(R.id.tab_teams)).perform(click()) + + Thread.sleep(2000) + + onView(withId(listTeam)).check(matches(isDisplayed())) + Thread.sleep(2000) + onView(withId(listTeam)).perform(RecyclerViewActions.scrollToPosition(7)) + Thread.sleep(2000) + onView(withId(listTeam)).perform(RecyclerViewActions.scrollToPosition(3)) + Thread.sleep(2000) + onView(withId(listTeam)).perform( + RecyclerViewActions.actionOnItemAtPosition( + 3, + click() + ) + ) + + pressBack() + + onView(ViewMatchers.withId(listTeam)).check(matches(isDisplayed())) + Thread.sleep(2000) + + onView(withId(spinner_teams)).check(matches(isDisplayed())) + onView(withId(spinner_teams)).perform(click()) + onView(withText("Spanish La Liga")).perform(click()) + + onView(withId(listTeam)).check(matches(isDisplayed())) + Thread.sleep(2000) + onView(withId(listTeam)).perform(RecyclerViewActions.scrollToPosition(10)) + Thread.sleep(2000) + onView(withId(listTeam)).perform(RecyclerViewActions.scrollToPosition(1)) + Thread.sleep(2000) + onView(withId(listTeam)).perform( + RecyclerViewActions.actionOnItemAtPosition( + 1, + click() + ) + ) + } + + @Test + fun testFavoriteTeam() { + Thread.sleep(2000) + + onView(withId(R.id.bottom_navigation)).check(matches(isDisplayed())) + onView(withId(R.id.tab_teams)).perform(click()) + + Thread.sleep(2000) + + onView(withId(listTeam)).check(matches(isDisplayed())) + Thread.sleep(2000) + onView(withId(listTeam)).perform( + RecyclerViewActions.actionOnItemAtPosition( + 3, + click() + ) + ) + Thread.sleep(2000) + + onView(withId(add_to_favorite)).check(matches(isDisplayed())) + onView(withId(add_to_favorite)).perform(click()) + onView(ViewMatchers.withText("Added to FavoriteTeams")).check(matches(isDisplayed())) + Thread.sleep(2000) + + onView(withId(add_to_favorite)).check(matches(isDisplayed())) + Thread.sleep(2000) + onView(withId(add_to_favorite)).perform(click()) + Thread.sleep(2000) + onView(ViewMatchers.withText("Removed from FavoriteTeams")).check(matches(isDisplayed())) + Thread.sleep(2000) + } + + @Test + fun testFavoriteLastMatch() { + Thread.sleep(2000) + + onView(allOf(withTagValue(`is`("Last_Match" as Any)), withId(listMatch))).check(matches(isDisplayed())) + + Thread.sleep(2000) + + onView( + allOf( + withTagValue(`is`("Last_Match" as Any)), + withId(listMatch) + ) + ).perform(RecyclerViewActions.actionOnItemAtPosition(5, click())) + + Thread.sleep(2000) + + onView(withId(add_to_favorite)).check(matches(isDisplayed())) + onView(withId(add_to_favorite)).perform(click()) + onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed())) + Thread.sleep(2000) + + onView(withId(add_to_favorite)).check(matches(isDisplayed())) + Thread.sleep(2000) + onView(withId(add_to_favorite)).perform(click()) + Thread.sleep(2000) + onView(ViewMatchers.withText("Removed from FavoriteMatches")).check(matches(isDisplayed())) + Thread.sleep(2000) + } + + @Test + fun testFavoriteNextMatch() { + Thread.sleep(2000) + + onView(withId(tabs)).check(matches(isDisplayed())) + + onView(withContentDescription("Next Match")).check(matches(isDisplayed())) + onView(withContentDescription("Next Match")).perform(click()) + + onView(allOf(withTagValue(`is`("Next_Match" as Any)), withId(listMatch))).check(matches(isDisplayed())) + + Thread.sleep(2000) + + onView( + allOf( + withTagValue(`is`("Next_Match" as Any)), + withId(listMatch) + ) + ).perform(RecyclerViewActions.actionOnItemAtPosition(5, click())) + + Thread.sleep(2000) + + onView(withId(add_to_favorite)).check(matches(isDisplayed())) + onView(withId(add_to_favorite)).perform(click()) + onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed())) + Thread.sleep(2000) + + onView(withId(add_to_favorite)).check(matches(isDisplayed())) + Thread.sleep(2000) + onView(withId(add_to_favorite)).perform(click()) + Thread.sleep(2000) + onView(ViewMatchers.withText("Removed from FavoriteMatches")).check(matches(isDisplayed())) + Thread.sleep(2000) + } + + @Test + fun testDetailViewTeam() { + Thread.sleep(2000) + + onView(withId(R.id.bottom_navigation)).check(matches(isDisplayed())) + onView(withId(R.id.tab_teams)).perform(click()) + + Thread.sleep(2000) + + onView(withId(listTeam)).check(matches(isDisplayed())) + Thread.sleep(2000) + onView(withId(listTeam)).perform( + RecyclerViewActions.actionOnItemAtPosition( + 0, + click() + ) + ) + + onView(withId(tabs_detail_team)).check(matches(isDisplayed())) + onView(withContentDescription("Overview")).check(matches(isDisplayed())) + Thread.sleep(2000) + + onView(withContentDescription("Players")).check(matches(isDisplayed())) + Thread.sleep(2000) + onView(withContentDescription("Players")).perform(click()) + + onView(withId(listPlayer)).check(matches(isDisplayed())) + Thread.sleep(2000) + onView(withId(listPlayer)).perform(RecyclerViewActions.scrollToPosition(10)) + Thread.sleep(2000) + onView(withId(listPlayer)).perform(RecyclerViewActions.scrollToPosition(0)) + Thread.sleep(2000) + onView(withId(listPlayer)).perform( + RecyclerViewActions.actionOnItemAtPosition( + 0, + click() + ) + ) + } + + @Test + fun testAddMatchToCalendar() { + Thread.sleep(2000) + + onView(withId(tabs)).check(matches(isDisplayed())) + + onView(withContentDescription("Next Match")).check(matches(isDisplayed())) + onView(withContentDescription("Next Match")).perform(click()) + + onView(allOf(withTagValue(`is`("Next_Match" as Any)), withId(listMatch))).check(matches(isDisplayed())) + + onView( + allOf( + withTagValue(`is`("Next_Match" as Any)), + withId(listMatch) + ) + ).perform( + RecyclerViewActions.actionOnItemAtPosition( + 0, + MyImageButtonAction.clickChildViewWithId(R.id.btn_to_calendar) + ) + ) + } + + @Test + fun testSearchTeam() { + Thread.sleep(1000) + + onView(withId(R.id.bottom_navigation)).check(matches(isDisplayed())) + onView(withId(R.id.tab_teams)).perform(click()) + + Thread.sleep(1000) + + onView(withId(button_search)).check(matches(isDisplayed())) + onView(withId(button_search)).perform(click()) + + onView(allOf(withId(action_search), withEffectiveVisibility(Visibility.VISIBLE))).check(matches(isDisplayed())) + onView(allOf(withId(R.id.action_search), withEffectiveVisibility(Visibility.VISIBLE))).perform( + typeSearchViewText("Chelsea") + ) + + Thread.sleep(1000) + + onView(withId(rv_search_team)).check(matches(isDisplayed())) + Thread.sleep(1000) + onView(withId(rv_search_team)).perform( + RecyclerViewActions.actionOnItemAtPosition( + 0, + click() + ) + ) + + } + + @Test + fun testSearchMatch() { + Thread.sleep(1000) + + onView(withId(button_search)).check(matches(isDisplayed())) + onView(withId(button_search)).perform(click()) + + onView(allOf(withId(action_search), withEffectiveVisibility(Visibility.VISIBLE))).check(matches(isDisplayed())) + onView(allOf(withId(R.id.action_search), withEffectiveVisibility(Visibility.VISIBLE))).perform( + typeSearchViewText("Chelsea") + ) + + Thread.sleep(1000) + + onView(withId(rv_search)).check(matches(isDisplayed())) + Thread.sleep(1000) + onView(withId(rv_search)).perform( + RecyclerViewActions.actionOnItemAtPosition( + 0, + click() + ) + ) + + } + +} + +object MyImageButtonAction { + + fun clickChildViewWithId(id: Int): ViewAction { + return object : ViewAction { + override fun getConstraints(): Matcher? { + return null + } + + override fun getDescription(): String { + return "Click on a child view with specified id." + } + + override fun perform(uiController: UiController, view: View) { + val v = view.findViewById(id) + v.performClick() + } + } + } + +} + +fun typeSearchViewText(text: String): ViewAction { + return object : ViewAction { + override fun getConstraints(): Matcher { + //Ensure that only apply if it is a SearchView and if it is visible. + return allOf(isDisplayed(), isAssignableFrom(SearchView::class.java)) + } + + override fun getDescription(): String { + return "Change view text" + } + + override fun perform(uiController: UiController, view: View) { + (view as SearchView).setQuery(text, false) + } + } +} \ No newline at end of file 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 deleted file mode 100644 index 298c651..0000000 --- a/app/src/androidTest/java/com/example/wijaya_pc/footballapps/MainActivityTest.kt +++ /dev/null @@ -1,198 +0,0 @@ -package com.example.wijaya_pc.footballapps - -import android.support.test.espresso.Espresso.onView -import android.support.test.espresso.Espresso.pressBack -import android.support.test.espresso.action.ViewActions.click -import android.support.test.espresso.assertion.ViewAssertions.matches -import android.support.test.espresso.contrib.RecyclerViewActions -import android.support.test.espresso.matcher.ViewMatchers -import android.support.test.espresso.matcher.ViewMatchers.isDisplayed -import android.support.test.espresso.matcher.ViewMatchers.withId -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 - -@RunWith(AndroidJUnit4::class) -class MainActivityTest { - @Rule - @JvmField var activityRule = ActivityTestRule(MainActivity::class.java) - - @Test - fun testRecyclerViewLastMatchBehaviour() { - Thread.sleep(1000) - - onView(withId(listMatch)).check(matches(isDisplayed())) - Thread.sleep(1000) - onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition(14)) - Thread.sleep(1000) - onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition(1)) - Thread.sleep(1000) - onView(withId(listMatch)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click())) - } - - @Test - fun testRecyclerViewNextMatchBehaviour() { - Thread.sleep(1000) - - onView(withId(bottom_navigation)).check(matches(isDisplayed())) - onView(withId(tab_next_match)).perform(click()) - Thread.sleep(1000) - - onView(withId(listMatch)).check(matches(isDisplayed())) - Thread.sleep(1000) - onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition(7)) - Thread.sleep(1000) - onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition(3)) - Thread.sleep(1000) - onView(withId(listMatch)).perform(RecyclerViewActions.actionOnItemAtPosition(3, click())) - } - - @Test - fun testRecyclerViewFavoritesBehaviour() { - Thread.sleep(1000) - - onView(withId(bottom_navigation)).check(matches(isDisplayed())) - onView(withId(favorites)).perform(click()) - Thread.sleep(1000) - - onView(withId(listFav)).check(matches(isDisplayed())) - Thread.sleep(1000) - onView(withId(listFav)).perform(RecyclerViewActions.scrollToPosition(14)) - Thread.sleep(1000) - onView(withId(listFav)).perform(RecyclerViewActions.scrollToPosition(0)) - Thread.sleep(1000) - onView(withId(listFav)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click())) - } - - - @Test - fun testAddFavoriteFromLastMatchBehaviour() { - Thread.sleep(1000) - - onView(withId(listMatch)).check(matches(isDisplayed())) - onView(ViewMatchers.withText("Crystal Palace")).perform(click()) - Thread.sleep(1000) - - onView(withId(add_to_favorite)).check(matches(isDisplayed())) - onView(withId(add_to_favorite)).perform(click()) - onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed())) - Thread.sleep(1000) - - onView(withId(add_to_favorite)).check(matches(isDisplayed())) - Thread.sleep(1000) - onView(withId(add_to_favorite)).perform(click()) - Thread.sleep(1000) - onView(ViewMatchers.withText("Removed from FavoriteMatches")).check(matches(isDisplayed())) - Thread.sleep(1000) - - onView(withId(add_to_favorite)).check(matches(isDisplayed())) - Thread.sleep(1000) - onView(withId(add_to_favorite)).perform(click()) - Thread.sleep(1000) - onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed())) - Thread.sleep(1000) - - pressBack() - - onView(withId(listMatch)).check(matches(isDisplayed())) - Thread.sleep(1000) - - onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition(5)) - Thread.sleep(1000) - onView(withId(listMatch)).perform(RecyclerViewActions.actionOnItemAtPosition(5, click())) - Thread.sleep(1000) - - onView(withId(add_to_favorite)).check(matches(isDisplayed())) - onView(withId(add_to_favorite)).perform(click()) - onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed())) - - pressBack() - - onView(withId(bottom_navigation)).check(matches(isDisplayed())) - onView(withId(favorites)).perform(click()) - Thread.sleep(1000) - } - - @Test - fun testAddFavoriteFromNextMatchBehaviour() { - Thread.sleep(1000) - - onView(withId(listMatch)).check(matches(isDisplayed())) - Thread.sleep(1000) - - onView(withId(bottom_navigation)).check(matches(isDisplayed())) - onView(withId(tab_next_match)).perform(click()) - Thread.sleep(1000) - - onView(withId(listMatch)).check(matches(isDisplayed())) - onView(ViewMatchers.withText("Liverpool")).perform(click()) - Thread.sleep(1000) - - onView(withId(add_to_favorite)).check(matches(isDisplayed())) - onView(withId(add_to_favorite)).perform(click()) - onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed())) - Thread.sleep(1000) - - onView(withId(add_to_favorite)).check(matches(isDisplayed())) - Thread.sleep(1000) - onView(withId(add_to_favorite)).perform(click()) - Thread.sleep(1000) - onView(ViewMatchers.withText("Removed from FavoriteMatches")).check(matches(isDisplayed())) - Thread.sleep(1000) - - onView(withId(add_to_favorite)).check(matches(isDisplayed())) - Thread.sleep(1000) - onView(withId(add_to_favorite)).perform(click()) - Thread.sleep(1000) - onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed())) - Thread.sleep(1000) - - pressBack() - - onView(withId(listMatch)).check(matches(isDisplayed())) - Thread.sleep(1000) - - onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition(8)) - Thread.sleep(1000) - onView(withId(listMatch)).perform(RecyclerViewActions.actionOnItemAtPosition(8, click())) - Thread.sleep(1000) - - onView(withId(add_to_favorite)).check(matches(isDisplayed())) - onView(withId(add_to_favorite)).perform(click()) - onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed())) - - pressBack() - - onView(withId(bottom_navigation)).check(matches(isDisplayed())) - onView(withId(favorites)).perform(click()) - Thread.sleep(1000) - } - - @Test - fun testDeleteFavoriteFromFavoritesFragmentBehaviour() { - Thread.sleep(1000) - - onView(withId(listMatch)).check(matches(isDisplayed())) - Thread.sleep(1000) - - onView(withId(bottom_navigation)).check(matches(isDisplayed())) - onView(withId(favorites)).perform(click()) - Thread.sleep(1000) - - onView(withId(listFav)).check(matches(isDisplayed())) - Thread.sleep(1000) - onView(withId(listFav)).perform(RecyclerViewActions.scrollToPosition(0)) - Thread.sleep(1000) - onView(withId(listFav)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click())) - - onView(withId(add_to_favorite)).check(matches(isDisplayed())) - onView(withId(add_to_favorite)).perform(click()) - onView(ViewMatchers.withText("Removed from FavoriteMatches")).check(matches(isDisplayed())) - Thread.sleep(1000) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/Utils.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/Utils.kt index 63d54bc..7827772 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/Utils.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/Utils.kt @@ -20,22 +20,14 @@ fun dateToSimpleString(date: Date?): String? = with(date ?: Date()) { SimpleDateFormat("EEE, dd MMM yyyy").format(this) } -@SuppressLint("SimpleDateFormat") -fun toGMTFormat(date: String?, time: String?): Date? { - val formatter = SimpleDateFormat("EEE, dd MMM yyyy HH:mm") - formatter.timeZone = TimeZone.getTimeZone("UTC") - val dateTime = "$date $time" - return formatter.parse(dateTime) -} - @SuppressLint("SimpleDateFormat") fun dateTimeToSimpleString(date: Date?): String? = with(date ?: Date()) { SimpleDateFormat("EEE, dd MMM yyyy HH:mm").format(this) } @SuppressLint("SimpleDateFormat") -fun toGMTFormatforCalendar(date: String?, time: String?): Date? { - val formatter = SimpleDateFormat("yyyy/MM/dd HH:mm") +fun toGMTFormat(date: String?, time: String?): Date? { + val formatter = SimpleDateFormat("EEE, dd MMM yyyy HH:mm") formatter.timeZone = TimeZone.getTimeZone("UTC") val dateTime = "$date $time" return formatter.parse(dateTime) @@ -49,4 +41,12 @@ fun dateToSimpleStringforCalendar(date: Date?): String? = with(date ?: Date()) { @SuppressLint("SimpleDateFormat") fun dateTimeToSimpleStringforCalendar(date: Date?): String? = with(date ?: Date()) { SimpleDateFormat("yyyy/MM/dd HH:mm").format(this) -} \ No newline at end of file +} + +@SuppressLint("SimpleDateFormat") +fun toGMTFormatforCalendar(date: String?, time: String?): Date? { + val formatter = SimpleDateFormat("yyyy/MM/dd HH:mm") + formatter.timeZone = TimeZone.getTimeZone("UTC") + val dateTime = "$date $time" + return formatter.parse(dateTime) +} diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/FavoriteMatchesAdapter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/FavoriteMatchesAdapter.kt index cec28fc..ca64194 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/FavoriteMatchesAdapter.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/FavoriteMatchesAdapter.kt @@ -14,7 +14,6 @@ import com.example.wijaya_pc.footballapps.ui.MatchUI import org.jetbrains.anko.AnkoContext import org.jetbrains.anko.find import org.jetbrains.anko.sdk25.coroutines.onClick -import org.w3c.dom.Text class FavoriteMatchesAdapter( private val favorite: MutableList, @@ -43,12 +42,12 @@ class FavoriteViewHolder(view: View) : RecyclerView.ViewHolder(view) { private val awayTeamScore: TextView = view.find(match_away_score) private val awayTeamName: TextView = view.find(match_away_team) - private val btnToCalendar : ImageButton = view.find(btn_to_calendar) + private val btnToCalendar: ImageButton = view.find(btn_to_calendar) fun bindItem(favorite: FavoriteMatches, listener: (FavoriteMatches) -> Unit) { - if(!(favorite.homeTeamScore.isNullOrBlank()) && !(favorite.awayTeamScore.isNullOrBlank())) { + if (!(favorite.homeTeamScore.isNullOrBlank()) && !(favorite.awayTeamScore.isNullOrBlank())) { btnToCalendar.invisible() } diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/FavoriteTeamsAdapter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/FavoriteTeamsAdapter.kt index eefa5c1..8363773 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/FavoriteTeamsAdapter.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/FavoriteTeamsAdapter.kt @@ -14,7 +14,10 @@ import org.jetbrains.anko.AnkoContext import org.jetbrains.anko.find import org.jetbrains.anko.sdk25.coroutines.onClick -class FavoriteTeamsAdapter(private val favoriteTeams: MutableList, private val listener: (FavoriteTeams) -> Unit) : RecyclerView.Adapter() { +class FavoriteTeamsAdapter( + private val favoriteTeams: MutableList, + private val listener: (FavoriteTeams) -> Unit +) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FavoriteTeamsViewHolder { return FavoriteTeamsViewHolder(TeamUI().createView(AnkoContext.create(parent.context, parent))) @@ -28,7 +31,7 @@ class FavoriteTeamsAdapter(private val favoriteTeams: MutableList } -class FavoriteTeamsViewHolder(view: View): RecyclerView.ViewHolder(view) { +class FavoriteTeamsViewHolder(view: View) : RecyclerView.ViewHolder(view) { private val teamBadge: ImageView = view.find(team_badge) private val teamName: TextView = view.find(team_name) diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/MatchAdapter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/MatchAdapter.kt index fb5ad6c..96cdd39 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/MatchAdapter.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/MatchAdapter.kt @@ -4,7 +4,6 @@ import android.content.Intent import android.os.Build import android.provider.CalendarContract import android.support.annotation.RequiresApi -import android.support.v4.content.ContextCompat.startActivity import android.support.v7.widget.RecyclerView import android.util.Log import android.view.View @@ -18,8 +17,6 @@ import com.example.wijaya_pc.footballapps.ui.MatchUI import org.jetbrains.anko.AnkoContext import org.jetbrains.anko.find import org.jetbrains.anko.sdk25.coroutines.onClick -import java.text.SimpleDateFormat -import java.time.format.DateTimeFormatter import java.util.* class MatchAdapter( @@ -48,7 +45,7 @@ class MatchViewHolder(view: View) : RecyclerView.ViewHolder(view) { private val matchAwayScore: TextView = view.find(match_away_score) private val matchAwayTeam: TextView = view.find(match_away_team) - private val btnToCalendar : ImageButton = view.find(btn_to_calendar) + private val btnToCalendar: ImageButton = view.find(btn_to_calendar) fun bindItem(matches: Match, listener: (Match) -> Unit) { val match_time = if (matches.matchTime == null) "00:00:00" else matches.matchTime @@ -64,25 +61,30 @@ class MatchViewHolder(view: View) : RecyclerView.ViewHolder(view) { matchAwayScore.text = matches.awayScore matchAwayTeam.text = matches.awayTeam - if(!(matches.homeScore.isNullOrBlank()) && !(matches.awayScore.isNullOrBlank())) { + if (!(matches.homeScore.isNullOrBlank()) && !(matches.awayScore.isNullOrBlank())) { btnToCalendar.invisible() } - + btnToCalendar.onClick { - val calendarDate = dateTimeToSimpleStringforCalendar(toGMTFormatforCalendar(dateToSimpleStringforCalendar(matches.matchDate), match_time)) - val year = calendarDate!!.substring(0,4).toInt() - val month = calendarDate!!.substring(5,7).toInt() - val day = calendarDate!!.substring(8,10).toInt() - val hour = calendarDate!!.substring(11,13).toInt() - val minute = calendarDate!!.substring(14,16).toInt() - - val startMatch : Long = Calendar.getInstance().run { - set(year, month-1, day, hour, minute) + val calendarDate = dateTimeToSimpleStringforCalendar( + toGMTFormatforCalendar( + dateToSimpleStringforCalendar(matches.matchDate), + match_time + ) + ) + val year = calendarDate!!.substring(0, 4).toInt() + val month = calendarDate!!.substring(5, 7).toInt() + val day = calendarDate!!.substring(8, 10).toInt() + val hour = calendarDate!!.substring(11, 13).toInt() + val minute = calendarDate!!.substring(14, 16).toInt() + + val startMatch: Long = Calendar.getInstance().run { + set(year, month - 1, day, hour, minute) timeInMillis } - val endMatch : Long = Calendar.getInstance().run { - set(year, month-1, day, hour+2, minute) + val endMatch: Long = Calendar.getInstance().run { + set(year, month - 1, day, hour + 2, minute) timeInMillis } diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/PlayerAdapter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/PlayerAdapter.kt index 0484656..e55cba4 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/PlayerAdapter.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/PlayerAdapter.kt @@ -14,7 +14,8 @@ import org.jetbrains.anko.AnkoContext import org.jetbrains.anko.find import org.jetbrains.anko.sdk15.coroutines.onClick -class PlayerAdapter(private val players: List, private val listener: (Player) -> Unit) : RecyclerView.Adapter() { +class PlayerAdapter(private val players: List, private val listener: (Player) -> Unit) : + RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, position: Int): PlayerViewHolder { return PlayerViewHolder(PlayerUI().createView(AnkoContext.create(parent.context, parent))) } @@ -29,9 +30,9 @@ class PlayerAdapter(private val players: List, private val listener: (Pl class PlayerViewHolder(view: View) : RecyclerView.ViewHolder(view) { - private val playerPhoto : ImageView = view.find(player_photo) - private val playerName : TextView = view.find(player_name) - private val playerPosition : TextView = view.find(player_position) + private val playerPhoto: ImageView = view.find(player_photo) + private val playerName: TextView = view.find(player_name) + private val playerPosition: TextView = view.find(player_position) fun bindItem(players: Player, listener: (Player) -> Unit) { Picasso.get().load(players.playerPhoto).placeholder(R.drawable.default_player).into(playerPhoto) diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/SearchMatchAdapter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/SearchMatchAdapter.kt deleted file mode 100644 index 6ec1ae1..0000000 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/SearchMatchAdapter.kt +++ /dev/null @@ -1,2 +0,0 @@ -package com.example.wijaya_pc.footballapps.adapter - 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 index 3b744e3..795fb4d 100644 --- 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 @@ -14,7 +14,8 @@ 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(){ +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))) @@ -29,8 +30,8 @@ class TeamAdapter(private val teams: List, private val listener: (Team) -> class TeamViewHolder(view: View) : RecyclerView.ViewHolder(view) { - private val teamBadge : ImageView = view.find(team_badge) - private val teamName : TextView = view.find(team_name) + 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) 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 3367546..eb351d7 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 @@ -24,7 +24,7 @@ object TheSportDBApi { return BuildConfig.BASE_URL + "api/v1/json/${BuildConfig.TSDB_API_KEY}" + "/all_leagues.php?s=Soccer" } - fun getAllTeams(leagueName: String?) : String { + fun getTeamList(leagueName: String?) : String { return BuildConfig.BASE_URL + "api/v1/json/${BuildConfig.TSDB_API_KEY}" + "/search_all_teams.php?l=" + leagueName } diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favorite/FavoriteFragment.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favorite/FavoriteFragment.kt index ea5d1d4..41fe347 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favorite/FavoriteFragment.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favorite/FavoriteFragment.kt @@ -13,13 +13,13 @@ import org.jetbrains.anko.find class FavoriteFragment : Fragment() { - private lateinit var viewPager : ViewPager - private lateinit var tabs : TabLayout + private lateinit var viewPager: ViewPager + private lateinit var tabs: TabLayout private lateinit var mFavoritePagerAdapter: FavoritePagerAdapter override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - val rootView = inflater.inflate(R.layout.fragment_favorite, container, false) + val rootView = inflater.inflate(R.layout.fragment_favorite, container, false) viewPager = rootView.find(R.id.viewPagerFavorite) as ViewPager tabs = rootView.find(R.id.tabsFavorite) as TabLayout diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favorite/ListFavoriteFragment.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favorite/ListFavoriteFragment.kt index 38c35f4..60974f0 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favorite/ListFavoriteFragment.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favorite/ListFavoriteFragment.kt @@ -23,7 +23,9 @@ import org.jetbrains.anko.* import org.jetbrains.anko.db.classParser import org.jetbrains.anko.db.select import org.jetbrains.anko.recyclerview.v7.recyclerView -import org.jetbrains.anko.support.v4.* +import org.jetbrains.anko.support.v4.ctx +import org.jetbrains.anko.support.v4.onRefresh +import org.jetbrains.anko.support.v4.swipeRefreshLayout class ListFavoriteFragment : Fragment(), AnkoComponent { @@ -66,11 +68,13 @@ class ListFavoriteFragment : Fragment(), AnkoComponent { favoritesMatches.clear() showFavoriteMatch() } - } - else - { + } else { favoriteTeamsAdapter = FavoriteTeamsAdapter(favoritesTeams) { - ctx.startActivity("id" to "${it.teamId}", "desc" to "${it.teamDescription}", "name" to "${it.teamName}") + ctx.startActivity( + "id" to "${it.teamId}", + "desc" to "${it.teamDescription}", + "name" to "${it.teamName}" + ) } listFav.adapter = favoriteTeamsAdapter @@ -104,6 +108,12 @@ class ListFavoriteFragment : Fragment(), AnkoComponent { listFav = recyclerView { id = R.id.listFav + if (arguments?.getInt(ListFavoriteFragment.ARG_SECTION_NUMBER) == 0) { + tag = "fav_match" + } + else { + tag = "fav_team" + } lparams(width = matchParent, height = wrapContent) layoutManager = LinearLayoutManager(ctx) } diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/DetailMatchActivity.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/DetailMatchActivity.kt index 96bd040..3777ea8 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/DetailMatchActivity.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/DetailMatchActivity.kt @@ -96,7 +96,8 @@ class DetailMatchActivity : AppCompatActivity(), DetailMatchView { detailPresenter.removeFromFavorite(ctx, matches.matchId) snackbar(detailView, "Removed from FavoriteMatches").show() } else { - val matchDateTime = dateTimeToSimpleString(toGMTFormat(dateToSimpleString(matches.matchDate), matches.matchTime)) + val matchDateTime = + dateTimeToSimpleString(toGMTFormat(dateToSimpleString(matches.matchDate), matches.matchTime)) detailPresenter.addToFavorite( ctx, matches.matchId, diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/ListMatchFragment.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/ListMatchFragment.kt index 09f1096..df163d2 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/ListMatchFragment.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/ListMatchFragment.kt @@ -1,9 +1,7 @@ package com.example.wijaya_pc.footballapps.feature.match import android.content.Context -import android.content.Intent import android.os.Bundle -import android.provider.CalendarContract import android.support.v4.app.Fragment import android.support.v4.widget.SwipeRefreshLayout import android.support.v7.widget.LinearLayoutManager @@ -25,8 +23,9 @@ 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.sdk25.coroutines.onClick -import org.jetbrains.anko.support.v4.* +import org.jetbrains.anko.support.v4.ctx +import org.jetbrains.anko.support.v4.onRefresh +import org.jetbrains.anko.support.v4.swipeRefreshLayout class ListMatchFragment : Fragment(), AnkoComponent, MatchView { @@ -42,7 +41,7 @@ class ListMatchFragment : Fragment(), AnkoComponent, MatchView { private var matches: MutableList = mutableListOf() - private var leagueName : String = "" + private var leagueName: String = "" companion object { private const val ARG_SECTION_NUMBER = "section_number" @@ -82,27 +81,109 @@ class ListMatchFragment : Fragment(), AnkoComponent, MatchView { 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") } } + 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" + ) + } + } } - } - 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") } } + } 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" + ) + } + } } } @@ -125,7 +206,9 @@ class ListMatchFragment : Fragment(), AnkoComponent, MatchView { leftPadding = dip(16) rightPadding = dip(16) - spinner = spinner() + spinner = spinner { + id = R.id.spinner_match + } swipeRefresh = swipeRefreshLayout { setColorSchemeResources( @@ -140,6 +223,13 @@ class ListMatchFragment : Fragment(), AnkoComponent, MatchView { listMatch = recyclerView { id = R.id.listMatch + if (arguments?.getInt(ARG_SECTION_NUMBER) == 0) { + tag = "Last_Match" + } + else + { + tag = "Next_Match" + } lparams(width = matchParent, height = wrapContent) layoutManager = LinearLayoutManager(ctx) } 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 index 18105e2..5d56eb4 100644 --- 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 @@ -14,15 +14,15 @@ import org.jetbrains.anko.support.v4.ctx class MatchFragment : Fragment() { - private lateinit var viewPager : ViewPager - private lateinit var tabs : TabLayout + private lateinit var viewPager: ViewPager + private lateinit var tabs: TabLayout private lateinit var mMatchPagerAdapter: MatchPagerAdapter private var menuItem: Menu? = null override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - val rootView = inflater.inflate(R.layout.fragment_match, container, false) + val rootView = inflater.inflate(R.layout.fragment_match, container, false) setHasOptionsMenu(true) @@ -47,7 +47,7 @@ class MatchFragment : Fragment() { } override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when(item.itemId) { + return when (item.itemId) { button_search -> { ctx.startActivity() true diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/SearchMatchActivity.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/SearchMatchActivity.kt index 30a4441..37128cc 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/SearchMatchActivity.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/SearchMatchActivity.kt @@ -1,8 +1,8 @@ package com.example.wijaya_pc.footballapps.feature.match -import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.support.v4.widget.SwipeRefreshLayout +import android.support.v7.app.AppCompatActivity import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.support.v7.widget.SearchView @@ -16,7 +16,6 @@ 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.Match -import com.example.wijaya_pc.footballapps.presenter.MatchPresenter import com.example.wijaya_pc.footballapps.presenter.SearchMatchPresenter import com.example.wijaya_pc.footballapps.view.SearchMatchView import com.example.wijaya_pc.footballapps.visible @@ -24,16 +23,14 @@ import com.google.gson.Gson import org.jetbrains.anko.ctx import org.jetbrains.anko.find import org.jetbrains.anko.startActivity -import org.jetbrains.anko.support.v4.onRefresh -import org.jetbrains.anko.toast class SearchMatchActivity : AppCompatActivity(), SearchMatchView { private lateinit var toolbar: Toolbar private lateinit var recyclerView: RecyclerView - private lateinit var searchView : SearchView - private lateinit var progressBar : ProgressBar - private lateinit var swipeRefresh : SwipeRefreshLayout + private lateinit var searchView: SearchView + private lateinit var progressBar: ProgressBar + private lateinit var swipeRefresh: SwipeRefreshLayout private var matches: MutableList = mutableListOf() diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/player/DetailPlayerActivity.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/player/DetailPlayerActivity.kt index 320ba90..4f55a47 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/player/DetailPlayerActivity.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/player/DetailPlayerActivity.kt @@ -1,10 +1,7 @@ package com.example.wijaya_pc.footballapps.feature.player -import android.media.Image import android.os.Bundle -import android.os.PersistableBundle import android.support.v7.app.AppCompatActivity -import android.view.Menu import android.view.MenuItem import android.widget.ImageView import android.widget.ProgressBar @@ -23,7 +20,6 @@ import com.google.gson.Gson import com.squareup.picasso.Picasso import org.jetbrains.anko.find import org.jetbrains.anko.setContentView -import org.jetbrains.anko.toast class DetailPlayerActivity : AppCompatActivity(), DetailPlayerView { @@ -77,19 +73,19 @@ class DetailPlayerActivity : AppCompatActivity(), DetailPlayerView { } override fun showPlayerDetail(data: Player) { - val playerThumb : ImageView = find(player_detail_photo) + val playerThumb: ImageView = find(player_detail_photo) Picasso.get().load(data.playerThumb).placeholder(R.drawable.default_player).into(playerThumb) - val playerWeight : TextView = find(player_detail_weight) + val playerWeight: TextView = find(player_detail_weight) playerWeight.text = data.playerWeight - val playerHeight : TextView = find(player_detail_height) + val playerHeight: TextView = find(player_detail_height) playerHeight.text = data.playerHeight - val playerPosition : TextView = find(player_detail_position) + val playerPosition: TextView = find(player_detail_position) playerPosition.text = data.playerPosition - val playerDesc : TextView = find(player_detail_description) + val playerDesc: TextView = find(player_detail_description) playerDesc.text = data.playerDescription } diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/player/PlayersFragment.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/player/PlayersFragment.kt index 657bf09..c2a0aa4 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/player/PlayersFragment.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/player/PlayersFragment.kt @@ -14,7 +14,6 @@ import android.widget.ProgressBar import com.example.wijaya_pc.footballapps.R import com.example.wijaya_pc.footballapps.adapter.PlayerAdapter import com.example.wijaya_pc.footballapps.api.ApiRepository -import com.example.wijaya_pc.footballapps.feature.team.OverviewTeamFragment import com.example.wijaya_pc.footballapps.invisible import com.example.wijaya_pc.footballapps.model.Player import com.example.wijaya_pc.footballapps.presenter.PlayerPresenter @@ -26,7 +25,6 @@ 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 -import org.jetbrains.anko.support.v4.toast class PlayersFragment : Fragment(), AnkoComponent, PlayerView { @@ -42,15 +40,15 @@ class PlayersFragment : Fragment(), AnkoComponent, PlayerView { } } - private lateinit var listPlayer : RecyclerView - private lateinit var progressBar : ProgressBar - private lateinit var swipeRefresh : SwipeRefreshLayout + private lateinit var listPlayer: RecyclerView + private lateinit var progressBar: ProgressBar + private lateinit var swipeRefresh: SwipeRefreshLayout - private var players: MutableList = mutableListOf() + private var players: MutableList = mutableListOf() private lateinit var playerPresenter: PlayerPresenter private lateinit var playerAdapter: PlayerAdapter - private lateinit var teamName : String + private lateinit var teamName: String override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) @@ -90,18 +88,20 @@ class PlayersFragment : Fragment(), AnkoComponent, PlayerView { R.color.colorAccent, android.R.color.holo_green_light, android.R.color.holo_orange_light, - android.R.color.holo_red_light) + android.R.color.holo_red_light + ) relativeLayout { lparams(width = matchParent, height = wrapContent) listPlayer = recyclerView { + id = R.id.listPlayer lparams(width = matchParent, height = wrapContent) layoutManager = LinearLayoutManager(ctx) } progressBar = progressBar { - }.lparams{ + }.lparams { centerHorizontally() } } 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 index 1a2c984..3e49b73 100644 --- 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 @@ -38,7 +38,7 @@ import org.jetbrains.anko.setContentView class DetailTeamActivity : AppCompatActivity(), DetailTeamView { - private lateinit var progressBar : ProgressBar + private lateinit var progressBar: ProgressBar private lateinit var linearLayout: LinearLayout private var menuItem: Menu? = null private var isFavorite: Boolean = false @@ -116,7 +116,7 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView { // apa yg dilakukan ketika menu diklik override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when(item.itemId) { + return when (item.itemId) { R.id.home -> { finish() true @@ -126,9 +126,9 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView { if (isFavorite) { presenter.removeFromFavoriteTeam(ctx, teams.teamId) snackbar(linearLayout, "Removed from FavoriteTeams").show() - } - else { - presenter.addToFavoriteTeam(ctx, + } else { + presenter.addToFavoriteTeam( + ctx, teams.teamId, teams.teamName, teams.teamBadge, @@ -157,12 +157,14 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView { } override fun showTeamDetail(data: List) { - teams = Team(data[0].teamId, + teams = Team( + data[0].teamId, data[0].teamName, data[0].teamBadge, data[0].teamFormedYear, data[0].teamStadium, - data[0].teamDescription) + data[0].teamDescription + ) Picasso.get().load(data[0].teamBadge).into(teamBadge) teamName.text = data[0].teamName @@ -181,11 +183,13 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView { } - private fun favoriteState(){ + private fun favoriteState() { databaseTeam.use { val result = select(FavoriteTeams.TABLE_FAVORITE_TEAMS) - .whereArgs("(TEAM_ID = {id})", - "id" to id) + .whereArgs( + "(TEAM_ID = {id})", + "id" to id + ) val favorite = result.parseList(classParser()) if (!favorite.isEmpty()) isFavorite = true } diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/SearchTeamActivity.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/SearchTeamActivity.kt index fb21923..a10c607 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/SearchTeamActivity.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/SearchTeamActivity.kt @@ -9,43 +9,34 @@ import android.support.v7.widget.SearchView import android.support.v7.widget.Toolbar import android.view.Menu import android.view.MenuItem -import android.view.View -import android.widget.AdapterView -import android.widget.ArrayAdapter import android.widget.ProgressBar -import android.widget.Spinner import com.example.wijaya_pc.footballapps.R import com.example.wijaya_pc.footballapps.R.layout.activity_search_team 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.SearchMatchPresenter import com.example.wijaya_pc.footballapps.presenter.SearchTeamPresenter -import com.example.wijaya_pc.footballapps.presenter.TeamPresenter import com.example.wijaya_pc.footballapps.view.SearchTeamView -import com.example.wijaya_pc.footballapps.view.TeamView import com.example.wijaya_pc.footballapps.visible import com.google.gson.Gson import org.jetbrains.anko.ctx import org.jetbrains.anko.find import org.jetbrains.anko.startActivity -import org.jetbrains.anko.support.v4.ctx -import org.jetbrains.anko.support.v4.onRefresh class SearchTeamActivity : AppCompatActivity(), SearchTeamView { private lateinit var toolbar: Toolbar private lateinit var recyclerView: RecyclerView - private lateinit var progressBar : ProgressBar - private lateinit var swipeRefresh : SwipeRefreshLayout + private lateinit var progressBar: ProgressBar + private lateinit var swipeRefresh: SwipeRefreshLayout - private var teams: MutableList = mutableListOf() + private var teams: MutableList = mutableListOf() private lateinit var teamPresenter: SearchTeamPresenter private lateinit var teamAdapter: TeamAdapter - private lateinit var searchView : SearchView + private lateinit var searchView: SearchView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -66,7 +57,11 @@ class SearchTeamActivity : AppCompatActivity(), SearchTeamView { recyclerView.layoutManager = LinearLayoutManager(ctx) teamAdapter = TeamAdapter(teams) { - ctx.startActivity("id" to "${it.teamId}", "desc" to "${it.teamDescription}", "name" to "${it.teamName}") + ctx.startActivity( + "id" to "${it.teamId}", + "desc" to "${it.teamDescription}", + "name" to "${it.teamName}" + ) } recyclerView.adapter = teamAdapter } 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 index 29b68cd..52b7efd 100644 --- 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 @@ -1,6 +1,5 @@ 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 @@ -9,12 +8,12 @@ import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.view.* import android.widget.* +import com.example.wijaya_pc.footballapps.R import com.example.wijaya_pc.footballapps.R.array.league import com.example.wijaya_pc.footballapps.R.color.colorAccent import com.example.wijaya_pc.footballapps.R.id.button_search import com.example.wijaya_pc.footballapps.adapter.TeamAdapter import com.example.wijaya_pc.footballapps.api.ApiRepository -import com.example.wijaya_pc.footballapps.feature.match.SearchMatchActivity import com.example.wijaya_pc.footballapps.invisible import com.example.wijaya_pc.footballapps.model.Team import com.example.wijaya_pc.footballapps.presenter.TeamPresenter @@ -29,16 +28,16 @@ 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 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 var teams: MutableList = mutableListOf() private lateinit var teamPresenter: TeamPresenter private lateinit var teamAdapter: TeamAdapter - private lateinit var leagueName : String + private lateinit var leagueName: String private var menuItem: Menu? = null @@ -50,11 +49,15 @@ class TeamsFragment : Fragment(), AnkoComponent, TeamView { teamPresenter = TeamPresenter(this, request, gson) val spinnerItems = resources.getStringArray(league) - val spinnerAdapter = ArrayAdapter(ctx, R.layout.simple_spinner_dropdown_item, spinnerItems) + val spinnerAdapter = ArrayAdapter(ctx, android.R.layout.simple_spinner_dropdown_item, spinnerItems) spinner.adapter = spinnerAdapter teamAdapter = TeamAdapter(teams) { - ctx.startActivity("id" to "${it.teamId}", "desc" to "${it.teamDescription}", "name" to "${it.teamName}") + ctx.startActivity( + "id" to "${it.teamId}", + "desc" to "${it.teamDescription}", + "name" to "${it.teamName}" + ) } listTeam.adapter = teamAdapter @@ -88,24 +91,29 @@ class TeamsFragment : Fragment(), AnkoComponent, TeamView { leftPadding = dip(16) rightPadding = dip(16) - spinner = spinner () + spinner = spinner { + id = R.id.spinner_teams + } swipeRefresh = swipeRefreshLayout { - setColorSchemeResources(colorAccent, + setColorSchemeResources( + colorAccent, android.R.color.holo_green_light, android.R.color.holo_orange_light, - android.R.color.holo_red_light) + android.R.color.holo_red_light + ) relativeLayout { lparams(width = matchParent, height = wrapContent) listTeam = recyclerView { + id = R.id.listTeam lparams(width = matchParent, height = wrapContent) layoutManager = LinearLayoutManager(ctx) } progressBar = progressBar { - }.lparams{ + }.lparams { centerHorizontally() } } @@ -121,7 +129,7 @@ class TeamsFragment : Fragment(), AnkoComponent, TeamView { } override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when(item.itemId) { + return when (item.itemId) { button_search -> { ctx.startActivity() true diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/model/FavoriteTeams.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/model/FavoriteTeams.kt index a7f2502..76f41e8 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/model/FavoriteTeams.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/model/FavoriteTeams.kt @@ -1,6 +1,14 @@ package com.example.wijaya_pc.footballapps.model -data class FavoriteTeams(val id: Long?, val teamId: String?, val teamName: String?, val teamBadge: String?, val teamFormedYear: String?, val teamStadium: String?, val teamDescription: String?) { +data class FavoriteTeams( + val id: Long?, + val teamId: String?, + val teamName: String?, + val teamBadge: String?, + val teamFormedYear: String?, + val teamStadium: String?, + val teamDescription: String? +) { companion object { const val TABLE_FAVORITE_TEAMS: String = "TABLE_FAVORITE_TEAMS" diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/model/League.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/model/League.kt index a14904b..6fa7598 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/model/League.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/model/League.kt @@ -2,10 +2,10 @@ package com.example.wijaya_pc.footballapps.model import com.google.gson.annotations.SerializedName -data class League ( +data class League( @SerializedName("idLeague") - var leagueId : String?, + var leagueId: String?, @SerializedName("strLeague") - var leagueName : String? + var leagueName: String? ) \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/model/Match.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/model/Match.kt index d4fc32f..c0569f6 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/model/Match.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/model/Match.kt @@ -7,29 +7,29 @@ import java.util.* @Parcelize data class Match( - @SerializedName("idEvent") var matchId: String? , - @SerializedName("dateEvent") var matchDate: Date? , + @SerializedName("idEvent") var matchId: String?, + @SerializedName("dateEvent") var matchDate: Date?, @SerializedName("strTime") var matchTime: String?, - @SerializedName("idHomeTeam") var idHomeTeam: String? , - @SerializedName("idAwayTeam") var idAwayTeam: String? , - @SerializedName("strHomeTeam") var homeTeam: String? , - @SerializedName("strAwayTeam") var awayTeam: String? , - @SerializedName("intHomeScore") var homeScore: String? , - @SerializedName("intAwayScore") var awayScore: String? , - @SerializedName("strHomeFormation") var homeFormation: String? , - @SerializedName("strAwayFormation") var awayFormation: String? , - @SerializedName("strHomeGoalDetails") var homeGoals: String? , - @SerializedName("strAwayGoalDetails") var awayGoals: String? , - @SerializedName("intHomeShots") var homeShots: String? , - @SerializedName("intAwayShots") var awayShots: String? , - @SerializedName("strHomeLineupGoalkeeper") var homeGoalKeeper: String? , - @SerializedName("strAwayLineupGoalkeeper") var awayGoalKeeper: String? , - @SerializedName("strHomeLineupDefense") var homeDefence: String? , - @SerializedName("strAwayLineupDefense") var awayDefence: String? , - @SerializedName("strHomeLineupMidfield") var homeMidfield: String? , - @SerializedName("strAwayLineupMidfield") var awayMidfield: String? , - @SerializedName("strHomeLineupForward") var homeForward: String? , - @SerializedName("strAwayLineupForward") var awayForward: String? , - @SerializedName("strHomeLineupSubstitutes") var homeSubstitutes: String? , + @SerializedName("idHomeTeam") var idHomeTeam: String?, + @SerializedName("idAwayTeam") var idAwayTeam: String?, + @SerializedName("strHomeTeam") var homeTeam: String?, + @SerializedName("strAwayTeam") var awayTeam: String?, + @SerializedName("intHomeScore") var homeScore: String?, + @SerializedName("intAwayScore") var awayScore: String?, + @SerializedName("strHomeFormation") var homeFormation: String?, + @SerializedName("strAwayFormation") var awayFormation: String?, + @SerializedName("strHomeGoalDetails") var homeGoals: String?, + @SerializedName("strAwayGoalDetails") var awayGoals: String?, + @SerializedName("intHomeShots") var homeShots: String?, + @SerializedName("intAwayShots") var awayShots: String?, + @SerializedName("strHomeLineupGoalkeeper") var homeGoalKeeper: String?, + @SerializedName("strAwayLineupGoalkeeper") var awayGoalKeeper: String?, + @SerializedName("strHomeLineupDefense") var homeDefence: String?, + @SerializedName("strAwayLineupDefense") var awayDefence: String?, + @SerializedName("strHomeLineupMidfield") var homeMidfield: String?, + @SerializedName("strAwayLineupMidfield") var awayMidfield: String?, + @SerializedName("strHomeLineupForward") var homeForward: String?, + @SerializedName("strAwayLineupForward") var awayForward: String?, + @SerializedName("strHomeLineupSubstitutes") var homeSubstitutes: String?, @SerializedName("strAwayLineupSubstitutes") var awaySubtitutes: String? ) : Parcelable diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/model/Player.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/model/Player.kt index d5d999b..e49f257 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/model/Player.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/model/Player.kt @@ -2,28 +2,28 @@ package com.example.wijaya_pc.footballapps.model import com.google.gson.annotations.SerializedName -data class Player ( +data class Player( @SerializedName("idPlayer") - var playerId : String?, + var playerId: String?, @SerializedName("strCutout") - var playerPhoto : String?, + var playerPhoto: String?, @SerializedName("strPlayer") - var playerName : String?, + var playerName: String?, @SerializedName("strPosition") - var playerPosition : String?, + var playerPosition: String?, @SerializedName("strFanart1") - var playerThumb : String?, + var playerThumb: String?, @SerializedName("strWeight") - var playerWeight : String?, + var playerWeight: String?, @SerializedName("strHeight") - var playerHeight : String?, + var playerHeight: String?, @SerializedName("strDescriptionEN") - var playerDescription : String? + var playerDescription: String? ) \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailPlayerPresenter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailPlayerPresenter.kt index 4e18623..a515df0 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailPlayerPresenter.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailPlayerPresenter.kt @@ -4,23 +4,24 @@ 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.PlayerDetailResponse -import com.example.wijaya_pc.footballapps.model.PlayerResponse import com.example.wijaya_pc.footballapps.view.DetailPlayerView import com.google.gson.Gson import kotlinx.coroutines.experimental.async import org.jetbrains.anko.coroutines.experimental.bg -class DetailPlayerPresenter(private val view: DetailPlayerView, - private val apiRepository: ApiRepository, - private val gson: Gson, - private val context: CoroutineContextProvider = CoroutineContextProvider() +class DetailPlayerPresenter( + private val view: DetailPlayerView, + private val apiRepository: ApiRepository, + private val gson: Gson, + private val context: CoroutineContextProvider = CoroutineContextProvider() ) { fun getPlayerDetails(playerId: String?) { view.showLoading() async(context.main) { val data = bg { - gson.fromJson(apiRepository.doRequest(TheSportDBApi.getPlayerDetails(playerId)), + gson.fromJson( + apiRepository.doRequest(TheSportDBApi.getPlayerDetails(playerId)), PlayerDetailResponse::class.java ) } 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 index 0085dd6..41b0ba6 100644 --- 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 @@ -16,20 +16,21 @@ import org.jetbrains.anko.coroutines.experimental.bg import org.jetbrains.anko.db.delete import org.jetbrains.anko.db.insert -class DetailTeamPresenter(private val view: DetailTeamView, - private val apiRepository: ApiRepository, - private val gson: Gson, - private val context: CoroutineContextProvider = CoroutineContextProvider() -) -{ +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)), + gson.fromJson( + apiRepository + .doRequest(TheSportDBApi.getTeamDetail(teamId)), TeamResponse::class.java ) } @@ -43,23 +44,33 @@ class DetailTeamPresenter(private val view: DetailTeamView, context.databaseTeam.use { delete(FavoriteTeams.TABLE_FAVORITE_TEAMS, "(TEAM_ID = {id})", "id" to "$teamId") } - } catch (e: SQLiteConstraintException){ + } catch (e: SQLiteConstraintException) { Log.d("failed delete fav", e.localizedMessage) } } - fun addToFavoriteTeam(context: Context, teamId: String?, teamName: String?, teamBadge: String?, teamFormedYear: String?, teamStadium: String?, teamDescription: String?) { + fun addToFavoriteTeam( + context: Context, + teamId: String?, + teamName: String?, + teamBadge: String?, + teamFormedYear: String?, + teamStadium: String?, + teamDescription: String? + ) { try { context.databaseTeam.use { - insert(FavoriteTeams.TABLE_FAVORITE_TEAMS, + insert( + FavoriteTeams.TABLE_FAVORITE_TEAMS, FavoriteTeams.TEAM_ID to teamId, FavoriteTeams.TEAM_NAME to teamName, FavoriteTeams.TEAM_BADGE to teamBadge, FavoriteTeams.TEAM_FORMED_YEAR to teamFormedYear, FavoriteTeams.TEAM_STADIUM to teamStadium, - FavoriteTeams.TEAM_DESCRIPTION to teamDescription) + FavoriteTeams.TEAM_DESCRIPTION to teamDescription + ) } - } catch (e: SQLiteConstraintException){ + } catch (e: SQLiteConstraintException) { Log.d("failed add fav", e.localizedMessage) } } diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/PlayerPresenter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/PlayerPresenter.kt index 82d0fab..70cebc2 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/PlayerPresenter.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/PlayerPresenter.kt @@ -9,17 +9,19 @@ import com.google.gson.Gson import kotlinx.coroutines.experimental.async import org.jetbrains.anko.coroutines.experimental.bg -class PlayerPresenter(private val view : PlayerView, - private val apiRepository: ApiRepository, - private val gson: Gson, - private val context: CoroutineContextProvider = CoroutineContextProvider() +class PlayerPresenter( + private val view: PlayerView, + private val apiRepository: ApiRepository, + private val gson: Gson, + private val context: CoroutineContextProvider = CoroutineContextProvider() ) { fun getPlayerTeam(teamName: String?) { view.showLoading() async(context.main) { val data = bg { - gson.fromJson(apiRepository.doRequest(TheSportDBApi.getPlayerTeam(teamName)), + gson.fromJson( + apiRepository.doRequest(TheSportDBApi.getPlayerTeam(teamName)), PlayerResponse::class.java ) } diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/SearchMatchPresenter.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/SearchMatchPresenter.kt index 469654a..89a66ec 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/SearchMatchPresenter.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/SearchMatchPresenter.kt @@ -3,7 +3,6 @@ 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.MatchResponse import com.example.wijaya_pc.footballapps.model.SearchMatchResponse import com.example.wijaya_pc.footballapps.view.SearchMatchView import com.google.gson.Gson 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 index 527bbba..777cccf 100644 --- 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 @@ -1,6 +1,5 @@ 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 @@ -9,22 +8,20 @@ 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() -) -{ +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)), + gson.fromJson( + apiRepository.doRequest(TheSportDBApi.getTeamList(league)), TeamResponse::class.java ) } 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 0804f5a..a600f08 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,8 +5,8 @@ import android.support.v4.content.ContextCompat import android.view.Gravity import android.view.View import android.widget.LinearLayout -import com.example.wijaya_pc.footballapps.feature.match.DetailMatchActivity import com.example.wijaya_pc.footballapps.R +import com.example.wijaya_pc.footballapps.feature.match.DetailMatchActivity import org.jetbrains.anko.* class DetailMatchUI : AnkoComponent { diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailPlayerUI.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailPlayerUI.kt index ab55397..1954036 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailPlayerUI.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailPlayerUI.kt @@ -6,10 +6,8 @@ import android.view.View import android.widget.ImageView import android.widget.LinearLayout import com.example.wijaya_pc.footballapps.R -import com.example.wijaya_pc.footballapps.feature.match.DetailMatchActivity import com.example.wijaya_pc.footballapps.feature.player.DetailPlayerActivity import org.jetbrains.anko.* -import org.jetbrains.anko.design.themedAppBarLayout class DetailPlayerUI : AnkoComponent { override fun createView(ui: AnkoContext): View = with(ui) { 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 index 9e198d4..b601ee4 100644 --- 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 @@ -2,22 +2,14 @@ package com.example.wijaya_pc.footballapps.ui import android.graphics.Color import android.support.design.widget.TabLayout -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.design.* -import org.jetbrains.anko.support.v4.swipeRefreshLayout +import org.jetbrains.anko.design.themedAppBarLayout +import org.jetbrains.anko.design.themedTabLayout import org.jetbrains.anko.support.v4.viewPager class DetailTeamUI : AnkoComponent { @@ -36,7 +28,7 @@ class DetailTeamUI : AnkoComponent { gravity = Gravity.CENTER_HORIZONTAL //team badge - imageView{ + imageView { id = R.id.team_badgeDetailTeam }.lparams(height = dip(75)) @@ -46,12 +38,12 @@ class DetailTeamUI : AnkoComponent { this.gravity = Gravity.CENTER textSize = 20f textColor = Color.WHITE - }.lparams{ + }.lparams { topMargin = dip(5) } //team formed year - textView{ + textView { id = R.id.team_formedyearDetailTeam textColor = Color.WHITE this.gravity = Gravity.CENTER @@ -82,7 +74,7 @@ class DetailTeamUI : AnkoComponent { progressBar { id = R.id.progressBarDetailTeam - }.lparams{ centerHorizontally() } + }.lparams { centerHorizontally() } } }.lparams(matchParent, matchParent) diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/MatchUI.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/MatchUI.kt index 83dad34..9fb95f3 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/MatchUI.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/MatchUI.kt @@ -6,7 +6,6 @@ import android.view.View import android.view.ViewGroup import android.widget.LinearLayout import com.example.wijaya_pc.footballapps.R -import com.example.wijaya_pc.footballapps.invisible import org.jetbrains.anko.* import org.jetbrains.anko.cardview.v7.cardView diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/PlayerUI.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/PlayerUI.kt index 94551c5..7284cb5 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/PlayerUI.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/PlayerUI.kt @@ -26,7 +26,7 @@ class PlayerUI : AnkoComponent { imageView { id = R.id.player_photo - }.lparams(width = dip(0)){ + }.lparams(width = dip(0)) { height = dip(50) width = dip(50) } @@ -42,7 +42,7 @@ class PlayerUI : AnkoComponent { id = R.id.player_position textSize = 16f gravity = Gravity.END - }.lparams(weight = 1f, width = dip(0)){ + }.lparams(weight = 1f, width = dip(0)) { rightMargin = dip(5) } } diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/SearchUI.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/SearchUI.kt index ce2a68a..21b6d52 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/ui/SearchUI.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/SearchUI.kt @@ -2,7 +2,6 @@ package com.example.wijaya_pc.footballapps.ui import android.support.v4.content.ContextCompat import android.view.View -import android.view.ViewGroup import android.widget.LinearLayout import com.example.wijaya_pc.footballapps.R import com.example.wijaya_pc.footballapps.feature.match.SearchMatchActivity @@ -28,7 +27,8 @@ class SearchUI : AnkoComponent { R.color.colorAccent, android.R.color.holo_green_light, android.R.color.holo_orange_light, - android.R.color.holo_red_light) + android.R.color.holo_red_light + ) relativeLayout { lparams(width = matchParent, height = wrapContent) @@ -40,7 +40,7 @@ class SearchUI : AnkoComponent { progressBar { id = R.id.progress_bar_search - }.lparams{ + }.lparams { centerHorizontally() } } 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 index bb08e70..9aef8bc 100644 --- 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 @@ -7,7 +7,7 @@ import com.example.wijaya_pc.footballapps.R import org.jetbrains.anko.* class TeamUI : AnkoComponent { - override fun createView(ui: AnkoContext): View = with(ui){ + override fun createView(ui: AnkoContext): View = with(ui) { linearLayout { lparams(matchParent, wrapContent) padding = dip(16) @@ -15,7 +15,7 @@ class TeamUI : AnkoComponent { imageView { id = R.id.team_badge - }.lparams{ + }.lparams { height = dip(50) width = dip(50) } @@ -23,7 +23,7 @@ class TeamUI : AnkoComponent { textView { id = R.id.team_name textSize = 16f - }.lparams{ + }.lparams { margin = dip(15) } } diff --git a/app/src/main/res/drawable/ic_last_match.xml b/app/src/main/res/drawable/ic_last_match.xml deleted file mode 100644 index 472f686..0000000 --- a/app/src/main/res/drawable/ic_last_match.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index d13dbfa..1445e71 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -2,8 +2,7 @@ diff --git a/app/src/main/res/layout/fragment_favorite.xml b/app/src/main/res/layout/fragment_favorite.xml index a94c036..1a7ce5a 100644 --- a/app/src/main/res/layout/fragment_favorite.xml +++ b/app/src/main/res/layout/fragment_favorite.xml @@ -6,7 +6,6 @@ android:layout_height="match_parent"> diff --git a/app/src/main/res/layout/fragment_list_match.xml b/app/src/main/res/layout/fragment_list_match.xml deleted file mode 100644 index 371e4ba..0000000 --- a/app/src/main/res/layout/fragment_list_match.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - diff --git a/app/src/main/res/layout/fragment_match.xml b/app/src/main/res/layout/fragment_match.xml index 0d7adec..5982794 100644 --- a/app/src/main/res/layout/fragment_match.xml +++ b/app/src/main/res/layout/fragment_match.xml @@ -6,7 +6,6 @@ android:layout_height="match_parent"> diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index 560806c..8cfb388 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -5,35 +5,14 @@ - - - - - - - - - - - - - - - - - - - - + - - @@ -79,6 +58,9 @@ + + + \ 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 e37dc0b..8862179 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -28,7 +28,6 @@ - Hello blank fragment Match Team Weight (KG) diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 01fc3eb..3c54f4b 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -14,6 +14,5 @@