Skip to content

Commit d1994f5

Browse files
authored
Fix some lint warnings (#355)
1 parent fb2b633 commit d1994f5

File tree

7 files changed

+47
-52
lines changed

7 files changed

+47
-52
lines changed

demo-playground/src/main/java/com/google/android/flexbox/FlexItemEditFragment.kt

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ internal class FlexItemEditFragment : DialogFragment() {
6767
super.onCreate(savedInstanceState)
6868
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
6969
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog)
70-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
71-
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Holo_Light_Dialog)
7270
} else {
7371
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Dialog)
7472
}
7573
arguments.let {
76-
flexItem = it.getParcelable<FlexItem>(FLEX_ITEM_KEY)
74+
flexItem = it.getParcelable(FLEX_ITEM_KEY)
7775
viewIndex = it.getInt(VIEW_INDEX_KEY)
7876
}
7977
flexItemInEdit = createNewFlexItem(flexItem)
@@ -241,16 +239,15 @@ internal class FlexItemEditFragment : DialogFragment() {
241239
// devices,
242240
// doing it programmatically.
243241
for (i in textViews.indices) {
244-
val index = i
245-
textViews[index].setOnEditorActionListener { v, actionId, event ->
242+
textViews[i].setOnEditorActionListener { v, actionId, event ->
246243
if (actionId == EditorInfo.IME_ACTION_NEXT ||
247244
actionId == EditorInfo.IME_ACTION_DONE ||
248245
actionId == EditorInfo.IME_NULL
249246
&& event.action == KeyEvent.ACTION_DOWN
250247
&& event.keyCode == KeyEvent.KEYCODE_ENTER) {
251-
if (index + 1 < textViews.size) {
252-
textViews[index + 1].requestFocus()
253-
} else if (index == textViews.size - 1) {
248+
if (i + 1 < textViews.size) {
249+
textViews[i + 1].requestFocus()
250+
} else if (i == textViews.size - 1) {
254251
val inputMethodManager = activity
255252
.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
256253
inputMethodManager.hideSoftInputFromWindow(v.windowToken, 0)
@@ -260,20 +257,20 @@ internal class FlexItemEditFragment : DialogFragment() {
260257
}
261258

262259
// Suppress the key focus change by KeyEvent.ACTION_UP of the enter key
263-
textViews[index].setOnKeyListener { _, keyCode, event -> keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP }
260+
textViews[i].setOnKeyListener { _, keyCode, event -> keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP }
264261
}
265262

266263
}
267264

268265
private fun alignSelfAsString(alignSelf: Int): String {
269-
when (alignSelf) {
270-
AlignSelf.AUTO -> return ALIGN_SELF_AUTO
271-
AlignItems.FLEX_START -> return ALIGN_SELF_FLEX_START
272-
AlignItems.FLEX_END -> return ALIGN_SELF_FLEX_END
273-
AlignItems.CENTER -> return ALIGN_SELF_CENTER
274-
AlignItems.BASELINE -> return ALIGN_SELF_BASELINE
275-
AlignItems.STRETCH -> return ALIGN_SELF_STRETCH
276-
else -> return ALIGN_SELF_AUTO
266+
return when (alignSelf) {
267+
AlignSelf.AUTO -> ALIGN_SELF_AUTO
268+
AlignItems.FLEX_START -> ALIGN_SELF_FLEX_START
269+
AlignItems.FLEX_END -> ALIGN_SELF_FLEX_END
270+
AlignItems.CENTER -> ALIGN_SELF_CENTER
271+
AlignItems.BASELINE -> ALIGN_SELF_BASELINE
272+
AlignItems.STRETCH -> ALIGN_SELF_STRETCH
273+
else -> ALIGN_SELF_AUTO
277274
}
278275
}
279276

@@ -297,7 +294,7 @@ internal class FlexItemEditFragment : DialogFragment() {
297294
}
298295

299296
override fun afterTextChanged(editable: Editable) {
300-
if (textInputLayout.isErrorEnabled || editable.isNullOrEmpty() ||
297+
if (textInputLayout.isErrorEnabled || editable.isEmpty() ||
301298
!inputValidator.isValidInput(editable.toString())) {
302299
return
303300
}

demo-playground/src/main/java/com/google/android/flexbox/FlexboxLayoutFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ class FlexboxLayoutFragment : Fragment() {
9090

9191
override fun onSaveInstanceState(outState: Bundle) {
9292
super.onSaveInstanceState(outState)
93-
val flexItems = (0..flexContainer.flexItemCount - 1)
93+
val flexItems = (0 until flexContainer.flexItemCount)
9494
.map { flexContainer.getFlexItemAt(it) }
95-
.mapTo(ArrayList<FlexItem>()) { it.layoutParams as FlexItem }
95+
.mapTo(ArrayList()) { it.layoutParams as FlexItem }
9696
outState.putParcelableArrayList(FLEX_ITEMS_KEY, flexItems)
9797
}
9898

demo-playground/src/main/java/com/google/android/flexbox/FragmentHelper.kt

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package com.google.android.flexbox
1818

1919
import android.content.SharedPreferences
2020
import android.support.design.widget.NavigationView
21-
import android.support.v4.view.MenuItemCompat
2221
import android.support.v7.preference.PreferenceManager
2322
import android.view.Menu
2423
import android.view.View
@@ -136,8 +135,7 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
136135
private fun initializeSpinner(currentValue: Int, menuItemId: Int, navigationMenu: Menu,
137136
arrayResourceId: Int, listener: AdapterView.OnItemSelectedListener,
138137
converter: ValueToStringConverter) {
139-
val spinner = MenuItemCompat
140-
.getActionView(navigationMenu.findItem(menuItemId)) as Spinner
138+
val spinner = navigationMenu.findItem(menuItemId).actionView as Spinner
141139
val adapter = ArrayAdapter.createFromResource(activity,
142140
arrayResourceId, R.layout.spinner_item)
143141
spinner.adapter = adapter
@@ -167,12 +165,12 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
167165
}
168166
}, object : ValueToStringConverter {
169167
override fun asString(value: Int): String {
170-
when (value) {
171-
FlexDirection.ROW -> return ROW
172-
FlexDirection.ROW_REVERSE -> return ROW_REVERSE
173-
FlexDirection.COLUMN -> return COLUMN
174-
FlexDirection.COLUMN_REVERSE -> return COLUMN_REVERSE
175-
else -> return ROW
168+
return when (value) {
169+
FlexDirection.ROW -> ROW
170+
FlexDirection.ROW_REVERSE -> ROW_REVERSE
171+
FlexDirection.COLUMN -> COLUMN
172+
FlexDirection.COLUMN_REVERSE -> COLUMN_REVERSE
173+
else -> ROW
176174
}
177175
}
178176
})
@@ -204,11 +202,11 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
204202
}
205203
}, object : ValueToStringConverter {
206204
override fun asString(value: Int): String {
207-
when (value) {
208-
FlexWrap.NOWRAP -> return NOWRAP
209-
FlexWrap.WRAP -> return WRAP
210-
FlexWrap.WRAP_REVERSE -> return WRAP_REVERSE
211-
else -> return NOWRAP
205+
return when (value) {
206+
FlexWrap.NOWRAP -> NOWRAP
207+
FlexWrap.WRAP -> WRAP
208+
FlexWrap.WRAP_REVERSE -> WRAP_REVERSE
209+
else -> NOWRAP
212210
}
213211
}
214212
})
@@ -235,13 +233,13 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
235233
}
236234
}, object : ValueToStringConverter {
237235
override fun asString(value: Int): String {
238-
when (value) {
239-
JustifyContent.FLEX_START -> return FLEX_START
240-
JustifyContent.FLEX_END -> return FLEX_END
241-
JustifyContent.CENTER -> return CENTER
242-
JustifyContent.SPACE_AROUND -> return SPACE_AROUND
243-
JustifyContent.SPACE_BETWEEN -> return SPACE_BETWEEN
244-
else -> return FLEX_START
236+
return when (value) {
237+
JustifyContent.FLEX_START -> FLEX_START
238+
JustifyContent.FLEX_END -> FLEX_END
239+
JustifyContent.CENTER -> CENTER
240+
JustifyContent.SPACE_AROUND -> SPACE_AROUND
241+
JustifyContent.SPACE_BETWEEN -> SPACE_BETWEEN
242+
else -> FLEX_START
245243
}
246244
}
247245
})
@@ -268,13 +266,13 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
268266
}
269267
}, object : ValueToStringConverter {
270268
override fun asString(value: Int): String {
271-
when (value) {
272-
AlignItems.FLEX_START -> return FLEX_START
273-
AlignItems.FLEX_END -> return FLEX_END
274-
AlignItems.CENTER -> return CENTER
275-
AlignItems.BASELINE -> return BASELINE
276-
AlignItems.STRETCH -> return STRETCH
277-
else -> return STRETCH
269+
return when (value) {
270+
AlignItems.FLEX_START -> FLEX_START
271+
AlignItems.FLEX_END -> FLEX_END
272+
AlignItems.CENTER -> CENTER
273+
AlignItems.BASELINE -> BASELINE
274+
AlignItems.STRETCH -> STRETCH
275+
else -> STRETCH
278276
}
279277
}
280278
})

demo-playground/src/main/java/com/google/android/flexbox/RecyclerViewFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ internal class RecyclerViewFragment : Fragment() {
4949
recyclerView.adapter = adapter
5050
if (savedInstanceState != null) {
5151
val layoutParams : List<FlexboxLayoutManager.LayoutParams>? = savedInstanceState
52-
.getParcelableArrayList<FlexboxLayoutManager.LayoutParams>(FLEX_ITEMS_KEY)
52+
.getParcelableArrayList(FLEX_ITEMS_KEY)
5353
layoutParams?.let {
5454
for (i in layoutParams.indices) {
5555
adapter.addItem(layoutParams[i])

demo-playground/src/main/java/com/google/android/flexbox/validators/DimensionInputValidator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DimensionInputValidator : InputValidator {
2525

2626
override fun isValidInput(charSequence: CharSequence): Boolean {
2727
// -1 represents match_parent, -2 represents wrap_content
28-
return !charSequence.isNullOrEmpty() && (TextUtils.isDigitsOnly(charSequence) ||
28+
return !charSequence.isEmpty() && (TextUtils.isDigitsOnly(charSequence) ||
2929
charSequence.toString() == "-1" ||
3030
charSequence.toString() == "-2")
3131
}

demo-playground/src/main/java/com/google/android/flexbox/validators/FixedDimensionInputValidator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ import android.text.TextUtils
2424
class FixedDimensionInputValidator : InputValidator {
2525

2626
override fun isValidInput(charSequence: CharSequence): Boolean {
27-
return !charSequence.isNullOrEmpty() && TextUtils.isDigitsOnly(charSequence)
27+
return !charSequence.isEmpty() && TextUtils.isDigitsOnly(charSequence)
2828
}
2929
}

demo-playground/src/main/java/com/google/android/flexbox/validators/FlexBasisPercentInputValidator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ class FlexBasisPercentInputValidator : InputValidator {
2525

2626
override fun isValidInput(charSequence: CharSequence): Boolean {
2727
// -1 represents not set
28-
return !charSequence.isNullOrEmpty() && (TextUtils.isDigitsOnly(charSequence) || charSequence.toString() == "-1")
28+
return !charSequence.isEmpty() && (TextUtils.isDigitsOnly(charSequence) || charSequence.toString() == "-1")
2929
}
3030
}

0 commit comments

Comments
 (0)