Skip to content

Commit

Permalink
fix PratyushSingh07#43: the state of selected tag is now saved
Browse files Browse the repository at this point in the history
  • Loading branch information
GautamCoder4019k authored and PratyushSingh07 committed Jan 5, 2024
1 parent 436f80e commit bcef1d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class IssuesFragment : Fragment() {
private lateinit var viewModel: IssuesViewModel
private var listState by mutableStateOf(emptyList<IssuesList>())
var isLoading by mutableStateOf(false)

private var storedTag = ""
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
Expand All @@ -39,11 +39,17 @@ class IssuesFragment : Fragment() {
}
}

override fun onPause() {
storedTag = viewModel.tag
super.onPause()
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.getIssueLink()
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.tagSelected(storedTag)
viewModel.observeIssueLiveData().collect {
when (it) {
is IssuesUiState.Loading -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class IssuesViewModel @Inject constructor(
private val repository: DataRepository
) : ViewModel() {
private var issueLiveData = MutableStateFlow<IssuesUiState>(IssuesUiState.Loading)
private val tags = listOf("Kotlin", "Java", "Python","Rust","React.js","Go","Javascript","Node.js")
private val tags =
listOf("Kotlin", "Java", "Python", "Rust", "React.js", "Go", "Javascript", "Node.js")
var tag = ""
private set

Expand Down

0 comments on commit bcef1d0

Please sign in to comment.