Ellen Spertus
05/04/2020, 10:50 PM// 1
override fun onCreateLoader(loaderId: Int, args: Bundle?): Loader<Cursor> {
val nickname = viewModel.nickname
return CursorLoader(
contactActivity,
ContactsContract.Contacts.CONTENT_URI,
PROJECTION,
SELECTION,
arrayOf(
nickname, // just the nickname
"$nickname %", // first name
"% $nickname", // last name
"% $nickname %" // middle name
),
null
)
}
or
// 2
override fun onCreateLoader(loaderId: Int, args: Bundle?) =
viewModel.nickname.let { nickname ->
CursorLoader(
contactActivity,
ContactsContract.Contacts.CONTENT_URI,
PROJECTION,
SELECTION,
arrayOf(
nickname, // just the nickname
"$nickname %", // first name
"% $nickname", // last name
"% $nickname %" // middle name
),
null
)
}
Mike
05/05/2020, 1:32 PMarrayOf
being hard-coded.
Even if nickname isn't a specific type, if the 'show it with all the locations' is a common operation, it would be a useful extension function, and you could use the second w/o the let
.
'show it with all locations' meaning the strings with 'nickname' and '%' in the various locations.Mike
05/05/2020, 1:33 PM1
, too. Using let
with that many lines makes it harder to see start and end of the function.
We're quite using to scanning the left for the curly-brace.Ellen Spertus
05/05/2020, 5:12 PMgildor
05/06/2020, 7:42 AM