Skip to content

Commit

Permalink
- time to gmt to string
Browse files Browse the repository at this point in the history
- detail team pager untuk menampilkan overview dan player fragment
  • Loading branch information
andremw96 committed Oct 31, 2018
1 parent 22d278c commit 93ad0ef
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 120 deletions.
13 changes: 13 additions & 0 deletions app/src/main/java/com/example/wijaya_pc/footballapps/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ fun dateToSimpleString(date: Date?): String? = with(date ?: Date()) {
SimpleDateFormat("EEE, dd MMM yyyy").format(this)
}

@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")
formatter.timeZone = TimeZone.getTimeZone("UTC")
val theTime = "$time"
return formatter.parse(time)
}

@SuppressLint("SimpleDateFormat")
fun toGMTFormat(date: String, time: String): Date? {
val formatter = SimpleDateFormat("dd/MM/yy HH:mm:ss")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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<FavoriteMatches>,
Expand All @@ -34,6 +35,7 @@ class FavoriteMatchesAdapter(
class FavoriteViewHolder(view: View) : RecyclerView.ViewHolder(view) {

private val matchDate: TextView = view.find(match_date)
private val matchTime: TextView = view.find(match_time)
private val homeTeamName: TextView = view.find(match_home_team)
private val homeTeamScore: TextView = view.find(match_home_score)
private val awayTeamScore: TextView = view.find(match_away_score)
Expand All @@ -42,6 +44,7 @@ class FavoriteViewHolder(view: View) : RecyclerView.ViewHolder(view) {

fun bindItem(favorite: FavoriteMatches, listener: (FavoriteMatches) -> Unit) {
matchDate.text = favorite.matchDate
matchTime.text = favorite.matchTime
homeTeamName.text = favorite.homeTeamName
homeTeamScore.text = favorite.homeTeamScore
awayTeamScore.text = favorite.awayTeamScore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import android.widget.TextView
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,7 +46,7 @@ class MatchViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindItem(matches: Match, listener: (Match) -> Unit) {

matchDate.text = dateToSimpleString(matches.matchDate)
matchTime.text = (matches.matchTime)!!.substring(0, 5)
matchTime.text = timeToSimpleString(timeToGMT(matches.matchTime))

matchHomeTeam.text = matches.homeTeam
matchHomeScore.text = matches.homeScore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.wijaya_pc.footballapps.adapter.pager

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter

class DetailTeamPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager) {
private val mFragmentList = ArrayList<Fragment>()
private val mFragmentTitleList = ArrayList<String>()

override fun getItem(position: Int): Fragment {
return mFragmentList[position]
}

override fun getCount(): Int {
return mFragmentList.size
}

fun addFrag(fragment: Fragment, title: String) {
mFragmentList.add(fragment)
mFragmentTitleList.add(title)
}

override fun getPageTitle(position: Int): CharSequence {
return mFragmentTitleList[position]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MyDatabaseFavoriteMatchHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx,
FavoriteMatches.ID to INTEGER + PRIMARY_KEY + AUTOINCREMENT,
FavoriteMatches.MATCH_ID to TEXT + UNIQUE,
FavoriteMatches.MATCH_DATE to TEXT,
FavoriteMatches.MATCH_TIME to TEXT,
FavoriteMatches.HOME_TEAM_ID to TEXT,
FavoriteMatches.AWAY_TEAM_ID to TEXT,
FavoriteMatches.HOME_TEAM_NAME to TEXT,
Expand Down
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}")
ctx.startActivity<DetailTeamActivity>("id" to "${it.teamId}", "desc" to "${it.teamDescription}")
}

listFav.adapter = favoriteTeamsAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.ScrollView
import android.widget.TextView
import com.example.wijaya_pc.footballapps.*
import com.example.wijaya_pc.footballapps.R.drawable.ic_add_to_favorites
import com.example.wijaya_pc.footballapps.R.drawable.ic_added_to_favorites
import com.example.wijaya_pc.footballapps.R.id.*
import com.example.wijaya_pc.footballapps.R.menu.detail_menu
import com.example.wijaya_pc.footballapps.api.ApiRepository
import com.example.wijaya_pc.footballapps.database.database
import com.example.wijaya_pc.footballapps.dateToSimpleString
import com.example.wijaya_pc.footballapps.invisible
import com.example.wijaya_pc.footballapps.model.FavoriteMatches
import com.example.wijaya_pc.footballapps.model.Match
import com.example.wijaya_pc.footballapps.model.Team
import com.example.wijaya_pc.footballapps.presenter.DetailMatchPresenter
import com.example.wijaya_pc.footballapps.ui.DetailMatchUI
import com.example.wijaya_pc.footballapps.view.DetailMatchView
import com.example.wijaya_pc.footballapps.visible
import com.google.gson.Gson
import com.squareup.picasso.Picasso
import org.jetbrains.anko.ctx
Expand Down Expand Up @@ -107,6 +105,7 @@ class DetailMatchActivity : AppCompatActivity(), DetailMatchView {
detailPresenter.addToFavorite(
ctx, matches.matchId,
dateToSimpleString(matches.matchDate),
timeToSimpleString(timeToGMT(matches.matchTime)),
matches.idHomeTeam,
matches.idAwayTeam,
matches.homeTeam,
Expand Down Expand Up @@ -157,64 +156,67 @@ class DetailMatchActivity : AppCompatActivity(), DetailMatchView {
data.awaySubtitutes
)

val matchDate: TextView = find(match_date)
val matchDate: TextView = find(detail_match_date)
matchDate.text = dateToSimpleString(data.matchDate)

val hometeam: TextView = find(match_home_team)
val awayteam: TextView = find(match_away_team)
val matchTime: TextView = find(detail_match_time)
matchTime.text = timeToSimpleString(timeToGMT(data.matchTime))

val hometeam: TextView = find(detail_match_home_team)
val awayteam: TextView = find(detail_match_away_team)
hometeam.text = data.homeTeam
awayteam.text = data.awayTeam

val homescore: TextView = find(match_home_score)
val awayscore: TextView = find(match_away_score)
val homescore: TextView = find(detail_match_home_score)
val awayscore: TextView = find(detail_match_away_score)
homescore.text = data.homeScore
awayscore.text = data.awayScore

val homegoals: TextView = find(match_home_goals)
val awaygoals: TextView = find(match_away_goals)
val homegoals: TextView = find(detail_match_home_goals)
val awaygoals: TextView = find(detail_match_away_goals)
homegoals.text = data.homeGoals
awaygoals.text = data.awayGoals

val homeshots: TextView = find(match_home_shots)
val awayshots: TextView = find(match_away_shots)
val homeshots: TextView = find(detail_match_home_shots)
val awayshots: TextView = find(detail_match_away_shots)
homeshots.text = data.homeShots
awayshots.text = data.awayShots

val homeformation: TextView = find(match_home_formation)
val awayformation: TextView = find(match_away_formation)
val homeformation: TextView = find(detail_match_home_formation)
val awayformation: TextView = find(detail_match_away_formation)
homeformation.text = data.homeFormation
awayformation.text = data.awayFormation

val homegoalkeeper: TextView = find(match_home_goalkeeper)
val awaygoalkeeper: TextView = find(match_away_goalkeeper)
val homegoalkeeper: TextView = find(detail_match_home_goalkeeper)
val awaygoalkeeper: TextView = find(detail_match_away_goalkeeper)
homegoalkeeper.text = data.homeGoalKeeper
awaygoalkeeper.text = data.awayGoalKeeper

val homedefense: TextView = find(match_home_defense)
val awaydefense: TextView = find(match_away_defense)
val homedefense: TextView = find(detail_match_home_defense)
val awaydefense: TextView = find(detail_match_away_defense)
homedefense.text = data.homeDefence
awaydefense.text = data.awayDefence

val homemidfield: TextView = find(match_home_midfield)
val awaymidfield: TextView = find(match_away_midfield)
val homemidfield: TextView = find(detail_match_home_midfield)
val awaymidfield: TextView = find(detail_match_away_midfield)
homemidfield.text = data.homeMidfield
awaymidfield.text = data.awayMidfield

val homeforward: TextView = find(match_home_forward)
val awayforward: TextView = find(match_away_forward)
val homeforward: TextView = find(detail_match_home_forward)
val awayforward: TextView = find(detail_match_away_forward)
homeforward.text = data.homeForward
awayforward.text = data.awayForward

val homesubs: TextView = find(match_home_subs)
val awaysubs: TextView = find(match_away_subs)
val homesubs: TextView = find(detail_match_home_subs)
val awaysubs: TextView = find(detail_match_away_subs)
homesubs.text = data.homeSubstitutes
awaysubs.text = data.awaySubtitutes
}


override fun getTeam(data: Team, homeTeam: Boolean) {
val homelogo: ImageView = find(home_logo)
val awaylogo: ImageView = find(away_logo)
val homelogo: ImageView = find(detail_home_logo)
val awaylogo: ImageView = find(detail_away_logo)
Picasso.get().load(data.teamBadge).into(if (homeTeam == true) homelogo else awaylogo)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ 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
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
import com.example.wijaya_pc.footballapps.R.drawable.ic_add_to_favorites
import com.example.wijaya_pc.footballapps.R.drawable.ic_added_to_favorites
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
Expand All @@ -28,48 +32,49 @@ 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 {

private lateinit var swipeRefresh : SwipeRefreshLayout
private lateinit var progressBar : ProgressBar
private lateinit var linearLayout: LinearLayout
private var menuItem: Menu? = null
private var isFavorite: Boolean = false

private lateinit var teamBadge: ImageView
private lateinit var teamName: TextView
private lateinit var teamFormedYear: TextView
private lateinit var teamStadium: TextView
private lateinit var teamDescription: TextView

private lateinit var presenter: DetailTeamPresenter
private lateinit var teams: Team
private lateinit var id: String
private lateinit var teamDescription: String

private lateinit var tabLayout: TabLayout
private lateinit var viewPager: ViewPager
private lateinit var mDetailTeamPagerAdapter: DetailTeamPagerAdapter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
DetailTeamUI().setContentView(this)

swipeRefresh = find(swipeRefreshDetailTeam)
progressBar = find(progressBarDetailTeam)
teamBadge = find(team_badgeDetailTeam)
teamName = find(team_nameDetailTeam)
teamFormedYear = find(team_formedyearDetailTeam)
teamStadium = find(team_stadiumDetailTeam)
teamDescription = find(team_descDetailTeam)


val intent = intent
id = intent.getStringExtra("id")
teamDescription = intent.getStringExtra("desc")

castingObjectFromUI()

// nambah toolbar judul dan tombol back
supportActionBar?.title = "Team Detail"
Expand All @@ -81,10 +86,29 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView {
val gson = Gson()
presenter = DetailTeamPresenter(this, request, gson)
presenter.getTeamDetail(id)
}

swipeRefresh.onRefresh {
presenter.getTeamDetail(id)
}
private fun castingObjectFromUI() {
linearLayout = find(detail_team_UI)
progressBar = find(progressBarDetailTeam)
teamBadge = find(team_badgeDetailTeam)
teamName = find(team_nameDetailTeam)
teamFormedYear = find(team_formedyearDetailTeam)
teamStadium = find(team_stadiumDetailTeam)

tabLayout = find(tabs_detail_team)
viewPager = find(viewpager_detail_team)

tabLayout.addTab(tabLayout.newTab().setText("Overview"))
tabLayout.addTab(tabLayout.newTab().setText("Players"))

mDetailTeamPagerAdapter = DetailTeamPagerAdapter(supportFragmentManager)
mDetailTeamPagerAdapter.addFrag(OverviewTeamFragment.newInstance(teamDescription), "Overview")
mDetailTeamPagerAdapter.addFrag(PlayersTeamFragment(), "Players")

viewPager.adapter = mDetailTeamPagerAdapter
viewPager.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabLayout))
tabLayout.addOnTabSelectedListener(TabLayout.ViewPagerOnTabSelectedListener(viewPager))

}

Expand All @@ -107,7 +131,7 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView {

if (isFavorite) {
presenter.removeFromFavoriteTeam(ctx, teams.teamId)
snackbar(swipeRefresh, "Removed from FavoriteTeams").show()
snackbar(linearLayout, "Removed from FavoriteTeams").show()
}
else {
presenter.addToFavoriteTeam(ctx,
Expand All @@ -118,7 +142,7 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView {
teams.teamStadium,
teams.teamDescription
)
snackbar(swipeRefresh, "Added to FavoriteTeams").show()
snackbar(linearLayout, "Added to FavoriteTeams").show()
}

isFavorite = !isFavorite
Expand Down Expand Up @@ -146,12 +170,12 @@ class DetailTeamActivity : AppCompatActivity(), DetailTeamView {
data[0].teamStadium,
data[0].teamDescription)

swipeRefresh.isRefreshing = false
Picasso.get().load(data[0].teamBadge).into(teamBadge)
teamName.text = data[0].teamName
teamDescription.text = data[0].teamDescription
teamFormedYear.text = data[0].teamFormedYear
teamStadium.text = data[0].teamStadium

//teamDescription = data[0].teamDescription.toString()
}

// fungsi untuk menandai tim yang favorite
Expand Down
Loading

0 comments on commit 93ad0ef

Please sign in to comment.