diff --git a/.idea/misc.xml b/.idea/misc.xml index 17426a4..3386629 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -29,7 +29,7 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c81235a..50acd89 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,6 +25,9 @@ + + + \ 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 a4b51e5..dd14723 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 @@ -21,22 +21,14 @@ fun dateToSimpleString(date: Date?): String? = with(date ?: Date()) { } @SuppressLint("SimpleDateFormat") -fun timeToSimpleString(time: Date?): String? = with(time ?: Date()) { - SimpleDateFormat("HH:mm").format(this) -} - -@SuppressLint("SimpleDateFormat") -fun timeToGMT(time: String?): Date? { - val formatter = SimpleDateFormat("HH:mm") +fun toGMTFormat(date: String?, time: String?): Date? { + val formatter = SimpleDateFormat("EEE, dd MMM yyyy HH:mm") formatter.timeZone = TimeZone.getTimeZone("UTC") - val theTime = "$time" - return formatter.parse(time) + val dateTime = "$date $time" + return formatter.parse(dateTime) } @SuppressLint("SimpleDateFormat") -fun toGMTFormat(date: String, time: String): Date? { - val formatter = SimpleDateFormat("dd/MM/yy HH:mm:ss") - formatter.timeZone = TimeZone.getTimeZone("UTC") - val dateTime = "$date $time" - return formatter.parse(dateTime) +fun dateTimeToSimpleString(date: Date?): String? = with(date ?: Date()) { + SimpleDateFormat("EEE, dd MMM yyyy HH:mm").format(this) } \ No newline at end of file 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 e84660e..4247668 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 @@ -3,14 +3,13 @@ package com.example.wijaya_pc.footballapps.adapter import android.os.Build import android.support.annotation.RequiresApi import android.support.v7.widget.RecyclerView +import android.util.Log import android.view.View import android.view.ViewGroup import android.widget.TextView +import com.example.wijaya_pc.footballapps.* import com.example.wijaya_pc.footballapps.R.id.* -import com.example.wijaya_pc.footballapps.dateToSimpleString import com.example.wijaya_pc.footballapps.model.Match -import com.example.wijaya_pc.footballapps.timeToGMT -import com.example.wijaya_pc.footballapps.timeToSimpleString import com.example.wijaya_pc.footballapps.ui.MatchUI import org.jetbrains.anko.AnkoContext import org.jetbrains.anko.find @@ -44,9 +43,13 @@ class MatchViewHolder(view: View) : RecyclerView.ViewHolder(view) { private val matchAwayTeam: TextView = view.find(match_away_team) fun bindItem(matches: Match, listener: (Match) -> Unit) { + val matchDateTime = dateTimeToSimpleString(toGMTFormat(dateToSimpleString(matches.matchDate), matches.matchTime)) - matchDate.text = dateToSimpleString(matches.matchDate) - matchTime.text = timeToSimpleString(timeToGMT(matches.matchTime)) + //matchDate.text = dateToSimpleString(matches.matchDate) + //matchTime.text = timeToSimpleString(timeToGMT(matches.matchTime)) + + matchDate.text = matchDateTime!!.substring(0, 16) + matchTime.text = matchDateTime!!.substring(17, 22) matchHomeTeam.text = matches.homeTeam matchHomeScore.text = matches.homeScore 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 new file mode 100644 index 0000000..0484656 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/adapter/PlayerAdapter.kt @@ -0,0 +1,44 @@ +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 +import com.example.wijaya_pc.footballapps.R.id.* +import com.example.wijaya_pc.footballapps.model.Player +import com.example.wijaya_pc.footballapps.ui.PlayerUI +import com.squareup.picasso.Picasso +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() { + override fun onCreateViewHolder(parent: ViewGroup, position: Int): PlayerViewHolder { + return PlayerViewHolder(PlayerUI().createView(AnkoContext.create(parent.context, parent))) + } + + override fun getItemCount(): Int = players.size + + override fun onBindViewHolder(holder: PlayerViewHolder, position: Int) { + holder.bindItem(players[position], listener) + } + +} + +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) + + fun bindItem(players: Player, listener: (Player) -> Unit) { + Picasso.get().load(players.playerPhoto).placeholder(R.drawable.default_player).into(playerPhoto) + + playerName.text = players.playerName + playerPosition.text = players.playerPosition + + itemView.onClick { listener(players) } + } +} \ 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 e038b5c..815b389 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 @@ -31,4 +31,12 @@ object TheSportDBApi { fun getTeamDetail(teamId: String?): String { return BuildConfig.BASE_URL + "api/v1/json/${BuildConfig.TSDB_API_KEY}" + "/lookupteam.php?id=" + teamId } + + fun getPlayerTeam(teamName: String?): String { + return BuildConfig.BASE_URL + "api/v1/json/${BuildConfig.TSDB_API_KEY}" + "/searchplayers.php?t=" + teamName + } + + fun getPlayerDetails(playerId: String?) : String { + return BuildConfig.BASE_URL + "api/v1/json/${BuildConfig.TSDB_API_KEY}" + "/lookupplayer.php?id=" + playerId + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favoritematch/ListFavoriteFragment.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favoritematch/ListFavoriteFragment.kt index 7b5b1e1..c433675 100644 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favoritematch/ListFavoriteFragment.kt +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/favoritematch/ListFavoriteFragment.kt @@ -72,7 +72,7 @@ class ListFavoriteFragment : Fragment(), AnkoComponent { else { favoriteTeamsAdapter = FavoriteTeamsAdapter(favoritesTeams) { - ctx.startActivity("id" to "${it.teamId}", "desc" to "${it.teamDescription}") + ctx.startActivity("id" to "${it.teamId}", "desc" to "${it.teamDescription}", "name" to "${it.teamName}") } listFav.adapter = favoriteTeamsAdapter 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 index 59f0c74..2118e1b 100644 --- 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 @@ -35,6 +35,15 @@ class MainActivity : AppCompatActivity() { } + private fun loadMatchFragment() { + supportFragmentManager + .beginTransaction() + .replace( + R.id.main_container, + MatchFragment(), MatchFragment::class.java.simpleName) + .commit() + } + private fun loadTeamsFragment() { supportFragmentManager .beginTransaction() @@ -53,13 +62,4 @@ class MainActivity : AppCompatActivity() { .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/feature/match/DetailMatchActivity.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/DetailMatchActivity.kt index 9b526b6..96bd040 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 @@ -33,12 +33,6 @@ import org.jetbrains.anko.setContentView class DetailMatchActivity : AppCompatActivity(), DetailMatchView { - - companion object { - const val dataParcel = "data_parcel" - } - - private lateinit var detailView: ScrollView private lateinit var progressBar: ProgressBar @@ -102,10 +96,12 @@ 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)) + detailPresenter.addToFavorite( ctx, matches.matchId, - dateToSimpleString(matches.matchDate), - timeToSimpleString(timeToGMT(matches.matchTime)), + matchDateTime!!.substring(0, 16), + matchDateTime!!.substring(17, 22), matches.idHomeTeam, matches.idAwayTeam, matches.homeTeam, @@ -156,11 +152,13 @@ class DetailMatchActivity : AppCompatActivity(), DetailMatchView { data.awaySubtitutes ) + val matchDateTime = dateTimeToSimpleString(toGMTFormat(dateToSimpleString(data.matchDate), data.matchTime)) + val matchDate: TextView = find(detail_match_date) - matchDate.text = dateToSimpleString(data.matchDate) + matchDate.text = matchDateTime!!.substring(0, 16) val matchTime: TextView = find(detail_match_time) - matchTime.text = timeToSimpleString(timeToGMT(data.matchTime)) + matchTime.text = matchDateTime!!.substring(17, 22) val hometeam: TextView = find(detail_match_home_team) val awayteam: TextView = find(detail_match_away_team) 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 new file mode 100644 index 0000000..320ba90 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/player/DetailPlayerActivity.kt @@ -0,0 +1,96 @@ +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 +import android.widget.ScrollView +import android.widget.TextView +import com.example.wijaya_pc.footballapps.R +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.Player +import com.example.wijaya_pc.footballapps.presenter.DetailPlayerPresenter +import com.example.wijaya_pc.footballapps.ui.DetailPlayerUI +import com.example.wijaya_pc.footballapps.view.DetailPlayerView +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.toast + +class DetailPlayerActivity : AppCompatActivity(), DetailPlayerView { + + private lateinit var detailView: ScrollView + private lateinit var progressBar: ProgressBar + + private lateinit var detailPresenter: DetailPlayerPresenter + + private lateinit var playerID: String + private lateinit var playerName: String + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + DetailPlayerUI().setContentView(this) + + val intent = intent + playerID = intent.getStringExtra("id") + playerName = intent.getStringExtra("name") + + supportActionBar?.title = playerName + supportActionBar?.setDisplayHomeAsUpEnabled(true) + + detailView = find(player_detail_sv) + progressBar = find(player_detail_progress) + + val request = ApiRepository() + val gson = Gson() + detailPresenter = DetailPlayerPresenter(this, request, gson) + + detailPresenter.getPlayerDetails(playerID) + + } + + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when (item.itemId) { + android.R.id.home -> { + finish() + true + } + else -> super.onOptionsItemSelected(item) + } + } + + override fun showLoading() { + progressBar.visible() + } + + override fun hideLoading() { + progressBar.invisible() + } + + override fun showPlayerDetail(data: Player) { + 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) + playerWeight.text = data.playerWeight + + val playerHeight : TextView = find(player_detail_height) + playerHeight.text = data.playerHeight + + val playerPosition : TextView = find(player_detail_position) + playerPosition.text = data.playerPosition + + val playerDesc : TextView = find(player_detail_description) + playerDesc.text = data.playerDescription + } + +} \ No newline at end of file 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 new file mode 100644 index 0000000..657bf09 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/player/PlayersFragment.kt @@ -0,0 +1,127 @@ +package com.example.wijaya_pc.footballapps.feature.player + +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.LinearLayout +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 +import com.example.wijaya_pc.footballapps.view.PlayerView +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 +import org.jetbrains.anko.support.v4.toast + +class PlayersFragment : Fragment(), AnkoComponent, PlayerView { + + companion object { + private const val ARG_TEAM_NAME = "team_name" + + fun newInstance(teamName: String?): PlayersFragment { + val fragment = PlayersFragment() + val args = Bundle() + args.putString(ARG_TEAM_NAME, teamName) + fragment.arguments = args + return fragment + } + } + + private lateinit var listPlayer : RecyclerView + private lateinit var progressBar : ProgressBar + private lateinit var swipeRefresh : SwipeRefreshLayout + + private var players: MutableList = mutableListOf() + private lateinit var playerPresenter: PlayerPresenter + private lateinit var playerAdapter: PlayerAdapter + + private lateinit var teamName : String + + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) + + teamName = arguments?.getString(PlayersFragment.ARG_TEAM_NAME).toString() + + val request = ApiRepository() + val gson = Gson() + playerPresenter = PlayerPresenter(this, request, gson) + + playerAdapter = PlayerAdapter(players) { + ctx.startActivity("id" to "${it.playerId}", "name" to "${it.playerName}") + } + listPlayer.adapter = playerAdapter + + playerPresenter.getPlayerTeam(teamName) + + swipeRefresh.onRefresh { + playerPresenter.getPlayerTeam(teamName) + } + } + + 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) + + swipeRefresh = swipeRefreshLayout { + setColorSchemeResources( + R.color.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) + + listPlayer = 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 showPlayerList(data: List) { + swipeRefresh.isRefreshing = false + players.clear() + players.addAll(data) + playerAdapter.notifyDataSetChanged() + } + +} \ 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 index 23e6b07..1a2c984 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 @@ -1,12 +1,10 @@ package com.example.wijaya_pc.footballapps.feature.team import android.R -import android.database.sqlite.SQLiteConstraintException import android.os.Bundle import android.support.design.widget.TabLayout import android.support.v4.content.ContextCompat import android.support.v4.view.ViewPager -import android.support.v4.widget.SwipeRefreshLayout import android.support.v7.app.AppCompatActivity import android.view.Menu import android.view.MenuItem @@ -20,9 +18,8 @@ import com.example.wijaya_pc.footballapps.R.id.* import com.example.wijaya_pc.footballapps.R.menu.detail_menu import com.example.wijaya_pc.footballapps.adapter.pager.DetailTeamPagerAdapter import com.example.wijaya_pc.footballapps.api.ApiRepository -import com.example.wijaya_pc.footballapps.database.database import com.example.wijaya_pc.footballapps.database.databaseTeam -import com.example.wijaya_pc.footballapps.feature.favoritematch.ListFavoriteFragment +import com.example.wijaya_pc.footballapps.feature.player.PlayersFragment import com.example.wijaya_pc.footballapps.invisible import com.example.wijaya_pc.footballapps.model.FavoriteTeams import com.example.wijaya_pc.footballapps.model.Team @@ -32,18 +29,12 @@ 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 kotlinx.android.synthetic.main.abc_dialog_title_material.view.* import org.jetbrains.anko.ctx import org.jetbrains.anko.db.classParser -import org.jetbrains.anko.db.delete -import org.jetbrains.anko.db.insert import org.jetbrains.anko.db.select import org.jetbrains.anko.design.snackbar -import org.jetbrains.anko.design.tabItem import org.jetbrains.anko.find import org.jetbrains.anko.setContentView -import org.jetbrains.anko.support.v4.onRefresh -import org.jetbrains.anko.toast class DetailTeamActivity : AppCompatActivity(), DetailTeamView { @@ -60,7 +51,9 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView { private lateinit var presenter: DetailTeamPresenter private lateinit var teams: Team private lateinit var id: String + private lateinit var teamDescription: String + private lateinit var mTeamName: String private lateinit var tabLayout: TabLayout private lateinit var viewPager: ViewPager @@ -73,6 +66,7 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView { val intent = intent id = intent.getStringExtra("id") teamDescription = intent.getStringExtra("desc") + mTeamName = intent.getStringExtra("name") castingObjectFromUI() @@ -104,7 +98,7 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView { mDetailTeamPagerAdapter = DetailTeamPagerAdapter(supportFragmentManager) mDetailTeamPagerAdapter.addFrag(OverviewTeamFragment.newInstance(teamDescription), "Overview") - mDetailTeamPagerAdapter.addFrag(PlayersTeamFragment(), "Players") + mDetailTeamPagerAdapter.addFrag(PlayersFragment.newInstance(mTeamName), "Players") viewPager.adapter = mDetailTeamPagerAdapter viewPager.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabLayout)) diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/PlayersTeamFragment.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/PlayersTeamFragment.kt deleted file mode 100644 index 42e6cb9..0000000 --- a/app/src/main/java/com/example/wijaya_pc/footballapps/feature/team/PlayersTeamFragment.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.example.wijaya_pc.footballapps.feature.team - -import android.content.Context -import android.os.Bundle -import android.support.v4.app.Fragment -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.LinearLayout -import org.jetbrains.anko.* -import org.jetbrains.anko.support.v4.ctx - -class PlayersTeamFragment : Fragment(), AnkoComponent { - 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) - - textView{ - text = "PLAYERS TEAM FRAGMENT" - } - } - } - -} \ 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 index b37cc1c..8d0149b 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 @@ -52,7 +52,7 @@ class TeamsFragment : Fragment(), AnkoComponent, TeamView { spinner.adapter = spinnerAdapter teamAdapter = TeamAdapter(teams) { - ctx.startActivity("id" to "${it.teamId}", "desc" to "${it.teamDescription}") + ctx.startActivity("id" to "${it.teamId}", "desc" to "${it.teamDescription}", "name" to "${it.teamName}") } listTeam.adapter = teamAdapter 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 new file mode 100644 index 0000000..d5d999b --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/model/Player.kt @@ -0,0 +1,29 @@ +package com.example.wijaya_pc.footballapps.model + +import com.google.gson.annotations.SerializedName + +data class Player ( + @SerializedName("idPlayer") + var playerId : String?, + + @SerializedName("strCutout") + var playerPhoto : String?, + + @SerializedName("strPlayer") + var playerName : String?, + + @SerializedName("strPosition") + var playerPosition : String?, + + @SerializedName("strFanart1") + var playerThumb : String?, + + @SerializedName("strWeight") + var playerWeight : String?, + + @SerializedName("strHeight") + var playerHeight : String?, + + @SerializedName("strDescriptionEN") + var playerDescription : String? +) \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/model/PlayerResponse.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/model/PlayerResponse.kt new file mode 100644 index 0000000..5c85f86 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/model/PlayerResponse.kt @@ -0,0 +1,9 @@ +package com.example.wijaya_pc.footballapps.model + +data class PlayerResponse( + val player: List +) + +data class PlayerDetailResponse( + val players: List +) \ 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 new file mode 100644 index 0000000..4e18623 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/DetailPlayerPresenter.kt @@ -0,0 +1,31 @@ +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.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() +) { + fun getPlayerDetails(playerId: String?) { + view.showLoading() + + async(context.main) { + val data = bg { + gson.fromJson(apiRepository.doRequest(TheSportDBApi.getPlayerDetails(playerId)), + PlayerDetailResponse::class.java + ) + } + view.showPlayerDetail(data.await().players[0]) + view.hideLoading() + } + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..82d0fab --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/presenter/PlayerPresenter.kt @@ -0,0 +1,30 @@ +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.PlayerResponse +import com.example.wijaya_pc.footballapps.view.PlayerView +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() +) { + fun getPlayerTeam(teamName: String?) { + view.showLoading() + + async(context.main) { + val data = bg { + gson.fromJson(apiRepository.doRequest(TheSportDBApi.getPlayerTeam(teamName)), + PlayerResponse::class.java + ) + } + view.showPlayerList(data.await().player) + view.hideLoading() + } + } +} 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 new file mode 100644 index 0000000..ab55397 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/DetailPlayerUI.kt @@ -0,0 +1,98 @@ +package com.example.wijaya_pc.footballapps.ui + +import android.support.v4.content.ContextCompat +import android.view.Gravity +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) { + linearLayout { + lparams(width = matchParent, height = wrapContent) + orientation = LinearLayout.VERTICAL + + imageView { + id = R.id.player_detail_photo + scaleType = ImageView.ScaleType.FIT_XY + }.lparams(width = matchParent, height = dip(250)) + + linearLayout { + lparams(width = matchParent) { + topMargin = dip(5) + bottomMargin = dip(10) + } + + linearLayout { + orientation = LinearLayout.VERTICAL + gravity = Gravity.CENTER + + textView { + text = context.getString(R.string.weight) + gravity = Gravity.CENTER + } + + textView { + id = R.id.player_detail_weight + textSize = 30f + textColor = ContextCompat.getColor(ctx, R.color.colorPrimary) + gravity = Gravity.CENTER + } + }.lparams(weight = 1f) + + linearLayout { + orientation = LinearLayout.VERTICAL + + textView { + text = context.getString(R.string.height) + gravity = Gravity.CENTER + } + + textView { + id = R.id.player_detail_height + textSize = 30f + textColor = ContextCompat.getColor(ctx, R.color.colorPrimary) + gravity = Gravity.CENTER + } + }.lparams(weight = 1f) + } + + textView { + id = R.id.player_detail_position + gravity = Gravity.CENTER + textColor = ContextCompat.getColor(ctx, R.color.colorPrimary) + } + + scrollView { + id = R.id.player_detail_sv + lparams(width = matchParent) + + verticalLayout { + lparams(width = matchParent) + + // line separator + view { + backgroundResource = android.R.color.darker_gray + }.lparams(width = matchParent, height = dip(1)) { + bottomMargin = dip(10) + } + + textView { + id = R.id.player_detail_description + padding = dip(8) + } + } + } + progressBar { + id = R.id.player_detail_progress + }.lparams { + + } + } + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..94551c5 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/ui/PlayerUI.kt @@ -0,0 +1,52 @@ +package com.example.wijaya_pc.footballapps.ui + +import android.support.v4.content.ContextCompat +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.LinearLayout +import com.example.wijaya_pc.footballapps.R +import org.jetbrains.anko.* +import org.jetbrains.anko.cardview.v7.cardView + +class PlayerUI : AnkoComponent { + override fun createView(ui: AnkoContext): View = with(ui) { + + linearLayout { + lparams(width = matchParent) + + cardView { + lparams(width = matchParent) + + linearLayout { + lparams(width = matchParent) + padding = dip(16) + orientation = LinearLayout.HORIZONTAL + gravity = Gravity.CENTER + + imageView { + id = R.id.player_photo + }.lparams(width = dip(0)){ + height = dip(50) + width = dip(50) + } + + textView { + id = R.id.player_name + textSize = 16f + textColor = ContextCompat.getColor(ctx, R.color.colorPrimary) + this.gravity = Gravity.START + }.lparams(weight = 1f, width = dip(0)) + + textView { + id = R.id.player_position + textSize = 16f + gravity = Gravity.END + }.lparams(weight = 1f, width = dip(0)){ + rightMargin = dip(5) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailPlayerView.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailPlayerView.kt new file mode 100644 index 0000000..995f694 --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/view/DetailPlayerView.kt @@ -0,0 +1,9 @@ +package com.example.wijaya_pc.footballapps.view + +import com.example.wijaya_pc.footballapps.model.Player + +interface DetailPlayerView { + fun showLoading() + fun hideLoading() + fun showPlayerDetail(data: Player) +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wijaya_pc/footballapps/view/PlayerView.kt b/app/src/main/java/com/example/wijaya_pc/footballapps/view/PlayerView.kt new file mode 100644 index 0000000..ae661cd --- /dev/null +++ b/app/src/main/java/com/example/wijaya_pc/footballapps/view/PlayerView.kt @@ -0,0 +1,9 @@ +package com.example.wijaya_pc.footballapps.view + +import com.example.wijaya_pc.footballapps.model.Player + +interface PlayerView { + fun showLoading() + fun hideLoading() + fun showPlayerList(data: List) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/default_player.png b/app/src/main/res/drawable/default_player.png new file mode 100644 index 0000000..9a0f3fa Binary files /dev/null and b/app/src/main/res/drawable/default_player.png differ diff --git a/app/src/main/res/layout/fragment_match.xml b/app/src/main/res/layout/fragment_match.xml index 0d7adec..ddc24f0 100644 --- a/app/src/main/res/layout/fragment_match.xml +++ b/app/src/main/res/layout/fragment_match.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + + + + + + + + + + \ 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 d07f231..53a1d32 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -31,5 +31,7 @@ Hello blank fragment Match Team + Weight (KG) + Height (m)