Created
November 1, 2019 10:08
-
-
Save alfianyusufabdullah/b2381fbb7e726fee67f87c7118a219b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/activity_main" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:fitsSystemWindows="true" | |
android:orientation="vertical"> | |
<com.google.android.material.appbar.AppBarLayout | |
android:id="@+id/appbar" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fitsSystemWindows="true" | |
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> | |
<com.google.android.material.appbar.CollapsingToolbarLayout | |
android:id="@+id/collapsing" | |
android:layout_width="match_parent" | |
android:layout_height="300dp" | |
android:fitsSystemWindows="true" | |
app:contentScrim="?attr/colorPrimary" | |
app:expandedTitleMarginEnd="64dp" | |
app:expandedTitleMarginStart="48dp" | |
app:layout_scrollFlags="scroll|exitUntilCollapsed"> | |
<ImageView | |
android:id="@+id/league_badge" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:fitsSystemWindows="true" | |
android:scaleType="centerCrop" | |
app:layout_collapseMode="parallax"/> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<ImageView | |
android:id="@+id/league_logo" | |
android:layout_width="100dp" | |
android:layout_height="100dp" | |
android:layout_marginEnd="32dp" | |
android:layout_marginBottom="?attr/actionBarSize" | |
android:paddingBottom="32dp" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
tools:src="@drawable/english" /> | |
<TextView | |
android:id="@+id/name_league" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="28dp" | |
android:textColor="@android:color/white" | |
android:textSize="28sp" | |
app:layout_constraintTop_toTopOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
android:layout_marginStart="28dp" | |
tools:text="@string/name_league" | |
android:shadowColor="#000" | |
android:shadowDx="1" | |
android:shadowDy="1" | |
android:shadowRadius="2"/> | |
<TextView | |
android:id="@+id/text_location" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="8dp" | |
android:text="@string/location" | |
android:textSize="14sp" | |
android:textColor="@android:color/white" | |
app:layout_constraintStart_toStartOf="@id/name_league" | |
app:layout_constraintTop_toBottomOf="@+id/name_league" | |
android:shadowColor="#000" | |
android:shadowDx="1" | |
android:shadowDy="1" | |
android:shadowRadius="2"/> | |
<TextView | |
android:id="@+id/league_loc" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:lineSpacingMultiplier="1" | |
android:textColor="@android:color/white" | |
app:layout_constraintTop_toBottomOf="@id/text_location" | |
app:layout_constraintStart_toStartOf="@id/name_league" | |
tools:text="@string/league_location" | |
android:shadowColor="#000" | |
android:shadowDx="1" | |
android:shadowDy="1" | |
android:shadowRadius="2"/> | |
<TextView | |
android:id="@+id/text_year" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="12dp" | |
android:text="@string/formed_year" | |
android:textSize="14sp" | |
android:textColor="@android:color/white" | |
app:layout_constraintTop_toBottomOf="@id/league_loc" | |
app:layout_constraintStart_toStartOf="@id/name_league" | |
android:shadowColor="#000" | |
android:shadowDx="1" | |
android:shadowDy="1" | |
android:shadowRadius="2"/> | |
<TextView | |
android:id="@+id/league_formed" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:lineSpacingMultiplier="1" | |
android:textColor="@android:color/white" | |
app:layout_constraintTop_toBottomOf="@id/text_year" | |
app:layout_constraintStart_toStartOf="@id/name_league" | |
tools:text="@string/dummy_year" | |
android:shadowColor="#000" | |
android:shadowDx="1" | |
android:shadowDy="1" | |
android:shadowRadius="2"/> | |
</androidx.constraintlayout.widget.ConstraintLayout> | |
<androidx.appcompat.widget.Toolbar | |
android:id="@+id/detail_toolbar" | |
android:layout_width="match_parent" | |
android:layout_height="?attr/actionBarSize" | |
android:layout_gravity="top" | |
android:layout_marginBottom="48dp" | |
app:layout_collapseMode="pin" | |
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> | |
<com.google.android.material.tabs.TabLayout | |
android:id="@+id/tabs" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_gravity="bottom" | |
app:tabIndicatorColor="@android:color/white" | |
app:tabSelectedTextColor="@android:color/white" | |
app:tabTextColor="@android:color/white"/> | |
</com.google.android.material.appbar.CollapsingToolbarLayout> | |
</com.google.android.material.appbar.AppBarLayout> | |
<androidx.core.widget.NestedScrollView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
app:layout_behavior="@string/appbar_scrolling_view_behavior"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
<androidx.viewpager.widget.ViewPager | |
android:id="@+id/view_pager_detail" | |
android:layout_width="match_parent" | |
android:layout_height="600dp"/> | |
</LinearLayout> | |
</androidx.core.widget.NestedScrollView> | |
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dicoding.picodiploma.sejiwaproject.features.league.detail | |
import android.graphics.Color | |
import android.os.Bundle | |
import androidx.appcompat.app.AppCompatActivity | |
import com.bumptech.glide.Glide | |
import com.bumptech.glide.request.RequestOptions | |
import com.dicoding.picodiploma.sejiwaproject.R | |
import com.dicoding.picodiploma.sejiwaproject.commons.api.ApiRepository | |
import com.dicoding.picodiploma.sejiwaproject.features.match.next.NextMatchFragment | |
import com.dicoding.picodiploma.sejiwaproject.features.match.previous.PreviousMatchFragment | |
import com.dicoding.picodiploma.sejiwaproject.features.league.detail.model.League | |
import com.dicoding.picodiploma.sejiwaproject.commons.utils.invisible | |
import com.dicoding.picodiploma.sejiwaproject.commons.utils.visible | |
import com.google.gson.Gson | |
import jp.wasabeef.glide.transformations.BlurTransformation | |
import kotlinx.android.synthetic.main.activity_detail.* | |
class DetailLeagueActivity : AppCompatActivity(), | |
DetailView { | |
private var leagues: MutableList<League> = mutableListOf() | |
private lateinit var presenter: DetailPresenter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_detail) | |
val nameLeague = intent.getStringExtra(EXTRA_KEY) | |
val request = ApiRepository() | |
val gson = Gson() | |
presenter = DetailPresenter( | |
this, | |
request, | |
gson | |
) | |
presenter.getDetailList(nameLeague) | |
val sectionsPagerAdapter = | |
DetailPagerAdapter( | |
supportFragmentManager | |
) | |
sectionsPagerAdapter.populateFragment( | |
PreviousMatchFragment.newInstance( | |
nameLeague ?: "4328" | |
), "Previous Match" | |
) | |
sectionsPagerAdapter.populateFragment( | |
NextMatchFragment.newInstance(nameLeague ?: "4328"), | |
"Next Match" | |
) | |
view_pager_detail.adapter = sectionsPagerAdapter | |
tabs.setupWithViewPager(view_pager_detail) | |
detail_toolbar.title = "Detail League" | |
collapsing.setExpandedTitleColor(Color.TRANSPARENT) | |
collapsing.setCollapsedTitleTextColor(Color.WHITE) | |
} | |
companion object { | |
const val EXTRA_KEY = "extra_key" | |
} | |
override fun showLoading() { | |
} | |
override fun hideLoading() { | |
} | |
override fun showDetailList(data: List<League>) { | |
if (data[0].teamName.isNullOrEmpty()) { | |
name_league.invisible() | |
league_loc.invisible() | |
league_formed.invisible() | |
league_badge.invisible() | |
league_logo.invisible() | |
} else { | |
name_league.text = data[0].teamName | |
league_loc.text = data[0].teamLocation | |
league_formed.text = data[0].teamFormed | |
Glide.with(this) | |
.load(data[0].teamPoster) | |
.apply(RequestOptions().override(550, 550)) | |
.apply(RequestOptions.bitmapTransform(BlurTransformation(20, 3))) | |
.into(league_badge) | |
/// implementation 'jp.wasabeef:glide-transformations:4.1.0' | |
Glide.with(this) | |
.load(data[0].teamLogo) | |
.apply(RequestOptions().override(550, 550)) | |
.into(league_logo) | |
} | |
leagues.clear() | |
leagues.addAll(data) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dicoding.picodiploma.sejiwaproject.features.match.previous | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import android.widget.ImageView | |
import android.widget.TextView | |
import androidx.recyclerview.widget.RecyclerView | |
import com.bumptech.glide.Glide | |
import com.dicoding.picodiploma.sejiwaproject.R | |
import com.dicoding.picodiploma.sejiwaproject.features.match.detail.DetailMatchActivity | |
import com.dicoding.picodiploma.sejiwaproject.features.match.detail.DetailMatchActivity.Companion.EXTRA_ID | |
import com.dicoding.picodiploma.sejiwaproject.features.match.previous.model.Matchs | |
import org.jetbrains.anko.startActivity | |
class PreviousMatchAdapter(private val list: MutableList<Matchs>) : RecyclerView.Adapter<PreviousMatchAdapter.MatchViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MatchViewHolder { | |
val view: View = LayoutInflater.from(parent.context).inflate(R.layout.item_previous_match, parent, false) | |
return MatchViewHolder(view) | |
} | |
override fun getItemCount(): Int = list.size | |
fun addMatches(matchs: Matchs){ | |
list.add(matchs) | |
notifyItemInserted(list.size - 1) | |
} | |
override fun onBindViewHolder(holder: MatchViewHolder, position: Int) { | |
val match = list[position] | |
holder.matchTitle.text = match.matchTitle | |
holder.homeTeam.text = match.teamHome | |
holder.awayTeam.text = match.teamAway | |
holder.homeScore.text = match.homeScore | |
holder.awayScore.text = match.awayScore | |
holder.dateMatch.text = match.dateMatch | |
Glide.with(holder.itemView) | |
.load(match.badgeHome) | |
.into(holder.homeLogo) | |
Glide.with(holder.itemView) | |
.load(match.badgeAway) | |
.into(holder.awayLogo) | |
holder.itemView.setOnClickListener { | |
it.context.startActivity<DetailMatchActivity>(EXTRA_ID to match.matchId) | |
} | |
} | |
inner class MatchViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
val matchTitle: TextView = itemView.findViewById(R.id.match_title) | |
val homeTeam: TextView = itemView.findViewById(R.id.team_home) | |
val awayTeam: TextView = itemView.findViewById(R.id.team_away) | |
val homeScore: TextView = itemView.findViewById(R.id.home_score) | |
val awayScore: TextView = itemView.findViewById(R.id.away_score) | |
val dateMatch: TextView = itemView.findViewById(R.id.date_match) | |
val homeLogo: ImageView = itemView.findViewById(R.id.home_logo) | |
val awayLogo: ImageView = itemView.findViewById(R.id.away_logo) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dicoding.picodiploma.sejiwaproject.features.match.previous | |
import android.os.Bundle | |
import android.util.Log | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.fragment.app.Fragment | |
import androidx.recyclerview.widget.LinearLayoutManager | |
import androidx.recyclerview.widget.RecyclerView | |
import com.dicoding.picodiploma.sejiwaproject.R | |
import com.dicoding.picodiploma.sejiwaproject.commons.api.ApiRepository | |
import com.dicoding.picodiploma.sejiwaproject.commons.utils.invisible | |
import com.dicoding.picodiploma.sejiwaproject.commons.utils.visible | |
import com.dicoding.picodiploma.sejiwaproject.features.match.previous.model.Matchs | |
import com.google.gson.Gson | |
import kotlinx.android.synthetic.main.fragment_next_match.* | |
/** | |
* A placeholder fragment containing a simple view. | |
*/ | |
class PreviousMatchFragment : Fragment(), | |
PreviousMatchView { | |
private lateinit var rvMatch: RecyclerView | |
private lateinit var presenter: PreviousMatchPresenter | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { | |
return inflater.inflate(R.layout.fragment_previous_match, container, false) | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
val listLeagueAdapter = PreviousMatchAdapter(mutableListOf()) | |
rvMatch = view.findViewById(R.id.rv_previous_match) | |
rvMatch.setHasFixedSize(true) | |
rvMatch.layoutManager = LinearLayoutManager(context) | |
rvMatch.adapter = listLeagueAdapter | |
val id = arguments?.getString(ID_LEAGUE) | |
val request = ApiRepository() | |
val gson = Gson() | |
presenter = | |
PreviousMatchPresenter( | |
this, | |
request, | |
gson | |
) | |
presenter.getPreviousMatch(id ?: "4328") | |
} | |
companion object { | |
private const val ID_LEAGUE = "id" | |
/** | |
* Returns a new instance of this fragment for the given section | |
* number. | |
*/ | |
@JvmStatic | |
fun newInstance(idLeague: String): PreviousMatchFragment { | |
return PreviousMatchFragment() | |
.apply { | |
arguments = Bundle().apply { | |
putString(ID_LEAGUE, idLeague) | |
} | |
} | |
} | |
} | |
override fun showLoading() { | |
progress_bar.visible() | |
} | |
override fun hideLoading() { | |
progress_bar.invisible() | |
} | |
override fun matchReady(matchs: Matchs) { | |
progress_bar.invisible() | |
(rvMatch.adapter as PreviousMatchAdapter).addMatches(matchs) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dicoding.picodiploma.sejiwaproject.features.match.previous | |
import com.dicoding.picodiploma.sejiwaproject.commons.api.ApiRepository | |
import com.dicoding.picodiploma.sejiwaproject.commons.api.TheSportDBApi | |
import com.dicoding.picodiploma.sejiwaproject.features.match.detail.model.LogoTeamResponse | |
import com.dicoding.picodiploma.sejiwaproject.features.match.previous.model.MatchsResponse | |
import com.google.gson.Gson | |
import org.jetbrains.anko.doAsync | |
import org.jetbrains.anko.uiThread | |
class PreviousMatchPresenter( | |
private val view: PreviousMatchView, | |
private val apiRepository: ApiRepository, | |
private val gson: Gson) { | |
fun getPreviousMatch(id: String) { | |
view.showLoading() | |
doAsync { | |
val data = gson.fromJson( | |
apiRepository | |
.doRequest(TheSportDBApi.getPreviousMatches(id)), | |
MatchsResponse::class.java | |
) | |
data.events.map { | |
val homeResponse = gson.fromJson( | |
apiRepository | |
.doRequest(TheSportDBApi.getTeamDetail(it.homeId)), | |
LogoTeamResponse::class.java | |
) | |
val awayResponse = gson.fromJson( | |
apiRepository | |
.doRequest(TheSportDBApi.getTeamDetail(it.awayId)), | |
LogoTeamResponse::class.java | |
) | |
val result = it.copy() | |
result.badgeHome = homeResponse.teams.first().teamLogo | |
result.badgeAway = awayResponse.teams.first().teamLogo | |
uiThread { | |
view.matchReady(result) | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dicoding.picodiploma.sejiwaproject.features.match.previous | |
import com.dicoding.picodiploma.sejiwaproject.features.match.previous.model.Matchs | |
interface PreviousMatchView{ | |
fun showLoading() | |
fun hideLoading() | |
fun matchReady(matchs: Matchs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment