Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ interface FootballDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertStandings(standings: List<StandingsEntity>)

@Query("SELECT * FROM STANDINGS_TABLE WHERE leagueId =:leagueId AND season =:season")
@Query("SELECT * FROM STANDINGS_TABLE WHERE leagueId =:leagueId AND season =:season ORDER BY rank")
fun getAllStandings(leagueId:Int,season:Int): List<StandingsEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.pancake.footballfever.ui.club_standing

import com.pancake.footballfever.R
import com.pancake.footballfever.domain.models.Standings
import com.pancake.footballfever.ui.base.BaseAdapter

class ClubStandingAdapter(listener: ClubStandingListener) : BaseAdapter<Standings>(listener) {
override val getLayoutId: Int
get() = R.layout.item_club_standing

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.pancake.footballfever.ui.club_standing

import android.os.Bundle
import androidx.fragment.app.viewModels
import com.pancake.footballfever.R
import com.pancake.footballfever.databinding.FragmentClubStandingBinding
import com.pancake.footballfever.ui.base.BaseFragment
import dagger.hilt.android.AndroidEntryPoint

private const val TEAM_ID = "teamId"
private const val SEASON = "season"

@AndroidEntryPoint
class ClubStandingFragment : BaseFragment<FragmentClubStandingBinding, ClubStandingViewModel>() {
override val layoutId = R.layout.fragment_club_standing
override val viewModel: ClubStandingViewModel by viewModels()

override fun setup() {
val adapter = ClubStandingAdapter(viewModel)
binding.recyclerStandingLeague.adapter = adapter

}

companion object {
@JvmStatic
fun newInstance(teamId: Int, season: Int) =
ClubStandingFragment().apply {
arguments = Bundle().apply {
putString(TEAM_ID, "$teamId")
putString(SEASON, "$season")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pancake.footballfever.ui.club_standing

import com.pancake.footballfever.ui.base.BaseAdapterListener

interface ClubStandingListener: BaseAdapterListener {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pancake.footballfever.ui.club_standing

import com.pancake.footballfever.domain.models.Standings

data class ClubStandingUIState(
val standings: List<Standings>? = null,
val isLoading: Boolean = true,
val errors: Error? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.pancake.footballfever.ui.club_standing

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.pancake.footballfever.domain.usecases.leagueStandingUseCase.FetchStandingsAndCacheUseCase
import com.pancake.footballfever.domain.usecases.leagueStandingUseCase.GetCachedStandingsUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import javax.inject.Inject

private const val HOME_TEAM_ID = "teamId"
private const val SEASON = "season"
@HiltViewModel
class ClubStandingViewModel @Inject constructor(
private val fetchStandingsAndCacheUseCase: FetchStandingsAndCacheUseCase,
private val getCachedStandingsUseCase: GetCachedStandingsUseCase,
savedStateHandle: SavedStateHandle
) : ViewModel(), ClubStandingListener {
private val _uiState = MutableStateFlow(ClubStandingUIState())
val uiState: StateFlow<ClubStandingUIState> = _uiState
val teamId = savedStateHandle.get<Int>(HOME_TEAM_ID)!!
val season = savedStateHandle.get<Int>(SEASON)!!

init {

viewModelScope.launch(Dispatchers.IO) {

fetchStandingsAndCacheUseCase.invoke(teamId, season)

_uiState.update {
it.copy(
isLoading = false,
standings = getCachedStandingsUseCase.invoke(teamId, season)
)
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.bumptech.glide.Glide
import com.pancake.footballfever.R
import com.pancake.footballfever.ui.base.BaseAdapter
import com.pancake.footballfever.ui.home.HomeUiState
import com.pancake.footballfever.ui.home.HomeViewModel
import com.pancake.footballfever.ui.home.adapter.FixtureHomeListener
import com.pancake.footballfever.ui.home.adapter.ParentHomeAdapter

Expand All @@ -31,7 +30,7 @@ fun setImageUrl(image: ImageView, url: String?) {
fun ProgressBar.showIfLoading(isLoading: Boolean) {
visibility = when (isLoading) {
true -> View.VISIBLE
false -> View.INVISIBLE
false -> View.GONE
}
}

Expand Down
71 changes: 71 additions & 0 deletions app/src/main/res/layout/fragment_club_standing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="viewModel"
type="com.pancake.footballfever.ui.club_standing.ClubStandingViewModel" />

</data>

<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Primary_color">

<TableRow
android:background="@drawable/table_header_background"
android:padding="@dimen/semi_large_padding">

<TextView
style="@style/table_column"
android:text="@string/pos" />

<TextView
android:layout_width="@dimen/no_width"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/semi_large_margin"
android:layout_weight="1"
android:text="@string/team"
android:textColor="@color/white87" />

<TextView
style="@style/table_column"
android:layout_marginStart="@dimen/semi_large_margin"
android:text="@string/p" />

<TextView
style="@style/table_column"
android:layout_marginStart="@dimen/semi_large_margin"
android:text="@string/w" />

<TextView
style="@style/table_column"
android:layout_marginStart="@dimen/semi_large_margin"
android:text="@string/pts" />

</TableRow>
<ProgressBar
android:id="@+id/progress_bar_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:showIfLoading="@{viewModel.uiState.loading}"
/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_standing_league"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:setRecyclerItems="@{viewModel.uiState.standings}"
tools:listitem="@layout/item_standings" />
</TableLayout>
</layout>
75 changes: 75 additions & 0 deletions app/src/main/res/layout/item_club_standing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<layout 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">

<data>


<variable
name="item"
type="com.pancake.footballfever.domain.models.Standings" />

</data>


<TableRow
android:id="@+id/club_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/Primary_color"
android:padding="@dimen/semi_large_padding">

<TextView
style="@style/table_column"
android:text="@{String.valueOf(item.rank)}"
tools:text="@string/rank_value" />

<LinearLayout
android:layout_width="@dimen/no_width"
android:layout_marginStart="@dimen/semi_large_margin"
android:layout_weight="1">

<ImageView
android:layout_width="@dimen/standings_team_logo_width"
android:layout_height="@dimen/standings_team_logo_height"
app:setImageUrl="@{item.teamLogoUrl}"
tools:src="@drawable/arsenal_logo" />

<TextView
android:layout_width="@dimen/no_width"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/small_margin"
android:layout_weight="1"
android:text="@{item.teamName}"
android:textColor="@color/white87"
android:textSize="@dimen/text_small"
tools:text="Arsenal" />

</LinearLayout>

<TextView
style="@style/table_column"
android:layout_marginStart="@dimen/semi_large_margin"
android:text="@{String.valueOf(item.played)}"
tools:text="@string/played_value" />

<TextView
style="@style/table_column"
android:layout_marginStart="@dimen/semi_large_margin"
android:text="@{String.valueOf(item.win)}"
tools:text="@string/win_value" />

<TextView
android:layout_width="@dimen/width_text_header_standings_table"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/semi_large_margin"
android:gravity="center"
android:text="@{String.valueOf(item.points)}"
android:textColor="@color/white87"
tools:text="@string/pts_value" />


</TableRow>

</layout>
4 changes: 4 additions & 0 deletions app/src/main/res/navigation/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,9 @@
android:id="@+id/action_splashFragment_to_homeFragment"
app:destination="@id/homeFragment" />
</fragment>
<fragment
android:id="@+id/clubStandingFragment"
android:name="com.pancake.footballfever.ui.club_standing.ClubStandingFragment"
android:label="ClubStandingFragment" />

</navigation>