From d3c9f3fc9d60a93908721d0878bc1343a2bd25ea Mon Sep 17 00:00:00 2001 From: Mohamed Ragab Date: Fri, 23 Jun 2023 09:46:23 +0300 Subject: [PATCH 1/9] edit standing query --- .../footballfever/data/local/database/daos/FootballDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/pancake/footballfever/data/local/database/daos/FootballDao.kt b/app/src/main/java/com/pancake/footballfever/data/local/database/daos/FootballDao.kt index 407e18c3..841b6958 100644 --- a/app/src/main/java/com/pancake/footballfever/data/local/database/daos/FootballDao.kt +++ b/app/src/main/java/com/pancake/footballfever/data/local/database/daos/FootballDao.kt @@ -46,6 +46,6 @@ interface FootballDao { @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertStandings(standings: List) - @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 } \ No newline at end of file From 6aec849b50af78f6583a99734408352d29c2a50d Mon Sep 17 00:00:00 2001 From: Mohamed Ragab Date: Fri, 23 Jun 2023 09:47:46 +0300 Subject: [PATCH 2/9] edit binding adapter --- .../java/com/pancake/footballfever/utilities/BindingAdapter.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/pancake/footballfever/utilities/BindingAdapter.kt b/app/src/main/java/com/pancake/footballfever/utilities/BindingAdapter.kt index 848cafde..59f2cb86 100644 --- a/app/src/main/java/com/pancake/footballfever/utilities/BindingAdapter.kt +++ b/app/src/main/java/com/pancake/footballfever/utilities/BindingAdapter.kt @@ -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 @@ -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 } } From 9fdaf31dddce72cb6ec2b36b9b53f5e2378aab94 Mon Sep 17 00:00:00 2001 From: Mohamed Ragab Date: Fri, 23 Jun 2023 09:48:33 +0300 Subject: [PATCH 3/9] add club standing ui state --- .../ui/clupStanding/ClubStandingListener.kt | 7 ++ .../ui/clupStanding/ClubStandingUIState.kt | 9 +++ .../main/res/layout/item_club_standing.xml | 75 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingListener.kt create mode 100644 app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingUIState.kt create mode 100644 app/src/main/res/layout/item_club_standing.xml diff --git a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingListener.kt b/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingListener.kt new file mode 100644 index 00000000..f5591ce8 --- /dev/null +++ b/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingListener.kt @@ -0,0 +1,7 @@ +package com.pancake.footballfever.ui.clupStanding + +import com.pancake.footballfever.ui.base.BaseAdapterListener + +interface ClubStandingListener: BaseAdapterListener { + +} \ No newline at end of file diff --git a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingUIState.kt b/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingUIState.kt new file mode 100644 index 00000000..170d0af3 --- /dev/null +++ b/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingUIState.kt @@ -0,0 +1,9 @@ +package com.pancake.footballfever.ui.clupStanding + +import com.pancake.footballfever.domain.models.Standings + +data class ClubStandingUIState( + val standings: List? = null, + val isLoading: Boolean = true, + val errors: Error? = null +) \ No newline at end of file diff --git a/app/src/main/res/layout/item_club_standing.xml b/app/src/main/res/layout/item_club_standing.xml new file mode 100644 index 00000000..2efe78d4 --- /dev/null +++ b/app/src/main/res/layout/item_club_standing.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From b4fccd8add465d41f031c3a4633d82658299e805 Mon Sep 17 00:00:00 2001 From: Mohamed Ragab Date: Fri, 23 Jun 2023 09:49:00 +0300 Subject: [PATCH 4/9] add club standing adapter --- .../ui/clupStanding/ClubStandingAdapter.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingAdapter.kt diff --git a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingAdapter.kt b/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingAdapter.kt new file mode 100644 index 00000000..03e28ed6 --- /dev/null +++ b/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingAdapter.kt @@ -0,0 +1,11 @@ +package com.pancake.footballfever.ui.clupStanding + +import com.pancake.footballfever.R +import com.pancake.footballfever.domain.models.Standings +import com.pancake.footballfever.ui.base.BaseAdapter + +class ClubStandingAdapter(listener: ClubStandingListener) : BaseAdapter(listener) { + override val getLayoutId: Int + get() = R.layout.item_club_standing + +} \ No newline at end of file From c453014c201a48729e421ad17091d2b118157b4d Mon Sep 17 00:00:00 2001 From: Mohamed Ragab Date: Fri, 23 Jun 2023 09:49:18 +0300 Subject: [PATCH 5/9] add club standing view model --- .../ui/clupStanding/ClubStandingViewModel.kt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingViewModel.kt diff --git a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingViewModel.kt b/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingViewModel.kt new file mode 100644 index 00000000..34bdc518 --- /dev/null +++ b/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingViewModel.kt @@ -0,0 +1,39 @@ +package com.pancake.footballfever.ui.clupStanding + +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 + +@HiltViewModel +class ClubStandingViewModel @Inject constructor( + private val fetchStandingsAndCacheUseCase: FetchStandingsAndCacheUseCase, + private val getCachedStandingsUseCase: GetCachedStandingsUseCase, +) : ViewModel(), ClubStandingListener { + private val _uiState = MutableStateFlow(ClubStandingUIState()) + val uiState: StateFlow = _uiState + + + init { + + viewModelScope.launch(Dispatchers.IO) { + + fetchStandingsAndCacheUseCase.invoke(39, 2019) + + _uiState.update { + it.copy( + isLoading = false, + standings = getCachedStandingsUseCase.invoke(39, 2019) + ) + } + + } + } +} \ No newline at end of file From 26479cf97f5664bd34b4f6caf02ee93821e8e2b6 Mon Sep 17 00:00:00 2001 From: Mohamed Ragab Date: Fri, 23 Jun 2023 09:49:42 +0300 Subject: [PATCH 6/9] add club standing fragment --- .../ui/clupStanding/ClubStandingFragment.kt | 34 +++++++++ .../res/layout/fragment_club_standing.xml | 71 +++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingFragment.kt create mode 100644 app/src/main/res/layout/fragment_club_standing.xml diff --git a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingFragment.kt b/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingFragment.kt new file mode 100644 index 00000000..7cd0c609 --- /dev/null +++ b/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingFragment.kt @@ -0,0 +1,34 @@ +package com.pancake.footballfever.ui.clupStanding + +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() { + 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") + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_club_standing.xml b/app/src/main/res/layout/fragment_club_standing.xml new file mode 100644 index 00000000..d4aafe92 --- /dev/null +++ b/app/src/main/res/layout/fragment_club_standing.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 07a7e9e2c3f784642f18223ecae795a20bc19afa Mon Sep 17 00:00:00 2001 From: Mohamed Ragab Date: Fri, 23 Jun 2023 09:50:05 +0300 Subject: [PATCH 7/9] add club standing fragment to navigation --- app/src/main/res/navigation/navigation.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/res/navigation/navigation.xml b/app/src/main/res/navigation/navigation.xml index 2df0edfa..e550d830 100644 --- a/app/src/main/res/navigation/navigation.xml +++ b/app/src/main/res/navigation/navigation.xml @@ -103,5 +103,9 @@ android:id="@+id/action_splashFragment_to_homeFragment" app:destination="@id/homeFragment" /> + \ No newline at end of file From 65282c663f5ffa988b0d289fb6c30ee3de384426 Mon Sep 17 00:00:00 2001 From: Mohamed Ragab Date: Fri, 23 Jun 2023 10:21:49 +0300 Subject: [PATCH 8/9] change package name --- .../ui/{clupStanding => club_standing}/ClubStandingAdapter.kt | 2 +- .../ui/{clupStanding => club_standing}/ClubStandingFragment.kt | 2 +- .../ui/{clupStanding => club_standing}/ClubStandingListener.kt | 2 +- .../ui/{clupStanding => club_standing}/ClubStandingUIState.kt | 2 +- .../ui/{clupStanding => club_standing}/ClubStandingViewModel.kt | 2 +- app/src/main/res/layout/fragment_club_standing.xml | 2 +- app/src/main/res/navigation/navigation.xml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename app/src/main/java/com/pancake/footballfever/ui/{clupStanding => club_standing}/ClubStandingAdapter.kt (86%) rename app/src/main/java/com/pancake/footballfever/ui/{clupStanding => club_standing}/ClubStandingFragment.kt (95%) rename app/src/main/java/com/pancake/footballfever/ui/{clupStanding => club_standing}/ClubStandingListener.kt (70%) rename app/src/main/java/com/pancake/footballfever/ui/{clupStanding => club_standing}/ClubStandingUIState.kt (79%) rename app/src/main/java/com/pancake/footballfever/ui/{clupStanding => club_standing}/ClubStandingViewModel.kt (96%) diff --git a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingAdapter.kt b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingAdapter.kt similarity index 86% rename from app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingAdapter.kt rename to app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingAdapter.kt index 03e28ed6..77c81fb6 100644 --- a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingAdapter.kt +++ b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingAdapter.kt @@ -1,4 +1,4 @@ -package com.pancake.footballfever.ui.clupStanding +package com.pancake.footballfever.ui.club_standing import com.pancake.footballfever.R import com.pancake.footballfever.domain.models.Standings diff --git a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingFragment.kt b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingFragment.kt similarity index 95% rename from app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingFragment.kt rename to app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingFragment.kt index 7cd0c609..2ccf50b5 100644 --- a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingFragment.kt +++ b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingFragment.kt @@ -1,4 +1,4 @@ -package com.pancake.footballfever.ui.clupStanding +package com.pancake.footballfever.ui.club_standing import android.os.Bundle import androidx.fragment.app.viewModels diff --git a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingListener.kt b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingListener.kt similarity index 70% rename from app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingListener.kt rename to app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingListener.kt index f5591ce8..c52b243d 100644 --- a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingListener.kt +++ b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingListener.kt @@ -1,4 +1,4 @@ -package com.pancake.footballfever.ui.clupStanding +package com.pancake.footballfever.ui.club_standing import com.pancake.footballfever.ui.base.BaseAdapterListener diff --git a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingUIState.kt b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingUIState.kt similarity index 79% rename from app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingUIState.kt rename to app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingUIState.kt index 170d0af3..230c2f83 100644 --- a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingUIState.kt +++ b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingUIState.kt @@ -1,4 +1,4 @@ -package com.pancake.footballfever.ui.clupStanding +package com.pancake.footballfever.ui.club_standing import com.pancake.footballfever.domain.models.Standings diff --git a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingViewModel.kt b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingViewModel.kt similarity index 96% rename from app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingViewModel.kt rename to app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingViewModel.kt index 34bdc518..c8b34768 100644 --- a/app/src/main/java/com/pancake/footballfever/ui/clupStanding/ClubStandingViewModel.kt +++ b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingViewModel.kt @@ -1,4 +1,4 @@ -package com.pancake.footballfever.ui.clupStanding +package com.pancake.footballfever.ui.club_standing import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope diff --git a/app/src/main/res/layout/fragment_club_standing.xml b/app/src/main/res/layout/fragment_club_standing.xml index d4aafe92..35bdd944 100644 --- a/app/src/main/res/layout/fragment_club_standing.xml +++ b/app/src/main/res/layout/fragment_club_standing.xml @@ -7,7 +7,7 @@ + type="com.pancake.footballfever.ui.club_standing.ClubStandingViewModel" /> diff --git a/app/src/main/res/navigation/navigation.xml b/app/src/main/res/navigation/navigation.xml index e550d830..79c64748 100644 --- a/app/src/main/res/navigation/navigation.xml +++ b/app/src/main/res/navigation/navigation.xml @@ -105,7 +105,7 @@ \ No newline at end of file From d6b99fb956243b0bfbebc04662637f72777a8580 Mon Sep 17 00:00:00 2001 From: Mohamed Ragab Date: Fri, 23 Jun 2023 16:53:29 +0300 Subject: [PATCH 9/9] add save state handle to view model --- .../ui/club_standing/ClubStandingViewModel.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingViewModel.kt b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingViewModel.kt index c8b34768..262e7011 100644 --- a/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingViewModel.kt +++ b/app/src/main/java/com/pancake/footballfever/ui/club_standing/ClubStandingViewModel.kt @@ -1,5 +1,6 @@ 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 @@ -12,25 +13,29 @@ 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 = _uiState - + val teamId = savedStateHandle.get(HOME_TEAM_ID)!! + val season = savedStateHandle.get(SEASON)!! init { viewModelScope.launch(Dispatchers.IO) { - fetchStandingsAndCacheUseCase.invoke(39, 2019) + fetchStandingsAndCacheUseCase.invoke(teamId, season) _uiState.update { it.copy( isLoading = false, - standings = getCachedStandingsUseCase.invoke(39, 2019) + standings = getCachedStandingsUseCase.invoke(teamId, season) ) }