Call directly instead of invoke when possible

pull/1274/head
mhmdanas 4 years ago committed by Alex Baker
parent 607935bda3
commit d318cf8b10

@ -27,7 +27,7 @@ class TranslationTests {
private fun forEachLocale(callback: (Resources) -> Unit) {
val locales = Locale.getAvailableLocales()
for (locale in locales) {
callback.invoke(getResourcesForLocale(locale))
callback(getResourcesForLocale(locale))
}
}

@ -6,7 +6,7 @@ import org.tasks.time.DateTimeUtils
class Freeze {
fun thawAfter(run: () -> Unit) {
try {
run.invoke()
run()
} finally {
thaw()
}

@ -7,7 +7,7 @@ class SuspendFreeze {
suspend fun thawAfter(run: suspend () -> Unit) {
try {
run.invoke()
run()
} finally {
thaw()
}

@ -97,7 +97,7 @@ class NavigationDrawerAdapter @Inject constructor(
}
}
private fun onClickFilter(filter: FilterListItem?) = onClick.invoke(if (filter == selected) null else filter)
private fun onClickFilter(filter: FilterListItem?) = onClick(if (filter == selected) null else filter)
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val item = getItem(position)

@ -72,7 +72,7 @@ class CriterionViewHolder(
}
@OnClick(R.id.row)
fun onClick() = this.onClick.invoke(criterion.id)
fun onClick() = onClick(criterion.id)
fun setMoving(moving: Boolean) {
if (moving) {

@ -30,7 +30,7 @@ class CustomFilterItemTouchHelper(
if (toPosition == 0) {
return false
}
onMove.invoke(src.adapterPosition, toPosition)
onMove(src.adapterPosition, toPosition)
return true
}
@ -60,10 +60,10 @@ class CustomFilterItemTouchHelper(
(viewHolder as CriterionViewHolder).setMoving(false)
onClear.invoke()
onClear()
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
onDelete.invoke(viewHolder.adapterPosition)
onDelete(viewHolder.adapterPosition)
}
}

@ -82,7 +82,7 @@ class Upgrader @Inject constructor(
private fun run(from: Int, version: Int, runnable: suspend () -> Unit) {
if (from < version) {
runBlocking {
runnable.invoke()
runnable()
}
preferences.setCurrentVersion(version)
}

@ -141,7 +141,7 @@ class SubtasksFilterUpdater @Inject constructor(
private suspend fun applyToDescendantsHelper(n: Node, visitor: suspend (Node) -> Unit) {
val children = n.children
for (child in children) {
visitor.invoke(child)
visitor(child)
applyToDescendantsHelper(child, visitor)
}
}

@ -105,7 +105,7 @@ class SubtasksHelper @Inject constructor(
var i = 0
while (i < children.size) {
val child = children[i]
val key = helper.invoke(child.uuid)
val key = helper(child.uuid)
val uuid = idMap[key]
if (!isValidUuid(uuid!!)) {
children.removeAt(i)

@ -107,7 +107,7 @@ class ListPicker : DialogFragment() {
.setSingleChoiceItems(filterAdapter,-1) { dialog: DialogInterface, which: Int ->
val item = filterAdapter.getItem(which)
if (item is GtasksFilter || item is CaldavFilter) {
handler.invoke(item as Filter)
handler(item as Filter)
}
dialog.dismiss()
}

@ -102,7 +102,7 @@ abstract class TaskDao(private val database: Database) {
open suspend fun fetchTasks(callback: suspend (SubtaskInfo) -> List<String>, subtasks: SubtaskInfo): List<TaskContainer> =
database.withTransaction {
val start = if (BuildConfig.DEBUG) DateUtilities.now() else 0
val queries = callback.invoke(subtasks)
val queries = callback(subtasks)
val last = queries.size - 1
for (i in 0 until last) {
query(SimpleSQLiteQuery(queries[i]))

@ -8,8 +8,8 @@ object SuspendDbUtils {
eachChunk(MAX_SQLITE_ARGS, action)
suspend fun <T> Iterable<T>.eachChunk(size: Int, action: suspend (List<T>) -> Unit) =
chunked(size).forEach { action.invoke(it) }
chunked(size).forEach { action(it) }
suspend fun <T, R> Iterable<T>.chunkedMap(transform: suspend (List<T>) -> Iterable<R>): List<R> =
dbchunk().flatMap { transform.invoke(it) }
dbchunk().flatMap { transform(it) }
}

@ -203,7 +203,7 @@ class EteSyncClient {
var journalEntries: List<JournalEntryManager.Entry>
do {
journalEntries = journalEntryManager.list(crypto, calendar.ctag, MAX_FETCH)
callback.invoke(journalEntries.map {
callback(journalEntries.map {
Pair.create(it, SyncEntry.fromJournalEntry(crypto, it))
})
} while (journalEntries.size >= MAX_FETCH)

@ -69,8 +69,8 @@ class AlphanumComparator<T>(private val getTitle: (T) -> String?) : Comparator<T
}
override fun compare(t1: T, t2: T): Int {
val s1 = getTitle.invoke(t1)
val s2 = getTitle.invoke(t2)
val s1 = getTitle(t1)
val s2 = getTitle(t2)
if (s1 == null || s2 == null) {
return 0
}

@ -186,14 +186,14 @@ class CommentBarFragment : TaskEditControlFragment() {
options.add(getString(R.string.take_a_picture))
}
if (clearImageOption != null) {
runnables.add { clearImageOption.invoke() }
runnables.add { clearImageOption() }
options.add(getString(R.string.actfm_picture_clear))
}
if (runnables.size == 1) {
runnables[0].invoke()
runnables[0]()
} else {
val listener = DialogInterface.OnClickListener { d: DialogInterface, which: Int ->
runnables[which].invoke()
runnables[which]()
d.dismiss()
}

@ -78,7 +78,7 @@ class BackupWork @WorkerInject constructor(
const val DAYS_TO_KEEP_BACKUP = 7
val BACKUP_FILE_NAME_REGEX = Regex("auto\\.[-\\d]+\\.json")
private val FILENAME_FILTER = { f: String -> f.matches(BACKUP_FILE_NAME_REGEX) }
val FILE_FILTER = FileFilter { f: File -> FILENAME_FILTER.invoke(f.name) }
val FILE_FILTER = FileFilter { f: File -> FILENAME_FILTER(f.name) }
private val BY_LAST_MODIFIED = { f1: File, f2: File ->
BackupConstants.getTimestamp(f2).compareTo(BackupConstants.getTimestamp(f1))
}
@ -89,7 +89,7 @@ class BackupWork @WorkerInject constructor(
private fun getDeleteList(fileArray: Array<DocumentFile>?) =
fileArray
?.filter { FILENAME_FILTER.invoke(it.name!!) }
?.filter { FILENAME_FILTER(it.name!!) }
?.sortedWith(DOCUMENT_FILE_COMPARATOR)
?.drop(DAYS_TO_KEEP_BACKUP)
?: emptyList()

@ -21,11 +21,11 @@ internal class Throttle constructor(
val sleep = throttle[oldest] - (currentTimeMillis() - periodMillis)
if (sleep > 0) {
Timber.v("$tag: Throttled for ${sleep}ms")
sleeper.invoke(sleep)
sleeper(sleep)
}
try {
runBlocking {
runnable.invoke()
runnable()
}
} catch (e: Exception) {
Timber.e(e)

@ -186,7 +186,7 @@ class Advanced : InjectingPreferenceFragment() {
}
private fun performAction(message: Int, callable: suspend () -> Int) = lifecycleScope.launch {
toaster.longToastUnformatted(message, callable.invoke())
toaster.longToastUnformatted(message, callable())
}
private fun resetPreferences() {

@ -12,7 +12,7 @@ class Debouncer constructor(private val tag: String, private val block: suspend
delay(1000)
if (immediate || thisCount == count) {
block.invoke(immediate)
block(immediate)
} else {
Timber.v("debouncing $tag")
}

@ -33,7 +33,7 @@ class TagPickerViewHolder internal constructor(
@OnClick(R.id.tag_row)
fun onClickRow() {
if (tagData!!.id == null) {
callback.invoke(tagData!!, this)
callback(tagData!!, this)
} else {
checkBox.toggle()
}
@ -41,7 +41,7 @@ class TagPickerViewHolder internal constructor(
@OnCheckedChanged(R.id.checkbox)
fun onCheckedChanged() {
callback.invoke(tagData!!, this)
callback(tagData!!, this)
}
fun bind(

@ -66,7 +66,7 @@ class HeaderViewHolder(
init {
header.setOnClickListener {
callback.invoke(sortGroup)
callback(sortGroup)
}
}
}

@ -18,7 +18,7 @@ open class ActionViewModel : ViewModel() {
errorObserver: (Throwable) -> Unit) {
completed.observe(lifecycleOwner) {
lifecycleOwner.lifecycleScope.launch {
completeObserver.invoke(it)
completeObserver(it)
}
}
error.observe(lifecycleOwner, errorObserver)
@ -28,7 +28,7 @@ open class ActionViewModel : ViewModel() {
if (!inProgress) {
inProgress = true
try {
action.invoke()
action()
completed.value = true
} catch (e: Exception) {
error.value = e

@ -17,7 +17,7 @@ abstract class CompletableViewModel<T> : ViewModel() {
errorObserver: (Throwable) -> Unit) {
data.observe(lifecycleOwner) {
lifecycleOwner.lifecycleScope.launch {
dataObserver.invoke(it)
dataObserver(it)
}
}
error.observe(lifecycleOwner, errorObserver)
@ -27,7 +27,7 @@ abstract class CompletableViewModel<T> : ViewModel() {
if (!inProgress) {
inProgress = true
try {
data.postValue(callable.invoke())
data.postValue(callable())
} catch (e: Exception) {
Timber.e(e)
error.postValue(e)

@ -108,7 +108,7 @@ class LocationControlSet : TaskEditControlFragment() {
dialogBuilder
.newDialog(location.displayName)
.setItems(items) { _, which: Int ->
options[which].second!!.invoke()
options[which].second!!()
}
.show()
}

Loading…
Cancel
Save