From bcef1d0c983ed2380189e2042c32e72b56eb3676 Mon Sep 17 00:00:00 2001 From: Gautam Shorewala <123801344+GautamCoder4019k@users.noreply.github.com> Date: Fri, 5 Jan 2024 22:20:41 +0530 Subject: [PATCH] fix #43: the state of selected tag is now saved --- .../com/example/findissues/ui/issues/IssuesFragment.kt | 8 +++++++- .../com/example/findissues/ui/issues/IssuesViewModel.kt | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/findissues/ui/issues/IssuesFragment.kt b/app/src/main/java/com/example/findissues/ui/issues/IssuesFragment.kt index 3fc0f4e..f4321b0 100644 --- a/app/src/main/java/com/example/findissues/ui/issues/IssuesFragment.kt +++ b/app/src/main/java/com/example/findissues/ui/issues/IssuesFragment.kt @@ -25,7 +25,7 @@ class IssuesFragment : Fragment() { private lateinit var viewModel: IssuesViewModel private var listState by mutableStateOf(emptyList()) var isLoading by mutableStateOf(false) - + private var storedTag = "" override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { @@ -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 -> { diff --git a/app/src/main/java/com/example/findissues/ui/issues/IssuesViewModel.kt b/app/src/main/java/com/example/findissues/ui/issues/IssuesViewModel.kt index 2a350f5..0064d5e 100644 --- a/app/src/main/java/com/example/findissues/ui/issues/IssuesViewModel.kt +++ b/app/src/main/java/com/example/findissues/ui/issues/IssuesViewModel.kt @@ -16,7 +16,8 @@ class IssuesViewModel @Inject constructor( private val repository: DataRepository ) : ViewModel() { private var issueLiveData = MutableStateFlow(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