Skip to content

Commit

Permalink
Avoid to reload feeds on every click of navigation drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
sLee0306 committed Dec 15, 2023
1 parent 3f7be0b commit 5c9e480
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions app/src/main/java/com/sample/android/tmdb/ui/feed/FeedFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.runtime.Composable
import com.sample.android.tmdb.domain.model.FeedWrapper
import com.sample.android.tmdb.domain.model.TmdbItem
import com.sample.android.tmdb.ui.base.BaseNavigationFragment
import com.sample.android.tmdb.ui.common.Content
Expand All @@ -12,22 +14,36 @@ import com.sample.android.tmdb.ui.common.composeView

abstract class FeedFragment<T : TmdbItem> : BaseNavigationFragment<Nothing>() {

private var feeds: List<FeedWrapper<T>>? = null

protected abstract val viewModel: FeedViewModel<T>

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View = composeView {
TmdbTheme {
Content(viewModel) {
FeedCollectionList(
navType,
it
) { tmdbItem ->
startDetailActivity(tmdbItem)
): View {
return composeView {
TmdbTheme {
if (feeds == null) {
Content(viewModel) {
feeds = it
FeedCollectionScreen()
}
} else {
FeedCollectionScreen()
}
}
}
}

@Composable
private fun FeedCollectionScreen() {
FeedCollectionList(
navType,
feeds!!
) { tmdbItem ->
startDetailActivity(tmdbItem)
}
}
}

0 comments on commit 5c9e480

Please sign in to comment.