Skip to content

Commit

Permalink
- mengubah date dan time ke GMT+7
Browse files Browse the repository at this point in the history
- membuat detail dari player
  • Loading branch information
andremw96 committed Oct 31, 2018
1 parent 93ad0ef commit 56b36af
Show file tree
Hide file tree
Showing 26 changed files with 597 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

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

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

</manifest>
20 changes: 6 additions & 14 deletions app/src/main/java/com/example/wijaya_pc/footballapps/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Player>, private val listener: (Player) -> Unit) : RecyclerView.Adapter<PlayerViewHolder>() {
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) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ListFavoriteFragment : Fragment(), AnkoComponent<Context> {
else
{
favoriteTeamsAdapter = FavoriteTeamsAdapter(favoritesTeams) {
ctx.startActivity<DetailTeamActivity>("id" to "${it.teamId}", "desc" to "${it.teamDescription}")
ctx.startActivity<DetailTeamActivity>("id" to "${it.teamId}", "desc" to "${it.teamDescription}", "name" to "${it.teamName}")
}

listFav.adapter = favoriteTeamsAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -53,13 +62,4 @@ class MainActivity : AppCompatActivity() {
.commit()
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}

}
Loading

0 comments on commit 56b36af

Please sign in to comment.