fix: replace Stack with ArrayDeque in SearchableRepositoryViewModel

This commit is contained in:
Harsh Shandilya 2023-06-04 02:18:13 +05:30
parent 469700f627
commit 0669f8a062
No known key found for this signature in database
2 changed files with 3 additions and 15 deletions

View file

@ -81,17 +81,6 @@
column="5"/> column="5"/>
</issue> </issue>
<issue
id="DenyListedApi"
message="For a stack use ArrayDeque which is more efficient internally."
errorLine1=" private val navigationStack = Stack&lt;NavigationStackEntry>()"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/passwordstore/util/viewmodel/SearchableRepositoryViewModel.kt"
line="297"
column="33"/>
</issue>
<issue <issue
id="DenyListedApi" id="DenyListedApi"
message="Use the structured concurrent CoroutineScope#launch and Flow#collect APIs instead of reactive Flow#onEach and Flow#launchIn. Suspend calls like Flow#collect can be refactored into standalone suspend funs and mixed in with regular control flow in a suspend context, but calls that invoke CoroutineScope#launch and Flow#collect at the same time hide the suspend context, encouraging the developer to continue working in the reactive domain." message="Use the structured concurrent CoroutineScope#launch and Flow#collect APIs instead of reactive Flow#onEach and Flow#launchIn. Suspend calls like Flow#collect can be refactored into standalone suspend funs and mixed in with regular control flow in a suspend context, but calls that invoke CoroutineScope#launch and Flow#collect at the same time hide the suspend context, encouraging the developer to continue working in the reactive domain."

View file

@ -35,7 +35,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import java.io.File import java.io.File
import java.text.Collator import java.text.Collator
import java.util.Locale import java.util.Locale
import java.util.Stack
import javax.inject.Inject import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
@ -294,7 +293,7 @@ constructor(
data class NavigationStackEntry(val dir: File, val recyclerViewState: Parcelable?) data class NavigationStackEntry(val dir: File, val recyclerViewState: Parcelable?)
private val navigationStack = Stack<NavigationStackEntry>() private val navigationStack = ArrayDeque<NavigationStackEntry>()
fun navigateTo( fun navigateTo(
newDirectory: File = root, newDirectory: File = root,
@ -305,7 +304,7 @@ constructor(
if (!newDirectory.exists()) return if (!newDirectory.exists()) return
require(newDirectory.isDirectory) { "Can only navigate to a directory" } require(newDirectory.isDirectory) { "Can only navigate to a directory" }
if (pushPreviousLocation) { if (pushPreviousLocation) {
navigationStack.push(NavigationStackEntry(_currentDir.value, recyclerViewState)) navigationStack.addFirst(NavigationStackEntry(_currentDir.value, recyclerViewState))
} }
searchActionFlow.update { searchActionFlow.update {
makeSearchAction( makeSearchAction(
@ -330,7 +329,7 @@ constructor(
*/ */
fun navigateBack(): Parcelable? { fun navigateBack(): Parcelable? {
if (!canNavigateBack) return null if (!canNavigateBack) return null
val (oldDir, oldRecyclerViewState) = navigationStack.pop() val (oldDir, oldRecyclerViewState) = navigationStack.removeFirst()
navigateTo(oldDir, pushPreviousLocation = false) navigateTo(oldDir, pushPreviousLocation = false)
return oldRecyclerViewState return oldRecyclerViewState
} }