No issue: Adds lint exception for when statement (#3685)
parent
309014139d
commit
4994554576
|
@ -77,7 +77,6 @@ class AppRequestInterceptor(private val context: Context) : RequestInterceptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("ComplexMethod")
|
|
||||||
private fun getRiskLevel(errorType: ErrorType): RiskLevel {
|
private fun getRiskLevel(errorType: ErrorType): RiskLevel {
|
||||||
return when (errorType) {
|
return when (errorType) {
|
||||||
// Low risk errors
|
// Low risk errors
|
||||||
|
|
|
@ -65,7 +65,6 @@ class BrowserToolbarBottomBehavior(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MagicNumber")
|
|
||||||
override fun onStopNestedScroll(
|
override fun onStopNestedScroll(
|
||||||
coordinatorLayout: CoordinatorLayout,
|
coordinatorLayout: CoordinatorLayout,
|
||||||
child: BrowserToolbar,
|
child: BrowserToolbar,
|
||||||
|
@ -73,7 +72,7 @@ class BrowserToolbarBottomBehavior(
|
||||||
type: Int
|
type: Int
|
||||||
) {
|
) {
|
||||||
if (shouldSnapAfterScroll || type == TYPE_NON_TOUCH) {
|
if (shouldSnapAfterScroll || type == TYPE_NON_TOUCH) {
|
||||||
if (child.translationY >= (child.height * 0.5f)) {
|
if (child.translationY >= (child.height / 2f)) {
|
||||||
animateSnap(child, SnapDirection.DOWN)
|
animateSnap(child, SnapDirection.DOWN)
|
||||||
} else {
|
} else {
|
||||||
animateSnap(child, SnapDirection.UP)
|
animateSnap(child, SnapDirection.UP)
|
||||||
|
@ -108,7 +107,6 @@ class BrowserToolbarBottomBehavior(
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MagicNumber")
|
|
||||||
private fun positionSnackbar(view: View) {
|
private fun positionSnackbar(view: View) {
|
||||||
val params = view.layoutParams as CoordinatorLayout.LayoutParams
|
val params = view.layoutParams as CoordinatorLayout.LayoutParams
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,6 @@ class BrowserToolbarTopBehavior(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MagicNumber")
|
|
||||||
override fun onStopNestedScroll(
|
override fun onStopNestedScroll(
|
||||||
coordinatorLayout: CoordinatorLayout,
|
coordinatorLayout: CoordinatorLayout,
|
||||||
child: BrowserToolbar,
|
child: BrowserToolbar,
|
||||||
|
@ -73,7 +72,7 @@ class BrowserToolbarTopBehavior(
|
||||||
type: Int
|
type: Int
|
||||||
) {
|
) {
|
||||||
if (shouldSnapAfterScroll || type == TYPE_NON_TOUCH) {
|
if (shouldSnapAfterScroll || type == TYPE_NON_TOUCH) {
|
||||||
if (child.translationY >= (-child.height * 0.5f)) {
|
if (child.translationY >= (-child.height / 2f)) {
|
||||||
animateSnap(child, SnapDirection.DOWN)
|
animateSnap(child, SnapDirection.DOWN)
|
||||||
} else {
|
} else {
|
||||||
animateSnap(child, SnapDirection.UP)
|
animateSnap(child, SnapDirection.UP)
|
||||||
|
@ -108,7 +107,6 @@ class BrowserToolbarTopBehavior(
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MagicNumber")
|
|
||||||
private fun positionSnackbar(view: View) {
|
private fun positionSnackbar(view: View) {
|
||||||
val params = view.layoutParams as CoordinatorLayout.LayoutParams
|
val params = view.layoutParams as CoordinatorLayout.LayoutParams
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@ import androidx.core.content.ContextCompat
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import io.reactivex.Observer
|
import io.reactivex.Observer
|
||||||
import kotlinx.android.synthetic.main.collections_list_item.view.*
|
import kotlinx.android.synthetic.main.collections_list_item.view.*
|
||||||
import kotlinx.android.synthetic.main.collections_list_item.view.collection_description
|
|
||||||
import kotlinx.android.synthetic.main.collections_list_item.view.collection_icon
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
@ -94,7 +92,7 @@ class CollectionViewHolder(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("ComplexMethod", "MagicNumber")
|
@Suppress("MagicNumber")
|
||||||
private fun getIconColor(id: Long): Int {
|
private fun getIconColor(id: Long): Int {
|
||||||
return when ((id % 5).toInt()) {
|
return when ((id % 5).toInt()) {
|
||||||
0 -> R.color.collection_icon_color_violet
|
0 -> R.color.collection_icon_color_violet
|
||||||
|
|
|
@ -234,7 +234,6 @@ sealed class Event {
|
||||||
get() = null
|
get() = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("ComplexMethod")
|
|
||||||
private fun Fact.toEvent(): Event? = when (Pair(component, item)) {
|
private fun Fact.toEvent(): Event? = when (Pair(component, item)) {
|
||||||
Component.FEATURE_FINDINPAGE to "previous" -> Event.FindInPagePrevious
|
Component.FEATURE_FINDINPAGE to "previous" -> Event.FindInPagePrevious
|
||||||
Component.FEATURE_FINDINPAGE to "next" -> Event.FindInPageNext
|
Component.FEATURE_FINDINPAGE to "next" -> Event.FindInPageNext
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.mozilla.fenix.R
|
||||||
|
|
||||||
var rootTitles: Map<String, String> = emptyMap()
|
var rootTitles: Map<String, String> = emptyMap()
|
||||||
|
|
||||||
@SuppressWarnings("ReturnCount", "ComplexMethod")
|
@SuppressWarnings("ComplexMethod")
|
||||||
suspend fun BookmarkNode?.withOptionalDesktopFolders(
|
suspend fun BookmarkNode?.withOptionalDesktopFolders(
|
||||||
context: Context?,
|
context: Context?,
|
||||||
showMobileRoot: Boolean = false
|
showMobileRoot: Boolean = false
|
||||||
|
@ -25,7 +25,7 @@ suspend fun BookmarkNode?.withOptionalDesktopFolders(
|
||||||
val loggedIn = context?.components?.backgroundServices?.accountManager?.authenticatedAccount() != null
|
val loggedIn = context?.components?.backgroundServices?.accountManager?.authenticatedAccount() != null
|
||||||
|
|
||||||
// If we're in the mobile root and logged in, add-in a synthetic "Desktop Bookmarks" folder.
|
// If we're in the mobile root and logged in, add-in a synthetic "Desktop Bookmarks" folder.
|
||||||
if ((this.guid == BookmarkRoot.Mobile.id) && loggedIn) {
|
return if (guid == BookmarkRoot.Mobile.id && loggedIn) {
|
||||||
// We're going to make a copy of the mobile node, and add-in a synthetic child folder to the top of the
|
// We're going to make a copy of the mobile node, and add-in a synthetic child folder to the top of the
|
||||||
// children's list that contains all of the desktop roots.
|
// children's list that contains all of the desktop roots.
|
||||||
val childrenWithVirtualFolder: MutableList<BookmarkNode> = mutableListOf()
|
val childrenWithVirtualFolder: MutableList<BookmarkNode> = mutableListOf()
|
||||||
|
@ -35,21 +35,20 @@ suspend fun BookmarkNode?.withOptionalDesktopFolders(
|
||||||
childrenWithVirtualFolder.addAll(children)
|
childrenWithVirtualFolder.addAll(children)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.copy(children = childrenWithVirtualFolder)
|
copy(children = childrenWithVirtualFolder)
|
||||||
} else if (this.guid == BookmarkRoot.Root.id) {
|
} else if (guid == BookmarkRoot.Root.id) {
|
||||||
return this.copy(
|
copy(
|
||||||
title = rootTitles[this.title],
|
title = rootTitles[this.title],
|
||||||
children = if (showMobileRoot) restructureMobileRoots(context, children)
|
children = if (showMobileRoot) restructureMobileRoots(context, children)
|
||||||
else restructureDesktopRoots(children)
|
else restructureDesktopRoots(children)
|
||||||
)
|
)
|
||||||
|
} else if (guid in listOf(BookmarkRoot.Menu.id, BookmarkRoot.Toolbar.id, BookmarkRoot.Unfiled.id)) {
|
||||||
// If we're looking at one of the desktop roots, change their titles to friendly names.
|
// If we're looking at one of the desktop roots, change their titles to friendly names.
|
||||||
} else if (this.guid in listOf(BookmarkRoot.Menu.id, BookmarkRoot.Toolbar.id, BookmarkRoot.Unfiled.id)) {
|
copy(title = rootTitles[this.title])
|
||||||
return this.copy(title = rootTitles[this.title])
|
} else {
|
||||||
|
// Otherwise, just return the node as-is.
|
||||||
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, just return the node as-is.
|
|
||||||
return this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun virtualDesktopFolder(context: Context?): BookmarkNode? {
|
private suspend fun virtualDesktopFolder(context: Context?): BookmarkNode? {
|
||||||
|
|
|
@ -295,7 +295,6 @@ class HomeFragment : Fragment(), AccountObserver {
|
||||||
requireComponents.backgroundServices.accountManager.register(this, owner = this)
|
requireComponents.backgroundServices.accountManager.register(this, owner = this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ComplexMethod")
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
requireComponents.core.tabCollectionStorage.register(collectionStorageObserver, this)
|
requireComponents.core.tabCollectionStorage.register(collectionStorageObserver, this)
|
||||||
|
@ -441,7 +440,6 @@ class HomeFragment : Fragment(), AccountObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("ComplexMethod")
|
|
||||||
private fun handleCollectionAction(action: CollectionAction) {
|
private fun handleCollectionAction(action: CollectionAction) {
|
||||||
when (action) {
|
when (action) {
|
||||||
is CollectionAction.Expand -> {
|
is CollectionAction.Expand -> {
|
||||||
|
|
|
@ -128,7 +128,6 @@ class SwipeToDeleteCallback(
|
||||||
const val MARGIN = 32
|
const val MARGIN = 32
|
||||||
const val DENSITY_CONVERSION = 160f
|
const val DENSITY_CONVERSION = 160f
|
||||||
|
|
||||||
@Suppress("LongParameterList")
|
|
||||||
private fun draw(
|
private fun draw(
|
||||||
background: Drawable,
|
background: Drawable,
|
||||||
icon: Drawable,
|
icon: Drawable,
|
||||||
|
|
|
@ -117,7 +117,7 @@ class CollectionViewHolder(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("ComplexMethod", "MagicNumber")
|
@Suppress("MagicNumber")
|
||||||
private fun getIconColor(id: Long): Int {
|
private fun getIconColor(id: Long): Int {
|
||||||
val sessionColorIndex = (id % 5).toInt()
|
val sessionColorIndex = (id % 5).toInt()
|
||||||
return when (sessionColorIndex) {
|
return when (sessionColorIndex) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.mozilla.fenix.ext.increaseTapArea
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
class BookmarkAdapter(val emptyView: View, val actionEmitter: Observer<BookmarkAction>) :
|
class BookmarkAdapter(val emptyView: View, val actionEmitter: Observer<BookmarkAction>) :
|
||||||
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
RecyclerView.Adapter<BookmarkAdapter.BookmarkNodeViewHolder>() {
|
||||||
|
|
||||||
private var tree: List<BookmarkNode> = listOf()
|
private var tree: List<BookmarkNode> = listOf()
|
||||||
private var mode: BookmarkState.Mode = BookmarkState.Mode.Normal
|
private var mode: BookmarkState.Mode = BookmarkState.Mode.Normal
|
||||||
|
@ -50,7 +50,7 @@ class BookmarkAdapter(val emptyView: View, val actionEmitter: Observer<BookmarkA
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BookmarkNodeViewHolder {
|
||||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.bookmark_row, parent, false)
|
val view = LayoutInflater.from(parent.context).inflate(R.layout.bookmark_row, parent, false)
|
||||||
|
|
||||||
return when (viewType) {
|
return when (viewType) {
|
||||||
|
@ -88,25 +88,12 @@ class BookmarkAdapter(val emptyView: View, val actionEmitter: Observer<BookmarkA
|
||||||
|
|
||||||
override fun getItemCount(): Int = tree.size
|
override fun getItemCount(): Int = tree.size
|
||||||
|
|
||||||
@SuppressWarnings("ComplexMethod")
|
override fun onBindViewHolder(holder: BookmarkNodeViewHolder, position: Int) {
|
||||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
holder.bind(
|
||||||
|
tree[position],
|
||||||
when (holder) {
|
mode,
|
||||||
is BookmarkItemViewHolder -> holder.bind(
|
tree[position] in selected
|
||||||
tree[position],
|
)
|
||||||
mode,
|
|
||||||
tree[position] in selected
|
|
||||||
)
|
|
||||||
is BookmarkFolderViewHolder -> holder.bind(
|
|
||||||
tree[position],
|
|
||||||
mode,
|
|
||||||
tree[position] in selected
|
|
||||||
)
|
|
||||||
is BookmarkSeparatorViewHolder -> holder.bind(
|
|
||||||
tree[position], mode,
|
|
||||||
tree[position] in selected
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open class BookmarkNodeViewHolder(
|
open class BookmarkNodeViewHolder(
|
||||||
|
|
|
@ -286,7 +286,6 @@ class BookmarkFragment : Fragment(), BackHandler, AccountObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ComplexMethod")
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.libraryClose -> {
|
R.id.libraryClose -> {
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.mozilla.fenix.ext.getColorIntFromAttr
|
||||||
import org.mozilla.fenix.library.bookmarks.BookmarksSharedViewModel
|
import org.mozilla.fenix.library.bookmarks.BookmarksSharedViewModel
|
||||||
|
|
||||||
class SelectBookmarkFolderAdapter(private val sharedViewModel: BookmarksSharedViewModel) :
|
class SelectBookmarkFolderAdapter(private val sharedViewModel: BookmarksSharedViewModel) :
|
||||||
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
RecyclerView.Adapter<SelectBookmarkFolderAdapter.BookmarkFolderViewHolder>() {
|
||||||
|
|
||||||
private var tree: List<BookmarkNodeWithDepth> = listOf()
|
private var tree: List<BookmarkNodeWithDepth> = listOf()
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class SelectBookmarkFolderAdapter(private val sharedViewModel: BookmarksSharedVi
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BookmarkFolderViewHolder {
|
||||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.bookmark_row, parent, false)
|
val view = LayoutInflater.from(parent.context).inflate(R.layout.bookmark_row, parent, false)
|
||||||
|
|
||||||
return when (viewType) {
|
return when (viewType) {
|
||||||
|
@ -49,27 +49,22 @@ class SelectBookmarkFolderAdapter(private val sharedViewModel: BookmarksSharedVi
|
||||||
|
|
||||||
override fun getItemCount(): Int = tree.size
|
override fun getItemCount(): Int = tree.size
|
||||||
|
|
||||||
@SuppressWarnings("ComplexMethod")
|
override fun onBindViewHolder(holder: BookmarkFolderViewHolder, position: Int) {
|
||||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
holder.bind(
|
||||||
|
tree[position],
|
||||||
when (holder) {
|
tree[position].node == sharedViewModel.selectedFolder,
|
||||||
is SelectBookmarkFolderAdapter.BookmarkFolderViewHolder -> holder.bind(
|
object : SelectionInterface {
|
||||||
tree[position],
|
override fun itemSelected(node: BookmarkNode) {
|
||||||
tree[position].node == sharedViewModel.selectedFolder,
|
sharedViewModel.apply {
|
||||||
object : SelectionInterface {
|
when (selectedFolder) {
|
||||||
override fun itemSelected(node: BookmarkNode) {
|
node -> selectedFolder = null
|
||||||
sharedViewModel.apply {
|
else -> selectedFolder = node
|
||||||
when (selectedFolder) {
|
|
||||||
node -> selectedFolder = null
|
|
||||||
else -> selectedFolder = node
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
notifyDataSetChanged()
|
|
||||||
}
|
}
|
||||||
})
|
notifyDataSetChanged()
|
||||||
else -> {
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SelectionInterface {
|
interface SelectionInterface {
|
||||||
|
|
|
@ -113,7 +113,6 @@ class HistoryFragment : Fragment(), BackHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("ComplexMethod")
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||||
R.id.share_history_multi_select -> {
|
R.id.share_history_multi_select -> {
|
||||||
val selectedHistory = (historyComponent.uiView as HistoryUIView).getSelected()
|
val selectedHistory = (historyComponent.uiView as HistoryUIView).getSelected()
|
||||||
|
@ -177,7 +176,6 @@ class HistoryFragment : Fragment(), BackHandler {
|
||||||
|
|
||||||
override fun onBackPressed(): Boolean = (historyComponent.uiView as HistoryUIView).onBackPressed()
|
override fun onBackPressed(): Boolean = (historyComponent.uiView as HistoryUIView).onBackPressed()
|
||||||
|
|
||||||
@SuppressWarnings("ComplexMethod")
|
|
||||||
private fun handleNewHistoryAction(action: HistoryAction) {
|
private fun handleNewHistoryAction(action: HistoryAction) {
|
||||||
when (action) {
|
when (action) {
|
||||||
is HistoryAction.Open ->
|
is HistoryAction.Open ->
|
||||||
|
|
|
@ -82,7 +82,7 @@ complexity:
|
||||||
ComplexMethod:
|
ComplexMethod:
|
||||||
active: true
|
active: true
|
||||||
threshold: 10
|
threshold: 10
|
||||||
ignoreSingleWhenExpression: false
|
ignoreSingleWhenExpression: true
|
||||||
LabeledExpression:
|
LabeledExpression:
|
||||||
active: false
|
active: false
|
||||||
LargeClass:
|
LargeClass:
|
||||||
|
|
Loading…
Reference in New Issue